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 !'); } } } }