/**
  * Finds archive dates
  *
  * @param Type $type This page type is queried for archived pages only
  *
  * @return Date[]
  */
 public function findByPageType(Type $type)
 {
     $query = $this->createQuery();
     $sql = "\n            SELECT\n                FROM_UNIXTIME(lastUpdated) as archive_date\n            FROM\n                pages\n            WHERE\n                doktype = ?\n                AND deleted = 0\n                AND hidden = 0\n            GROUP BY\n                DATE_FORMAT(FROM_UNIXTIME(lastUpdated), '%Y-%m')\n            ORDER BY\n                archive_date DESC\n        ";
     $query->statement($this->objectManager->get(PreparedStatement::class, $sql, 'pages'), [$type->getValue()]);
     $rawResults = $query->execute(true);
     return $this->hydrate($rawResults);
 }
Beispiel #2
0
 /**
  * CriteriaContainPageTypeAndDateRangeValues
  *
  * @return void
  */
 public function testCriteriaContainPageTypeAndDateRangeValues()
 {
     $this->pageTypeMock->expects($this->once())->method('getValue')->will($this->returnValue('blog'));
     $startDate = new \DateTime('01.04.2015');
     $this->dateRangeMock->expects($this->once())->method('getStartDate')->will($this->returnValue($startDate));
     $endDate = new \DateTime('30.04.2015');
     $this->dateRangeMock->expects($this->once())->method('getEndDate')->will($this->returnValue($endDate));
     $criteria = $this->sut->getCriteria();
     $this->assertSame(['blog', $startDate->getTimestamp(), $endDate->getTimestamp()], $criteria);
 }
 /**
  * Performs archive search
  *
  * @param string $month Month, numeric 1-12
  * @param int $year Year, numeric yyyy
  *
  * @ignorevalidation $month
  * @ignorevalidation $year
  *
  * @return void
  */
 public function showAction($month, $year)
 {
     $this->search->setDateRange(DateRange::fromMonthAndYear($month, $year));
     $this->search->setPageType(Type::fromString($this->settings['pageType']));
     $pages = $this->pageRepository->findArchived($this->search);
     $this->view->assign('pages', $pages);
     $this->view->assign('search', $this->search);
 }
 /**
  * Returns the available/allowed doktypes
  *
  * @return array
  */
 public function getPageTypes()
 {
     $pageTypes = isset($this->settings['doktypes']) ? $this->settings['doktypes'] : [1];
     foreach ($pageTypes as $pageType) {
         $this->pageTypes->add(Type::fromString($pageType));
     }
     return $this->pageTypes;
 }
 /**
  * Lists last updated pages
  *
  * @return void
  */
 public function listAction()
 {
     $pageType = Type::fromString($this->settings['pageType']);
     $offset = (int) $this->settings['offset'];
     $limit = (int) $this->settings['limit'];
     $pages = $this->pageRepository->findLastUpdated($pageType, $offset - 1, $limit);
     $this->view->assign('pages', $pages);
 }
 /**
  * Archive listing
  *
  * @return void
  */
 public function showAction()
 {
     $dates = $this->dateRepository->findByPageType(Type::fromString($this->settings['pageType']));
     $this->view->assign('dates', $dates);
 }
Beispiel #7
0
 /**
  * Returns the persistence layer query criteria
  *
  * @return array
  */
 public function getCriteria()
 {
     return [$this->pageType->getValue(), $this->dateRange->getStartDate()->getTimestamp(), $this->dateRange->getEndDate()->getTimestamp()];
 }
 /**
  * Returns the page type label reference for the configured page type.
  *
  * @param Type $pageType Set page type
  *
  * @return string
  */
 private function getPageTypeLabelReference(Type $pageType)
 {
     $registeredTypes = ArrayUtility::getValueByPath($GLOBALS, 'TCA/pages/columns/doktype/config/items');
     $typeConfigurations = array_filter($registeredTypes, function ($configuration) use($pageType) {
         return (int) $configuration[1] === $pageType->getValue();
     });
     $typeConfiguration = array_shift($typeConfigurations);
     return array_shift($typeConfiguration);
 }
 /**
  * Finds last updated pages of type $pageType
  *
  * @param Type $type Page type to query
  * @param int $offset Start here
  * @param int $limit Limit to this
  *
  * @return Page[]
  */
 public function findLastUpdated(Type $type, $offset = 0, $limit = 1)
 {
     $query = $this->createQuery();
     $sql = '
         SELECT
             *,
             FROM_UNIXTIME(crdate) as created_at,
             FROM_UNIXTIME(lastUpdated) as last_updated_at
         FROM
             pages
         WHERE
             doktype = ?
             AND deleted = 0
             AND hidden = 0
         ORDER BY
             lastUpdated DESC
         LIMIT ' . $offset . ', ' . $limit . '
     ';
     $query->statement($this->objectManager->get(PreparedStatement::class, $sql, 'pages'), [$type->getValue()]);
     $rawResults = $query->execute(true);
     return $this->hydrate($rawResults);
 }