Esempio n. 1
0
 /**
  * @param string $family
  * @param array $options
  */
 public function __construct($family, $options = [])
 {
     $this->_family = $family;
     $this->_sizes = isset($options[self::OPTION_SIZES]) && is_array($options[self::OPTION_SIZES]) && !QuarkObject::isAssociative($options[self::OPTION_SIZES]) ? $options[self::OPTION_SIZES] : $this->_sizes;
     $this->_subsets = isset($options[self::OPTION_SUBSETS]) && is_array($options[self::OPTION_SUBSETS]) && !QuarkObject::isAssociative($options[self::OPTION_SUBSETS]) ? $options[self::OPTION_SUBSETS] : $this->_subsets;
 }
Esempio n. 2
0
 /**
  * @param IQuarkModel $model
  * @param             $criteria
  * @param array $options
  *
  * @return array
  */
 public function Find(IQuarkModel $model, $criteria, $options = [])
 {
     $buffer = self::_find($criteria, $options);
     if (isset($options[QuarkModel::OPTION_SORT]) && QuarkObject::isAssociative($options[QuarkModel::OPTION_SORT])) {
         $sort = $options[QuarkModel::OPTION_SORT];
         foreach ($sort as $key => $rule) {
             usort($buffer, function ($a, $b) use($key) {
                 if (!isset($a[$key]) || !isset($b[$key])) {
                     return 0;
                 }
                 if (is_bool($a[$key]) || is_bool($b[$key])) {
                     return self::_cmp($a[$key], $b[$key]);
                 }
                 if (is_string($a[$key]) || is_string($b[$key])) {
                     return strnatcmp($a[$key], $b[$key]);
                 }
                 return 0;
             });
             if ($rule == -1) {
                 $buffer = array_reverse($buffer);
             }
         }
     }
     return $buffer;
 }