public function deletesAction()
 {
     // In smoothbox
     $this->_helper->layout->setLayout('admin-simple');
     if ($this->getRequest()->isPost()) {
         $ids = $this->_getParam('id');
         $bookTbl = new Book_Model_DbTable_Books();
         if (!empty($ids) && is_array($ids)) {
             $bookSelect = $bookTbl->getSelect();
             $bookSelect->where('book_id IN (?)', $ids);
             $books = $bookTbl->fetchAll($bookSelect);
             $db = Engine_Db_Table::getDefaultAdapter();
             $db->beginTransaction();
             try {
                 foreach ($books as $book) {
                     $book->delete();
                 }
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollBack();
                 throw $e;
             }
             return $this->_forward('success', 'utility', 'core', array('layout' => 'default-simple', 'parentRefresh' => true, 'messages' => array(Zend_Registry::get('Zend_Translate')->_('The books are deleted successfully.'))));
         }
     }
 }
Exemple #2
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();
     }
 }
Exemple #3
0
 public function indexAction()
 {
     $request = Zend_Controller_Front::getInstance()->getRequest();
     if ($request->isPost()) {
         $this->getElement()->clearDecorators();
     }
     $bookTable = new Book_Model_DbTable_Books();
     $bookTableName = $bookTable->info(Zend_Db_Table_Abstract::NAME);
     $bookSelect = $bookTable->getSelect();
     $popularityTbl = new Book_Model_DbTable_Popularities();
     $popularityTblName = $popularityTbl->info(Zend_Db_Table_Abstract::NAME);
     $bookSelect->joinLeft($popularityTblName, "{$popularityTblName}.resource_id = {$bookTableName}.book_id", array("{$popularityTblName}.point"));
     $bookSelect->where("{$popularityTblName}.resource_type = ?", 'book');
     $bookSelect->order("{$popularityTblName}.point DESC");
     $bookSelect->order("{$popularityTblName}.posted_date DESC");
     $this->view->paginator = $paginator = Zend_Paginator::factory($bookSelect);
     if ($paginator->getTotalItemCount() == 0) {
         return $this->setNoRender();
     }
     $itemCountPerPage = $this->_getParam('itemCountPerPage', 12);
     if (empty($itemCountPerPage)) {
         $itemCountPerPage = 12;
     }
     $paginator->setItemCountPerPage($itemCountPerPage);
     $paginator->setCurrentPageNumber($this->_getParam('page', 1));
     $this->view->viewInfo = $this->_getParam('viewInfo');
 }
Exemple #4
0
 public function indexAction()
 {
     $request = Zend_Controller_Front::getInstance()->getRequest();
     if ($request->isPost()) {
         $this->getElement()->clearDecorators();
     }
     $numberOfBooks = $this->_getParam('itemCountPerPage', 12);
     $bookTable = new Book_Model_DbTable_Books();
     $bookSelect = $bookTable->getSelect();
     $bookSelect->limit($numberOfBooks);
     $bookSelect->order('RAND()');
     $this->view->paginator = $paginator = Zend_Paginator::factory($bookSelect);
     if ($paginator->getTotalItemCount() == 0) {
         return $this->setNoRender();
     }
     if ($paginator->getTotalItemCount() == 0) {
         return $this->setNoRender();
     }
     $itemCountPerPage = $this->_getParam('itemCountPerPage', 12);
     if (empty($itemCountPerPage)) {
         $itemCountPerPage = 12;
     }
     $paginator->setItemCountPerPage($itemCountPerPage);
     $paginator->setCurrentPageNumber($this->_getParam('page', 1));
 }
Exemple #5
0
 public function indexAction()
 {
     $numberOfBooks = $this->_getParam('itemCountPerPage', 5);
     $bookTable = new Book_Model_DbTable_Books();
     $bookSelect = $bookTable->getSelect();
     $bookSelect->limit($numberOfBooks);
     $bookSelect->order('RAND()');
     $this->view->books = $books = $bookTable->fetchAll($bookSelect);
 }
Exemple #6
0
 public function getBookFromBookLinkId($bookLinkId)
 {
     $bookTbl = new Book_Model_DbTable_Books();
     $bookTblName = $bookTbl->info(Zend_Db_Table_Abstract::NAME);
     $rawBookTblName = $this->info(Zend_Db_Table_Abstract::NAME);
     $bookSelect = $bookTbl->select()->setIntegrityCheck(false);
     $bookSelect->join($rawBookTblName, "{$bookTblName}.rawbook_id = {$rawBookTblName}.rawbook_id");
     $bookSelect->where("{$rawBookTblName}.link_id=?", $bookLinkId);
     return $bookTbl->fetchRow($bookSelect);
 }
Exemple #7
0
 public function getNewestBooks($limit, $params = NULL)
 {
     $table = new Book_Model_DbTable_Books();
     $tableName = $table->info(Zend_Db_Table_Abstract::NAME);
     $select = $table->getSelect();
     $select->where("{$tableName}.category_id = ?", $this->getIdentity());
     if ($params && isset($params['text']) && !empty($params['text'])) {
         $select->where("{$tableName}.book_name LIKE ?", "%{$params['text']}%");
     }
     $select->limit($limit);
     return $table->fetchAll($select);
 }
Exemple #8
0
 public function indexAction()
 {
     $bookTable = new Book_Model_DbTable_Books();
     $signatureTable = new Book_Model_DbTable_Signatures();
     $signatureTableName = $signatureTable->info('name');
     $bookSelect = $bookTable->getSelect()->order("{$signatureTableName}.rating_count DESC");
     $this->view->paginator = $paginator = Zend_Paginator::factory($bookSelect);
     if ($paginator->getTotalItemCount() == 0) {
         return $this->setNoRender();
     }
     $paginator->setItemCountPerPage($this->_getParam('itemCountPerPage', 12));
     $paginator->setCurrentPageNumber($this->_getParam('page', 1));
 }
Exemple #9
0
 public function getTaggedBooks()
 {
     $tagTbl = new Book_Model_DbTable_Tags();
     $tagSelect = $tagTbl->select()->where('object_type = ?', 'book')->where('post_id = ?', $this->getIdentity());
     $bookIds = array();
     foreach ($tagTbl->fetchAll($tagSelect) as $row) {
         array_push($bookIds, $row->object_id);
     }
     if (!empty($bookIds)) {
         $bookTbl = new Book_Model_DbTable_Books();
         $bookTblName = $bookTbl->info(Zend_Db_Table_Abstract::NAME);
         $bookSelect = $bookTbl->getSelect();
         $bookSelect->where("{$bookTblName}.book_id in (?)", $bookIds);
         return $bookTbl->fetchAll($bookSelect);
     }
     return array();
 }
Exemple #10
0
 public function indexAction()
 {
     // Get subject and check auth
     $subject = Engine_Api::_()->core()->getSubject();
     $bookTable = new Book_Model_DbTable_Books();
     $bookTableName = $bookTable->info(Zend_Db_Table_Abstract::NAME);
     $bookSelect = $bookTable->getSelect();
     $bookSelect->where("{$bookTableName}.user_id = ?", $subject->getIdentity());
     $this->view->paginator = $paginator = Zend_Paginator::factory($bookSelect);
     // Do not render if nothing to show
     if ($paginator->getTotalItemCount() <= 0) {
         return $this->setNoRender();
     } else {
         $this->_childCount = $paginator->getTotalItemCount();
         $paginator->setItemCountPerPage($this->_getParam('itemCountPerPage', 10));
         $paginator->setCurrentPageNumber($this->_getParam('page', 1));
     }
 }
Exemple #11
0
 public function indexAction()
 {
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $catId = $request->getParam('category_id', NULL);
     $bookTable = new Book_Model_DbTable_Books();
     $select = $bookTable->getSelect();
     $params = $request->getParams();
     $page = $request->getParam('page', 1);
     if (!($catId == NULL || $catId == '')) {
         if (isset($params['text']) && !empty($params['text'])) {
             $bookTableName = $bookTable->info('name');
             $select->where("{$bookTableName}.book_name LIKE ?", "%{$params['text']}%");
         }
         $select->where('category_id = ?', $catId);
         $this->view->category = $category = Engine_Api::_()->getItem('book_category', $catId);
         $bookPaginator = Zend_Paginator::factory($select);
         $bookPaginator->setCurrentPageNumber($page);
         $bookPaginator->setItemCountPerPage(20);
         $this->view->bookPaginator = $bookPaginator;
     } else {
         $bookCategoryTable = new Book_Model_DbTable_Categories();
         $bookCategoryTableName = $bookCategoryTable->info('name');
         $bookTable = new Book_Model_DbTable_Books();
         $bookTableName = $bookTable->info('name');
         $categorySelect = $bookCategoryTable->select();
         $bookSelectExist = $bookTable->getSelect();
         if (isset($params['text']) && !empty($params['text'])) {
             $bookSelectExist->where("{$bookTableName}.book_name LIKE ?", "%{$params['text']}%");
         }
         $bookSelectExist->where("{$bookTableName}.category_id = {$bookCategoryTableName}.category_id");
         $categorySelect->where(new Zend_Db_Expr('exists (' . $bookSelectExist . ')'));
         $this->view->categoryPaginator = $categoryPaginator = Zend_Paginator::factory($categorySelect);
         $categoryPaginator->setCurrentPageNumber($page);
         $booksByCategory = array();
         foreach ($categoryPaginator->getCurrentItems() as $cat) {
             $booksByCategory[$cat->category_id] = array();
             foreach ($cat->getNewestBooks(10, $params) as $book) {
                 array_push($booksByCategory[$cat->category_id], $book);
             }
         }
         $this->view->booksByCategory = $booksByCategory;
         $this->view->numberOfBooks = Engine_Api::_()->book()->getTotalBookCount($params);
     }
 }
Exemple #12
0
 public function indexAction()
 {
     $userTable = Engine_Api::_()->getItemTable('user');
     $userTableName = $userTable->info('name');
     $bookTable = new Book_Model_DbTable_Books();
     $bookTableName = $bookTable->info('name');
     $userSelect = $userTable->select()->from($userTableName);
     $userSelect->setIntegrityCheck(false);
     $userSelect->join($bookTableName, "{$bookTableName}.publisher_id = {$userTableName}.user_id", array("COUNT(*) AS num_books"));
     $userSelect->group(array("{$userTableName}.user_id"));
     $userSelect->where("{$userTableName}.level_id IN (?)", array(Book_Plugin_Constants::PUBLISHER_LEVEL, Book_Plugin_Constants::BOOK_COMPANY_LEVEL));
     $userSelect->where("{$userTableName}.enabled = ?", 1);
     $userSelect->where("{$userTableName}.verified = ?", 1);
     $userSelect->where("{$userTableName}.approved = ?", 1);
     $numberOfPublishers = $this->_getParam('itemCountPerPage', 5);
     $userSelect->order('RAND()');
     $userSelect->limit($numberOfPublishers);
     $this->view->authors = $users = $userTable->fetchAll($userSelect);
 }
Exemple #13
0
 public function indexAction()
 {
     $request = Zend_Controller_Front::getInstance()->getRequest();
     if ($request->isPost()) {
         $this->getElement()->clearDecorators();
     }
     $bookTable = new Book_Model_DbTable_Books();
     $bookTableName = $bookTable->info('name');
     $bookSelect = $bookTable->getSelect()->order("{$bookTableName}.creation_date DESC");
     $this->view->paginator = $paginator = Zend_Paginator::factory($bookSelect);
     if ($paginator->getTotalItemCount() == 0) {
         return $this->setNoRender();
     }
     $itemCountPerPage = $this->_getParam('itemCountPerPage', 12);
     if (empty($itemCountPerPage)) {
         $itemCountPerPage = 12;
     }
     $this->view->paginator->setItemCountPerPage($itemCountPerPage);
     $this->view->paginator->setCurrentPageNumber($this->_getParam('page', 1));
     $this->view->viewInfo = $this->_getParam('viewInfo');
 }
 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());
 }
Exemple #15
0
 public function indexAction()
 {
     $post = Engine_Api::_()->core()->getSubject();
     if (!empty($post->parent_object_type) && !empty($post->parent_object_id)) {
         if ($post->parent_object_type == 'book') {
             $bookTbl = new Book_Model_DbTable_Books();
             $bookSelect = $bookTbl->getSelect()->where('book_id = ?', $post->parent_object_id);
             $this->view->book = $book = $bookTbl->fetchRow($bookSelect);
             $this->view->authors = $authors = $book->getAuthors(0);
             $categoryTable = new Book_Model_DbTable_Categories();
             $this->view->category = $categoryTable->findRow($book->category_id);
             $bookApi = Engine_Api::_()->book();
             $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
             $this->view->rated = $bookApi->checkRated($book->getIdentity(), $book->getType(), $viewer->getIdentity());
             if ($book->is_foreign) {
                 $this->view->translators = $translators = $book->getAuthors(1);
             }
         }
     } else {
         return $this->setNoRender();
     }
 }
 private function _getBook()
 {
     $bookId = $this->_getParam('id');
     if ($bookId) {
         $bookTbl = new Book_Model_DbTable_Books();
         $book = $bookTbl->fetchRow($bookTbl->select()->where('book_id = ?', $bookId));
         return $book;
     }
 }
Exemple #17
0
 public function importRawBooks()
 {
     try {
         $bookTbl = new Book_Model_DbTable_Books();
         $select = $bookTbl->select();
         $select->from($bookTbl->info('name'), new Zend_Db_Expr('MAX(`rawbook_id`) as max_rawbook_id'));
         $data = $select->query()->fetch();
         $maxRawbookId = (int) $data['max_rawbook_id'];
         $userTbl = new User_Model_DbTable_Users();
         $rawBookTbl = new Book_Model_DbTable_Rawbooks();
         $rawBookSelect = $rawBookTbl->select();
         $rawBookSelect->where('rawbook_id > ?', $maxRawbookId);
         $rawBookSelect->order('rawbook_id ASC');
         $rawBookSelect->limit(self::DEFAULT_LIMIT);
         $rawBooks = $rawBookTbl->fetchAll($rawBookSelect);
         foreach ($rawBooks as $rawBook) {
             if (!empty($rawBook['publisher'])) {
                 $publisherSelect = $userTbl->select()->where('displayname LIKE ?', $rawBook['publisher']);
                 $publisher = $userTbl->fetchRow($publisherSelect);
             }
             if (!empty($rawBook['book_company'])) {
                 $bookCompanySelect = $userTbl->select()->where('displayname LIKE ?', $rawBook['book_company']);
                 $bookCompany = $userTbl->fetchRow($bookCompanySelect);
             }
             $data = array('book_name' => $rawBook->book_name, 'published_date' => date('Y-m-d H:i:s', $rawBook->published_date), 'price' => $rawBook->price, 'num_page' => $rawBook->num_page, 'description' => $rawBook->description, 'rawbook_id' => $rawBook->getIdentity(), 'user_id' => 1);
             if (isset($publisher) && !empty($publisher)) {
                 $data['publisher_id'] = $publisher->getIdentity();
             }
             if (isset($bookCompany) && !empty($bookCompany)) {
                 $data['book_company_id'] = $bookCompany->getIdentity();
             }
             $book = $bookTbl->createRow($data);
             $book->save();
             if (!empty($rawBook['photo'])) {
                 $image = Engine_Image::factory();
                 $name = basename($rawBook['photo']);
                 $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary';
                 $params = array('parent_id' => $book->getIdentity(), 'parent_type' => $book->getType(), 'user_id' => 1);
                 // Save
                 $storage = Engine_Api::_()->storage();
                 $image->open($rawBook['photo'])->write($path . '/m_' . $name)->destroy();
                 // Store
                 $iMain = $storage->create($path . '/m_' . $name, $params);
                 // Remove temp files
                 @unlink($path . '/m_' . $name);
                 $book->photo_id = $iMain->getIdentity();
                 $book->save();
                 $photoTbl = new Book_Model_DbTable_Photos();
                 $photo = $photoTbl->createRow(array('parent_object_type' => $book->getType(), 'parent_object_id' => $book->getIdentity(), 'file_id' => $iMain->getIdentity(), 'user_id' => 1, 'approved' => 1, 'default' => 1));
                 $photo->save();
             }
         }
         return true;
     } catch (Exception $e) {
         throw $e;
     }
 }
 public function suggestAction()
 {
     $text = $this->_getParam('value');
     if (!empty($text)) {
         $parent_id = $this->_getParam('parent_id', 0);
         $bookTable = new Book_Model_DbTable_Books();
         $select = $bookTable->select()->where('book_name LIKE ?', "%{$text}%");
         if ($parent_id != 0) {
             $select->where('book_id != ?', $parent_id);
         }
         $data = array();
         foreach ($bookTable->fetchAll($select) as $book) {
             $record = array('id' => $book->getIdentity(), 'label' => $book->book_name, 'photo' => $this->view->itemPhoto($book, 'thumb.icon'), 'url' => $book->getHref(), 'type' => $book->getType(), 'id' => $book->getIdentity(), 'guid' => $book->getGuid());
             array_push($data, $record);
         }
         return $this->_helper->json($data);
     }
 }