Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
form_question_rule_type_selection.inc
1 <?php
18 require_once dirname(__FILE__).'/../../form_question_rule/form_question_rule.inc';
19 
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
54  public static function isValidationRule()
55  {
56  return false;
57 
58  }//end isValidationRule()
59 
60 
68  public static function getOperators()
69  {
70  $operators = Array(
71  1 => translate('core_form_rule_selection_true'),
72  0 => translate('core_form_rule_selection_false'),
73  );
74 
75  return $operators;
76 
77  }//end getOperators()
78 
79 
92  function generateJSCode(&$q_asset, $rule_data)
93  {
94  // this isn't used as a validation rule, so no JS code is required
95  return '';
96 
97  }//end generateJSCode()
98 
99 
113  function evaluate($answer, $rule_data)
114  {
115  $operator = array_get_index($rule_data, 'operator', 1);
116  $value = array_get_index($rule_data, 'value', '');
117 
118  if (!is_array($answer)) { // not an array, could be selection type
119  $answer = Array($answer);
120  } else if (count($answer) == 0) { // no selections made at all
121  $answer = Array();
122  }
123 
124  $valid = (array_search($value, $answer) !== false);
125 
126  return ($valid == $operator);
127 
128  }//end evaluate()
129 
130 
140  function ruleDescription(&$q_asset, $rule_data)
141  {
142  $operator = array_get_index($rule_data, 'operator', 1);
143  $value = array_get_index($rule_data, 'value', '');
144 
145  return translate('core_form_rule_selection_desc_'.($operator ? 'true' : 'false'), $q_asset->getSummary($value), $q_asset->attr('name'));
146 
147  }//end ruleDescription()
148 
149 
150 }//end class
151 ?>