public function recordsAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $this->getResponse()->setHeader('Content-Type', 'application/json'); // require_once APPLICATION_PATH . '/modules/asset/models/DbTable/Loan.php'; $loan = new Asset_Model_DbTable_Loan(); $sort_column = $this->_getParam('sortname', 'Ma_tai_san'); # this will default to undefined $sort_order = $this->_getParam('sortorder', 'desc'); # this will default to undefined $page = $this->_getParam('page', 1); $limit = $this->_getParam('rp', 10); $offset = ($page - 1) * $limit; $search_column = $this->_getParam('qtype', 'Ma_tai_san'); $search_for = $this->_getParam('query', ''); $mode = (int) $this->_getParam('mode', 2); switch ($mode) { case 1: // list all item $select = $loan->select(Zend_Db_Table::SELECT_WITH_FROM_PART)->setIntegrityCheck(false)->join(array('u' => 'memberinfor'), 'loaninfor.UserID = u.UserID', array('Username' => 'u.Username'))->join(array('i' => 'iteminfor'), 'loaninfor.Ma_tai_san = i.Ma_tai_san', array('ItemID' => 'i.ItemID', 'Ten_tai_san' => 'i.Ten_tai_san', 'Description' => 'i.Description', 'Type' => 'i.Type', 'StartDate' => 'i.StartDate', 'Price' => 'i.Price', 'WarrantyTime' => 'i.WarrantyTime', 'Status' => 'i.Status', 'Place' => 'i.Place'))->order("{$sort_column} {$sort_order}")->limit($limit, $offset); break; case 2: // list all item user dang muon // list all item user dang muon default: $uid = Zend_Auth::getInstance()->getIdentity()->UserID; $select = $loan->select(Zend_Db_Table::SELECT_WITH_FROM_PART)->setIntegrityCheck(false)->join(array('u' => 'memberinfor'), 'loaninfor.UserID = u.UserID', array('Username' => 'u.Username'))->join(array('i' => 'iteminfor'), 'loaninfor.Ma_tai_san = i.Ma_tai_san', array('ItemID' => 'i.ItemID', 'Ten_tai_san' => 'i.Ten_tai_san', 'Description' => 'i.Description', 'Type' => 'i.Type', 'StartDate' => 'i.StartDate', 'Price' => 'i.Price', 'WarrantyTime' => 'i.WarrantyTime', 'Status' => 'i.Status', 'Place' => 'i.Place'))->where("loaninfor.UserID = '{$uid}'")->order("{$sort_column} {$sort_order}")->limit($limit, $offset); break; } if (!empty($search_column) && !empty($search_for)) { $select->where($search_column . ' LIKE ?', '%' . $search_for . '%'); } $pager = Zend_Paginator::factory($select); $pager->setCurrentPageNumber($page); $pager->setItemCountPerPage($limit); $records = $pager->getIterator(); $total = $pager->getTotalItemCount(); if ($total == 0) { echo Zend_Json::encode(array('page' => $page, 'total' => $total, 'rows' => NULL)); exit; } foreach ($records as $record) { //If cell's elements have named keys, they must match column names //Only cell's with named keys and matching columns are order independent. if (isset($record['Type']) && isset($record['Status'])) { switch ($record['Type']) { case 0: $record['Type'] = 'Bảo mật cao'; break; case 1: $record['Type'] = 'Bảo mật thấp'; break; default: $record['Type'] = '-'; break; } switch ($record['Status']) { case 0: $record['Status'] = 'Có thể mượn'; break; case 1: $record['Status'] = 'Đang cho mượn'; break; case 2: $record['Status'] = 'Hỏng'; break; default: $record['Status'] = '-'; break; } } $rows[] = array('id' => $record['Ma_tai_san'], 'cell' => $record->toArray()); } $jsonData = array('page' => $page, 'total' => $total, 'rows' => $rows); echo Zend_Json::encode($jsonData); }