Ejemplo n.º 1
0
 public function showFileAction()
 {
     $commentMapper = new CommentMapper();
     $fileMapper = new FileMapper();
     $downloadsMapper = new DownloadsMapper();
     $id = $this->getRequest()->getParam('id');
     $downloadsId = $this->getRequest()->getParam('downloads');
     if ($this->getRequest()->getPost('downloads_comment_text')) {
         $commentModel = new CommentModel();
         $commentModel->setKey('downloads/index/showfile/downloads/' . $downloadsId . '/id/' . $id);
         $commentModel->setText($this->getRequest()->getPost('downloads_comment_text'));
         $date = new \Ilch\Date();
         $commentModel->setDateCreated($date);
         $commentModel->setUserId($this->getUser()->getId());
         $commentMapper->save($commentModel);
     }
     $downloads = $downloadsMapper->getDownloadsById($downloadsId);
     $comments = $commentMapper->getCommentsByKey('downloads/index/showfile/downloads/' . $downloadsId . '/id/' . $id);
     $file = $fileMapper->getFileById($id);
     $model = new FileModel();
     $model->setFileId($file->getFileId());
     $model->setVisits($file->getVisits() + 1);
     $fileMapper->saveVisits($model);
     $this->getLayout()->set('metaTitle', $this->getTranslator()->trans('downloads') . ' - ' . $this->getTranslator()->trans('file') . ' - ' . $file->getFileTitle());
     $this->getLayout()->set('metaDescription', $this->getTranslator()->trans('downloads') . ' - ' . $file->getFileDesc());
     $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuDownloadsOverview'), array('action' => 'index'))->add($downloads->getTitle(), array('action' => 'show', 'id' => $downloadsId))->add($file->getFileTitle(), array('action' => 'showfile', 'downloads' => $downloadsId, 'id' => $id));
     $this->getView()->set('file', $fileMapper->getFileById($id));
     $this->getView()->set('comments', $comments);
 }
Ejemplo n.º 2
0
 public function treatDownloadsAction()
 {
     $fileMapper = new FileMapper();
     $pagination = new \Ilch\Pagination();
     $downloadsMapper = new DownloadsMapper();
     $id = $this->getRequest()->getParam('id');
     $downloadsTitle = $downloadsMapper->getDownloadsById($id);
     if ($this->getRequest()->getPost('action') == 'delete') {
         foreach ($this->getRequest()->getPost('check_downloads') as $fileId) {
             $fileMapper->deleteById($fileId);
         }
         $this->addMessage('deleteSuccess');
         $this->redirect(array('action' => 'treatdownloads', 'id' => $id));
     }
     if ($this->getRequest()->getPost()) {
         foreach ($this->getRequest()->getPost('check_image') as $fileId) {
             $catId = $this->getRequest()->getParam('id');
             $model = new \Modules\Downloads\Models\File();
             $model->setFileId($fileId);
             $model->setCat($catId);
             $fileMapper->save($model);
         }
     }
     $pagination->setPage($this->getRequest()->getParam('page'));
     $this->getView()->set('file', $fileMapper->getFileByDownloadsId($id, $pagination));
     $this->getView()->set('pagination', $pagination);
     $this->getView()->set('downloadsTitle', $downloadsTitle->getTitle());
 }
Ejemplo n.º 3
0
 public function indexAction()
 {
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('downloads'), array('action' => 'index'));
     $downloadsMapper = new DownloadsMapper();
     $fileMapper = new FileMapper();
     /*
      * Saves the item tree to database.
      */
     if ($this->getRequest()->isPost()) {
         if ($this->getRequest()->getPost('save')) {
             $sortItems = json_decode($this->getRequest()->getPost('hiddenMenu'));
             $items = $this->getRequest()->getPost('items');
             $oldItems = $downloadsMapper->getDownloadsItems(1);
             /*
              * Deletes old entries from database.
              */
             if (!empty($oldItems)) {
                 foreach ($oldItems as $oldItem) {
                     if (!isset($items[$oldItem->getId()])) {
                         $downloadsMapper->deleteItem($oldItem);
                     }
                 }
             }
             if ($items) {
                 $sortArray = array();
                 foreach ($sortItems as $sortItem) {
                     if ($sortItem->item_id !== null) {
                         $sortArray[$sortItem->item_id] = (int) $sortItem->parent_id;
                     }
                 }
                 foreach ($items as $item) {
                     $downloadsItem = new \Modules\Downloads\Models\DownloadsItem();
                     if (strpos($item['id'], 'tmp_') !== false) {
                         $tmpId = str_replace('tmp_', '', $item['id']);
                     } else {
                         $downloadsItem->setId($item['id']);
                     }
                     $downloadsItem->setDownloadsId(1);
                     $downloadsItem->setType($item['type']);
                     $downloadsItem->setTitle($item['title']);
                     $downloadsItem->setDesc($item['desc']);
                     $newId = $downloadsMapper->saveItem($downloadsItem);
                     if (isset($tmpId)) {
                         foreach ($sortArray as $id => $parentId) {
                             if ($id == $tmpId) {
                                 unset($sortArray[$id]);
                                 $sortArray[$newId] = $parentId;
                             }
                             if ($parentId == $tmpId) {
                                 $sortArray[$id] = $newId;
                             }
                         }
                     }
                 }
                 $sort = 0;
                 foreach ($sortArray as $id => $parent) {
                     $downloadsItem = new \Modules\Downloads\Models\DownloadsItem();
                     $downloadsItem->setId($id);
                     $downloadsItem->setSort($sort);
                     $downloadsItem->setParentId($parent);
                     $downloadsMapper->saveItem($downloadsItem);
                     $sort += 10;
                 }
             }
         }
         $this->addMessage('saveSuccess');
         $this->redirect(array('action' => 'index'));
     }
     $downloadsItems = $downloadsMapper->getDownloadsItemsByParent(1, 0);
     $this->getView()->set('downloadsItems', $downloadsItems);
     $this->getView()->set('downloadsMapper', $downloadsMapper);
     $this->getView()->set('fileMapper', $fileMapper);
 }