示例#1
0
 public function getChapters($published = NULL)
 {
     $chapterTbl = new Book_Model_DbTable_Chapters();
     $select = $chapterTbl->select()->where('work_id = ?', $this->getIdentity());
     if ($published != NULL) {
         $select->where('published = ?', $published);
     }
     return $chapterTbl->fetchAll($select);
 }
示例#2
0
 public function getOrder()
 {
     $id = $this->getIdentity();
     $workId = $this->work_id;
     if (!empty($id) && !empty($workId)) {
         $chapterTbl = new Book_Model_DbTable_Chapters();
         $chapterTblName = $chapterTbl->info('name');
         $select = $chapterTbl->select()->setIntegrityCheck(false)->from($chapterTblName, new Zend_Db_Expr('COUNT(chapter_id) AS ordering'))->where("{$chapterTblName}.work_id = ?", $this->work_id)->where("{$chapterTblName}.chapter_id < ?", $this->getIdentity());
         $data = $chapterTbl->fetchRow($select);
         if ($data) {
             return (int) $data->ordering + 1;
         }
     }
 }
示例#3
0
 public function editAction()
 {
     $this->_initActions();
     $subject = $this->_getSubject();
     $this->_checkSubject();
     $this->_checkAuthorization('view');
     $this->view->form = $form = new Book_Form_Work(array('workTitle' => 'Edit the work'));
     $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
     if (!$this->getRequest()->isPost()) {
         $values = $subject->toArray();
         $form->populate($values);
         return;
     }
     if ($form->isValid($this->getRequest()->getPost())) {
         $values = $form->getValues();
         $db = Engine_Db_Table::getDefaultAdapter();
         $db->beginTransaction();
         try {
             $preIsLong = $subject->is_long;
             $subject->setFromArray($values);
             $subject->save();
             if (!$subject->is_long && !$preIsLong) {
                 $chapter = $subject->getChapters()->current();
                 $chapter->content = $values['content'];
                 $chapter->save();
             } else {
                 $chapterTbl = new Book_Model_DbTable_Chapters();
                 $chapterTbl->delete(array('work_id = ?' => $subject->getIdentity()));
                 $chapter = $chapterTbl->createRow(array('title' => null, 'content' => trim($values['content']), 'work_id' => $subject->getIdentity(), 'published' => $subject->published));
                 $chapter->save();
             }
             if (!empty($values['photo'])) {
                 $subject->setPhoto($form->photo);
             }
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         if ($subject->published) {
             $actionTbl = Engine_Api::_()->getDbTable('actions', 'activity');
             $actions = $actionTbl->getActionsByObjectAndType($subject, 'work_new');
             if (empty($actions)) {
                 $action = $actionTbl->addActivity($viewer, $work, 'work_new');
             }
         }
         $this->_redirectCustom($subject);
     }
 }