/** * @param $slug * @param $callback * * @throws \Exception */ public function getDropDown($slug, $callback) { $dropDown = $this->links->where('slug', $this->snakeName($slug))->first(); if ($dropDown) { call_user_func($callback, $dropDown); } else { throw new \Exception("Drop down {$slug} not found"); } }
/** * Get the current flash message. * * @return string */ public function get($level = null) { if (isset($level)) { return $this->getMessage(); } return $this->current->where('level', $level); }
function tour_compare_add() { $id = request()->input('id'); if ($id) { $query['id'] = $id; $query['with_travel_agent'] = true; $api_response = json_decode($this->api->get($this->api_url . '/tours?' . http_build_query(array_merge($query, ['access_token' => Session::get('access_token')])))->getBody()); if ($api_response->data->data[0]) { $tour = $api_response->data->data[0]; $comparison = session()->get('tour_comparison'); if (!$comparison) { $comparison = new Collection(); } // Check if there's already max amount of comparable tour if ($comparison->count() >= 4) { return response()->json(JSend::fail(['comparison' => 'Tidak dapat membandingkan lebih dari 4 paket tour'])->asArray()); } // Make sure no duplicated tour if (!$comparison->where('_id', $tour->_id)->count()) { $comparison->push($tour); } session()->put('tour_comparison', $comparison); return response()->json(JSend::success($comparison->toArray())->asArray()); } else { return app::abort(404); } } else { return app()->abort(400); } }
/** * Display a group of widgets * @param string $group * @return string */ public function getWidgets($group = 'demo') { $collection = new Collection($this->widgets); $widgets = $collection->where('group', $group)->sortBy('order'); $output = ""; foreach ($widgets as $widget) { $params = isset($widget['params']) ? $widget['params'] : []; $output .= Widget::call($widget['name'], $params); } return $output; }
public function getAllFixtures($team = null) { $response = $this->client->request('GET', self::FIXTURES_URL); $collection = new Collection(json_decode($response->getBody())); $fixtures = new Collection($collection->get('fixtures')); if (is_null($team)) { return $fixtures->where('status', 'FINISHED'); } else { return $fixtures->filter(function ($value, $key) use($team) { return strtolower($value->homeTeamName) == strtolower($team) || strtolower($value->awayTeamName) == strtolower($team) ? $value : null; }); } }
private function createTorneosClubes($cant_grupos, $torneo, $request) { $mensajes = new Collection(); $torneos_clubes = new Collection(); for ($i = 1; $i <= $cant_grupos; $i++) { $equipos_grupo = $request->get("grupo_" . $i); $cant_equipos = sizeof($equipos_grupo); for ($j = 0; $j < $cant_equipos; $j++) { $club_id = $equipos_grupo[$j]; // corroboro que el club no este participando ya del torneo $existe_en_torneo = $torneos_clubes->where('club_id', $club_id); if ($existe_en_torneo->isEmpty()) { $torneo_club = new TorneoClub(); //$torneo_club->pseudonimo = chr($j+96); $torneo_club->club_id = $club_id; $torneo_club->torneo_id = $torneo->id; $torneo_club->save(); $torneos_clubes->push($torneo_club); // Me fijo si el club esta jugando en otra division, de la misma categoría, en alguno de los restantes torneos de la misma temporada. $existe_instancia = TorneoClub::with('club')->with('torneo.division')->select('torneos_clubes.*')->join('clubes', 'clubes.id', '=', 'torneos_clubes.club_id')->join('torneos', 'torneos.id', '=', 'torneos_clubes.torneo_id')->join('tipos_torneos', 'tipos_torneos.id', '=', 'torneos.tipo_torneo_id')->join('temporadas', 'temporadas.id', '=', 'torneos.temporada_id')->join('divisiones', 'divisiones.id', '=', 'torneos.division_id')->join('categorias', 'categorias.id', '=', 'divisiones.categoria_id')->where('clubes.id', $club_id)->where('torneos.id', '!=', $torneo->id)->where('temporadas.id', '=', $torneo->temporada_id)->where('divisiones.id', '!=', $torneo->division_id)->where('categorias.id', '=', $torneo->categoria->id)->first(); if ($existe_instancia) { $error_msg = ''; $error_msg .= ' El Club ' . $existe_instancia->club->full_name; $error_msg .= ' esta jugando el ' . $existe_instancia->torneo->full_name; $error_msg .= ' en ' . $existe_instancia->torneo->division->full_name . '.'; $mensajes->push($error_msg); } } } } $cant_equipos_ingresados = $torneos_clubes->count(); $cant_max = $torneo->tipo_torneo->cant_equipos; $cant_min = 0; if ($cant_equipos_ingresados > $cant_max or $cant_equipos_ingresados < $cant_min) { $error_msg = 'Se ingresaron mas equipos de los que el tipo de torneo define. '; $mensajes->push($error_msg); } //return $cant_equipos_ingresados; //return $torneos_clubes; return $mensajes; }
public function testWhere() { $c = new Collection([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3'], ['v' => 4]]); $this->assertEquals([['v' => 3]], $c->where('v', 3)->values()->all()); }
/** * Iterate through result set to fetch the requested resources to include. * * @param Illuminate\Database\Eloquent\Collection|JsonApi\Model $models * @return array */ protected function getIncludedModels($models) { $links = new Collection(); $models = $models instanceof Collection ? $models : [$models]; foreach ($models as $model) { foreach ($this->exposedRelationsFromRequest($model) as $relationName) { $value = static::getModelsForRelation($model, $relationName); if (is_null($value)) { continue; } foreach ($value as $obj) { // Check whether the object is already included in the response on it's ID $duplicate = false; $items = $links->where('id', $obj->getKey()); if (count($items) > 0) { foreach ($items as $item) { if ($item->getResourceType() === $obj->getResourceType()) { $duplicate = true; break; } } if ($duplicate) { continue; } } //add type property $attributes = $obj->getAttributes(); $attributes['type'] = $obj->getResourceType(); $obj->setRawAttributes($attributes); $links->push($obj); } } } return $links->toArray(); }
/** * Checks if given model/result is in Collection already * by checking id and table. * @param Model $obj * @param Collection $links * @return bool */ protected function isModelInCollection($obj, $links) { $items = $links->where('id', $obj->getKey()); if (count($items) > 0) { foreach ($items as $item) { if ($item->getTable() === $obj->getTable()) { return true; } } } return false; }
public function postStore($id = null) { // ---------------------------------------- HANDLE REQUEST ---------------------------------------- // handle id if (!is_null($id)) { $data = $this->model->findorfail($id); } else { $data = $this->model->newInstance(); } // ---------------------------------------- CHECK TAG ---------------------------------------- $tags_in_db = \App\Tag::whereIn('tag', Input::get('tags'))->get(); if (!$tags_in_db) { $tags_in_db = new Collection(); } foreach (Input::get('tags') as $x) { if (!$tags_in_db->where('tag', $x)->first()->id) { $new_tag = new \App\Tag(['tag' => $x]); if (!$new_tag->save()) { dd($new_tag->getErrors()); } $tags_in_db->push($new_tag); } } // ---------------------------------------- HANDLE SAVE ---------------------------------------- $input = Input::all(); // tour travel agent $input['travel_agent_id'] = $input['travel_agent']; // tour destinations $input['destination_ids'] = $input['destinations']; // tour places $input['place_ids'] = $input['places']; // tags $input['tag_ids'] = $tags_in_db->pluck('id')->toArray(); // tour options foreach ($input['tour_options'] as $x) { $input['option_ids'][$x] = ['description' => $input['tour_options_description_' . $x]]; } // published_at if ($input['published_at']) { $input['published_at'] = \Carbon\Carbon::createFromFormat('d/m/Y H:i', $input['published_at'])->format('Y-m-d H:i:s'); } else { $input['published_at'] = null; } $data->fill($input); if ($data->save()) { if (!$this->save_required_images($data, $input)) { return redirect()->back()->withInput()->withErrors($data->getErrors()); } return redirect()->route('admin.' . $this->view_name . '.show', ['id' => $data->id])->with('alert_success', '"' . $data->{$data->getNameField()} . '" has been saved successfully'); } else { return redirect()->back()->withInput()->withErrors($data->getErrors()); } }
public function testWhere() { $c = new Collection([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3'], ['v' => 4]]); $this->assertEquals([['v' => 3], ['v' => '3']], $c->where('v', 3)->values()->all()); $this->assertEquals([['v' => 3], ['v' => '3']], $c->where('v', '=', 3)->values()->all()); $this->assertEquals([['v' => 3], ['v' => '3']], $c->where('v', '==', 3)->values()->all()); $this->assertEquals([['v' => 3], ['v' => '3']], $c->where('v', 'garbage', 3)->values()->all()); $this->assertEquals([['v' => 3]], $c->where('v', '===', 3)->values()->all()); $this->assertEquals([['v' => 1], ['v' => 2], ['v' => 4]], $c->where('v', '<>', 3)->values()->all()); $this->assertEquals([['v' => 1], ['v' => 2], ['v' => 4]], $c->where('v', '!=', 3)->values()->all()); $this->assertEquals([['v' => 1], ['v' => 2], ['v' => '3'], ['v' => 4]], $c->where('v', '!==', 3)->values()->all()); $this->assertEquals([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3']], $c->where('v', '<=', 3)->values()->all()); $this->assertEquals([['v' => 3], ['v' => '3'], ['v' => 4]], $c->where('v', '>=', 3)->values()->all()); $this->assertEquals([['v' => 1], ['v' => 2]], $c->where('v', '<', 3)->values()->all()); $this->assertEquals([['v' => 4]], $c->where('v', '>', 3)->values()->all()); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { function buildTree(array $elements, $parentId = 0) { $branch = array(); foreach ($elements as $element) { if ($element['mdl_parent'] == $parentId) { $children = buildTree($elements, $element['id']); if ($children) { $element['children'] = $children; } else { $element['children'] = 0; } $branch[] = $element; } } return $branch; } function displayArrayRecursively($arr, $indent = '') { if ($arr) { echo "<li class=\"\">"; foreach ($arr as $value) { if (is_array($value)) { // displayArrayRecursively($value, $indent . '--'); } else { // Output echo "{$indent} {$value} \n"; } } } } $user = $this->auth->user(); // Creates Modules List based on the user if (!is_null($user)) { // Get the list of all modules enabled, assigned to role and with access permission. $ModulesQ = Modules::where('mdl_enabled', 1)->join('permissions', 'permissions.id_mdl', '=', 'modules.id')->distinct(); if (!$user->is_sadmin) { $ModulesQ = $ModulesQ->where('pm_access', 1)->where('id_rl', $user->usr_role)->where('mdl_isadmin', 0); } $Modules = new Collection($ModulesQ->get(['modules.id as id', 'mdl_name', 'mdl_slug', 'mdl_description', 'mdl_faicon', 'mdl_menu', 'mdl_plural', 'mdl_singular', 'mdl_parent'])); $SidebarModules = buildTree($Modules->where('mdl_menu', 1)->toArray()); // Assing a view variable for each menu, currently is hard coded to the menu # but it should get the values from the menus table. $this->view->share('SidebarModules', $SidebarModules); $this->view->share('TopModules', $Modules->where('mdl_menu', 2)); $this->view->share('UserModules', $Modules->where('mdl_menu', 3)); $this->view->share('SettingsModules', $Modules->where('mdl_menu', 4)); $this->view->share('UserPanel', $Modules->where('mdl_menu', 5)); $this->view->share('DashboardModules', $Modules->where('mdl_menu', 6)); // Get the current module to display the details on the VIEW (slug, plural, singular, etc) $slug = Route::getCurrentRoute()->getPath(); $slugOnly = explode('/', $slug); $CurrentModule = $Modules->where('mdl_slug', $slugOnly[0]); if ($CurrentModule->isEmpty()) { abort(403, 'Middle 403'); } $this->view->share('CurrentModule', $CurrentModule); // Get the permissions details for the current module. $PrmMdl = DB::table('modules')->join('permissions', 'permissions.id_mdl', '=', 'modules.id')->select('modules.id as i', 'pm_access as a', 'pm_create as c', 'pm_read as r', 'pm_update as u', 'pm_destroy as d')->where('id_mdl', $CurrentModule->first()->id)->where('id_rl', $user->usr_role)->where('mdl_isadmin', 0)->get(); $request->PrmMdl = json_encode($PrmMdl); // Get the current action to display the details on the VIEW $action = Route::getCurrentRoute()->getActionName(); $actionOnly = explode('@', $action); if ($actionOnly[1] == 'index') { $this->view->share('CurrentAction', 'Listado'); } elseif ($actionOnly[1] == 'create') { $this->view->share('CurrentAction', 'Agregar'); } elseif ($actionOnly[1] == 'show') { $this->view->share('CurrentAction', 'Ver'); } elseif ($actionOnly[1] == 'edit') { $this->view->share('CurrentAction', 'Editar'); } elseif ($actionOnly[1] == 'search') { $this->view->share('CurrentAction', 'Búsqueda'); } else { $this->view->share('CurrentAction', 'Ruta No Definida'); } } return $next($request); }
private function attachVotesShortInfo(Answer &$model, \Illuminate\Support\Collection $votes) { $likes = $votes->whereLoose('sign', 1)->count(); $dislikes = $votes->count() - $likes; $rating = $likes - $dislikes; $users_vote = $votes->where('user_id', Auth::user()->id)->first(); $model->vote_likes = $likes; $model->vote_dislikes = $dislikes; $model->vote_value = $rating; if ($users_vote) { $model->vote = $users_vote; } }
private function getProperties($data) { $data = new Collection($data); $articleNumbers = $data->lists('Artnr'); $properties = DB::connection('askas')->table('Artiklar_Egenskaper')->leftJoin('Artiklar_Egenskaper_Falt', 'Artiklar_Egenskaper.ArtFalt_ID', '=', 'Artiklar_Egenskaper_Falt.ArtFalt_ID')->whereIn('Artiklar_Egenskaper.Artnr', $articleNumbers)->where('Sprak_Suffix', 'SV')->whereNotNull('Namn_SV')->select(['Artiklar_Egenskaper.Artnr', 'Artiklar_Egenskaper.Varde', 'Artiklar_Egenskaper_Falt.Namn_SV'])->get(); $properties = new Collection($properties); //need to make it an array again. The edit in foreach won't work otherwise $data = $data->toArray(); foreach ($data as &$article) { $article = (array) $article; $article['properties'] = $properties->where('Artnr', $article['Artnr'])->all(); $article['recommendedPrice'] = $this->getProperty($properties, "Rek. pris", $article["Artnr"]); $article['supplierArticleNumber'] = $this->getProperty($properties, "Leverantörs artikelnummer", $article["Artnr"]); $article['series'] = $this->getProperty($properties, "SERIE", $article["Artnr"]); $article['color'] = $this->getProperty($properties, 'Färg', $article["Artnr"]); } return $data; }