/** * * $newsletter */ protected function getMaps() { $posts = new Collection(); $projects = new Collection(); $this->each(function ($widget) use($projects, $posts) { if ($widget->resource) { if ($widget->resource_type == Post::class) { $posts->push($widget->resource_id); } if ($widget->resource_type == Project::class) { $projects->push($widget->resource_id); } } if ($widget->other_resource) { if ($widget->other_resource_type == Post::class) { $posts->push($widget->other_resource_id); } if ($widget->other_resource_type == Project::class) { $projects->push($widget->other_resource_id); } } }); $posts = Post::whereIn('posts.id', $posts->all())->with(['translations', 'images', 'images.sizes'])->get(); $projects = Project::whereIn('portfolio_projects.id', $projects->all())->with(['translations', 'images', 'images.sizes'])->get(); return [$posts, $projects]; }
public function create(Request $request, $student_id = null) { $message_types = $this->message_type->orderBy('message_type_name')->lists('message_type_name', 'id')->all(); $schools = $this->school->lists('school_name', 'id')->all(); if (isset($student_id)) { $student = $this->contact->find($student_id); } else { $student = null; } $all_contacts = $this->contact->allStudents(); $contacts = array(); foreach ($all_contacts as $contact) { $contacts[$contact->id] = $contact->name . ' ' . $contact->surname; } if ($request->input('message_id')) { $messages = Message::processIds($request->input('message_id')); } else { $selected = null; } $students = new Collection(); $selected = array(); if (isset($messages)) { foreach ($messages as $message) { $students->add($message->Contact); $selected[] = $message->Contact->id; } $students = $students->unique(); } return view()->make('messages.create', compact('message_types', 'schools', 'contacts', 'student', 'selected')); }
/** * Render the likes into a string. * * @param Collection $likesCollection The likes to render. * * @param string $viewAllLikesLink The link to view all of the likes for the content. * * @return string */ public function render(Collection $likesCollection, $viewAllLikesLink) { $numLikesToList = $this->settings->get('posts.likes_to_show', 3); $numOtherLikes = $likesCollection->count() - $numLikesToList; $userId = $this->guard->user()->getAuthIdentifier(); $likes = []; $likesCollection = $likesCollection->filter(function (Like $like) use(&$likes, &$numLikesToList, $userId) { if ($like->user->id === $userId) { $like->user->name = $this->lang->get('likes.current_user'); $likes[] = $like; $numLikesToList--; return false; } return true; }); $numLikesInCollection = $likesCollection->count(); if ($numLikesInCollection > 0 && $numLikesToList > 0) { if ($numLikesInCollection < $numLikesToList) { $numLikesToList = $numLikesInCollection; } $randomLikes = $likesCollection->random($numLikesToList); if (!is_array($randomLikes)) { // random returns a single model if $numLikesToList is 1... $randomLikes = array($randomLikes); } foreach ($randomLikes as $key => $like) { $likes[] = $like; } } return $this->viewFactory->make('likes.list', compact('numOtherLikes', 'likes', 'viewAllLikesLink'))->render(); }
/** * @return Post * * @SuppressWarnings(PHPMD.StaticAccess) */ private function getRandomPost() { if ($this->posts === null) { $this->posts = Post::all(); } return $this->posts->random(); }
protected function getCounty($municipality_id) { $county_id = substr(str_pad($municipality_id, 4, '0', STR_PAD_LEFT), 0, 2); /* @var County $county */ $county = $this->counties->find($county_id); return $county; }
/** * @return Board * * @SuppressWarnings(PHPMD.StaticAccess) */ private function getRandomBoard() { if ($this->boards === null) { $this->boards = Board::all(); } return $this->boards->random(); }
public function update_groupe_post(Request $request, $id) { $user = Auth::user(); if ($user->profil->intitule == "administrateur") { $erreurs = new Collection(); $this->validate($request, ['intitule' => 'required', 'description' => 'required', 'parcours' => 'exists:parcours,id']); $groupes = Groupe::all(); $groupe = Groupe::find($id); foreach ($groupes as $g) { if ($request->input('intitule') != $groupe->intitule) { if ($request->input('intitule') == $g->intitule) { $erreurs->prepend("Cet intitulé existe déjà !"); break; } } } $groupe->intitule = $request->input('intitule'); $groupe->description = $request->input('description'); $groupe->parcours_id = $request->input('parcours'); $parcours = Parcours::all(); if (count($erreurs) > 0) { return response()->view('groupe/update_groupe', ['groupe' => $groupe, 'erreurs' => $erreurs, 'parcours' => $parcours]); } $groupe->save(); return redirect('admin/groupe'); } return "Vous êtes pas administrateur"; }
public function collection(Collection $collection) { $this->data = $collection->map(function ($item) { return $this->makeData($item); })->all(); return $this; }
public function update_profil_post(Request $request, $id) { $user = Auth::user(); if ($user->profil->intitule == "administrateur") { $erreurs = new Collection(); $this->validate($request, ['intitule' => 'required']); $profils = Profil::all(); $profil = Profil::find($id); foreach ($profils as $p) { if ($request->input('intitule') != $profil->intitule) { if ($request->input('intitule') == $p->intitule) { $erreurs->prepend("Cet intitulé existe déjà !"); break; } } } $profil->intitule = $request->input('intitule'); if (count($erreurs) > 0) { return response()->view('profil/update_profil', ['profil' => $profil, 'erreurs' => $erreurs]); } $profil->save(); return redirect('admin/profil'); } return "Vous êtes pas administrateur"; }
public function addTrainingData($user, $training) { $collection = new Collection(); $visible = true; foreach ($training as $itemKey => $item) { $item['visible'] = $visible; foreach ($item['relations'] as $relationKey => $relation) { $done = true; foreach ($relation as $elementKey => $element) { $element['id'] = "{$item['id']}.{$element['id']}"; $element['watch-url'] = route('training.watch', ['year' => 2016, 'item' => $element['id']]); $element['watched'] = Watched::where('subscription_id', $user->id)->where('item_id', $element['id'])->first(); $element['visible'] = $visible || $element['watched']; $done = $done && $element['watched']; if ($relationKey == 'quiz') { $element['answer'] = $element['watched'] ? $element['watched']->answer : null; } $visible = $element['watched'] !== null; $item['relations'][$relationKey][$elementKey] = $element; } } $item['done'] = $done; $collection->push($item); } return $collection; }
private function getRawCollectionData(Collection $collection) { foreach ($collection as $element) { $this->execute_with_relations ? $element->loadDisplayableRelations() : null; } return $collection->toArray(); }
public function upload(PhotoUploadRequest $request) { $user = Auth::user(); $destinationPath = 'uploads/'; if ($request->hasFile('files')) { $photos = new Collection(); $i = 0; foreach ($request->file('files') as $file) { $extension = $file->getClientOriginalExtension(); $new_filename = time() . uniqid() . str_random(rand(5, 15)) . '.' . $extension; $file->move($destinationPath, $new_filename); $photos[$i] = new Photo(); $photos[$i]->content_type = $file->getClientMimeType(); $photos[$i]->disk_name = $new_filename; $photos[$i]->file_name = $file->getClientOriginalName(); $photos[$i]->path = $destinationPath . $new_filename; $photos[$i]->file_size = $file->getClientSize(); $photos[$i]->user_id = $user->id; $photos[$i]->save(); $i++; } return $photos->first(); } return response()->json(['status' => 'error']); }
/** * @param $items * @return array */ public function transformCollection(Collection $items, $showHref = false) { $data = $items->map(function ($item) use($showHref) { return $this->transform($item, $showHref); })->toArray(); return $data; }
/** * @param Collection $model * @param string $single * * @return string */ public function createData($model, string $single) { $str = sprintf("\n\t\t\$scope.%s = new Minute.Models.%sArray(null);\n", $single, $this->fixName($single)); $str .= sprintf("\t\t\$scope.%s.load(%s);\n", $single, json_encode($model->toArray(), JSON_PRETTY_PRINT)); //{metadata: {offset: 0, limit: 2, total: %d}, items: %s} return $str; }
/** * Execute the console command. * * @return mixed */ public function handle() { $month = new Carbon($this->argument('month')); $billboards = Billboard::activated()->get(); $pictures = Storage::files(); $missing_pictures = new Collection(); foreach ($billboards as $billboard) { $facings = $billboard->facings->all(); foreach ($facings as $facing) { $ref = $this->reference($billboard, $facing, $month); $image_url = "{$ref}.jpg"; if (in_array($image_url, $pictures)) { try { $this->trackingRepository->create(['facing_id' => $facing->id, 'image_url' => $image_url, 'tracking_date' => $month, 'location_id' => $billboard->location_id]); $this->info('Tracking #' . $ref . ' with image url ' . $image_url . ' created successfully.'); } catch (\Illuminate\Database\QueryException $e) { $this->error('Tracking #' . $ref . ' already exists.'); } } else { $this->error('Facing #' . $ref . ' picture missing.'); $missing_pictures->push(["name" => $facing->name, "image_url" => $image_url]); } } } if (!$missing_pictures->isEmpty()) { $this->notifyMissingPictures($missing_pictures, "*****@*****.**"); } }
public function index() { $sections = Section::all(); if (Auth::user()) { $cart = Auth::user()->cart; } else { $cart = new Collection(); if (Session::has('cart')) { foreach (Session::get('cart') as $item) { $elem = new Cart(); $elem->product_id = $item['product_id']; $elem->amount = $item['qty']; if (isset($item['options'])) { $elem->options = $item['options']; } $cart->add($elem); } } } $total = 0; $options = new Collection(); foreach ($cart as $item) { $total += $item->product->price * $item->amount; if ($item->options) { $values = explode(',', $item->options); foreach ($values as $value) { $options->add(OptionValue::find($value)); } } } return view('site.cart', compact('sections', 'total', 'cart', 'options')); }
public static function updateArrangement(Collection $collection, array $arrangement) { $order = 0; foreach ($arrangement as $parent) { /** @var \CipeMotion\Medialibrary\Entities\Category $category */ $category = $collection->find(array_get($parent, 'id', 0)); $children = array_get($parent, 'children', []); if (!is_null($category)) { $category->order = $order; $category->parent_id = null; $category->save(); if (count($children) > 0) { $childOrder = 0; foreach ($children as $child) { /** @var \CipeMotion\Medialibrary\Entities\Category $childCategory */ $childCategory = $collection->find(array_get($child, 'id', 0)); if (!is_null($childCategory)) { $childCategory->order = $childOrder; $childCategory->parent_id = $category->id; $childCategory->save(); $childOrder++; } } } $order++; } } }
public static function remove($key) { if (!empty($key)) { return self::$app_options->where('key', $key)->delete(); } return false; }
/** * @return User * * @SuppressWarnings(PHPMD.StaticAccess) */ protected function getRandomUser() { if ($this->users === null) { $this->users = User::all(); } return $this->users->random(); }
/** * Display the specified resource. * * @param int|null $id * * @return \Illuminate\Http\Response */ public function show($id = null) { if ($id === null) { $profile = Auth::user()->getProfile(); } else { $profile = Profile::findOrFail($id); } $is_mine = $profile->user_id == \Flocc\Auth::getUserId(); if ($is_mine === true) { $activities = (new Activities())->get(); $tribes = (new Tribes())->get(); $events_time_lines = new Collection(); foreach ($profile->getTimeLine()->getLatestUpdatedEvents() as $event) { foreach ($event->getTimeLine() as $line) { if ($line->isMessage()) { $events_time_lines->push(['id' => $event->getId(), 'slug' => $event->getSlug(), 'event' => $event->getTitle(), 'date' => $line->getTime(), 'message' => $line->getMessage()]); } } } $events_time_lines = $events_time_lines->sortByDesc('date')->slice(0, 5); return view('dashboard', compact('profile', 'is_mine', 'activities', 'tribes', 'events_time_lines')); } else { return view('profiles.show', compact('profile', 'is_mine', 'id')); } }
/** * Countable in cart. */ public function it_additems(ItemInterface $item, ItemInterface $item2) { $collection = new Collection(); $collection->add($item); $collection->add($item2); $this->addItems($collection)->shouldHaveCount(4); }
/** * * Cache posts if caching is enabled * * @param Collection $posts */ protected function cachePosts($posts) { $cache = $this->property('cacheLifetime'); if ($cache) { Cache::put('blogarchive_random_posts', $posts->toArray(), $cache); } }
/** * * Cache photos if caching is enabled * * @param Collection $photos */ protected function cachePhotos($photos) { $cache = $this->property('cacheLifetime'); if ($cache) { Cache::put('photoalbums_random_photos', $photos->toArray(), $cache); } }
public function map($hash, $title = true) { if (strlen($hash) < 1) { $hash = '9999999999'; } if (Hashes::$items == null) { $this->getItems(); } $object = Hashes::$items->filter(function ($item) use($hash) { return $item->hash == $hash; })->first(); if ($object instanceof Hash) { if ($title) { return $object->title; } return $object; } else { if ($this->allowedRetry) { $this->updateHashes(); return $this->map($hash, $title); } else { $classified = Hash::where('hash', '9999999999')->first(); if ($title) { return $classified->title; } return $classified; // throw new HashNotLocatedException($hash); } } }
/** * Create a collection of instances of the given model and persist them to the database. * * @param integer $total * @param array $customValues * * @return \Illuminate\Database\Eloquent\Collection */ public function createMultiple($total, array $customValues = array()) { $collection = new Collection(); for ($i = 1; $i <= $total; $i++) { $collection->add($this->create($customValues)); } return $collection; }
public static function collectionAsItem(Collection $collection, array $columns, $cache = null) { $output = []; foreach ($collection->toArray() as $row) { $output[] = ['value' => isset($columns['value']) ? $row[$columns['value']] : $row['id'], 'text' => $row[$columns['text']]]; } return $output; }
public function getAll() { $collection = new Collection(); foreach ($this->readData() as $article) { $collection->add(new Article($article)); } return $collection; }
/** * Return collection of tags related to the tagged model * TODO : I'm sure there is a faster way to build this, but * If anyone knows how to do that, me love you long time. * * @return Illuminate\Database\Eloquent\Collection */ public function getTagsAttribute() { $tags = new Collection(); foreach ($this->tagged as $tagged) { $tags->add($tagged->tag); } return $tags; }
/** * Format an Eloquent collection. * * @param \Illuminate\Database\Eloquent\Collection $collection * @return string */ public function formatEloquentCollection($collection) { if ($collection->isEmpty()) { return $this->encode([]); } $key = str_plural($collection->first()->getTable()); return $this->encode([$key => $collection->toArray()]); }
public function maps($tournament) { $maps = new Collection(); $this->reports($tournament)->get()->each(function ($report) use(&$maps) { $maps->push(Map::find($report->map)); }); return $maps; }