public function setDefaultPhotoAction() { $book = $this->_getBook(); if (isset($book) && is_object($book)) { $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer(); //$authors = $book->getAuthors(Book_Plugin_Constants::AUTHOR, TRUE); $concernedUsers = $book->getConcernedUsers(); $allowSetDefault = false; if ($viewer->isAdmin() || $viewer->getIdentity() == $book->user_id) { $allowSetDefault = true; } else { foreach ($concernedUsers as $u) { if ($viewer->isSelf($u)) { $allowSetDefault = true; } } } if ($allowSetDefault) { $photoId = $this->_getParam('photo_id'); if ($photoId) { $db = Engine_Db_Table::getDefaultAdapter(); $db->beginTransaction(); try { $photoTbl = new Book_Model_DbTable_Photos(); $photoTbl->update(array('default' => 0), array('parent_object_id = ?' => $book->getIdentity(), 'parent_object_type = ?' => $book->getType())); $select = $photoTbl->select()->where("photo_id = ?", $photoId); $photo = $photoTbl->fetchRow($select); $photo->default = 1; $photo->save(); $book->photo_id = $photo->file_id; $book->save(); $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } $this->view->status = 1; $this->view->message = Zend_Registry::get('Zend_Translate')->_('The photo is set as default successfully !'); } } } }