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.'))));
         }
     }
 }
Esempio n. 2
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);
 }
Esempio n. 3
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);
 }
Esempio n. 4
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();
 }
Esempio n. 5
0
 public function fixBookAction()
 {
     echo 'fix books' . PHP_EOL;
     $bookTbl = new Book_Model_DbTable_Books();
     $bookSelect = $bookTbl->select()->where('rawbook_id > 0');
     $bookSelect->limit(200);
     $rawBookIds = array();
     $books = $bookTbl->fetchAll($bookSelect);
     echo 'number of books : ' . count($books) . PHP_EOL;
     foreach ($books as $book) {
         array_push($rawBookIds, $book->rawbook_id);
     }
     $rawBookTbl = new Book_Model_DbTable_Rawbooks();
     $rawBookTbl->delete(array('rawbook_id IN (?)' => $rawBookIds));
     foreach ($books as $book) {
         $book->delete();
     }
     echo 'The books have been deleted !' . PHP_EOL;
     die;
 }
Esempio n. 6
0
 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);
     }
 }