Exemple #1
0
 /**
  * Gets all gallery items by gallery id.
  */
 public function getGalleryItems($galleryId)
 {
     $items = array();
     $itemRows = $this->db()->select('*')->from('users_gallery_items')->where(array('gallery_id' => $galleryId))->order(array('sort' => 'ASC'))->execute()->fetchRows();
     if (empty($itemRows)) {
         return null;
     }
     foreach ($itemRows as $itemRow) {
         $itemModel = new GalleryItem();
         $itemModel->setId($itemRow['id']);
         $itemModel->setUserId($itemRow['user_id']);
         $itemModel->setType($itemRow['type']);
         $itemModel->setTitle($itemRow['title']);
         $itemModel->setDesc($itemRow['description']);
         $itemModel->setParentId($itemRow['parent_id']);
         $itemModel->setGalleryId($galleryId);
         $items[] = $itemModel;
     }
     return $items;
 }
Exemple #2
0
 public function galleryAction()
 {
     $galleryMapper = new GalleryMapper();
     $imageMapper = new GalleryImageMapper();
     $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuPanel'), array('controller' => 'panel', 'action' => 'index'))->add($this->getTranslator()->trans('menuGallery'), array('controller' => 'panel', 'action' => 'gallery'));
     /*
      * Saves the item tree to database.
      */
     if ($this->getRequest()->getPost('saveGallery')) {
         $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 GalleryItemModel();
                 if (strpos($item['id'], 'tmp_') !== false) {
                     $tmpId = str_replace('tmp_', '', $item['id']);
                 } else {
                     $galleryItem->setId($item['id']);
                 }
                 $galleryItem->setGalleryId(1);
                 $galleryItem->setUserId($this->getUser()->getId());
                 $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 GalleryItemModel();
                 $galleryItem->setId($id);
                 $galleryItem->setSort($sort);
                 $galleryItem->setParentId($parent);
                 $galleryMapper->saveItem($galleryItem);
                 $sort += 10;
             }
         }
         $this->addMessage('saveSuccess');
         $this->redirect(array('action' => 'gallery'));
     }
     $this->getView()->set('galleryItems', $galleryMapper->getGalleryItemsByParent($this->getUser()->getId(), 1, 0));
     $this->getView()->set('galleryMapper', $galleryMapper);
     $this->getView()->set('imageMapper', $imageMapper);
 }