public function indexAction() { $this->view->book = $subject = Engine_Api::_()->core()->getSubject(); $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer(); if ($viewer->isAdmin() || $subject->isBookAuthor($viewer) || $subject->user_id == $viewer->getIdentity()) { $photoTbl = new Book_Model_DbTable_Photos(); $select = $photoTbl->select()->where('parent_object_type = ?', $subject->getType())->where('parent_object_id = ?', $subject->getIdentity()); $this->view->photos = $photos = $photoTbl->fetchAll($select); return; } return $this->setNoRender(); }
public function deletePhotoAction() { $book = $this->_getBook(); if (isset($book) && is_object($book)) { $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer(); $authors = $book->getAuthors(); $allowDelete = false; if ($viewer->isAdmin() || $viewer->getIdentity() != $book->user_id) { $allowDelete = true; } else { foreach ($authors as $author) { if ($viewer->isSelf($author)) { $allowDelete = true; } } } if ($allowDelete) { $photoId = $this->_getParam('photo_id'); if ($photoId) { $db = Engine_Db_Table::getDefaultAdapter(); $db->beginTransaction(); try { $photoTbl = new Book_Model_DbTable_Photos(); $select = $photoTbl->select()->where("photo_id = ?", $photoId); $photo = $photoTbl->fetchRow($select); $photo->delete(); $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } $this->view->status = 1; $this->view->message = Zend_Registry::get('Zend_Translate')->_('The photo is deleted successfully !'); } } } }
public function getAllApprovedPhotos() { $photoTbl = new Book_Model_DbTable_Photos(); $select = $photoTbl->select(); $select->where("parent_object_type = ?", $this->getType())->where("parent_object_id = ?", $this->getIdentity())->where("approved = ?", 1); $select->order('default DESC'); $photos = array(); $storageApi = Engine_Api::_()->storage(); foreach ($photoTbl->fetchAll($select) as $photo) { $file = $storageApi->get($photo->file_id); if (!empty($file)) { array_push($photos, $file->storage_path); } } return $photos; }