public function addAction()
 {
     $request = $this->getRequest();
     $form = new Application_Form_Megavideo();
     $form->setAction($this->_helper->url('add'));
     $isAjax = $request->getParam('isAjax', false);
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($request->getPost())) {
             $idVideo = $form->getValue('idVideo');
             @(list($idVideo, $type) = explode('_', $idVideo));
             if ($type == 'd') {
                 // this is a megaupload->megavideo file. I need to find the real id
                 $idVideo = $this->_getRealMegavideoId($idVideo);
             }
             $video = new Application_Model_Megavideo($form->getValues());
             $video->setIdVideo($idVideo);
             // Nel caso in cui sia un edit request
             if (!is_null($request->getParam('id', null))) {
                 $video->setId($request->getParam('id', null));
             }
             $mapper = Application_Model_MegavideoMapper::i();
             $mapper->save($video);
             if ($isAjax) {
                 header('Content-Type:text/plain');
                 echo '1';
                 $this->_helper->viewRenderer->setNoRender(true);
                 $this->_helper->layout->disableLayout();
                 return;
             } else {
                 //return $this->_helper->redirector('index');
                 $this->_helper->redirector('category', 'megavideo', 'default', array('id' => urlencode($video->getCategory())));
             }
         }
     }
     if ($isAjax) {
         header('Content-Type:text/plain');
         echo '0';
         $this->_helper->viewRenderer->setNoRender(true);
         $this->_helper->layout->disableLayout();
     } else {
         $this->view->form = $form;
     }
 }
 public function fetchByCategory($categoryName)
 {
     $resultSet = $this->getDbTable()->fetchAll('category LIKE "' . $categoryName . '"');
     $entries = array();
     foreach ($resultSet as $row) {
         $entry = new Application_Model_Megavideo();
         $entry->setId($row->id)->setDescription($row->description)->setLabel($row->label)->setCategory($row->category)->setIdVideo($row->idVideo);
         $entries[] = $entry;
     }
     return $entries;
 }
 /**
  * Restore backupped videos 
  * This is not a trigger of plugin API. It's called by Backupper plugin
  */
 function restoreItems($items)
 {
     //return parent::restoreItems($items);
     $models = Application_Model_MegavideoMapper::i()->fetchAll();
     // cleaning up all shares
     foreach ($models as $model) {
         Application_Model_MegavideoMapper::i()->delete($model->getId());
     }
     foreach (@$items['videos'] as $modelInfo) {
         $model = new Application_Model_Megavideo();
         $model->setIdVideo(@$modelInfo['idVideo'])->setDescription(@$modelInfo['description'])->setCategory(@$modelInfo['category'])->setLabel(@$modelInfo['label']);
         // i don't set id, or db adapter will try to update old data that i cleaned
         Application_Model_MegavideoMapper::i()->directSave($model);
     }
     return X_Env::_('p_megavideo_backupper_restoreditems') . ": " . count($items['videos']);
 }