Example #1
0
 private function Order($closure, $direction = self::PLINQ_ORDER_ASC)
 {
     $applicables = $this->GetApplicables($closure, 0, self::PLINQ_CLOSURE_RETURN_TYPE_OBJECT);
     $applicables->rewind();
     $sortType = self::PLINQ_ORDER_TYPE_NUMERIC;
     if (is_a($applicables->current(), 'DateTime')) {
         $sortType = self::PLINQ_ORDER_TYPE_DATETIME;
     } elseif (!is_numeric($applicables->current())) {
         $sortType = self::PLINQ_ORDER_TYPE_ALPHANUMERIC;
     }
     if ($sortType == self::PLINQ_ORDER_TYPE_DATETIME) {
         $p = new self($applicables->ToArray());
         $applicables = $p->Select(function ($k, $v) {
             return $v->getTimeStamp();
         });
         $sortType = self::PLINQ_ORDER_TYPE_NUMERIC;
     }
     $applicables = $applicables->ToArray();
     if ($direction == self::PLINQ_ORDER_ASC) {
         asort($applicables, $sortType == self::PLINQ_ORDER_TYPE_NUMERIC ? SORT_NUMERIC : SORT_LOCALE_STRING);
     } else {
         arsort($applicables, $sortType == self::PLINQ_ORDER_TYPE_NUMERIC ? SORT_NUMERIC : SORT_LOCALE_STRING);
     }
     $ordered = new self();
     foreach ($applicables as $key => $value) {
         $ordered[$key] = $this[$key];
     }
     return $ordered;
 }