/** * @param int $currentPage * @return void */ public function indexAction($currentPage = 1) { // set current page $this->currentPage = (int) $currentPage; if ($this->currentPage < 1) { $this->currentPage = 1; } if ($this->currentPage > $this->numberOfPages) { // set $modifiedObjects to NULL if the page does not exist $modifiedObjects = null; } else { // modify query $this->itemsPerPage = (int) $this->configuration['itemsPerPage']; $query = $this->objects->getQuery(); $query->setLimit($this->itemsPerPage); $this->offset = $this->itemsPerPage * ($this->currentPage - 1); if ($this->currentPage > 1) { $query->setOffset($this->offset); } $modifiedObjects = $query->execute(); } $this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects)); $this->view->assign('configuration', $this->configuration); $this->view->assign('pagination', $this->buildPagination()); }
/** * @param string $order */ public function indexAction($order = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING) { $order = $order == \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING ? \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING : \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING; $query = $this->objects->getQuery(); $query->setOrderings(array($this->widgetConfiguration['property'] => $order)); $modifiedObjects = $query->execute(); $this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects)); $this->view->assign('order', $order); }
/** * @param string $order */ public function indexAction($char = '%') { $query = $this->objects->getQuery(); // just get objects with configured beginning char $query->matching($query->like($this->widgetConfiguration['property'], $char . '%')); $modifiedObjects = $query->execute(); $this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects)); $this->view->assign('letters', range('A', 'Z')); $this->view->assign('char', $char); }
/** * @param string $order */ public function indexAction($char = '%') { $query = $this->objects->getQuery(); // get selected objects only (title starting with specific letter) $query->matching($query->like($this->widgetConfiguration['property'], $char . '%')); $modifiedObjects = $query->execute(); $this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects)); // create an array with all letters from A to Z foreach (range('A', 'Z') as $letter) { $letters[] = $letter; } $this->view->assign('letters', $letters); $this->view->assign('char', $char); }
/** * Main action which does all the fun * * @param integer $currentPage * @return void */ public function indexAction($currentPage = 1) { // set current page $this->currentPage = (int) $currentPage; if ($this->currentPage < 1) { $this->currentPage = 1; } elseif ($this->currentPage > $this->numberOfPages) { $this->currentPage = $this->numberOfPages; } // modify query $itemsPerPage = (int) $this->configuration['itemsPerPage']; if (is_a($this->objects, '\\TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface') || is_a($this->objects, 'TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface')) { $query = $this->objects->getQuery(); // limit should only be used if needed and pagination only if results > itemsPerPage if ($itemsPerPage < $this->objects->count()) { $query->setLimit($itemsPerPage); } if ($this->currentPage > 1) { $query->setOffset((int) ($itemsPerPage * ($this->currentPage - 1))); } $modifiedObjects = $query->execute(); } else { if (empty($this->objects)) { return null; } $offset = 0; if ($this->currentPage > 1) { $offset = (int) ($itemsPerPage * ($this->currentPage - 1)); } $modifiedObjects = array_slice($this->objects, $offset, (int) $itemsPerPage); } $this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects)); $this->view->assign('configuration', $this->configuration); $this->view->assign('pagination', $this->buildPagination()); }
/** * Main action terms will be sorted * by the currentCharacter * * @param string $character * * @throws Exception * * @return void */ public function indexAction($character = '') { if (TRUE === empty($character)) { $this->query->setLimit(1)->setOrderings(array($this->field => QueryInterface::ORDER_ASCENDING)); $firstObject = $this->query->execute()->toArray(); $this->query = $this->objects->getQuery(); if (TRUE === empty($firstObject)) { $this->view->assign('noObjects', TRUE); } else { $getter = 'get' . GeneralUtility::underscoredToUpperCamelCase($this->field); if (TRUE === method_exists($firstObject[0], $getter)) { $this->currentCharacter = strtoupper(substr($firstObject[0]->{$getter}(), 0, 1)); } else { throw new Exception('Getter for "' . $this->field . '" in "' . get_class($firstObject[0]) . '" does not exist', 1433257601); } } } else { $this->currentCharacter = $character; } $this->currentCharacter = str_replace(array('AE', 'OE', 'UE'), array('Ä', 'Ö', 'Ü'), $this->currentCharacter); $objects = $this->getMatchings()->execute()->toArray(); $this->view->assign('configuration', $this->configuration); $this->view->assign('pagination', $this->buildPagination()); $this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $objects)); }
/** * Main action * * @param integer $currentPage * @return void */ public function indexAction($currentPage = 1) { // set current page $this->currentPage = (int) $currentPage; if ($this->currentPage < 1) { $this->currentPage = 1; } if ($this->currentPage > $this->numberOfPages) { // set $modifiedObjects to NULL if the page does not exist $modifiedObjects = null; } else { // modify query $itemsPerPage = (int) $this->configuration['itemsPerPage']; $query = $this->objects->getQuery(); if ($this->currentPage === $this->numberOfPages && $this->initialLimit > 0) { $difference = $this->initialLimit - (int) ($itemsPerPage * ($this->currentPage - 1)); if ($difference > 0) { $query->setLimit($difference); } else { $query->setLimit($itemsPerPage); } } else { $query->setLimit($itemsPerPage); } if ($this->currentPage > 1) { $offset = (int) ($itemsPerPage * ($this->currentPage - 1)); $offset = $offset + $this->initialOffset; $query->setOffset($offset); } elseif ($this->initialOffset > 0) { $query->setOffset($this->initialOffset); } $modifiedObjects = $query->execute(); } $this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects)); $this->view->assign('configuration', $this->configuration); $this->view->assign('pagination', $this->buildPagination()); if (!empty($this->templatePath)) { $this->view->setTemplatePathAndFilename($this->templatePath); } }
/** * Main action which does all the fun * * @param integer $currentPage * @return void */ public function indexAction($currentPage = 1) { // ugly patch to work without extbase (sry for that) $widgetIdentifier = '__widget_0'; if (tx_additionalreports_util::intFromVer(TYPO3_version) >= 6002000) { $widgetIdentifier = '@widget_0'; } if ($currentPage == 1 && !empty($_GET['tx__'][$widgetIdentifier]['currentPage'])) { $currentPage = (int) $_GET['tx__'][$widgetIdentifier]['currentPage']; } // set current page $this->currentPage = (int) $currentPage; if ($this->currentPage < 1) { $this->currentPage = 1; } elseif ($this->currentPage > $this->numberOfPages) { $this->currentPage = $this->numberOfPages; } // modify query $itemsPerPage = (int) $this->configuration['itemsPerPage']; if (is_a($this->objects, '\\TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface')) { $query = $this->objects->getQuery(); // limit should only be used if needed and pagination only if results > itemsPerPage if ($itemsPerPage < $this->objects->count()) { $query->setLimit($itemsPerPage); } if ($this->currentPage > 1) { $query->setOffset((int) ($itemsPerPage * ($this->currentPage - 1))); } $modifiedObjects = $query->execute(); } else { $offset = 0; if ($this->currentPage > 1) { $offset = (int) ($itemsPerPage * ($this->currentPage - 1)); } $modifiedObjects = array_slice($this->objects, $offset, (int) $itemsPerPage); } $this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects)); $this->view->assign('configuration', $this->configuration); $this->view->assign('pagination', $this->buildPagination()); }
/** * @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); } }
/** * Main action * * @param int $currentPage * @param array $order * @return void */ public function indexAction($currentPage = 1, $order = NULL) { // set current page $this->currentPage = (int) $currentPage; if ($this->currentPage < 1) { $this->currentPage = 1; } if ($this->currentPage > $this->numberOfPages) { // set $modifiedObjects to NULL if the page does not exist $modifiedObjects = NULL; } else { // modify query $itemsPerPage = (int) $this->configuration['itemsPerPage']; $query = $this->objects->getQuery(); if (is_array($order) && count($order)) { if (strtolower($order['dir']) == "desc") { $dir = QueryInterface::ORDER_DESCENDING; } else { $dir = QueryInterface::ORDER_ASCENDING; } $setOrderings[$order['by']] = $dir; $lookupTcaTable = $this->configuration['orderByFields'][$order['by']]['config']['model']; if ($lookupTcaTable != "" && isset($GLOBALS['TCA'][$lookupTcaTable]['columns'][$order['by']]['moox']['sortable']['additional_sorting']) && $GLOBALS['TCA'][$lookupTcaTable]['columns'][$order['by']]['moox']['sortable']['additional_sorting'] != "") { foreach (explode(",", $GLOBALS['TCA'][$lookupTcaTable]['columns'][$order['by']]['moox']['sortable']['additional_sorting']) as $additionalSorting) { $additionalSorting = explode(" ", $additionalSorting); $field = $additionalSorting[0]; $direction = $additionalSorting[1]; if (strtolower($direction) == "desc") { $setOrderings[$field] = QueryInterface::ORDER_DESCENDING; } else { $setOrderings[$field] = QueryInterface::ORDER_ASCENDING; } } } $query->setOrderings($setOrderings); $this->order = $order; } else { if (strtolower($this->order['dir']) == "desc") { $dir = QueryInterface::ORDER_DESCENDING; } else { $dir = QueryInterface::ORDER_ASCENDING; } $query->setOrderings([$this->order['by'] => $dir]); } if ($this->currentPage === $this->numberOfPages && $this->initialLimit > 0) { $difference = $this->initialLimit - (int) ($itemsPerPage * ($this->currentPage - 1)); if ($difference > 0) { $query->setLimit($difference); } else { $query->setLimit($itemsPerPage); } } else { $query->setLimit($itemsPerPage); } if ($this->currentPage > 1) { $offset = (int) ($itemsPerPage * ($this->currentPage - 1)); $offset = $offset + $this->initialOffset; $query->setOffset($offset); } elseif ($this->initialOffset > 0) { $query->setOffset($this->initialOffset); } $modifiedObjects = $query->execute(); } $this->view->assign('contentArguments', [$this->widgetConfiguration['as'] => $modifiedObjects]); $this->view->assign('configuration', $this->configuration); $this->view->assign('pagination', $this->buildPagination($this->order)); if (!empty($this->templatePath)) { $this->view->setTemplatePathAndFilename($this->templatePath); } }
/** * Like rows() but works with an existing QueryResult. * * @param QueryResultInterface $result * @param null $keyField See \CIC\Cicbase\Arr::column * @param null $valueField See \CIC\Cicbase\Arr::column * @return array * @throws \Exception */ public function rowsFromQueryResult(QueryResultInterface $result, $keyField = NULL, $valueField = NULL) { $rows = $this->persistenceManager->getObjectDataByQuery($result->getQuery()); if ($keyField !== NULL || $valueField !== NULL) { return Arr::column($rows, $valueField, $keyField); } return $rows; }