Exemplo n.º 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_Infotab_Image::find(array('where' => array('infotab_id' => $item->unique_id), 'order_by' => array('sort' => 'asc')));
                 }, $item->unique_id, 'images');
                 // Get content files
                 $item->get_files = static::lazy_load(function () use($item) {
                     return Model_Infotab_File::find(array('where' => array('infotab_id' => $item->id, 'product_id' => $item->product_id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'files');
             }
         }
     }
     // return the result
     return $result;
 }
Exemplo n.º 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_Infotab_Image::find(array('where' => array('infotab_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->image = NULL;
                         $image->alt_text = NULL;
                     } else {
                         // Delete only video but not whole hotspot
                         $image->video = NULL;
                         $image->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_Infotab_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_Infotab_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());
         }
     }
 }