Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
condition_logical.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/system/conditions/condition/condition.inc';
18 
31 {
32 
33 
40  function __construct($assetid=0)
41  {
42  parent::__construct($assetid);
43 
44  }//end constructor
45 
46 
56  public static function getLogicalKeywords(Array &$condition_data)
57  {
58  return $condition_data['logical_keywords'];
59 
60  }//end getLogicalKeywords()
61 
62 
72  public static function setLogicalKeywords(Array &$condition_data, Array $logical_keywords)
73  {
74  $condition_data['logical_keywords'] = $logical_keywords;
75 
76  }//end setLogicalKeywords()
77 
78 
88  public static function evaluate(Asset $asset, $condition_data)
89  {
90  $ret = FALSE;
91 
92  if (!empty($condition_data['operator']) && !empty($condition_data['logical_keywords'])) {
93  // replace global and non-global keywords
94  foreach ($condition_data['logical_keywords'] as $keyword => $value) {
95  if (preg_match('/^globals_/', $keyword)) {
96  $value = '%'.$keyword.'%';
97  replace_global_keywords($value);
98  } else {
99  $value = $asset->getKeywordReplacement($keyword);
100  }
101  $condition_data['logical_keywords'][$keyword] = $value;
102  }
103 
104  switch ($condition_data['operator']) {
105  case 'ALL':
106  $ret = TRUE;
107  foreach ($condition_data['logical_keywords'] as $logical_value) {
108  if (!$logical_value) {
109  $ret = FALSE;
110  break;
111  }
112  }
113  break;
114 
115  case 'ANY':
116  $ret = FALSE;
117  foreach ($condition_data['logical_keywords'] as $logical_value) {
118  if ($logical_value) {
119  $ret = TRUE;
120  break;
121  }
122  }
123  break;
124  }
125  }
126 
127  return $ret;
128 
129  }//end evaluate()
130 
131 
146  public static function updateKeywords(Array $logical_keywords, Array &$condition_data)
147  {
148  $condition_logical_keywords = self::getLogicalKeywords($condition_data);
149  foreach (array_keys($condition_logical_keywords) as $condition_logical_keyword_name) {
150  $condition_logical_keywords[$condition_logical_keyword_name] = isset($logical_keywords[$condition_logical_keyword_name]) ? $logical_keywords[$condition_logical_keyword_name] : '';
151  }
152 
153  self::setLogicalKeywords($condition_data, $condition_logical_keywords);
154 
155  }//end updateKeywords()
156 
157 
171  public static function getRequiredKeywords($condition_data)
172  {
173  return array_keys(self::getLogicalKeywords($condition_data));
174 
175  }//end getRequiredKeywords()
176 
177 
178 }//end class
179 
180 ?>