Ejemplo n.º 1
0
 /**
  * Returns paged content.
  */
 private function getPagedContentData(SmartContentContainer $container, $page, $pageSize, $excludeUuid)
 {
     $config = $container->getConfig();
     $limitResult = isset($config['limitResult']) && !empty($config['limitResult']) ? intval($config['limitResult']) : null;
     $limit = intval($pageSize);
     $offset = ($page - 1) * $limit;
     $position = $limit * $page;
     if ($limitResult !== null && $position >= $limitResult) {
         $limit = $limitResult - $offset;
         $loadLimit = $limit;
     } else {
         $loadLimit = $limit + 1;
     }
     if ($limit < 0) {
         $container->setHasNextPage(false);
         return [];
     }
     $data = $container->getData([$excludeUuid], $loadLimit, $offset);
     if (sizeof($data) > $limit) {
         $container->setHasNextPage(true);
         $data = array_splice($data, 0, $limit);
     } else {
         $container->setHasNextPage(false);
     }
     return $data;
 }
Ejemplo n.º 2
0
 public function testReadPreview()
 {
     $smartContentContainerPreview = new SmartContentContainer($this->contentQuery, $this->contentQueryBuilder, $this->tagManager, ['page_parameter' => 'p', 'properties' => []], 'test', 'en', 's');
     $smartContentContainerPreview->setConfig(['tags' => ['Tag1', 'Tag2'], 'limitResult' => '2']);
     $node = $this->getMockForAbstractClass('Sulu\\Bundle\\ContentBundle\\Tests\\Unit\\Content\\Types\\NodeInterface', [], '', true, true, true, ['getPropertyValueWithDefault']);
     $property = $this->getMockForAbstractClass('Sulu\\Component\\Content\\Compat\\PropertyInterface', [], '', true, true, true, ['setValue']);
     $node->expects($this->any())->method('getPropertyValueWithDefault')->will($this->returnValueMap([['property', '{}', '{"tags":[1,2],"limitResult":"2"}']]));
     $property->expects($this->any())->method('getName')->will($this->returnValue('property'));
     $property->expects($this->any())->method('getParams')->will($this->returnValue([]));
     $property->expects($this->exactly(1))->method('setValue')->with($smartContentContainerPreview->getConfig());
     $this->smartContent->readForPreview(['tags' => ['Tag1', 'Tag2'], 'limitResult' => 2], $property, 'test', 'en', 's');
 }