toArray() public method

Converts the current object into an array
public toArray ( $callback = null ) : array
return array
 public function testMap()
 {
     $this->collection->map(function ($item) {
         return sprintf('%s %s', $item['first_name'], $item['last_name']);
     });
     $this->assertEquals(['john smith', 'kara trace', 'phil mcKay', 'rose smith'], $this->collection->toArray());
 }
 public function getIncompleteProductLoads($user_id)
 {
     //get user and in progress product requests / ideas
     $user = $this->eloquent->with(['ideas' => function ($query) {
         $query->where('is_fulfilled', '=', 0);
     }])->with(['productRequests' => function ($query) {
         $query->whereNull('product_id');
     }])->find($user_id);
     if (empty($user)) {
         return [];
     }
     $user = $user->toArray();
     $product_requests = $user['product_requests'];
     $ideas = $user['ideas'];
     //compile inprogress items
     $inprogress_items = new \Collection();
     foreach ($product_requests as $product_request) {
         $inprogress_items->add(['type' => 'id load', 'human_time_diff' => \Carbon::createFromFormat('Y-m-d H:i:s', $product_request['created_at'])->diffForHumans(), 'created_at' => $product_request['created_at'], 'updated_at' => $product_request['updated_at'], 'id' => $product_request['id'], 'description' => $product_request['vendor'] . ' ' . $product_request['vendor_id'], 'query' => ['vendor' => $product_request['vendor'], 'vendor_id' => $product_request['vendor_id']]]);
     }
     foreach ($ideas as $idea) {
         $inprogress_items->add(['type' => 'idea load', 'human_time_diff' => \Carbon::createFromFormat('Y-m-d H:i:s', $idea['created_at'])->diffForHumans(), 'created_at' => $idea['created_at'], 'updated_at' => $idea['updated_at'], 'id' => $idea['id'], 'description' => $idea['description'], 'query' => ['idea_description' => $idea['description']]]);
     }
     $inprogress_items->sortBy('created_at');
     return $inprogress_items->toArray();
 }
Example #3
0
 public static function fromCollection(Collection $initialData)
 {
     $tree = new self();
     foreach ($initialData->toArray() as $element) {
         $tree->insert($element);
     }
     return $tree;
 }
Example #4
0
 /**
  * Provide a lossless cachable/storable array of the configuration of the
  * ticket and it's timeline
  *
  * @return array
  */
 public function toArray()
 {
     // We want to flatten certain values for quicker searching from store
     $participants = array_map(function ($item) {
         return $item->toArray();
     }, $this->getParticipants());
     $roles = [];
     foreach ($this->getRoles() as $key => $role) {
         $roles[$key] = array_map(function ($item) {
             return $item->toArray();
         }, array_values($role));
     }
     return ['id' => $this->id, 'status' => (string) $this->getStatus(), 'channel' => (string) $this->getChannel(), 'assigned_to' => (string) $this->getAssignedTo(), 'participants' => $participants, 'roles' => $roles, 'tags' => $this->getTags(), 'timeline' => $this->timeline->toArray()];
 }
Example #5
0
 /**
  * @param array|Collection $data
  * @return $this
  */
 public function merge($data)
 {
     if ($data instanceof Collection) {
         $this->_data = array_merge($this->_data, $data->toArray());
     } else {
         $this->_data = array_merge($this->_data, array_values($data));
     }
     $this->_clearIndexes();
     return $this;
 }
Example #6
0
 /**
  * @return array
  */
 public function getAllBundles()
 {
     return array_merge($this->bundles->toArray(), $this->contributionBundles->toArray());
 }
 public function getResponses()
 {
     return $this->responses->toArray();
 }
Example #8
0
 /**
  * Adds elements from another collection
  *
  * @param Collection $col
  */
 public function merge(Collection $col)
 {
     $this->elements = array_merge($this->elements, $col->toArray());
 }
 public function getCategories()
 {
     return $this->categories->toArray();
 }
$collection->add('sixteen', 'diez y seis');
$collection->add('seventeen', 'diez y siete');
$collection->add('eighteen', 'diez y ocho');
$collection->add('ninetten', 'diez y nueve');
$collection->add('twenty', 'viente');
$collection->add('twenty one', 'viente uno');
$collection->add('twenty two', 'viente dos');
$collection->add('twenty three', 'viente tres');
$collection->add('twenty four', 'viente cuatro');
$collection->add('twenty five', 'viente cinco');
$collection->add('twenty six', 'viente seis');
$collection->add('twenty seven', 'viente siete');
$collection->add('twenty eight', 'viente ocho');
$collection->add('twenty nine', 'viente nueve');
$collection->add('thirty', 'treinte');
$datasource = new A_Pager_Array($collection->toArray());
// temporary hack until pager supports Collections
$pager = new A_Pager($datasource);
$pager->setPageSize(3);
// create a request processor to set pager from GET parameters
$request = new A_Pager_Request($pager);
$request->process();
$template = new A_Template_Include('templates/standard_pagination.tpl');
// create a HTML writer to output
#$helper = new A_Pager_HTMLWriter($pager);
// get rows of data
$start_row = $pager->getStartRow();
$end_row = $pager->getEndRow();
$rows = $datasource->getRows($start_row, $end_row);
$helper = new PagerHelper($pager, $template, 2);
?>
Example #11
0
 public function testToArray()
 {
     $this->assertCount(4, $this->collection->toArray());
 }
Example #12
0
 public function toArray()
 {
     $data = parent::toArray();
     if (isset($this->id)) {
         $data['id'] = $this->id;
     }
     return $data;
 }
 /**
  * @param Collection $elements
  * @return boolean
  */
 public function retainAll(Collection $elements)
 {
     $intersection = array_intersect($this->elements, (array) $elements->toArray());
     $newElements = array_values($intersection);
     $result = $newElements != $this->elements;
     $this->elements = $newElements;
     return $result;
 }
 /**
  * Creates new collection using data from another collection
  * 
  * @param \tjsd\collections\Collection $initialData collection providing data to be used
  * @return \self collection filled with given data
  */
 public static function fromCollection(Collection $initialData)
 {
     return new static($initialData->toArray());
 }
 /**
  * {@inheritdoc}
  */
 public function toArray()
 {
     $this->initialize();
     return $this->coll->toArray();
 }
 public function getItems()
 {
     return $this->items->toArray();
 }
 public function insertAll($index, Collection $c)
 {
     if ($index < 0 || $index > $this->size) {
         throw new IndexOutOfBoundsException("Index: {$index}, Size: {$this->size}");
     }
     $a = $c->toArray();
     $numNew = count($a);
     if ($numNew == 0) {
         return false;
     }
     $successor = $index == $this->size ? $this->header : $this->entry($index);
     $predecessor = $successor->previous;
     for ($i = 0; $i < $numNew; $i++) {
         $e = new LinkedListEntry($a[$i], $successor, $predecessor);
         $predecessor->next = $e;
         $predecessor = $e;
     }
     $successor->previous = $predecessor;
     $this->size += $numNew;
     return true;
 }
Example #18
0
 /**
  * @inheritDoc
  */
 public function getRoles()
 {
     return $this->roles->toArray();
 }
Example #19
0
 /**
  * @param Collection $items
  * @return $this
  */
 public function mergeRecursive($items)
 {
     $merged_dot = array_merge(static::dotify($this->toArray()), static::dotify($items->toArray()));
     $merged = [];
     foreach ($merged_dot as $key => $value) {
         static::set($merged, $key, $value);
     }
     foreach ($merged as $key => $value) {
         $class = get_class($this->get($key) ?: $items->get($key));
         static::set($merged, $key, new $class($value));
     }
     $result = new static($merged);
     return $result;
 }