示例#1
0
 /**
  * @param int $itemsPerPage
  * @param int $offset
  *
  * @return array|QueryResultInterface
  * @throws \InvalidArgumentException
  */
 protected function prepareObjectsSlice($itemsPerPage, $offset)
 {
     if ($this->objects instanceof QueryResultInterface) {
         $query = $this->objects->getQuery();
         $query->setLimit($itemsPerPage);
         if ($offset > 0) {
             $query->setOffset($offset);
         }
         $modifiedObjects = $query->execute();
         return $modifiedObjects;
     } elseif ($this->objects instanceof ObjectStorage) {
         $modifiedObjects = array();
         $endOfRange = $offset + $itemsPerPage;
         for ($i = $offset; $i < $endOfRange; $i++) {
             $modifiedObjects[] = $this->objects->toArray()[$i];
         }
         return $modifiedObjects;
     } elseif (is_array($this->objects)) {
         $modifiedObjects = array_slice($this->objects, $offset, $itemsPerPage);
         return $modifiedObjects;
     } else {
         throw new \InvalidArgumentException('The view helper "' . get_class($this) . '" accepts as argument "QueryResultInterface", "\\SplObjectStorage", "ObjectStorage" or an array. ' . 'given: ' . get_class($this->objects), 1385547291);
     }
 }
 /**
  * Sort entities by the localized name
  *
  * @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $entities to be sorted
  * @param string $orderDirection may be "asc" or "desc". Default is "asc".
  * @return array entities ordered by localized name
  */
 public function localizedSort(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface $entities, $orderDirection = 'asc')
 {
     $result = $entities->toArray();
     $locale = \SJBR\StaticInfoTables\Utility\LocalizationUtility::setCollatingLocale();
     if ($locale !== FALSE) {
         if ($orderDirection === 'asc') {
             uasort($result, array($this, 'strcollOnLocalizedName'));
         } else {
             uasort($result, array($this, 'strcollOnLocalizedNameDesc'));
         }
     }
     return $result;
 }