Exemplo n.º 1
0
 public function treatGalleryAction()
 {
     $imageMapper = new ImageMapper();
     $pagination = new \Ilch\Pagination();
     $galleryMapper = new GalleryMapper();
     $id = $this->getRequest()->getParam('id');
     $galleryTitle = $galleryMapper->getGalleryById($id);
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('gallery'), array('action' => 'index'))->add($this->getTranslator()->trans($galleryTitle->getTitle()), array('action' => 'treatgallery', 'id' => $id));
     if ($this->getRequest()->getPost('action') == 'delete') {
         foreach ($this->getRequest()->getPost('check_gallery') as $imageId) {
             $imageMapper->deleteById($imageId);
         }
         $this->addMessage('deleteSuccess');
         $this->redirect(array('action' => 'treatgallery', 'id' => $id));
     }
     if ($this->getRequest()->getPost()) {
         foreach ($this->getRequest()->getPost('check_image') as $imageId) {
             $catId = $this->getRequest()->getParam('id');
             $model = new \Modules\Gallery\Models\Image();
             $model->setImageId($imageId);
             $model->setCat($catId);
             $imageMapper->save($model);
         }
     }
     $pagination->setPage($this->getRequest()->getParam('page'));
     $this->getView()->set('image', $imageMapper->getImageByGalleryId($id, $pagination));
     $this->getView()->set('pagination', $pagination);
     $this->getView()->set('galleryTitle', $galleryTitle->getTitle());
 }
Exemplo n.º 2
0
 public function showImageAction()
 {
     $commentMapper = new CommentMapper();
     $imageMapper = new ImageMapper();
     $galleryMapper = new GalleryMapper();
     $id = $this->getRequest()->getParam('id');
     $galleryId = $this->getRequest()->getParam('gallery');
     if ($this->getRequest()->getPost('saveComment')) {
         $date = new \Ilch\Date();
         $commentModel = new CommentModel();
         if ($this->getRequest()->getPost('fkId')) {
             $commentModel->setKey('gallery/index/showimage/gallery/' . $galleryId . '/id/' . $id . '/id_c/' . $this->getRequest()->getPost('fkId'));
             $commentModel->setFKId($this->getRequest()->getPost('fkId'));
         } else {
             $commentModel->setKey('gallery/index/showimage/gallery/' . $galleryId . '/id/' . $id);
         }
         $commentModel->setText($this->getRequest()->getPost('gallery_comment_text'));
         $commentModel->setDateCreated($date);
         $commentModel->setUserId($this->getUser()->getId());
         $commentMapper->save($commentModel);
     }
     $gallery = $galleryMapper->getGalleryById($galleryId);
     $comments = $commentMapper->getCommentsByKey('gallery/index/showimage/gallery/' . $galleryId . '/id/' . $id);
     $image = $imageMapper->getImageById($id);
     $model = new ImageModel();
     $model->setImageId($image->getImageId());
     $model->setVisits($image->getVisits() + 1);
     $imageMapper->saveVisits($model);
     $this->getLayout()->set('metaTitle', $this->getTranslator()->trans('gallery') . ' - ' . $this->getTranslator()->trans('image') . ' - ' . $image->getImageTitle());
     $this->getLayout()->set('metaDescription', $this->getTranslator()->trans('gallery') . ' - ' . $image->getImageDesc());
     $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuGalleryOverview'), array('action' => 'index'))->add($gallery->getTitle(), array('action' => 'show', 'id' => $galleryId))->add($image->getImageTitle(), array('action' => 'showimage', 'gallery' => $galleryId, 'id' => $id));
     $this->getView()->set('image', $imageMapper->getImageById($id));
     $this->getView()->set('comments', $comments);
 }
Exemplo n.º 3
0
 public function indexAction()
 {
     $galleryMapper = new GalleryMapper();
     $imageMapper = new ImageMapper();
     /*
      * 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 = $galleryMapper->getGalleryItems(1);
             /*
              * Deletes old entries from database.
              */
             if (!empty($oldItems)) {
                 foreach ($oldItems as $oldItem) {
                     if (!isset($items[$oldItem->getId()])) {
                         $galleryMapper->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) {
                     $galleryItem = new \Modules\Gallery\Models\GalleryItem();
                     if (strpos($item['id'], 'tmp_') !== false) {
                         $tmpId = str_replace('tmp_', '', $item['id']);
                     } else {
                         $galleryItem->setId($item['id']);
                     }
                     $galleryItem->setGalleryId(1);
                     $galleryItem->setType($item['type']);
                     $galleryItem->setTitle($item['title']);
                     $galleryItem->setDesc($item['desc']);
                     $newId = $galleryMapper->saveItem($galleryItem);
                     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) {
                     $galleryItem = new \Modules\Gallery\Models\GalleryItem();
                     $galleryItem->setId($id);
                     $galleryItem->setSort($sort);
                     $galleryItem->setParentId($parent);
                     $galleryMapper->saveItem($galleryItem);
                     $sort += 10;
                 }
             }
         }
         $this->addMessage('saveSuccess');
         $this->redirect(array('action' => 'index'));
     }
     $galleryItems = $galleryMapper->getGalleryItemsByParent(1, 0);
     $this->getView()->set('galleryItems', $galleryItems);
     $this->getView()->set('galleryMapper', $galleryMapper);
     $this->getView()->set('imageMapper', $imageMapper);
 }