Example #1
0
 /**
  * {@inheritDoc}
  */
 public function slice($offset, $length = null)
 {
     $array = [];
     foreach ($this->collection->slice($offset, $length) as $element) {
         $array[$this->getKey($element)] = $element;
     }
     return $array;
 }
Example #2
0
 public function testSlice()
 {
     $this->_coll[] = 'one';
     $this->_coll[] = 'two';
     $this->_coll[] = 'three';
     $slice = $this->_coll->slice(0, 1);
     $this->assertInternalType('array', $slice);
     $this->assertEquals(array('one'), $slice);
     $slice = $this->_coll->slice(1);
     $this->assertEquals(array(1 => 'two', 2 => 'three'), $slice);
     $slice = $this->_coll->slice(1, 1);
     $this->assertEquals(array(1 => 'two'), $slice);
 }
 /**
  * Normalizes the warnings
  *
  * @param Collection $warnings
  * @param array      $context
  *
  * @return array
  */
 protected function normalizeWarnings(Collection $warnings, array $context = [])
 {
     $result = [];
     $selectedWarnings = [];
     if (isset($context['limit_warnings']) && $context['limit_warnings'] > 0) {
         $selectedWarnings = $warnings->slice(0, $context['limit_warnings']);
     } else {
         $selectedWarnings = $warnings;
     }
     foreach ($selectedWarnings as $warning) {
         $result[] = ['label' => $this->translator->trans($warning->getName()), 'reason' => $this->translator->trans($warning->getReason(), $warning->getReasonParameters()), 'item' => $warning->getItem()];
     }
     return $result;
 }
 /**
  * Extract a slice of $length elements starting at position $offset from the Collection.
  *
  * If $length is null it returns all elements from $offset to the end of the Collection.
  * Keys have to be preserved by this method. Calling this method will only return the
  * selected slice and NOT change the elements contained in the collection slice is called on.
  *
  * @param int $offset
  * @param int $length
  * @return array
  */
 public function slice($offset, $length = null)
 {
     if (!$this->initialized && !$this->isDirty && $this->association['fetch'] == Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY) {
         return $this->em->getUnitOfWork()->getCollectionPersister($this->association)->slice($this, $offset, $length);
     }
     $this->initialize();
     return $this->coll->slice($offset, $length);
 }
 /**
  * {@inheritDoc}
  */
 public function slice($offset, $length = null)
 {
     $this->initialize();
     return $this->collection->slice($offset, $length);
 }
 /**
  * {@inheritdoc}
  */
 public function findAll($page = 1, $pageSize = null)
 {
     return array_values($this->taskExecutionCollection->slice(($page - 1) * $pageSize, $pageSize));
 }
 /**
  * {@inheritDoc}
  */
 public function getItems($offset, $itemCountPerPage)
 {
     return array_values($this->collection->slice($offset, $itemCountPerPage));
 }
 public static function extractCommentsPage(Collection $comments, $from)
 {
     return ['from' => $from, 'entities' => $comments->slice($from, AbstractCommentRepository::COMMENTS_PER_PAGE), 'total_count' => $comments->count(), 'entities_per_page' => self::COMMENTS_PER_PAGE];
 }
 public static function extractPage(Collection $collection, $from)
 {
     return ['from' => $from, 'entities' => $collection->slice($from, self::getEntitiesPerPage()), 'total_count' => $collection->count(), 'entities_per_page' => self::getEntitiesPerPage()];
 }
 /**
  * {@inheritdoc}
  */
 public function slice($offset, $length = null)
 {
     return $this->inner->slice($offset, $length);
 }
Example #11
0
 /**
  * @dataProvider provideCollection
  */
 public function testSlice(Collection $coll, array $elements)
 {
     $this->assertSame(array_slice($elements, 0, -1, true), $coll->slice(0, -1));
 }
Example #12
0
 /**
  * Get all historical scores indexed by date
  *
  * @param integer $limit
  *
  * @return array
  */
 public function getScores($limit = null)
 {
     if (null === $limit) {
         return $this->scores;
     }
     return $this->scores->slice(0, $limit);
 }
Example #13
0
 /**
  * Slices a doctrine collection from an array of filters
  * @param  Collection                $storeNewsCollection
  * @param  array                     $filters
  * @throws \InvalidArgumentException
  * @return array
  * @author Yohann Marillet
  */
 public function slice(Collection $collection, array $filters)
 {
     if (!isset($filters['offset'])) {
         throw new \InvalidArgumentException('Filter key "offset" must be specified');
     }
     if (!isset($filters['limit'])) {
         $filters['limit'] = null;
     } else {
         $filters['limit'] = (int) $filters['limit'];
     }
     $return = $collection->slice((int) $filters['offset'], $filters['limit']);
     return $return;
 }