You are here

function subscriptions_content_subscriptions in Subscriptions 2.0.x

Same name and namespace in other branches
  1. 5.2 subscriptions_content.module \subscriptions_content_subscriptions()
  2. 6 subscriptions_content.module \subscriptions_content_subscriptions()
  3. 7 subscriptions_content.module \subscriptions_content_subscriptions()

Implements hook_subscriptions().

Parameters

string $op:

mixed|null $arg0:

mixed|null $arg1:

mixed|null $arg2:

Return value

array|string|null

File

subscriptions_content/subscriptions_content.module, line 27
Subscriptions to content events.

Code

function subscriptions_content_subscriptions($op, $arg0 = NULL, $arg1 = NULL, $arg2 = NULL) {
  static $stypes = [
    'node' => [
      'node',
      'nid',
    ],
    'type' => [
      'node',
      'type',
    ],
  ];
  $function = '_subscriptions_content_' . $op;
  if (function_exists($function)) {
    return $function($arg0, $arg1, $arg2);
  }
  switch ($op) {
    case 'queue':

      // $arg0 is $event array.
      if ($arg0['module'] == 'node') {
        $node = $arg0['node'];
        $params['node']['nid']['value'] = $node->nid;
        $params['node']['type']['value'] = $node->type;
        if ($arg0['type'] == 'comment') {
          $where[] = [
            's.send_comments',
            1,
            '=',
          ];
        }
        elseif ($arg0['type'] == 'node' && $arg0['action'] == 'update') {
          $where[] = [
            's.send_updates',
            1,
            '=',
          ];
        }
        if (isset($where)) {
          $params['node']['nid']['where'] = $where;
          $params['node']['type']['where'] = $where;
        }
        return $params;
      }
      break;

    // Parameter is module.
    case 'fields':
      if ($arg0 == 'node' || $arg0 == 'comment') {
        return [
          'nid' => [
            'data_function' => 'subscriptions_content_data',
            'subs_mod' => 'subscriptions_content',
            'subs_type' => t('thread'),
            'mailkey' => 'node-type-',
          ],
          'type' => [
            'data_function' => 'subscriptions_content_data',
            'subs_mod' => 'subscriptions_content',
            'subs_type' => t('content type'),
            'mailkey' => 'node-type-',
          ],
        ];
      }
      break;
    case 'stypes':
      return $stypes;
    case 'stype':
      return isset($stypes[$arg0]) ? array_merge($stypes[$arg0], [
        $arg1,
        $arg2,
      ]) : NULL;
    case 'mailkeys':
      $mailkeys = [];
      foreach (node_type_get_types() as $key => $type) {
        $mailkeys['node-type-' . $key] = t('Notifications for %type !content_type subscriptions', [
          '%type' => $type->name,
          '!content_type' => t('content type'),
        ]);
      }
      return $mailkeys;
    case 'mailkey_alter':
      if ($arg0 == 'node-type-') {
        return $arg0 . $arg1->type;
      }
      break;
    case 'token_types':
      if (strpos($arg0, 'node-type-') === 0) {
        return [
          'node',
          'comment',
        ];
      }
      break;
  }
  return NULL;
}