You are here

function privatemsg_rules_thread_has_tag in Privatemsg 7.2

Same name and namespace in other branches
  1. 6.2 privatemsg_rules/privatemsg_rules.rules.inc \privatemsg_rules_thread_has_tag()
  2. 7 privatemsg_rules/privatemsg_rules.rules.inc \privatemsg_rules_thread_has_tag()

Check if a thread has a specific tag.

Parameters

$thread_id: Which thread to check.

$account: Which user should be checked.

$tag_settings: Rules settings, includes the tag that should be checked.

Return value

TRUE if the thread has such a tag, FALSe otherwise.

File

privatemsg_rules/privatemsg_rules.rules.inc, line 350
Hooks and callback functions for rules.module integration.

Code

function privatemsg_rules_thread_has_tag($thread_id, $account, $tag_string, $check_all = FALSE) {
  $tags = explode(',', $tag_string);
  $tag_ids = privatemsg_filter_create_tags($tags);
  if (empty($tag_ids)) {
    rules_log('No valid tag could be loaded or created.', array(), RulesLog::ERROR);
    return;
  }
  $query = _privatemsg_assemble_query(array(
    'tags',
    'privatemsg_filter',
  ), $account, array(
    $thread_id,
  ));
  $tag_ids_on_thread = $query
    ->execute()
    ->fetchCol();
  if ($check_all) {

    // If check_all is set, only return TRUE if all tags exist.
    if (count(array_diff($tag_ids, $tag_ids_on_thread)) == 0) {
      return TRUE;
    }
  }
  else {

    // If not, then it is enough it at least one of the submitted tags is used
    // on the thread.
    if (count(array_diff($tag_ids, $tag_ids_on_thread)) < count($tag_ids)) {
      return TRUE;
    }
  }
  return FALSE;
}