/**
  * Return singleton
  * @return Application_Model_YoutubeVideosMapper
  */
 public static function i()
 {
     if (self::$instance === null) {
         self::$instance = new Application_Model_YoutubeVideosMapper();
     }
     return self::$instance;
 }
 function dvideoAction()
 {
     $videoId = $this->getRequest()->getParam('idVideo', false);
     if ($videoId != false && $videoId != null && $videoId != '') {
         $video = new Application_Model_YoutubeVideo();
         Application_Model_YoutubeVideosMapper::i()->find($videoId, $video);
         if ($videoId == $video->getId()) {
             $idCategory = $video->getIdCategory();
             try {
                 Application_Model_YoutubeVideosMapper::i()->delete($video);
                 $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_delete_completed_video'), 'type' => 'info'));
             } catch (Exception $e) {
                 $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_delete_err_dberror') . ": {$e->getMessage()}", 'type' => 'error'));
             }
             $this->_helper->redirector('category', 'youtube', 'default', array('idCategory' => $idCategory));
         } else {
             $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_delete_invaliddata'), 'type' => 'error'));
         }
     }
     $this->_helper->redirector('index', 'youtube');
 }
 protected function libraryMenu(X_Page_ItemList_PItem $items, $submode = false)
 {
     X_Debug::i("Submode requested: " . print_r($submode, true));
     // disabling cache plugin
     try {
         $cachePlugin = X_VlcShares_Plugins::broker()->getPlugins('cache');
         if (method_exists($cachePlugin, 'setDoNotCache')) {
             $cachePlugin->setDoNotCache();
         }
     } catch (Exception $e) {
         // cache plugin not registered, no problem
     }
     if ($submode === false || $submode == null) {
         // load all categories in the library
         $categories = Application_Model_YoutubeCategoriesMapper::i()->fetchAll();
         foreach ($categories as $category) {
             /* @var $category Application_Model_YoutubeCategory */
             $item = new X_Page_Item_PItem('youtube-category-' . $category->getId(), $category->getLabel());
             $item->setThumbnail($category->getThumbnail())->setIcon('/images/youtube/icons/category.png')->setCustom(__CLASS__ . ':location', self::MODE_LIBRARY . "/" . $category->getId())->setLink(array('l' => X_Env::encode(self::MODE_LIBRARY . "/" . $category->getId())), 'default', false)->setGenerator(__CLASS__);
             $items->append($item);
         }
     } else {
         // load all video inside a category categories
         /* @var $category Application_Model_YoutubeCategory */
         $category = new Application_Model_YoutubeCategory();
         Application_Model_YoutubeCategoriesMapper::i()->find($submode, $category);
         X_Debug::i('Category found: ' . print_r($category, true));
         if ($category->getId() != null && $category->getId() == $submode) {
             $videos = Application_Model_YoutubeVideosMapper::i()->fetchByCategory($category->getId());
             foreach ($videos as $video) {
                 /* @var $video Application_Model_YoutubeVideo */
                 $item = new X_Page_Item_PItem('youtube-library-' . $video->getId(), $video->getLabel());
                 $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setIcon('/images/youtube/icons/video.png')->setDescription($video->getDescription())->setThumbnail($video->getThumbnail())->setCustom(__CLASS__ . ':location', self::MODE_LIBRARY . "/" . $category->getId() . "/0/" . $video->getId())->setLink(array('action' => 'mode', 'l' => X_Env::encode(self::MODE_LIBRARY . "/" . $category->getId() . "/0/" . $video->getId())), 'default', false)->setGenerator(__CLASS__);
                 $items->append($item);
             }
         }
     }
 }