示例#1
0
 public function manageBooksAction()
 {
     /*--search options---*/
     $search = trim($this->_getParam('search'));
     $status = trim($this->_getParam('status'));
     $where = '1=1';
     $linkArray = array();
     $this->view->search = "Search...";
     if ($search != "" && $search != "Search...") {
         $where = "(b.title like '%{$search}%' or b.isbn like '%{$search}%' or b.author like '%{$search}%' or b.description like '%{$search}%' or b.publisher like '%{$search}%')";
         $linkArray['search'] = $search;
         $this->view->search = $search;
     }
     if ($status != "") {
         $linkArray['status'] = $status;
         $this->view->status = $status;
         if ($status == "available") {
             $status = "bu.issue_date is null";
         } else {
             $status = "bu.issue_date is not null";
         }
         if (is_null($where)) {
             $where .= " {$status}";
         } else {
             $where .= " and {$status}";
         }
     }
     /*----search options----*/
     $this->view->linkArray = $linkArray;
     $this->view->page_size = $page_size = $this->_getParam('page_size', 25);
     $page = $this->_getParam('page', 1);
     $model = new Application_Model_Book();
     $table = $model->getMapper()->getDbTable();
     $select = $table->select()->setIntegrityCheck(false)->from(array("b" => 'book'))->joinLeft(array('bu' => 'book_user'), ' b.id = bu.book_id and bu.return_date is null', array("issue_date" => "issue_date", "return_date" => "return_date", "estimated_return_date" => "estimated_return_date", "user_id" => "user_id"))->order('addedon desc')->where($where);
     //echo $sql = $select->__toString();
     $paginator = Base_Paginator::factory($select);
     $paginator->setItemCountPerPage($page_size);
     $paginator->setCurrentPageNumber($page);
     $this->view->totalItems = $paginator->getTotalItemCount();
     $this->view->paginator = $paginator;
 }