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_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');
             }
         }
     }
     // return the result
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Удаление записи
  * 
  * @param int $id
  */
 public function action_delete($id = null)
 {
     is_null($id) and \Response::redirect_back('admin/videos');
     if ($video = \Model_Video::find($id)) {
         $video->delete();
         \Session::set_flash('success', 'Видео удалено.');
     } else {
         \Session::set_flash('error', 'Could not delete video #' . $id);
     }
     \Response::redirect_back('admin/videos');
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 /**
  * Delete content file
  * 
  * @param $video_id		= Video ID
  * @param $content_id	= Content ID
  */
 public function action_delete_video($video_id = false, $content_id = false)
 {
     if ($video_id && $content_id) {
         $videos = Model_Video::find(array('where' => array('content_id' => $content_id), 'order_by' => array('sort' => 'asc')), 'id');
         if ($videos) {
             if (isset($videos[$video_id])) {
                 $video = $videos[$video_id];
                 // If there is only one video and video is required
                 if (count($videos) == 1) {
                     if (\Config::get('details.video.required', false)) {
                         \Messages::error('You can\'t delete all videos. Please add new video in order to delete this one.');
                     } else {
                         // Reset sort fields
                         \DB::update(Model_Video::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $video->sort)->execute();
                         // Delete video
                         $this->delete_image($video->thumbnail, 'video');
                         $video->delete();
                         \Messages::success('Video was successfully deleted.');
                     }
                 } else {
                     // Reset sort fields
                     \DB::update(Model_Video::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $video->sort)->execute();
                     // Delete video
                     $this->delete_image($video->thumbnail, 'video');
                     $video->delete();
                     \Messages::success('Video was successfully deleted.');
                 }
             } else {
                 \Messages::error('Video you are trying to delete don\'t exists. Check your url and try again.');
             }
         } else {
             \Messages::error('Video you are trying to delete don\'t exists. Check your url and try again.');
         }
     }
     \Response::redirect(\Input::referrer(\Uri::create('admin/application/list')));
 }
Exemplo n.º 5
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 first content image
                 $item->get_image = static::lazy_load(function () use($item) {
                     if (!empty($item->images)) {
                         return $item->images[0];
                     }
                 }, $item->id, 'image', 'object');
                 // 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 parent
                 $item->get_parent = static::lazy_load(function () use($item) {
                     return Model_Page::find_one_by_id($item->parent_id);
                 }, $item->id, 'parent', 'object');
                 // Get content children
                 $item->get_children = static::lazy_load(function () use($item) {
                     return Model_Page::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');
             }
         }
     }
     // return the result
     return $result;
 }
Exemplo n.º 6
0
 /**
  * Действие для отображения слайдера
  */
 public function action_videos()
 {
     // Выбираем первых 5 слайдеров
     $data['videos'] = \Model_Video::find('all');
     return \View::forge('widgets/videos', $data)->render();
 }