예제 #1
0
 /**
  * Get additional content data selected
  * 
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get content images
                 $item->get_images = static::lazy_load(function () use($item) {
                     return Model_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'images');
                 // Get content files
                 $item->get_files = static::lazy_load(function () use($item) {
                     return Model_File::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'files');
                 // Get content videos
                 $item->get_videos = static::lazy_load(function () use($item) {
                     return Model_Video::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'videos');
                 // Get content children
                 $item->get_children = static::lazy_load(function () use($item) {
                     return Model_Casestudy::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'children');
                 // Get content accordions
                 $item->get_accordions = static::lazy_load(function () use($item) {
                     return Model_Accordion::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'accordions');
                 // Get content children
                 $item->get_seo = static::lazy_load(function () use($item) {
                     return Model_Seo::find_one_by_content_id($item->id);
                 }, $item->id, 'seo', 'object');
                 // Get related products
                 $item->get_related_products = static::lazy_load(function () use($item) {
                     $related = Model_Application_To_Related::find(function ($query) use($item) {
                         return $query->where('application_id', $item->id);
                     }, 'related_id');
                     if (!empty($related)) {
                         $related = '(' . implode(',', array_keys($related)) . ')';
                         return \Product\Model_Product::find(function ($query) use($related, $item) {
                             $query->where('id', 'IN', \DB::expr($related));
                             $query->where('id', '<>', $item->id);
                             $query->order_by('sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'related_products');
                 // Get hotspot images
                 $item->get_hotspot = static::lazy_load(function () use($item) {
                     $return = new \stdClass();
                     $return->images = Model_Application_Image::find_by_application_id($item->id);
                     return $return;
                 }, $item->id, 'hotspot', 'object');
             }
         }
     }
     // return the result
     return $result;
 }
예제 #2
0
 /**
  * Delete content image
  * 
  * @param $image_id		= Image ID
  * @param $content_id	= Content ID
  * @param $type			= Type of content (infotab or hotspot)
  * @param $delete		= If type is "hotspot" we can either delete image or video
  */
 public function action_delete_infotab_image($image_id = false, $content_id = false, $type = 'infotab', $delete = 'image')
 {
     if ($image_id && $content_id) {
         $images = Model_Application_Image::find(array('where' => array('application_id' => $content_id), 'order_by' => array('sort' => 'asc')), 'id');
         if ($images) {
             if (isset($images[$image_id])) {
                 $image = $images[$image_id];
                 if (strtolower($type) == 'hotspot') {
                     // Delete only part of hotspot, either image or video
                     if ($delete == 'image') {
                         // Delete only image but not whole hotspot
                         $this->delete_infotab_image($image->image);
                         $image->set(array('image' => null, 'alt_text' => null));
                     } else {
                         // Delete only video but not whole hotspot
                         $image->set(array('video' => null, 'video_title' => null));
                     }
                     $image->save();
                     \Messages::success(ucfirst($type) . ' ' . strtolower($delete) . ' was successfully deleted.');
                 } else {
                     // If there is only one image and image is required
                     if (count($images) == 1) {
                         if (\Config::get('infotab.image.required', false) && !\Request::is_hmvc()) {
                             \Messages::error('You can\'t delete all images. Please add new image in order to delete this one.');
                         } else {
                             // Reset sort fields
                             \DB::update(Model_Application_Image::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $image->sort)->execute();
                             // Delete image
                             $this->delete_infotab_image($image->image);
                             $image->delete();
                             \Messages::success(ucfirst($type) . ' image was successfully deleted.');
                         }
                     } else {
                         if ($image->cover == 1 && !\Request::is_hmvc()) {
                             \Messages::error('You can\'t delete cover image. Set different image as cover in order to delete this one.');
                         } else {
                             // Reset sort fields
                             \DB::update(Model_Application_Image::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $image->sort)->execute();
                             // Delete image
                             $this->delete_infotab_image($image->image);
                             $image->delete();
                             \Messages::success(ucfirst($type) . ' image was successfully deleted.');
                         }
                     }
                 }
             } else {
                 \Messages::error(ucfirst($type) . ' image you are trying to delete don\'t exists. Check your url and try again.');
             }
         } else {
             \Messages::error(ucfirst($type) . ' image you are trying to delete don\'t exists. Check your url and try again.');
         }
     }
     if (\Input::is_ajax()) {
         \Messages::reset();
         \Messages::success('Hotspot was successfully deleted.');
         echo \Messages::display();
     } else {
         if (\Request::is_hmvc()) {
             \Messages::reset();
         } else {
             \Response::redirect(\Input::referrer());
         }
     }
 }