Esempio n. 1
0
 public static function getFrontend($type)
 {
     $collections = self::with('mainImage')->where('type_id', $type)->take(8)->orderBy('order_no', 'asc')->get();
     $arrData = [];
     if (!$collections->isempty()) {
         foreach ($collections as $collection) {
             $image = null;
             if (isset($collection->main_image[0])) {
                 $image = $collection->main_image[0];
             } else {
                 $image = CollectionImage::select('images.id', 'images.short_name', 'images.name', 'image_details.ratio')->join('images', 'images.id', '=', 'collections_images.image_id')->join('image_details', 'image_details.image_id', '=', 'images.id')->where('collections_images.collection_id', $collection->id)->first();
             }
             if ($image) {
                 $image = ['id' => $image->id, 'short_name' => $image->short_name, 'name' => $image->name, 'ratio' => $image->ratio];
             } else {
                 $image = [];
             }
             $arrData[] = ['id' => $collection->id, 'name' => $collection->name, 'short_name' => $collection->short_name, 'image' => $image];
         }
     }
     return $arrData;
 }
 public function updateImage()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     $id = Input::has('id') ? Input::get('id') : 0;
     $image_id = Input::has('image_id') ? Input::get('image_id') : 0;
     $name = Input::has('name') ? Input::get('name') : '';
     $arrReturn = ['status' => 'error', 'message' => 'Collection was not existed.'];
     if ($id && $image_id) {
         try {
             $collection = Collection::findorFail($id);
         } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return App::abort(404);
         }
         $type = Input::has('type') ? Input::get('type') : '';
         $arrReturn = ['message' => 'Please do a valid type action. [Append, Delete]'];
         if (!empty($type)) {
             if ($type == 'append') {
                 $collection->images()->attach([$image_id]);
                 $arrReturn = ['status' => 'ok', 'message' => 'Image <b>' . $name . '</b> has been added to collection <b>' . $collection->name . '</b>.'];
             } else {
                 if ($type == 'delete') {
                     $collection->images()->detach([$image_id]);
                     $arrReturn = ['status' => 'ok', 'message' => 'Image <b>' . $name . '</b> has been removed from collection <b>' . $collection->name . '</b>.'];
                 } else {
                     if ($type == 'main') {
                         CollectionImage::where('collection_id', $id)->update(['collections_images.type' => NULL]);
                         $main = Input::get('main');
                         if ($main) {
                             CollectionImage::where('collection_id', $id)->where('image_id', $image_id)->update(['collections_images.type' => 'main']);
                             $arrReturn = ['status' => 'ok', 'message' => 'Image <b>' . $name . '</b> has been set as main Photo'];
                         } else {
                             $arrReturn = ['status' => 'ok', 'message' => 'Image <b>' . $name . '</b> has been unset as main Photo'];
                         }
                     }
                 }
             }
         }
     }
     return $arrReturn;
 }
 public function loadFeaturedLightbox()
 {
     $collections = Collection::select('id', 'name as collection_name', 'short_name as collection_short_name', 'order_no')->rightJoin('collections_images', 'collections_images.collection_id', '=', 'collections.id')->orderBy('order_no', 'desc')->groupBy('collections.id')->distinct()->take(10)->get()->toArray();
     foreach ($collections as $key => $value) {
         $image = CollectionImage::where('collection_id', '=', $value['id'])->where('collections_images.type', '=', 'main')->leftJoin('images', 'collections_images.image_id', '=', 'images.id')->leftJoin('image_details', 'image_details.image_id', '=', 'collections_images.image_id')->groupBy('collection_id')->get()->toArray();
         if (count($image) == 0) {
             $image = CollectionImage::where('collection_id', '=', $value['id'])->leftJoin('images', 'collections_images.image_id', '=', 'images.id')->leftJoin('image_details', 'image_details.image_id', '=', 'collections_images.image_id')->groupBy('collection_id')->get()->toArray();
         }
         $collections[$key]['image'] = count($image) > 0 ? $image[0] : array();
     }
     $arrFeaturedLightbox = array();
     if (count($collections)) {
         $i = 0;
         foreach ($collections as $value) {
             $arrFeaturedLightbox[$i]['collection_id'] = $value['id'];
             $arrFeaturedLightbox[$i]['collection_short_name'] = $value['collection_short_name'];
             $arrFeaturedLightbox[$i]['collection_name'] = $value['collection_name'];
             $arrFeaturedLightbox[$i]['path'] = '/pic/thumb/' . $value['image']['short_name'] . '-' . $value['image']['image_id'] . '.jpg';
             $arrFeaturedLightbox[$i]['width'] = $value['image']['width'];
             $arrFeaturedLightbox[$i]['height'] = $value['image']['height'];
             $i++;
         }
     }
     if (Request::ajax()) {
         $html = View::make('frontend.lightbox.featured-lightboxs')->with('arrFeaturedLightbox', $arrFeaturedLightbox)->render();
         $arrReturn = ['status' => 'ok', 'message' => '', 'html' => $html];
         $response = Response::json($arrReturn);
         $response->header('Content-Type', 'application/json');
         return $response;
     }
     return View::make('frontend.types.featured-collections')->with('arrFeaturedCollection', $arrFeaturedLightbox)->render();
 }