You are here

function comment_notify_get_watchers in Comment Notify 8

Same name and namespace in other branches
  1. 7 comment_notify.inc \comment_notify_get_watchers()

Get a list of mails which need to be contacted for an entity.

Parameters

int $entity_id: The entity id.

string $comment_type: The comment type.

Return value

\Drupal\comment\CommentInterface[] A list of comment entities.

1 call to comment_notify_get_watchers()
_comment_notify_mailalert in ./comment_notify.module
Private function to send the notifications.

File

./comment_notify.inc, line 121
Contains functions which utilize the database and other internal helpers.

Code

function comment_notify_get_watchers($entity_id, $comment_type) {
  $cids = \Drupal::database()
    ->query("SELECT c.cid FROM {comment_field_data} c INNER JOIN {comment_notify} cn ON c.cid = cn.cid LEFT JOIN {users_field_data} u ON c.uid = u.uid WHERE c.entity_id = :entity_id AND c.comment_type = :comment_type AND c.status = :status AND cn.notify <> :notify AND (u.uid = 0 OR u.status = 1)", [
    ':entity_id' => $entity_id,
    ':comment_type' => $comment_type,
    ':status' => CommentInterface::PUBLISHED,
    ':notify' => COMMENT_NOTIFY_DISABLED,
  ])
    ->fetchCol();
  return \Drupal::entityTypeManager()
    ->getStorage('comment')
    ->loadMultiple($cids);
}