You are here

function notifications_admin_event_triggers in Notifications 7

Get assigned triggers for event

@todo Better coding, get from db?

1 call to notifications_admin_event_triggers()
notifications_admin_events_form in ./notifications.admin.inc
Event configuration administration

File

./notifications.admin.inc, line 267

Code

function notifications_admin_event_triggers($type) {
  static $action_info, $trigger_info;
  if (!isset($action_info)) {
    $action_info = module_invoke_all('action_info');
    $trigger_info = module_invoke_all('trigger_info');
  }
  $result = array();
  if ($event_triggers = notifications_event_type($type, 'triggers', array())) {
    $event_actions = notifications_event_type($type, 'actions', array());
    foreach ($event_triggers as $trigger_type => $hooks) {
      if (in_array('any', $hooks) && isset($trigger_info[$trigger_type])) {
        $hooks = array_keys($trigger_info[$trigger_type]);
      }
      foreach ($hooks as $hook) {
        foreach (trigger_get_assigned_actions($hook) as $trigger_action) {
          $aid = $trigger_action['aid'];
          if (is_numeric($aid)) {
            $aid = db_query('SELECT callback FROM {actions} WHERE aid = :aid', array(
              ':aid' => $aid,
            ))
              ->fetchField();
          }
          if ($aid && in_array($aid, $event_actions)) {
            $result[$hook] = $trigger_info[$trigger_type][$hook]['label'];
          }
        }
      }
    }
  }
  return $result;
}