pull() public method

Get and remove an item from the collection.
public pull ( mixed $key, mixed $default = null ) : mixed
$key mixed
$default mixed
return mixed
 /**
  * Process the payload.
  * @param Collection $payload
  * @return Collection
  */
 public function process($payload)
 {
     $series = $payload->pull('series');
     $series->persist();
     if ($payload->has('game')) {
         $game = $payload->get('game');
         $series->relatesToGame($game);
     }
     $payload->put('series', $series->model);
     return $payload;
 }
Example #2
0
 /**
  * Получение массива перебранных данных
  *
  * @return array
  * @throws \Exception
  * @throws \Throwable
  */
 public function get()
 {
     $this->setRequest();
     $this->_hasColumns();
     $search = $this->_request->pull('search', '');
     $page = (int) $this->_request->pull('page', 1);
     $limit = (int) $this->_request->pull('count', 10);
     $sortName = $this->_request->pull('sortName', 'id');
     $orderBy = $this->_request->pull('orderBy', 'ASC');
     $filters = $this->filterScopes();
     $this->filterSearch($search);
     $this->filterOrderBy($sortName, $orderBy);
     $data = $this->pagination($page, $limit);
     /** @var \Illuminate\Support\HtmlString $pagination */
     //        $pagination = $data->links(self::NAME . '::pagination.grid-pagination');
     return ['data' => $data, 'pagination' => $this->getPaginationToArray($data), 'headers' => $this->columns->toArray(), 'createButton' => $this->getCreateButton()->render(), 'customButton' => $this->getCustomButtons(), 'page' => $page, 'orderBy' => $orderBy, 'search' => $search, 'count' => $limit, 'sortName' => $sortName, 'filter' => $filters->toArray()];
 }
Example #3
0
 /**
  * Get the results for the given query.
  *
  * @param string|array|\Spatie\SearchIndex\Query\Algolia\SearchQuery $query
  *
  * @return mixed
  */
 public function getResults($query)
 {
     $parameters = [];
     if (is_object($query) && $query instanceof SearchQuery) {
         $query = $query->toArray();
     }
     if (is_array($query)) {
         $collection = new Collection($query);
         $query = $collection->pull('query', '');
         $parameters = $collection->toArray();
     }
     return $this->index->search($query, $parameters);
 }
Example #4
0
 public function testPullReturnsDefault()
 {
     $c = new Collection([]);
     $value = $c->pull(0, 'foo');
     $this->assertEquals('foo', $value);
 }
Example #5
0
 /**
  * Generate Form Tag
  *
  * @param $attributes
  * @param Collection $attributes
  * @return string
  */
 protected function generateTag(Collection $attributes = null)
 {
     /**
      * Process Append Class
      */
     if ($appendClass = $attributes->pull('appendClass', null)) {
         $attributes->put('class', $attributes->get('class') . ' ' . $appendClass);
     }
     /**
      * Process Label
      */
     if ($label = $attributes->pull('label', null)) {
         $label = $this->makeLabel($this->trans($label));
     }
     /**
      * Process Errors
      */
     $error = $attributes->pull('error', null);
     $params = $this->collection->make();
     /**
      * Remove Element from attributes list
      * Define Attribute to be send for each kind of tag
      */
     switch ($tag = $attributes->pull('element')) {
         case 'hidden':
             $params->push([$attributes]);
             break;
         case 'select':
             $params->push([$attributes->forget('type'), $attributes->pull('collection'), $attributes->pull('placeholder'), $label]);
             break;
         case 'button':
             $params->push([$attributes, $attributes->pull('content')]);
             break;
         case 'errorMessage':
             $params->push([$attributes, $attributes->pull('errors'), $attributes->pull('title')]);
             break;
         default:
             $params->push([$attributes, $label, $error]);
             break;
     }
     /**
      * Call function with params
      */
     return call_user_func_array(array($this, 'make' . title_case($tag)), $params->collapse()->toArray());
 }
Example #6
0
 /**
  * Remove a tenant so that queries are no longer scoped by it.
  *
  * @param string|Model $tenant
  */
 public function removeTenant($tenant)
 {
     $this->tenants->pull($this->getTenantKey($tenant));
 }
 /**
  * Apply aliases to a group of columns
  */
 protected function aliasColumns(Collection $columns)
 {
     if (is_array($this->aliases) && !empty($this->aliases)) {
         foreach ($this->aliases as $csv_column => $alias_column) {
             if ($columns->contains($csv_column)) {
                 $columns->put($alias_column, $columns->get($csv_column));
                 $columns->pull($csv_column);
             }
         }
     }
     return $columns;
 }
Example #8
0
 /**
  * @return Collection
  */
 public function collection(EloquentCollection $collection)
 {
     $standings = new Collection();
     $collection->map(function ($match) use($standings) {
         $homeTeam = $standings->pull($match->homeTournamentTeam->id);
         $awayTeam = $standings->pull($match->awayTournamentTeam->id);
         $defaultTeamData = ['matches' => 0, 'position' => 0, 'wins' => 0, 'draws' => 0, 'losts' => 0, 'points' => 0, 'goalsScored' => 0, 'goalsAgainsted' => 0, 'goalsDifference' => 0];
         if (!$homeTeam) {
             $homeTeam = array_merge(['teamId' => $match->homeTournamentTeam->id, 'name' => $match->homeTournamentTeam->team->name], $defaultTeamData);
         }
         if (!$awayTeam) {
             $awayTeam = array_merge(['teamId' => $match->awayTournamentTeam->id, 'name' => $match->awayTournamentTeam->team->name], $defaultTeamData);
         }
         if (Match::STATUS_FINISHED == $match->status) {
             $homeTeam['matches']++;
             $awayTeam['matches']++;
             $homeTeam['goalsScored'] += $match->homeScore;
             $homeTeam['goalsAgainsted'] += $match->awayScore;
             $homeTeam['goalsDifference'] = $homeTeam['goalsScored'] - $homeTeam['goalsAgainsted'];
             $awayTeam['goalsScored'] += $match->awayScore;
             $awayTeam['goalsAgainsted'] += $match->homeScore;
             $awayTeam['goalsDifference'] = $awayTeam['goalsScored'] - $awayTeam['goalsAgainsted'];
             switch ($match->resultType) {
                 case Match::RESULT_TYPE_HOME_WIN:
                     $homeTeam['wins']++;
                     $homeTeam['points'] += Match::POINTS_WIN;
                     $awayTeam['losts']++;
                     break;
                 case Match::RESULT_TYPE_AWAY_WIN:
                     $awayTeam['wins']++;
                     $homeTeam['losts']++;
                     $awayTeam['points'] += Match::POINTS_WIN;
                     break;
                 case Match::RESULT_TYPE_DRAW:
                     $homeTeam['draws']++;
                     $awayTeam['draws']++;
                     $homeTeam['points'] += Match::POINTS_DRAW;
                     $awayTeam['points'] += Match::POINTS_DRAW;
                     break;
             }
         }
         $standings->put($match->homeTournamentTeam->id, $homeTeam);
         $standings->put($match->awayTournamentTeam->id, $awayTeam);
     });
     // sort by points and goal difference
     $standings = $standings->sort(function ($a, $b) {
         if ($b['points'] === $a['points']) {
             return $b['goalsDifference'] - $a['goalsDifference'];
         }
         return $b['points'] - $a['points'];
     });
     $previousRow = null;
     $position = 1;
     $standings = $standings->map(function ($row) use(&$previousRow, &$position) {
         if ($previousRow && $previousRow['points'] > 0 && $previousRow['points'] == $row['points'] && $previousRow['goalsDifference'] == $row['goalsDifference'] && $previousRow['goalsScored'] == $row['goalsScored']) {
             $row['position'] = $previousRow['position'];
         } else {
             $row['position'] = $position;
         }
         $position++;
         $previousRow = $row;
         return $row;
     });
     // alphabetical sort for teams on the same position
     $standings = $standings->sortBy(function ($team) {
         return $team['position'] . '-' . $team['name'];
     }, SORT_NUMERIC);
     return $standings;
 }