public function getUsedCount() { $table = new Book_Model_DbTable_Books(); $tblName = $table->info('name'); $select = $table->select()->from($tblName, "COUNT(*) as count")->where("{$tblName}.category_id = ?", $this->getIdentity()); $total = $table->fetchRow($select); return $total['count']; }
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); }
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; }
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; } }
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); } }
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; } }