Пример #1
0
 /**
  * Checks to see if a record matches a condition
  * 
  * @internal
  * 
  * @param  string $operator  The record to check
  * @param  mixed  $value     The value to compare to
  * @param  mixed $result     The result of the method call(s)
  * @return boolean  If the comparison was successful
  */
 private static function checkCondition($operator, $value, $result)
 {
     $was_array = is_array($value);
     if (!$was_array) {
         $value = array($value);
     }
     foreach ($value as $i => $_value) {
         if (is_object($_value)) {
             if ($_value instanceof fActiveRecord) {
                 continue;
             }
             if (method_exists($_value, '__toString')) {
                 $value[$i] = $_value->__toString();
             }
         }
     }
     if (!$was_array) {
         $value = $value[0];
     }
     $was_array = is_array($result);
     if (!$was_array) {
         $result = array($result);
     }
     foreach ($result as $i => $_result) {
         if (is_object($_result)) {
             if ($_result instanceof fActiveRecord) {
                 continue;
             }
             if (method_exists($_result, '__toString')) {
                 $result[$i] = $_result->__toString();
             }
         }
     }
     if (!$was_array) {
         $result = $result[0];
     }
     if ($operator == '~' && !is_array($value) && is_array($result)) {
         $value = fORMDatabase::parseSearchTerms($value, TRUE);
     }
     if (in_array($operator, array('~', '&~', '!~', '^~', '$~'))) {
         settype($value, 'array');
         settype($result, 'array');
     }
     switch ($operator) {
         case '&~':
             foreach ($value as $_value) {
                 if (fUTF8::ipos($result[0], $_value) === FALSE) {
                     return FALSE;
                 }
             }
             break;
         case '~':
             // Handles fuzzy search on multiple method calls
             if (count($result) > 1) {
                 foreach ($value as $_value) {
                     $found = FALSE;
                     foreach ($result as $_result) {
                         if (fUTF8::ipos($_result, $_value) !== FALSE) {
                             $found = TRUE;
                         }
                     }
                     if (!$found) {
                         return FALSE;
                     }
                 }
                 break;
             }
             // No break exists since a ~ on a single method call acts
             // similar to the other LIKE operators
         // No break exists since a ~ on a single method call acts
         // similar to the other LIKE operators
         case '!~':
         case '^~':
         case '$~':
             if ($operator == '$~') {
                 $result_len = fUTF8::len($result[0]);
             }
             foreach ($value as $_value) {
                 $pos = fUTF8::ipos($result[0], $_value);
                 if ($operator == '^~' && $pos === 0) {
                     return TRUE;
                 } elseif ($operator == '$~' && $pos === $result_len - fUTF8::len($_value)) {
                     return TRUE;
                 } elseif ($pos !== FALSE) {
                     return $operator != '!~';
                 }
             }
             if ($operator != '!~') {
                 return FALSE;
             }
             break;
         case '=':
             if ($value instanceof fActiveRecord && $result instanceof fActiveRecord) {
                 if (get_class($value) != get_class($result) || !$value->exists() || !$result->exists() || self::hash($value) != self::hash($result)) {
                     return FALSE;
                 }
             } elseif (is_array($value) && !in_array($result, $value)) {
                 return FALSE;
             } elseif (!is_array($value) && $result != $value) {
                 return FALSE;
             }
             break;
         case '!':
             if ($value instanceof fActiveRecord && $result instanceof fActiveRecord) {
                 if (get_class($value) == get_class($result) && $value->exists() && $result->exists() && self::hash($value) == self::hash($result)) {
                     return FALSE;
                 }
             } elseif (is_array($value) && in_array($result, $value)) {
                 return FALSE;
             } elseif (!is_array($value) && $result == $value) {
                 return FALSE;
             }
             break;
         case '<':
             if ($result >= $value) {
                 return FALSE;
             }
             break;
         case '<=':
             if ($result > $value) {
                 return FALSE;
             }
             break;
         case '>':
             if ($result <= $value) {
                 return FALSE;
             }
             break;
         case '>=':
             if ($result < $value) {
                 return FALSE;
             }
             break;
     }
     return TRUE;
 }
Пример #2
0
 /**
  * Checks to see if a record matches a condition
  * 
  * @internal
  * 
  * @param  string $operator  The record to check
  * @param  mixed  $value     The value to compare to
  * @param  mixed $result     The result of the method call(s)
  * @return boolean  If the comparison was successful
  */
 private static function checkCondition($operator, $value, $result)
 {
     $was_array = is_array($value);
     if (!$was_array) {
         $value = array($value);
     }
     foreach ($value as $i => $_value) {
         if (is_object($_value)) {
             if ($_value instanceof fActiveRecord) {
                 continue;
             }
             if (method_exists($_value, '__toString')) {
                 $value[$i] = $_value->__toString();
             }
         }
     }
     if (!$was_array) {
         $value = $value[0];
     }
     $was_array = is_array($result);
     if (!$was_array) {
         $result = array($result);
     }
     foreach ($result as $i => $_result) {
         if (is_object($_result)) {
             if ($_result instanceof fActiveRecord) {
                 continue;
             }
             if (method_exists($_result, '__toString')) {
                 $result[$i] = $_result->__toString();
             }
         }
     }
     if (!$was_array) {
         $result = $result[0];
     }
     $match_all = $operator == '&~';
     $negate_like = $operator == '!~';
     switch ($operator) {
         case '&~':
         case '!~':
         case '~':
             if (!$match_all && !$negate_like && !is_array($value) && is_array($result)) {
                 $value = fORMDatabase::parseSearchTerms($value, TRUE);
             }
             settype($value, 'array');
             settype($result, 'array');
             if (count($result) > 1) {
                 foreach ($value as $_value) {
                     $found = FALSE;
                     foreach ($result as $_result) {
                         if (fUTF8::ipos($_result, $_value) !== FALSE) {
                             $found = TRUE;
                         }
                     }
                     if (!$found) {
                         return FALSE;
                     }
                 }
             } else {
                 $found = FALSE;
                 foreach ($value as $_value) {
                     if (fUTF8::ipos($result[0], $_value) !== FALSE) {
                         $found = TRUE;
                     } elseif ($match_all) {
                         return FALSE;
                     }
                 }
                 if (!$negate_like && !$found || $negate_like && $found) {
                     return FALSE;
                 }
             }
             break;
         case '=':
             if ($value instanceof fActiveRecord && $result instanceof fActiveRecord) {
                 if (get_class($value) != get_class($result) || !$value->exists() || !$result->exists() || self::hash($value) != self::hash($result)) {
                     return FALSE;
                 }
             } elseif (is_array($value) && !in_array($result, $value)) {
                 return FALSE;
             } elseif (!is_array($value) && $result != $value) {
                 return FALSE;
             }
             break;
         case '!':
             if ($value instanceof fActiveRecord && $result instanceof fActiveRecord) {
                 if (get_class($value) == get_class($result) && $value->exists() && $result->exists() && self::hash($value) == self::hash($result)) {
                     return FALSE;
                 }
             } elseif (is_array($value) && in_array($result, $value)) {
                 return FALSE;
             } elseif (!is_array($value) && $result == $value) {
                 return FALSE;
             }
             break;
         case '<':
             if ($result >= $value) {
                 return FALSE;
             }
             break;
         case '<=':
             if ($result > $value) {
                 return FALSE;
             }
             break;
         case '>':
             if ($result <= $value) {
                 return FALSE;
             }
             break;
         case '>=':
             if ($result < $value) {
                 return FALSE;
             }
             break;
     }
     return TRUE;
 }
Пример #3
0
 /**
  * Reorders an array of messages based on the requested order
  * 
  * @param  array  $messages  An array of the messages
  * @return array  The reordered messages
  */
 private function reorderMessages($messages)
 {
     if (!$this->message_order) {
         return $messages;
     }
     $ordered_items = array_fill(0, sizeof($this->message_order), array());
     $other_items = array();
     foreach ($messages as $key => $message) {
         foreach ($this->message_order as $num => $match_string) {
             if (fUTF8::ipos($message, $match_string) !== FALSE) {
                 $ordered_items[$num][$key] = $message;
                 continue 2;
             }
         }
         $other_items[$key] = $message;
     }
     $final_list = array();
     foreach ($ordered_items as $ordered_item) {
         $final_list = array_merge($final_list, $ordered_item);
     }
     return array_merge($final_list, $other_items);
 }
 /**
  * Reorders list items in an html string based on their contents
  *
  * @internal
  *
  * @param  string $class     The class to reorder messages for
  * @param  array  $messages  An array of the messages
  * @return array  The reordered messages
  */
 public static function reorderMessages($class, $messages)
 {
     if (!isset(self::$message_orders[$class])) {
         return $messages;
     }
     $matches = self::$message_orders[$class];
     $ordered_items = array_fill(0, sizeof($matches), array());
     $other_items = array();
     foreach ($messages as $key => $message) {
         foreach ($matches as $num => $match_string) {
             $string = is_array($message) ? $message['name'] : $message;
             if (fUTF8::ipos($string, $match_string) !== FALSE) {
                 $ordered_items[$num][$key] = $message;
                 continue 2;
             }
         }
         $other_items[$key] = $message;
     }
     $final_list = array();
     foreach ($ordered_items as $ordered_item) {
         $final_list = array_merge($final_list, $ordered_item);
     }
     return array_merge($final_list, $other_items);
 }