Example #1
0
 public function indexAction()
 {
     if (!Engine_Api::_()->core()->hasSubject()) {
         return $this->setNoRender();
     }
     $subject = Engine_Api::_()->core()->getSubject();
     if ($subject->getType() == 'user' && $subject->level_id == Book_Plugin_Constants::AUTHOR_LEVEL) {
         $bookTable = new Book_Model_DbTable_Books();
         $bookTableName = $bookTable->info('name');
         $bookSelect = $bookTable->getSelect();
         $bookAuthorTable = new Book_Model_DbTable_BookAuthor();
         $bookAuthorTableName = $bookAuthorTable->info('name');
         $bookSelect->join($bookAuthorTableName, "{$bookTableName}.book_id = {$bookAuthorTableName}.book_id");
         $bookSelect->where("{$bookAuthorTableName}.author_id = ?", $subject->getIdentity());
         $bookSelect->order('RAND()');
         $this->view->paginator = $paginator = Zend_Paginator::factory($bookSelect);
         $paginator->setItemCountPerPage($this->_getParam('itemCountPerPage', 5));
         $paginator->setCurrentPageNumber($this->_getParam('page', 1));
         $itemCount = $paginator->getTotalItemCount();
         if ($itemCount == 0) {
             return $this->setNoRender();
         } else {
             $this->_childCount = $paginator->getTotalItemCount();
             $paginator->setItemCountPerPage($this->_getParam('itemCountPerPage', 10));
             $paginator->setCurrentPageNumber($this->_getParam('page', 1));
         }
     } else {
         return $this->setNoRender();
     }
 }
Example #2
0
 public function getSelect($selectedColumns = null)
 {
     $select = parent::getSelect($selectedColumns);
     $tableName = $this->info(Zend_Db_Table_Abstract::NAME);
     $bookAuthorTable = new Book_Model_DbTable_BookAuthor();
     $bookAuthorTableName = $bookAuthorTable->info(Zend_Db_Table_Abstract::NAME);
     //         $select->joinLeft(
     //                 $bookAuthorTableName,
     //                 "$tableName.book_id = $bookAuthorTableName.book_id",
     //                 array('GROUP_CONCAT(author_id) As author_ids', 'GROUP_CONCAT(author_name) As author_names')
     //         );
     //         $select->where("$bookAuthorTableName.type = ?", Book_Plugin_Constants::AUTHOR);
     $bookAuthorSelect = $bookAuthorTable->select()->from($bookAuthorTableName, array(new Zend_Db_Expr('GROUP_CONCAT(author_id) As author_ids', 'GROUP_CONCAT(author_name) As author_names')))->where("{$bookAuthorTableName}.type = ?", Book_Plugin_Constants::AUTHOR);
     $select->columns(new Zend_Db_Expr('(' . $bookAuthorSelect->assemble() . ')'));
     return $select;
 }
Example #3
0
 public function indexAction()
 {
     $userTable = Engine_Api::_()->getItemTable('user');
     $userTableName = $userTable->info('name');
     $bookAuthorTable = new Book_Model_DbTable_BookAuthor();
     $bookAuthorTableName = $bookAuthorTable->info('name');
     $userSelect = $userTable->select()->from($userTableName);
     $userSelect->setIntegrityCheck(false);
     $userSelect->join($bookAuthorTableName, "{$bookAuthorTableName}.author_id = {$userTableName}.user_id", array("COUNT(*) AS num_books"));
     $userSelect->group(array("{$userTableName}.user_id"));
     $userSelect->where("{$userTableName}.level_id = ?", Book_Plugin_Constants::AUTHOR_LEVEL);
     $userSelect->where("{$userTableName}.enabled = ?", 1);
     $userSelect->where("{$userTableName}.verified = ?", 1);
     $userSelect->where("{$userTableName}.approved = ?", 1);
     $numberOfAuthors = $this->_getParam('itemCountPerPage', 5);
     $userSelect->order('RAND()');
     $userSelect->limit($numberOfAuthors);
     $this->view->authors = $users = $userTable->fetchAll($userSelect);
 }
Example #4
0
 protected function _postDelete()
 {
     parent::_postDelete();
     $bookPhotoTbl = new Book_Model_DbTable_Photos();
     $bookPhotoTbl->delete(array('parent_object_type = ?' => $this->getType(), 'parent_object_id = ?' => $this->getIdentity()));
     $bookAuthorTbl = new Book_Model_DbTable_BookAuthor();
     $bookAuthorTbl->delete(array('book_id = ?' => $this->getIdentity()));
     $bookFavTbl = new Book_Model_DbTable_Favorites();
     $bookFavTbl->delete(array('parent_object_type = ?' => $this->getType(), 'parent_object_id = ?' => $this->getIdentity()));
     $bookPostTbl = new Book_Model_DbTable_Posts();
     $bookPostTbl->update(array('parent_id' => NULL, 'parent_type' => NULL), array('parent_id = ?' => $this->getIdentity(), 'parent_type = ?' => $this->getType()));
     $bookRatingTbl = new Book_Model_DbTable_Ratings();
     $bookRatingTbl->delete(array('parent_object_type = ?' => $this->getType(), 'parent_object_id = ?' => $this->getIdentity()));
     $popularityTbl = new Book_Model_DbTable_Popularities();
     $popularity = $popularityTbl->delete(array('resource_id = ?' => $this->getIdentity(), 'resource_type = ?' => $this->getType()));
 }
Example #5
0
 public function createAction()
 {
     if (!$this->_helper->requireUser()->isValid()) {
         return;
     }
     $viewer = Engine_Api::_()->user()->getViewer();
     $this->view->form = $form = new Book_Form_Book(array('bookTitle' => 'Post a book'));
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $values = $form->getValues();
     $bookTable = new Book_Model_DbTable_Books();
     $bookAuthorTable = new Book_Model_DbTable_BookAuthor();
     $db = Engine_Db_Table::getDefaultAdapter();
     $db->beginTransaction();
     try {
         $book = $bookTable->createRow($values);
         $book->creation_date = date('Y-m-d H:i:s');
         $book->modified_date = $book->creation_date;
         $book->category_id = $this->_getParam('category_id_0', 0);
         $book->user_id = $viewer->getIdentity();
         $book->save();
         if (!empty($values['photo'])) {
             try {
                 $book = $book->setPhoto($form->photo);
                 $photoTable = new Book_Model_DbTable_Photos();
                 $photo = $photoTable->createRow(array('parent_object_id' => $book->getIdentity(), 'parent_object_type' => $book->getType(), 'file_id' => $book->photo_id, 'user_id' => $viewer->getIdentity(), 'approved' => 1, 'default' => 1));
                 $photo->save();
             } catch (Engine_Image_Adapter_Exception $e) {
                 Zend_Registry::get('Zend_Log')->log($e->__toString(), Zend_Log::WARN);
             }
         }
         $authorIds = explode(',', $values['toValues']);
         if (!empty($authorIds)) {
             foreach ($authorIds as $authorId) {
                 if (!empty($authorId)) {
                     $bookAuthor = $bookAuthorTable->createRow();
                     $bookAuthor->book_id = $book->getIdentity();
                     $bookAuthor->author_id = $authorId;
                     $bookAuthor->save();
                 }
             }
         }
         $authorsName = explode(',', $values['authors']);
         foreach ($authorsName as $name) {
             if (!empty($name)) {
                 $bookAuthor = $bookAuthorTable->createRow();
                 $bookAuthor->book_id = $book->getIdentity();
                 $bookAuthor->author_id = 0;
                 $bookAuthor->author_name = $name;
                 $bookAuthor->save();
             }
         }
         if ($book->is_foreign && !empty($values['toTranslatorsValues'])) {
             $translatorIds = explode(',', $values['toTranslatorsValues']);
             if (!empty($translatorIds)) {
                 foreach ($translatorIds as $translatorId) {
                     if (!empty($translatorId)) {
                         $bookAuthor = $bookAuthorTable->createRow();
                         $bookAuthor->book_id = $book->getIdentity();
                         $bookAuthor->author_id = $translatorId;
                         $bookAuthor->type = Book_Plugin_Constants::TRANSLATOR;
                         $bookAuthor->save();
                     }
                 }
             }
             $translatorsName = explode(',', $values['translators']);
             foreach ($translatorsName as $name) {
                 if (!empty($name)) {
                     $bookAuthor = $bookAuthorTable->createRow();
                     $bookAuthor->book_id = $book->getIdentity();
                     $bookAuthor->author_id = 0;
                     $bookAuthor->author_name = $name;
                     $bookAuthor->type = Book_Plugin_Constants::TRANSLATOR;
                     $bookAuthor->save();
                 }
             }
         }
         // CREATE AUTH STUFF HERE
         $auth = Engine_Api::_()->authorization()->context;
         $roles = array('owner', 'parent_member', 'registered', 'everyone');
         foreach ($roles as $i => $role) {
             $auth->setAllowed($book, $role, 'view', true);
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     $actionTbl = Engine_Api::_()->getDbTable('actions', 'activity');
     $action = $actionTbl->addActivity($viewer, $book, 'book_new');
     if ($action != null) {
         $actionTbl->attachActivity($action, $book);
     }
     $this->_redirectCustom($book->getHref());
 }
Example #6
0
 public function createBookAction()
 {
     if (!$this->_helper->requireUser()->isValid()) {
         return;
     }
     $viewer = Engine_Api::_()->user()->getViewer();
     $this->view->form = $form = new Book_Form_Book_Create();
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $values = $form->getValues();
     $bookTable = new Book_Model_DbTable_Books();
     $bookAuthorTable = new Book_Model_DbTable_BookAuthor();
     $db = Engine_Db_Table::getDefaultAdapter();
     $db->beginTransaction();
     try {
         $book = $bookTable->createRow($values);
         $book->creation_date = date('Y-m-d H:i:s');
         $book->modified_date = $book->creation_date;
         $book->category_id = $this->_getParam('category_id_0', 0);
         $book->user_id = $viewer->getIdentity();
         $book->save();
         if (!empty($values['photo'])) {
             try {
                 $book->setPhoto($form->photo);
                 $bookPhotoTable = new Book_Model_DbTable_Photos();
                 $bookPhoto = $bookPhotoTable->createRow(array('parent_type' => $book->getType(), 'parent_id' => $book->getIdentity(), 'file_id' => $book->photo_id, 'approved' => 1, 'default' => 1));
                 $bookPhoto->save();
             } catch (Engine_Image_Adapter_Exception $e) {
                 Zend_Registry::get('Zend_Log')->log($e->__toString(), Zend_Log::WARN);
             }
         }
         $authorIds = explode(',', $values['toValues']);
         foreach ($authorIds as $authorId) {
             $bookAuthor = $bookAuthorTable->createRow();
             $bookAuthor->book_id = $book->getIdentity();
             $bookAuthor->author_id = $authorId;
             $bookAuthor->save();
         }
         $photoTbl = new Book_Model_DbTable_Photos();
         $photo = $photoTbl->createRow(array('parent_object_type' => $book->getType(), 'parent_object_id' => $book->getIdentity(), 'file_id' => $book->photo_id, 'user_id' => $viewer->getIdentity(), 'default' => 1, 'approved' => 1));
         $photo->save();
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     $this->_redirectCustom($book->getHref());
 }