/** * Ce controller à pour but de gérer la logique de recherche d'un film dans la base de données * Le controller gère aussi les topics lorsque l'utilisateur fait une recherche via les checkboxes sur * la page de d'affichage des résultats. * Les fonctions paginate servent à créer le paginator qui est simplement l'affichage des films 20 par 20. * * * @return \Illuminate\Http\Response */ public function index() { $search = Input::get('search'); $topics = Input::except('search', 'page'); if (empty($topics)) { // Pas de topics on renvoie simplement les films correspondants $allMovies = Movies::where('title', 'like', "%{$search}%")->paginate(20)->appends(Input::except('page')); } else { // SI on a des topics dans l'input il est nécessaire de filtrer $movies = Topics::whereIn('topic_name', $topics)->with('movies')->get(); $moviesCollection = Collection::make(); foreach ($movies as $movy) { $moviesCollection->add($movy->movies()->where('title', 'like', "%{$search}%")->get()); } $moviesCollection = $moviesCollection->collapse(); // Il n'est pas possible de créer la paginator directement, on le crée donc à la main $page = Input::get('page', 1); $perPage = 20; $offset = $page * $perPage - $perPage; $allMovies = new LengthAwarePaginator($moviesCollection->slice($offset, $perPage, true), $moviesCollection->count(), $perPage); $allMovies->setPath(Paginator::resolveCurrentPath()); $allMovies->appends(Input::except('page')); } // A la vue correspondante on lui renvoie une liste des films correspondants à la recherche, le tout paginé return view('search', compact('allMovies')); }
/** * Serialize all toManys to keys * * @param ArrayableInterface $instance * @return $instance */ public function serializeKeys(ArrayableInterface $instance) { $is_collection = True; $result = new Collection(); if (!$this->isCollection($instance)) { $is_collection = False; $collection = new Collection(); $instance = $collection->add($instance); } $instance->transform(function ($item) { $side_loads = $item->getSideLoads(); foreach ($side_loads as $load) { $relation = $item->{$load}; $item->__unset($load); if (!$this->isEmptyOrNull($relation)) { if ($relation instanceof Collection) { // If is a collection then the result is a list of // id. e.g: [1, 2, 3] $item->setRelation($load, Collection::make($relation->unique()->modelKeys())); } else { // otherwise the result is an id. e.g: 2 $item->setAttribute($load, $relation->getKey()); } } } return $item; }); if (!$is_collection) { return $instance->pop(); } return $instance; }
/** * Return a Collection of countries with the name given. * @param String $name Country name * @return Collection Collection of countries. */ public function findByName($name) { if (!is_string($name)) { return Collection::make([]); } return $this->where('name', $name)->get(); }
/** @test */ function it_creates_a_form_with_fields() { $builder = $this->getBuilder(); $this->assertFileNotExists($builder->getClassFilePath('project')); $builder->build('project', Collection::make([NodeField::create(['name' => 'description', 'type' => 'text', 'description' => 'Some hints', 'label' => 'Project Description', 'rules' => '\'required|max:5000\'', 'default_value' => '\'Texty text\'', 'position' => 1, 'search_priority' => 10]), NodeField::create(['name' => 'type', 'type' => 'select', 'description' => 'Some hints for type', 'label' => 'Project Type', 'position' => 2, 'options' => "'choices' => [1 => 'Housing', 2 => 'Cultural'], 'selected' => function(\$data) {return 1;}, 'empty_value' => '---no type---'", 'search_priority' => 0])])); $this->assertFileExists($builder->getClassFilePath('project')); }
/** * Get Table Filter * * @author WN * @return Collection */ protected function getFilters() { if (!$this->filters) { $this->filters = Collection::make(Request::capture()->except(['limit', 'page', 'download'])); } return $this->filters; }
/** * Find news by category identifier * * @param $slug * @param int $page * @return Collection */ public function findByCategory($slug, $page = 1) { if ($category = $this->fetchCategory($slug)) { return $category->news()->with('categories')->take($this->perPage)->forPage($page)->orderBy('created_at', 'desc')->get(); } return Collection::make([]); }
/** * Create a new command instance. * * @return void */ public function __construct() { $this->country = App::make('Filmoteca\\Models\\Exhibitions\\Country'); $this->film = App::make('Filmoteca\\Models\\Exhibitions\\Film'); $this->genre = App::make('Filmoteca\\Models\\Exhibitions\\Genre'); $this->newGenres = Collection::make([]); parent::__construct(); }
/** * Return an array of permissions through roles * * @return Collection **/ public function permissions() { $permissions = []; foreach ($this->roles as $role) { $permissions = array_merge($permissions, $role->perms->toArray()); } return Collection::make($permissions); }
/** * Display a listing of the resource. * @param \App\Criteria $criteria * @return \Illuminate\Http\Response */ public function index(Criteria $criteria) { $criteria->load(['options', 'options.langs', 'langs']); $options = $criteria->options()->sort()->get(); $criteria = $this->loadLangs(Collection::make([$criteria]))->first(); $options = $this->loadLangs($options); return view('admin.criteria.option.index', ['title' => $criteria->dbLangs->get(dbTrans())->title . ' ' . trans('static.options'), 'url' => action('Admin\\CriteriaOptionController@create', [$criteria->id]), 'back' => action('Admin\\CriteriaController@index'), 'options' => $options, 'criteria' => $criteria]); }
protected function makeCollection(ResultSet $resultSet) { $models = []; foreach ($resultSet as $row) { $params = array_merge($row['friends']->getProperties(), ['id' => $row['friends']->getId()]); $models[] = $this->model->newFromBuilder($params); } return Collection::make($models); }
public function getTimesAttribute() { $result = \Illuminate\Database\Eloquent\Collection::make(); foreach ($this->tickets as $ticket) { foreach ($ticket->times as $time) { $result->push($time); } } return $result; }
public function getSpeakersAttribute() { if (!$this->speakers) { foreach ($this->speakers_pivot()->get() as $pivot) { /** @var EventSpeaker $pivot */ $this->speakers[] = $pivot->user; } $this->speakers = Collection::make($this->speakers); } return $this->speakers; }
/** * Returns all products contained in the orders associated with a freeproduct * @return freeproducts collection of all the products contained in the orders associated with freeproduct, but defined as a property of the model */ public static function getWithProducts(Collection $items) { $freeproducts = $items->each(function ($item, $key) { $list_products_orders = Collection::make(); foreach ($item->orders as $order) { $list_products_orders = $list_products_orders->merge($order->products); } $item->products = $list_products_orders; }); return $freeproducts; }
public function test_map_correctly_maps_results_to_models() { $client = Mockery::mock('Elasticsearch\\Client'); $engine = new ElasticsearchEngine($client, 'scout'); $model = Mockery::mock('Illuminate\\Database\\Eloquent\\Model'); $model->shouldReceive('getKeyName')->andReturn('id'); $model->shouldReceive('whereIn')->once()->with('id', ['1'])->andReturn($model); $model->shouldReceive('get')->once()->andReturn(Collection::make([new ElasticsearchEngineTestModel()])); $results = $engine->map(['hits' => ['total' => '1', 'hits' => [['_id' => '1']]]], $model); $this->assertEquals(1, count($results)); }
public function deleteDestroy() { $modelArray = array(); $deleteModels = Input::json('models'); foreach ($deleteModels as $model) { $deleteComputerClassroom = ComputerClassroom::find($model['id']); $deleteComputerClassroom->delete(); array_push($modelArray, $deleteComputerClassroom); $returnModels = BaseCollection::make($modelArray); } echo $returnModels->toJson(); }
/** * Set up the tests object */ public function setUp() { parent::setUp(); $token = new Token(); foreach ($this->tokenConsts as $scope) { $this->tokensCollection[$scope] = Collection::make(); for ($i = 0; $i <= 4; $i++) { $item = $token->newInstance(['token_name' => 'val_' . ($i + 1), 'token_value' => "val-{$scope}-" . ($i + 1), 'token_scope' => $scope]); $this->tokensCollection[$scope]->add($item); } } }
public function deleteDestroy() { $modelArray = array(); $deleteModels = Input::json('models'); foreach ($deleteModels as $model) { $deleteAdminSchedule = AdminSchedule::find($model['id']); $deleteAdminSchedule->delete(); array_push($modelArray, $deleteAdminSchedule); $returnModels = BaseCollection::make($modelArray); } echo $returnModels->toJson(); }
public static function search($query) { if (empty($query)) { return Collection::make(); } return Employee::where('first_name', 'like', '%' . $query . '%')->orWhere('last_name', 'like', '%' . $query . '%')->orderBy('first_name', 'asc')->orderBy('last_name', 'asc')->take(5)->get(array('id', 'first_name', 'last_name'))->map(function ($employee) { $employee->label = $employee->first_name . ' ' . $employee->last_name; $employee->type = 'employee'; $employee->url = route('employees.show', $employee->id); return $employee; }); }
/** * Execute current query and return list of models. * * @return \Illuminate\Database\Eloquent\Collection */ public function get() { $models = $this->runner->getCachedModels($this->query); if (null === $models) { $models = $this->runner->models($this->query); $this->runner->setCachedModels($this->query, $models); $this->runner->setCachedTotal($this->query, $models->count()); } if ($this->limit) { $models = $models->slice($this->offset, $this->limit); } return Collection::make($models->reload()->all()); }
/** * Get all user's group permissions. * * @return Collection */ public function groupPermissions() { $permissions = []; $groups = $this->groups; foreach ($groups as $group) { $groupPermissions = Cache::rememberForever('groups.permissions', function () use($group) { return $group->permissions; }); foreach ($groupPermissions as $permission) { $permissions[$permission->id] = $permission; } } return Collection::make($permissions); }
private function getSmoothnessLabels() { $labels = array_get($this->smoothness, 'labels', []); foreach ($labels as $key => $label) { if (starts_with($label, 'label::')) { $method = camel_case(str_replace('::', '_', $label)); if (method_exists($this, $method)) { $labels[$key] = $this->{$method}(); } else { throw new \Exception('Method ' . $method . '() Not Found.'); } } } return Collection::make($labels); }
/** * Set components state based on parameters * * @throws ModelNotFoundException */ public function setState() { $showSlugFilter = $this->property('showSlugFilter'); if (!empty($showSlugFilter)) { $this->show = Show::query()->where('slug', $showSlugFilter)->firstOrFail(); $this->episode = $this->show->episodes()->getQuery()->where('published', true)->orderBy('release', 'desc')->with(['releases', 'releases.release_type', 'image', 'tags', 'show'])->firstOrFail(); } else { $this->episode = Episode::query()->where('published', true)->orderBy('release', 'desc')->with(['releases', 'releases.release_type', 'image', 'tags', 'show'])->firstOrFail(); } $this->releases = Collection::make($this->episode->releases); // Creates a copy $this->releases->sort(function (Release $a, Release $b) { // Order by the sort_order column $aRating = $a->release_type->sort_order; $bRating = $b->release_type->sort_order; return $aRating - $bRating; }); }
/** * Execute the console command. * * @return mixed */ public function fire(Almaty $almaty, Astana $astana) { $city = $this->option('city'); if ($city == 1) { $this->city = $almaty; } else { $this->city = $astana; } $insertCollection = Collection::make(); $updateCollection = Collection::make(); $wialon = new Wialon($this->city); $start_day = strtotime('now 00:00:00'); $end_day = strtotime('now 23:59:00'); $drivers = $wialon->get_drivers(); $get_exec = $wialon->select_exec(); $violations = \App\Models\Violations::on($this->city->db)->whereBetween('vio_date', [$start_day, $end_day])->get(['id', 'vio_nomer', 'vio_date', 'updated']); if (!$violations->isEmpty()) { foreach ($violations as $db) { foreach ($get_exec as $key => $a) { $number_car = $a->r[0]->c[1]; $number_car = substr($number_car, 0, 5); $vio = $a->r[0]->c[3]->t; $date_vio_timestamp = $a->r[0]->c[2]->v; if ($db->vio_date == $date_vio_timestamp && $number_car == $db->vio_nomer) { $db->updated = date('Y-m-d H:i:s', time()); $db->save(); unset($get_exec[$key]); } } } } if (!isset($get_exec->error) && !empty($get_exec)) { foreach ($get_exec as $k => $a) { $number_car = substr($a->r[0]->c[1], 0, 5); $vio = $a->r[0]->c[3]->t; $date_vio = $a->r[0]->c[2]->v; $insertion = ['vio_nomer' => $number_car, 'vio_date' => $date_vio, 'vio_text' => $vio, 'status' => 0, 'city' => $this->city->city, 'updated' => date('Y-m-d H:i:s', time())]; $insertCollection->push($insertion); } } \App\Models\Violations::on($this->city->db)->insert($insertCollection->toArray()); $this->endUpdate($start_day); $this->call('drivers:violation', ['--city' => $city]); }
/** * Fill `parent` and `children` relationships for every node in the collection. * * This will overwrite any previously set relations. * * @return $this */ public function linkNodes() { if ($this->isEmpty()) { return $this; } $groupedNodes = $this->groupBy($this->first()->getParentIdName()); /** @var NodeTrait|Model $node */ foreach ($this->items as $node) { if (!$node->getParentId()) { $node->setRelation('parent', null); } $children = $groupedNodes->get($node->getKey(), []); /** @var Model|NodeTrait $child */ foreach ($children as $child) { $child->setRelation('parent', $node); } $node->setRelation('children', BaseCollection::make($children)); } return $this; }
/** * Execute the console command. * * @return mixed */ public function fire(Almaty $almaty, Astana $astana) { $city = $this->option('city'); $start_day = strtotime('now 00:00:00'); $end_day = strtotime('now 23:59:59'); $insertCollection = Collection::make(); $updateCollection = Collection::make(); if ($city == 1) { $this->city = $almaty; } else { $this->city = $astana; } $tm = new TMBase($this->city); $shifts = $tm->get_shifts($start_day, $end_day); DB::beginTransaction(); foreach ($shifts as $v) { $crew = Crews::on($this->city->db)->where('driver', $v->driver_id)->first(); $insertion = ['id' => empty($v->shift_id) ? 'NULL' : $v->shift_id, 'driver' => empty($v->driver_id) ? 'NULL' : $v->driver_id, 'begin' => empty($v->plan_shift_start_time) ? 'NULL' : strtotime($v->plan_shift_start_time), 'end' => empty($v->plan_shift_finish_time) ? 'NULL' : strtotime($v->plan_shift_finish_time), 'crew' => isset($crew->id) ? $crew->id : 'NULL', 'type' => empty($v->shift_state) ? 'NULL' : $v->shift_state, 'uptime' => time()]; $shift = \App\Models\Smens::on($this->city->db)->find($v->shift_id); if (empty($shift)) { $insertCollection->push($insertion); $driver = Driver::on($this->city->db)->find($v->driver_id); if (!empty($driver) && $v->plan_shift_cost != 1 && $this->city->transfer_to_debtors == "1") { $locked_alias = Driver::getLockedDriver($this->city->db, $driver->name); if (!empty($locked_alias)) { $summ = $locked_alias->balans > -2000 ? abs($locked_alias->balans) : $this->city->transfer_to_debtor_price; $this->call('drivers:operations', ['driver' => $driver->id, 'op' => '0', 'summ' => $summ, 'reason' => 'Перевод в счет долга', 'time' => time(), '--city' => $city]); $this->call('drivers:operations', ['driver' => $locked_alias->id, 'op' => '1', 'summ' => $summ, 'reason' => 'Перевод в счет долга', 'time' => time(), '--city' => $city]); $locked_a2 = Driver::on($this->city->db)->find($locked_alias->id); if (isset($locked_a2) && $locked_a2->balans >= 0) { $this->call('drivers:delete', ['id' => $locked_a2->id, '--city' => $city]); } } } } } if (!$insertCollection->isEmpty()) { \App\Models\Smens::on($this->city->db)->insert($insertCollection->toArray()); } DB::commit(); }
/** * Execute the console command. * * @return mixed */ public function fire(Almaty $almaty, Astana $astana) { $city = $this->option('city'); if ($city == 1) { $this->city = $almaty; } else { $this->city = $astana; } $tm = new TMBase($this->city); $crews = $tm->get_crew_coords(); $collection = Collection::make(); DB::beginTransaction(); if (!empty($crews)) { DB::connection($this->city->db)->table('crews_inline')->truncate(); foreach ($crews as $v) { $insertion = ['id' => empty($v->crew_id) ? 'NULL' : $v->crew_id, 'code' => empty($v->crew_code) ? 'NULL' : $v->crew_code, 'lat' => empty($v->lat) ? 'NULL' : $v->lat, 'lon' => empty($v->lon) ? 'NULL' : $v->lon, 'status' => empty($v->state_kind) ? 'NULL' : $v->state_kind, 'uptime' => time()]; $collection->push($insertion); } DB::connection($this->city->db)->table('crews_inline')->insert($collection->toArray()); } DB::commit(); }
/** * Execute the console command. * * @return mixed */ public function fire(Almaty $almaty, Astana $astana) { $city = $this->option('city'); if ($city == 1) { $this->city = $almaty; } else { $this->city = $astana; } $tm = new TMBase($this->city); $cars = $tm->get_cars_info(); $collection = Collection::make(); if (!empty($cars)) { DB::beginTransaction(); DB::connection($this->city->db)->table('cars')->truncate(); foreach ($cars as $v) { $insertion = ['id' => empty($v->car_id) ? 'NULL' : $v->car_id, 'code' => empty($v->code) ? 'NULL' : $v->code, 'gn' => empty($v->gos_number) ? 'NULL' : $v->gos_number, 'color' => empty($v->color) ? 'NULL' : $v->color, 'mark' => empty($v->mark) ? 'NULL' : $v->mark, 'is_locked' => empty($v->is_locked) ? 'NULL' : $v->is_locked, 'deleted' => 0, 'uptime' => time(), 'last_call' => 0]; $collection->push($insertion); } DB::connection($this->city->db)->table('cars')->insert($collection->toArray()); } DB::commit(); }
/** * Execute the console command. * * @return mixed */ public function fire(Almaty $almaty, Astana $astana) { $city = $this->option('city'); if ($city == 1) { $this->city = $almaty; } else { $this->city = $astana; } $tm = new TMBase($this->city); $crews = $tm->get_all_crews(); $collection = Collection::make(); DB::beginTransaction(); if (!empty($crews)) { DB::connection($this->city->db)->table('crews')->truncate(); foreach ($crews as $v) { $insertion = ['id' => isset($v->crew_id) ? $v->crew_id : 0, 'code' => isset($v->code) ? $v->code : 0, 'car' => isset($v->car_id) ? $v->car_id : NULL, 'driver' => isset($v->driver_id) ? $v->driver_id : NULL, 'uptime' => time(), 'deleted' => 0]; $collection->push($insertion); } DB::connection($this->city->db)->table('crews')->insert($collection->toArray()); } DB::commit(); }
/** * Execute the console command. * * @return mixed */ public function fire(Almaty $almaty, Astana $astana) { $city = $this->option('city'); if ($city == 1) { $this->city = $almaty; } else { $this->city = $astana; } $tm = new TMBase($this->city); $cars = $tm->get_cars_info(); $collection = Collection::make(); if (!empty($cars)) { DB::beginTransaction(); DB::connection($this->city->db)->table('cars_info')->truncate(); foreach ($cars as $v) { $insertion = ['car_id' => empty($v->car_id) ? 'NULL' : $v->car_id, 'code' => empty($v->code) ? 'NULL' : $v->code, 'name' => empty($v->name) ? 'NULL' : $v->name, 'gos_nomer' => empty($v->gos_number) ? 'NULL' : $v->gos_number, 'color' => empty($v->color) ? 'NULL' : $v->color, 'mark' => empty($v->mark) ? 'NULL' : $v->mark, 'model' => empty($v->model) ? 'NULL' : $v->model, 'short_name' => empty($v->short_name) ? 'NULL' : $v->short_name, 'production_year' => empty($v->production_year) ? 'NULL' : $v->production_year, 'is_locked' => empty($v->is_locked) ? 'NULL' : $v->is_locked, 'updated' => date('Y-m-d H:i:s', time())]; $collection->push($insertion); } DB::connection($this->city->db)->table('cars_info')->insert($collection->toArray()); } DB::commit(); }
/** * Execute the console command. * * @return mixed */ public function fire(Almaty $almaty, Astana $astana) { $city = $this->option('city'); if ($city == 1) { $this->city = $almaty; } else { $this->city = $astana; } $tm = new TMBase($this->city); $crews = $tm->get_all_crews(); $collection = Collection::make(); DB::beginTransaction(); if (!empty($crews)) { DB::connection($this->city->db)->table('crews_info')->truncate(); foreach ($crews as $v) { $insertion = ['crew_id' => empty($v->crew_id) ? 'NULL' : $v->crew_id, 'code' => empty($v->code) ? 'NULL' : $v->code, 'name' => empty($v->name) ? 'NULL' : $v->name, 'driver_id' => empty($v->driver_id) ? 'NULL' : $v->driver_id, 'car_id' => empty($v->car_id) ? 'NULL' : $v->car_id, 'shashka' => empty($v->car_id) ? 'NULL' : $v->has_light_house, 'updated' => date('Y-m-d H:i:s', time())]; $collection->push($insertion); } DB::connection($this->city->db)->table('crews_info')->insert($collection->toArray()); } DB::commit(); }