public function postAjaxOrderSave() { $poss = Input::get('poss'); $pls = Photo::whereIn('id', $poss)->get(); if ($pls) { foreach ($pls as $pl) { $pl->order = array_search($pl->id, $poss); $pl->save(); } } return Response::make('1'); }
*/ ?> <?php $sliders = Dic::valuesBySlug('slider_in_main', function ($query) { $query->orderBy("dictionary_values.lft"); }, 'all', TRUE); $images = array(); if (count($sliders)) { $images_ids = array(); foreach ($sliders as $index => $slider) { if (!empty($slider->slide)) { $images_ids[] = $slider->slide; } } if (!empty($images_ids)) { foreach (Photo::whereIn('id', $images_ids)->get() as $image) { $images[$image->id] = $image->name; } } } ?> @extends(Helper::layout()) @section('style') @stop @section('content') @if(count($sliders)) <div id="carousel" class="cf" style="margin-bottom: 0;"> <div class="photo-wrapper clear"> @foreach($sliders as $slider) @if(isset($slider->slide) && isset($images[$slider->slide])) <a class="promo-banner"
/** * С помощью данного метода можно подгрузить изображения (Photo) к элементам коллекции по их ID, хранящемся в поле * В качестве третьего параметра можно передать название поля элемента коллекции, например связи один-ко-многим. * * Пример вызова: * $specials = DicLib::loadImages($specials, ['special_photo', 'special_plan']); * * @param $collection * @param string $key * @param string/null $field * @return Collection */ public static function loadImages($collection, $key = 'image_id', $field = null) { #Helper::tad($collection); if (!is_array($key)) { $key = (array) $key; } #Helper::ta(get_class($collection)); #Helper::tad($collection instanceof Collection); #Helper::ta((int)($collection instanceof \Illuminate\Pagination\Paginator)); #dd($collection); #var_dump($collection); $single_mode = false; $paginator_mode = false; #die($collection instanceof Collection); if ($collection instanceof Collection || $collection instanceof Illuminate\Database\Eloquent\Collection) { ## all ok } elseif ($collection instanceof \Illuminate\Pagination\Paginator) { $paginator_mode = true; $paginator = clone $collection; $collection = $collection->getItems(); } else { $single_mode = true; $temp = $collection; $collection = new Collection(); $collection->put(0, $temp); } #Helper::tad('single: ' . $single_mode . ', paginator: ' . $paginator_mode . ', key: ' . print_r($key, 1)); #Helper::tad($collection); #dd($collection); if (!count($collection) || !count($key)) { return $collection; } $images_ids_attr = array(); $images_ids = array(); /** * Перебираем все объекты в коллекции */ foreach ($collection as $obj) { /** * Если при вызове указано поле (связь) - берем ее вместо текущего объекта */ $work_obj = $field ? $obj->{$field} : $obj; #dd($work_obj->$key[0]); #dd($work_obj); #Helper::tad($work_obj); if (!is_object($work_obj)) { dd($work_obj); } /** * Перебираем все переданные ключи с ID изображений */ foreach ($key as $attr) { #Helper::ta($attr . ' - ' . is_numeric($work_obj->$attr)); /** * Собираем ID изображений - в общий список и в список с разбиением по ключу */ if (is_numeric($work_obj->{$attr})) { /** * Собираем ID изображений из обычных полей */ $images_ids_attr[$attr][] = $work_obj->{$attr}; $images_ids[] = $work_obj->{$attr}; } elseif (isset($work_obj->allfields) && count($work_obj->allfields)) { /** * Собираем ID изображений из i18n полей */ #Helper::tad($work_obj->allfields); foreach ($work_obj->allfields as $locale_sign => $locale_fields) { foreach ($locale_fields as $locale_key => $locale_value) { if ($locale_key == $attr) { #Helper::tad($locale_key . ' == ' . $attr); /** * Work good */ $images_ids[] = $locale_value; } #Helper::tad($locale_key); } } } } } #Helper::dd($images_ids); #Helper::d($images_ids_attr); #Helper::ta($images_locale_ids_attr); #Helper::tad($images_locale_ids); $images = []; if (count($images_ids)) { $images = Photo::whereIn('id', $images_ids); if (NULL != ($db_remember_timeout = Config::get('app.settings.main.db_remember_timeout')) && $db_remember_timeout > 0) { $images->remember($db_remember_timeout); } $images = $images->get(); $images = self::modifyKeys($images, 'id'); #Helper::tad($images); } #dd($collection); if (count($images)) { /** * Перебираем все объекты в коллекции */ foreach ($collection as $o => $obj) { /** * Если при вызове указано поле (связь) - берем ее вместо текущего объекта */ $work_obj = $field ? $obj->{$field} : $obj; /** * Перебираем все переданные ключи с ID изображений */ foreach ($key as $attr) { if (is_object($work_obj)) { #Helper::tad($work_obj); if (isset($work_obj->{$attr}) && is_numeric($work_obj->{$attr})) { /** * Заменяем ID изображений на объекты в обычных полях */ if (@$images[$work_obj->{$attr}]) { $tmp = $work_obj->{$attr}; $image = $images[$tmp]; $work_obj->setAttribute($attr, $image); } } elseif (isset($work_obj->allfields) && count($work_obj->allfields)) { /** * Заменяем ID изображений на объекты в i18n полях */ #Helper::tad($work_obj->allfields); $temp = $work_obj->allfields; foreach ($work_obj->allfields as $locale_sign => $locale_fields) { foreach ($locale_fields as $locale_key => $locale_value) { if ($locale_key == $attr) { #Helper::tad($locale_key . ' == ' . $attr); if (@$images[$temp[$locale_sign][$locale_key]]) { $temp[$locale_sign][$locale_key] = $images[$temp[$locale_sign][$locale_key]]; } } #Helper::tad($locale_key); } } $work_obj->allfields = $temp; } } } if ($field) { $obj->{$field} = $work_obj; #} else { # $obj = $work_obj; } if (is_object($collection)) { $collection->put($o, $obj); } else { $collection[$o] = $obj; } } } #dd($single_mode); if ($paginator_mode) { $paginator->setItems($collection); $collection = $paginator; } else { if ($single_mode) { $collection = $collection[0]; } } #Helper::tad($collection); #dd($collection); #var_dump($collection); #Helper::ta('<hr/>'); return $collection; }
/** * Display the specified resource. * GET /recettes/{id} * * @param int $id * @return Response */ public function show($id) { $recette = Recette::find($id); // On ajoute le pays pour la recette. $recette['country'] = array(); $countries = Country::where('id', '=', $recette['idPays'])->firstOrFail(); $recette['country'] = $countries->nom; // On ajoute les auteurs pour la recette. $recette['authors'] = array(); $listIdauthors = DB::table('link_recette_author')->where('idRecette', '=', $recette['id'])->lists('idAutheur'); // On recherche les id de tous les auteurs de la recette $autheurs = Autheur::whereIn('id', $listIdauthors)->lists('nom'); // on recherche tous les noms des auteurs de la recette. $recette['authors'] = $autheurs; // On ajoute les catégories pour la recette. $recette['categories'] = array(); $listIdcategories = DB::table('link_recette_categorie')->where('idRecette', '=', $recette['id'])->lists('idCategorie'); $categories = Categorie::whereIn('id', $listIdcategories)->lists('nom'); $recette['categories'] = $categories; // On ajoute les photos pour chaque recette. $recette['photos'] = array(); $listIdphotos = DB::table('link_recette_photo')->where('idRecette', '=', $recette['id'])->lists('idPhoto'); $photos = Photo::whereIn('id', $listIdphotos)->lists('nom'); $recette['photos'] = $photos; // On ajoute la liste de chaque categorie d'ingredients pour chaque recette. $recette['ingredients'] = array(); $listIdCategorieIngred = DB::table('link_recette_ingred')->where('idRecette', '=', $recette['id'])->distinct()->lists('idCategorie'); $listIdIngred = DB::table('link_recette_ingred')->where('idRecette', '=', $recette['id'])->lists('idIngredient'); $listQuantIngred = DB::table('link_recette_ingred')->where('idRecette', '=', $recette['id'])->lists('idQuantite'); $listOrdreIngred = DB::table('link_recette_ingred')->where('idRecette', '=', $recette['id'])->lists('Ordre'); // On met dans un tableau le nombre d'ingredient par categorie $listNbrIngrParCat = array(); foreach ($listIdCategorieIngred as $idCatIngre) { $listNbrIngrParCat[sizeof($listNbrIngrParCat)] = DB::table('link_recette_ingred')->where('idRecette', '=', $recette['id'])->where('idCategorie', '=', $idCatIngre)->distinct()->count(); } //On récupère le nom des catégories. $nomsCatIngredients = CategorieIngredient::whereIn('id', $listIdCategorieIngred)->lists('nom'); $ingredients = array(); foreach ($listIdIngred as $idIngredCurrent) { $ing = Ingredient::where('id', '=', $idIngredCurrent)->firstOrFail(); array_push($ingredients, $ing->nom); } $ingredientsFinal = array(); for ($j = 0; $j < sizeof($listIdCategorieIngred); $j++) { $ingredientsArray = array(); $offset = 0; // on a créé un décalage pour parcourir la lsite des ingrédients. if ($j != 0) { $offset = $listNbrIngrParCat[$j - 1]; } for ($i = 0 + $offset; $i < $listNbrIngrParCat[$j] + $offset; $i++) { $ingredientsArray[$i] = array('Ordre' => $listOrdreIngred[$i], 'Ingredient' => $ingredients[$i], 'lien' => ""); } $ingredientsFinal[$j] = array('Titre' => $nomsCatIngredients[$j], 'DetailsIngre' => $ingredientsArray); } $recette['ingredients'] = $ingredientsFinal; // On ajoute la liste de chaque categorie de préparations pour la recette. $recette['preparations'] = array(); $listIdCategoriePrepa = DB::table('link_recette_preparation')->where('idRecette', '=', $recette['id'])->distinct()->lists('idCatPrepa'); $listIdPhrasePrepa = DB::table('link_recette_preparation')->where('idRecette', '=', $recette['id'])->lists('idPhrasePrepa'); $listOrdrePhrase = DB::table('link_recette_preparation')->where('idRecette', '=', $recette['id'])->lists('Ordre'); // On met dans un tableau le nombre de phrase de préparation par categorie $listNbrPhraseParCat = array(); foreach ($listIdCategoriePrepa as $idCatPrepa) { $listNbrPhraseParCat[sizeof($listNbrPhraseParCat)] = DB::table('link_recette_preparation')->where('idRecette', '=', $recette['id'])->where('idCatPrepa', '=', $idCatPrepa)->distinct()->count(); } //On récupère le nom des catégories de préparation. $nomsCatPhrase = CategoriePrepa::whereIn('id', $listIdPhrasePrepa)->lists('nom'); $phrases = array(); foreach ($listIdPhrasePrepa as $idPhrasePrepaCurrent) { $phrase = PhrasePrepa::where('id', '=', $idPhrasePrepaCurrent)->firstOrFail(); array_push($phrases, $phrase->phrase); } $phrasesFinal = array(); for ($j = 0; $j < sizeof($listIdCategoriePrepa); $j++) { $phrasesArray = array(); $offset = 0; // on a créé un décalage pour parcourir la lsite des ingrédients. if ($j != 0) { $offset = $listNbrPhraseParCat[$j - 1]; } for ($i = 0 + $offset; $i < $listNbrPhraseParCat[$j] + $offset; $i++) { $phrasesArray[$i] = array('Ordre' => $listOrdrePhrase[$i], 'Phrase' => $phrases[$i]); } $phrasesFinal[$j] = array('Titre' => $nomsCatPhrase[$j], 'Phrases' => $phrasesArray); } $recette['preparations'] = $phrasesFinal; return Response::json($recette); }
<span class='btn btn-primary btn-sm save-image-data' data-photo-id='{{ $photo->id }}'>Сохранить</span> </div> </div>" data-image-title="{{ $photo->title }}" data-html="true"> <span class="photo-preview sortable_item" data-id="{{ $photo->id }}" style="background-image:url({{ URL::to($photo->thumb()) }});"> {{--<a href="{{ URL::to($photo->path()) }}" target="_blank" title="Полноразмерное изображение" style="display:block; height:100%; color:#090; background:transparent; display:none"></a>--}} <span href="#" class="photo-delete" data-photo-id="{{ $photo->id }}" style="">Удалить</span> </span> </a> @endforeach </div> @endif @endif </div> <div class="clear"></div> <? #/* if (isset($bad_photos) && is_array($bad_photos) && count($bad_photos) && Input::get('delete_bad_photos') == 1) { #Photo::whereIn('id', $bad_photos)->full_delete(); $photos = Photo::whereIn('id', $bad_photos)->get(); foreach ($photos as $photo) $photo->full_delete(); } #*/ ?>
public static function getPhotoByAlbum($checked_albums, $pagination = 30) { $album_ids = Album::getIdByName($checked_albums); return Photo::whereIn('album_id', $album_ids)->orderBy('id', 'desc')->paginate($pagination); }