You are here

function votingapi_node_properties_handler in Voting API 5

File

./votingapi_actions.inc, line 263

Code

function votingapi_node_properties_handler($op, $content = NULL, $votes = NULL, $results = NULL, $rule = NULL) {
  if ($op == 'process') {

    //  for this handler, $rule->data is a keyed array of comaprisons by node property name:
    //
    //  $rule->data = array(
    //    'status' => array('==' => 1),   // must be published
    //    'uid' => array('!=' => 1),      // not authored by the admin account
    //  );
    //
    //  The keys in the sub-array are comparison operators, and the values are the value to
    //  compare to. This is mainly useful for ensuring that a node hasn't yet been promoted
    //  before promoting it, etc. At present only == and != are supported by this handler.
    $property = $rule['data']['property'];
    $comparison = $rule['data']['comparison'];
    $value = $rule['data']['value'];
    switch ($comparison) {
      case '==':
        if (!($content->{$property} == $value)) {
          return FALSE;
        }
        break;
      case '!=':
        if (!($content->{$property} != $value)) {
          return FALSE;
        }
        break;
    }
    return TRUE;
  }
  else {
    if ($op == 'form') {
      $form['theme'] = 'votingapi_standard_handler_form';
      $form['property'] = array(
        '#type' => 'textfield',
        '#maxlength' => 10,
      );
      $form['comparison'] = array(
        '#type' => 'select',
        '#options' => array(
          '==' => 'Is',
          '!=' => 'Is not',
        ),
      );
      $form['value'] = array(
        '#type' => 'textfield',
        '#maxlength' => 10,
      );
      return $form;
    }
    else {
      if ($op == 'name') {
        return array(
          'votingapi_node_properties_handler' => 'Node properties',
        );
      }
    }
  }
}