You are here

function comment_notify_add_notification in Comment Notify 8

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

Add a notification against a comment.

Parameters

int $cid: Comment Id.

int $notify: The notification type.

string $notify_hash: The comment hash.

int|null $notified: If the user has been already notified.

Return value

bool TRUE if the notification was added correctly.

3 calls to comment_notify_add_notification()
CommentNotifyNotificationsTest::testCommentTypeNotification in tests/src/Functional/CommentNotifyNotificationsTest.php
Tests the notifications are sent correctly with multiple comment types.
CommentNotifyTokenReplaceTest::testNodeTokenReplacement in tests/src/Kernel/CommentNotifyTokenReplaceTest.php
Tests the tokens generated by comment notify.
_comment_notify_submit_comment_form in ./comment_notify.module
Additional submit handler for the comment form.

File

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

Code

function comment_notify_add_notification($cid, $notify, $notify_hash, $notified) {

  // Check if comment already exist.
  $results = \Drupal::database()
    ->select('comment_notify', 'cn')
    ->fields('cn', [
    'cid',
  ])
    ->condition('cn.cid', $cid)
    ->execute()
    ->fetchField();

  // Update comment if exist.
  if ($results) {
    return (bool) \Drupal::database()
      ->update('comment_notify')
      ->fields([
      'notify' => $notify === NULL ? 0 : $notify,
      'notify_hash' => $notify_hash,
      'notified' => $notified === NULL ? 0 : $notified,
    ])
      ->condition('cid', $cid)
      ->execute();
  }
  else {
    return (bool) \Drupal::database()
      ->insert('comment_notify')
      ->fields([
      'cid' => $cid,
      'notify' => $notify === NULL ? 0 : $notify,
      'notify_hash' => $notify_hash,
      'notified' => $notified === NULL ? 0 : $notified,
    ])
      ->execute();
  }
}