Exemple #1
0
 /**
  * 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 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());
 }
 /**
  * Get center from query result based on center of all coordinates. If only one
  * is found this is used. In case none was found the center based on the request
  * gets calculated
  *
  * @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $queryResult
  *
  * @return Model\Location
  */
 protected function getCenterOfQueryResult($queryResult)
 {
     if ($queryResult->count() == 1) {
         return $queryResult->getFirst();
     } elseif (!$queryResult->count()) {
         return $this->getCenter();
     }
     /** @var Model\Location $center */
     $center = $this->objectManager->get('Evoweb\\StoreFinder\\Domain\\Model\\Location');
     $x = $y = $z = 0;
     /** @var Model\Location $location */
     foreach ($queryResult as $location) {
         $x += cos($location->getLatitude()) * cos($location->getLongitude());
         $y += cos($location->getLatitude()) * sin($location->getLongitude());
         $z += sin($location->getLatitude());
     }
     $x /= $queryResult->count();
     $y /= $queryResult->count();
     $z /= $queryResult->count();
     $center->setLongitude(atan2($y, $x));
     $center->setLatitude(atan2($z, sqrt($x * $x + $y * $y)));
     return $center;
 }