/** * Prepares the environment before running a test. */ protected function setUp() { parent::setUp(); $this->_scrollingStyle = new Zend_Paginator_ScrollingStyle_Elastic(); $this->_paginator = Zend_Paginator::factory(range(1, 101)); $this->_paginator->setItemCountPerPage(5); $this->_paginator->setPageRange(5); }
/** * Prepares the environment before running a test. */ protected function setUp() { parent::setUp(); $this->_scrollingStyle = new Zend_Paginator_ScrollingStyle_Jumping(); $this->_paginator = Zend_Paginator::factory(range(1, 101)); $this->_paginator->setItemCountPerPage(10); $this->_paginator->setPageRange(10); $this->_expectedRange = array_combine(range(1, 10), range(1, 10)); }
/** * Dot_Paginator constructor that sets the main parameters * If $page is 0 (zero), Zend_Paginator will not be called * @access public * @param Zend_Db_Select $select * @param int $page [optional] * @param int $resultsPerPage [optional] * @return Dot_Paginator */ public function __construct($select, $page = 0, $resultsPerPage = 0) { $this->db = Zend_Registry::get('database'); $this->_select = $select; $this->_currentPage = $page; $this->_itemCountPerPage = $resultsPerPage; $settings = Zend_Registry::get('settings'); if ($this->_currentPage > 0) { $adapter = new Zend_Paginator_Adapter_DbSelect($select); $this->_paginator = new Zend_Paginator($adapter); $this->_paginator->totalItems = $adapter->count(); // page range = the pages on the left + the pages on the right + the current page $this->_paginator->setPageRange($settings->paginationStep * 2 + 1); } }
public function testGetSetPageRange() { $this->_restorePaginatorDefaults(); $this->assertEquals(10, $this->_paginator->getPageRange()); $this->_paginator->setPageRange(15); $this->assertEquals(15, $this->_paginator->getPageRange()); }
public function selectAll($pageNumber = 1, $filter = array()) { $db = $this->siteDbAdapter->select()->from($this->tablename); foreach ($filter as $key => $val) { if ($val) { if (is_int($val)) { $db->where($key . ' = ?', $val); } else { $db->where($key . ' LIKE ?', '%' . $val . '%'); } } } $db->order('log_date DESC'); $adapter = new Zend_Paginator_Adapter_DbSelect($db); $paginator = new Zend_Paginator($adapter); $paginator->setCurrentPageNumber($pageNumber); $paginator->setItemCountPerPage($this->countPerPage); $paginator->setPageRange($this->pageRange); return $paginator; /* $select = $this->siteDbAdapter->select(); $select->from($this->tablename); $select->order(array('log_id')); $log = $this->siteDbAdapter->fetchAll($select->__toString()); return $log; */ }
public function listAction() { // create search form $searchForm = new Admin_Form_RouteSearch(); $searchForm->setAction('/admin/route/list')->setMethod('post'); $this->view->searchForm = $searchForm; // get params from request $sorter = $this->_request->getParam('sorter', null); $filter = $this->_request->getParam('filter', null); $filterText = $this->_request->getParam('filterText', null); // populate them to form $searchForm->getElement('sorter')->setValue($sorter); $searchForm->getElement('filter')->setValue($filter); $searchForm->getElement('filterText')->setValue($filterText); // list route $routeModel = new Admin_Model_Route(); $routeAdapter = $routeModel->getRoutePaginatorAdapter($filter, $filterText, $sorter); if ($routeAdapter) { $paginator = new Zend_Paginator($routeAdapter); $page = $this->_request->getParam('page', 1); $paginator->setItemCountPerPage(5); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(8); $this->view->paginator = $paginator; } }
public function testNoPagesBeforeSecondLastPageEqualsPageRangeMinTwo() { $this->_paginator->setPageRange(3); $this->_paginator->setCurrentPageNumber(19); $pages = $this->_paginator->getPages('Elastic'); $this->assertEquals(5, count($pages->pagesInRange)); }
public function createPaginator($totalItem, $arrPaginator, $options = null) { $adapter = new Zend_Paginator_Adapter_Null($totalItem); $paginator = new Zend_Paginator($adapter); $paginator->setItemCountPerPage($arrPaginator['itemCountPerPage']); $paginator->setPageRange($arrPaginator['pageRange']); $paginator->setCurrentPageNumber($arrPaginator['currentPage']); return $paginator; }
/** * @group ZF-4193 */ public function testCastsIntegerValuesToInteger() { // Current page number $this->_paginator->setCurrentPageNumber(3.3); $this->assertTrue($this->_paginator->getCurrentPageNumber() == 3); // Item count per page $this->_paginator->setItemCountPerPage(3.3); $this->assertTrue($this->_paginator->getItemCountPerPage() == 3); // Page range $this->_paginator->setPageRange(3.3); $this->assertTrue($this->_paginator->getPageRange() == 3); }
public function indexAction() { // 博客列表 $modelBlog = new Page(); $where = array('type' => 'now'); $blogs = $modelBlog->getPages($where); $paginator = new Zend_Paginator($blogs); $paginator->setItemCountPerPage(5); $paginator->setPageRange(5); // 获得当前显示的页码 $page = $this->_request->getParam('page'); $paginator->setCurrentPageNumber($page); // 渲染到视图 $this->view->blogs = $paginator; $this->_helper->cache(array('index', 'view'), array('gook')); }
/** * Constructor * * Registers form view helper as decorator * * @param mixed $options * @return void */ public function __construct($select, $numberOfColumns, $itemViewscript = null, $options = null) { $this->_db = Zend_registry::get('db'); $_frontController = Zend_Controller_Front::getInstance(); $this->_request = $_frontController->getRequest(); if (null === $this->_view) { require_once 'Zend/Controller/Action/HelperBroker.php'; $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $this->_view = $viewRenderer->view; } if (!empty($options['paginationViewScript'])) { $this->_view->assign('paginationViewScript', $options['paginationViewScript']); } else { $this->_view->assign('paginationViewScript', null); } $this->_view->assign('numberOfColumns', $numberOfColumns); $this->_view->assign('itemViewScript', $itemViewscript); $adapter = new Zend_Paginator_Adapter_DbSelect($select); $paginator = new Zend_Paginator($adapter); $_config = Zend_Registry::get('config'); $itemPerPage = 12; if (!empty($_config->products->itemPerPage)) { $itemPerPage = $_config->products->itemPerPage; } if (!empty($options['list_options']['perPage'])) { $itemPerPage = $options['list_options']['perPage']; } if ($this->_request->getParam('perPage')) { $itemPerPage = $this->_request->getParam('perPage') == 'all' ? $paginator->getTotalItemCount() : $this->_request->getParam('perPage'); } $pageRange = 5; if (!empty($_config->products->pageRange)) { $pageRange = $_config->products->pageRange; } $paginator->setItemCountPerPage($itemPerPage); $paginator->setCurrentPageNumber($this->_request->getParam('page')); $paginator->setPageRange($pageRange); $this->_view->assign('paginator', $paginator); }
/** * Returns the result of a database query for all records * of persons helped, associated with user name and id * * @return Persons_Model_Person */ public function getAll($params = array('from' => 'v_person_helped', 'appaccount_id' => 0, 'orderby' => 'name', 'paginator' => true)) { $db = $this->getDefaultAdapter(); $sql = $db->select()->from($params['from'])->where('appaccount_id = ?', $params['appaccount_id'])->order($params['orderby']); if (isset($params['filter-keyword'])) { $normalize = new Agana_Filter_Normalize(); $sql->where('lower(unaccented(name)) LIKE ?', $normalize->filter($params['filter-keyword'])); } $db->setFetchMode(Zend_DB::FETCH_ASSOC); if ($params['paginator']) { $adapter = new Zend_Paginator_Adapter_DbSelect($sql); $paginator = new Zend_Paginator($adapter); $page = isset($params['page']) ? $params['page'] : 1; $paginator->setCurrentPageNumber($page); $itemCountPerPage = isset($params['itemCountPerPage']) ? $params['itemCountPerPage'] : 20; $paginator->setItemCountPerPage($itemCountPerPage); $pageRange = isset($params['pageRange']) ? $params['pageRange'] : 7; $paginator->setPageRange($pageRange); return $paginator; } else { return $this->_prepareReturnData($db->fetchAll($sql)); } }
public function selectAll($pageNumber = 1, $filter = array()) { $db = $this->allDbAdapter->select()->from(array('t' => $this->tablename), array('*', 'ip' => 'INET_NTOA(request_limits_user_ip)')); foreach ($filter as $key => $val) { if ($val) { if ($key == 'request_limits_user_ip') { $db->where('INET_NTOA(request_limits_user_ip) LIKE ?', '%' . $val . '%'); } else { if ((int) $val == $val) { $db->where($key . ' = ?', (int) $val); } else { $db->where($key . ' LIKE ?', '%' . $val . '%'); } } } } $db->order('request_limits_id ASC'); $adapter = new Zend_Paginator_Adapter_DbSelect($db); $paginator = new Zend_Paginator($adapter); $paginator->setCurrentPageNumber($pageNumber); $paginator->setItemCountPerPage($this->countPerPage); $paginator->setPageRange($this->pageRange); return $paginator; }
public function selectAll($pageNumber = 1, $filter = array()) { $db = $this->allDbAdapter->select()->from($this->tablename); foreach ($filter as $key => $val) { if ($val) { if ($key == 'bl_site_id') { $db->where($key . ' LIKE ?', '%"' . $val . '"%'); } else { if (is_int($val)) { $db->where($key . ' = ?', $val); } else { $db->where($key . ' LIKE ?', '%' . $val . '%'); } } } } $db->order('bl_id ASC'); $adapter = new Zend_Paginator_Adapter_DbSelect($db); $paginator = new Zend_Paginator($adapter); $paginator->setCurrentPageNumber($pageNumber); $paginator->setItemCountPerPage($this->countPerPage); $paginator->setPageRange($this->pageRange); return $paginator; }
/** * 内容查询 * */ public function searchAction() { //获取页面提交参数 $keyWord = urldecode($this->_request->getParam('keyWord')); $page = $this->_request->getParam('page'); $this->view->keyWord = urlencode($keyWord); //关键字数组 $keywordsStrArray = explode(' ', $keyWord); $this->view->keywordsStrArray = $keywordsStrArray; //开始查询 $array = array(); //新闻 $model = new Model_DbTable_News(); $infos = $model->findByLike($keyWord); $tmpArray = array(); foreach ($infos as $info) { $tmpArray['flag'] = 0; $tmpArray['id'] = $info['id']; $tmpArray['title'] = $info['title']; $tmpArray['uncontent'] = $info['uncontent']; $tmpArray['addtime'] = $info['addtime']; array_push($array, $tmpArray); } //分页参数 if ($page == null) { $page = 1; } $pageRange = 10; $itemCountPerPage = 10; //实例并构建Zend_Paginator对象 $paginatorAdapter = new Zend_Paginator_Adapter_Array($array); $paginator = new Zend_Paginator($paginatorAdapter); $paginator->setPageRange($pageRange)->setItemCountPerPage($itemCountPerPage)->setCurrentPageNumber($page); $this->view->paginator = $paginator; //设置布局 $this->_helper->layout->disableLayout(); //页面信息 $this->view->title = '内容查询-' . $this->_config['pageInfo']['default']['title']; }
public function indexAction() { // BEGIN:FILTERS $filters = array(); //array with variables to send to pagination (filters) $searchTxt = $this->getRequest()->getParam('searchTxt'); if (!empty($searchTxt)) { $filters['searchTxt'] = $searchTxt; } $this->view->search = $filters; // END:FILTERS //BEGIN:SEARCH FORM $formSearch = new Default_Form_FileManagerSearch(); $formSearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/file-manager-search.phtml')))); $this->view->formSearch = $formSearch; //END:SEARCH FORM //BEGIN:FORM ADD $replyId = $this->getRequest()->getParam('replyId'); $form = new Default_Form_FileManager(); $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/file-manager.phtml')))); $this->view->form = $form; $formshare = new Default_Form_ShareFile(); if ($this->getRequest()->isPost()) { $post = $this->getRequest()->getPost(); if (!empty($post['action']) && $post['action'] == 'add') { //if is valid save message if ($form->isValid($this->getRequest()->getPost())) { //BEGIN:SAVE ATTACHMENTS if (!empty($post['galleryFiles']) && is_array($post['galleryFiles'])) { foreach ($post['galleryFiles'] as $valuesGallery) { $tmpFiles = new Default_Model_TempFiles(); if ($tmpFiles->find($valuesGallery)) { $post = $this->getRequest()->getPost(); $gallery = new Default_Model_FileManager(); $gallery->setOptions($form->getValues()); $gallery->setType($tmpFiles->getFileType()); $gallery->setSize($tmpFiles->getFileSize()); $gallery->setModule('sharedfiles'); $gallery->setName($tmpFiles->getFileName()); $savedId = $gallery->save(); if ($savedId) { $shared = new Default_Model_SharedList(); $shared->setIdUser(Zend_Registry::get('user')->getId()); $shared->setIdFile($savedId); $shared->save(); } //copy picture and crop $tempFile = APPLICATION_PUBLIC_PATH . '/media/temps/' . $tmpFiles->getFileName(); $targetFile = APPLICATION_PUBLIC_PATH . '/media/files/' . $tmpFiles->getFileName(); @copy($tempFile, $targetFile); @unlink($tempFile); $tmpFiles->delete(); } } //END:SAVE ATTACHMENTS $this->_flashMessenger->addMessage("<div class='success canhide'><p>Your file was succesfully uploaded.</p><a href='javascript:;'></a></div>"); } else { $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Error uploading file!</p><a href='javascript:;'></a></div>"); } $this->_redirect(WEBROOT . 'file-manager'); } } if (!empty($post['action']) && $post['action'] == 'sharefile') { //if is valid save shared file message if ($formshare->isValid($this->getRequest()->getPost())) { $model = new Default_Model_Messages(); $model->setOptions($formshare->getValues()); $model->setIdUserFrom(Zend_Registry::get('user')->getId()); $model->save(); //BEGIN:SAVE ATTACHMENTS $shared = new Default_Model_SharedList(); $shared->setOptions($formshare->getValues()); //echo $formshare->getValue('idUserTo'); //die();//aici e ok $shared->setIdUser($formshare->getValue('idUserTo')); //aici nu seteaza $shared->save(); //END:SAVE ATTACHMENTS $this->_flashMessenger->addMessage("<div class='success canhide'><p>Your file was succesfully shared.</p><a href='javascript:;'></a></div>"); } else { $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Error sharing file!</p><a href='javascript:;'></a></div>"); } $this->_redirect(WEBROOT . 'file-manager'); } } //END:FORM ADD //BEGIN:LISTING $model = new Default_Model_FileManager(); $select = $model->getMapper()->getDbTable()->select(); //if(!empty($type) && $type == 'sent'){ //sent $select->from(array('sl' => 'shared_list'), array('sl.idUser', 'sl.created'))->joinLeft(array('uf' => 'uploaded_files'), 'uf.id = sl.idFile', array('uf.id', 'uf.name', 'uf.description', 'uf.type', 'uf.size'))->where('sl.idUser = ?', Zend_Registry::get('user')->getId())->where('NOT sl.deleted'); // } if (!empty($searchTxt)) { $select->where("uf.name LIKE ('%" . $searchTxt . "%') OR uf.description LIKE ('%" . $searchTxt . "%')"); } $select->order('sl.created DESC')->setIntegrityCheck(false); // pagination $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginator->setItemCountPerPage(10); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setPageRange(5); Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $filters)); $this->view->result = $paginator; $this->view->itemCountPerPage = $paginator->getItemCountPerPage(); $this->view->totalItemCount = $paginator->getTotalItemCount(); //END:LISTING }
/** * 新闻分页显示 * * @param int|string $flag * @param int $orderIndex * @param int $page * @param int $itemCountPerPage * @param int $pageRange * @return Zend_paginator */ public function findByPage($flag, $orderIndex, $page = 1, $itemCountPerPage = 10, $pageRange = 5) { //生成select对象 $select = $this->getAdapter()->select(); $select->from($this->_name); //isTodayCommend-今日推荐 all-全部 0-站内新闻 1-IT人物 2-高端访谈 3-产品快讯 4-企业动态 5-互联网 6-游戏资讯 7-广告传媒 8-财经报道 9-图片新闻 10-综合资讯 if ($flag !== 'all') { if ($flag === 'ttj') { $where = 'istodaycommend = true'; } else { $where = $this->getAdapter()->quoteInto('flag = ?', $flag); } $select->where($where); } //排序方式 if ($orderIndex == 0) { $order = 'addtime desc'; } elseif ($orderIndex == 1) { $order = 'addtime'; } elseif ($orderIndex == 2) { $order = 'browse desc'; } elseif ($orderIndex == 3) { $order = 'browse'; } $select->order($order); //实例并构建Zend_Paginator对象 $paginatorAdapter = new Zend_Paginator_Adapter_DbSelect($select); $paginator = new Zend_Paginator($paginatorAdapter); $paginator->setPageRange($pageRange)->setItemCountPerPage($itemCountPerPage)->setCurrentPageNumber($page); return $paginator; }
/** * get with paginator * @param string $sql * @param int $page * @param int $rows * @return object */ protected function getWithPaginator($sql, $page, $rows) { $paginator = new \Zend_Paginator(new \Zend_Paginator_Adapter_DbSelect($sql)); $paginator->setCurrentPageNumber($page); $paginator->setItemCountPerPage($rows); $paginator->setPageRange(10); return $paginator; }
/** * @param Object_Medecine_List $list * @param integer $page * @param integer $perPage * @return Zend_Paginator */ public function _paginate(Object\Person\Listing $list) { $start = $this->getParam('start', 0); $perPage = $this->getParam('limit', 10); $currentpage = $this->getParam('page', 1); $paginator = new \Zend_Paginator($list); $paginator->setItemCountPerPage((int) $perPage); $paginator->setCurrentPageNumber((int) $page); $paginator->setPageRange((int) 10); return $paginator; }
public function testAcceptsPageRangeLargerThanPageCount() { $this->_paginator->setPageRange(100); $pages = $this->_paginator->getPages(); $this->assertEquals(11, $pages->last); }
/** * Retorna vários registros * * @param string|array $where OPTIONAL An SQL WHERE clause * @param string|array $order OPTIONAL An SQL ORDER clause. * @param int $count OPTIONAL An SQL LIMIT count. * @param int $offset OPTIONAL An SQL LIMIT offset. * * @return array|null Lista de registros ou nulo se não localizar nenhum */ public function fetchAll($where = null, $order = null, $count = null, $offset = null) { // Cria a assinatura da consulta if ($where instanceof Zend_Db_Select) { $md5 = md5($where->assemble()); } else { $md5 = md5(var_export($this->showDeleted, true) . var_export($this->usePaginator, true) . var_export($where, true) . var_export($order, true) . var_export($count, true) . var_export($offset, true)); } // Verifica se tem no cache // o Zend_Paginator precisa do Zend_Paginator_Adapter_DbSelect para acessar o cache if ($this->getUseCache() && !$this->getUsePaginator() && $this->getCache()->test($md5)) { return $this->getCache()->load($md5); } else { // Define a consulta if ($where instanceof Zend_Db_Select) { $select = $where; } else { $select = $this->getSelect($where, $order, $count, $offset); } // Verifica se deve usar o Paginator if ($this->getUsePaginator()) { $fetchAll = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); // Verifica se deve usar o cache if ($this->getUseCache()) { $fetchAll->setCacheEnabled(true)->setCache($this->getCache()); } // Configura o paginator $fetchAll->setPageRange($this->getPaginator()->getPageRange()); $fetchAll->setCurrentPageNumber($this->getPaginator()->getCurrentPageNumber()); $fetchAll->setItemCountPerPage($this->getPaginator()->getItemCountPerPage()); } else { // Recupera os registros do banco de dados $fetchAll = $this->getTableGateway()->fetchAll($select); // Verifica se foi localizado algum registro if (!is_null($fetchAll) && count($fetchAll) > 0) { // Passa o $fetch para array para poder incluir campos extras $fetchAll = $fetchAll->toArray(); // Verifica se deve adiciopnar campos extras $fetchAll = $this->getFetchAllExtraFields($fetchAll); } else { $fetchAll = null; } // Grava a consulta no cache if ($this->getUseCache()) { $this->getCache()->save($fetchAll, $md5); } } // Some garbage collection unset($select); // retorna o resultado da consulta return $fetchAll; } }
public function listAction() { $this->setViewPathes(); $tableName = $this->z_model->info('name'); $select = Zend_Db_Table_Abstract::getDefaultAdapter()->select()->from($tableName); $this->setJoinsToSelect($select, $this->z_joins); $this->setConditionsToSelect($select, $this->z_conditions); $this->setOrdersToSelect($select, $this->z_order); $this->setGroupToSelect($select, $this->z_group); $urlfilter = $this->_getParam('filter'); $urlfiltervalue = $this->_getParam('filtervalue'); if ($urlfilter && $urlfiltervalue) { $select->where($urlfilter . '=?', $urlfiltervalue); } // echo $select->assemble(); if ($this->z_datatype == 'band') { $pagitatorAdapter = new Zend_Paginator_Adapter_DbSelect($select); $paginator = new Zend_Paginator($pagitatorAdapter); $paginator->setItemCountPerPage($this->z_paginate); $paginator->setPageRange(10); $paginator->setCurrentPageNumber($this->_getParam('page', 1)); $this->view->paginator = $paginator; } elseif ($this->z_datatype == 'catalog') { $catalogParent = $this->_getParam('z_catalog_sysparentid', 0); $select->where('parentid=?', $catalogParent); $items = $select->query()->fetchAll(); foreach ($items as $key => $item) { $items[$key]['z_have_subcat'] = $this->z_model->select(true)->reset(Zend_Db_Select::COLUMNS)->where('parentid=?', $item['id'])->columns('COUNT(*)')->query()->fetchColumn(); } $this->view->items = $items; $this->view->catalogParent = $catalogParent; $this->getRequest()->setParam('z_catalog_sysparentid', NULL); if ($catalogParent != 0) { $this->setTarget('#catalog' . $catalogParent); $this->_helper->viewRenderer->setViewScriptPathSpec('datacontrol/' . $this->z_datatype . '/sublist.:suffix'); } } }
public function indexAction() { // BEGIN:FILTERS $filters = array(); //array with variables to send to pagination (filters) // END:FILTERS //BEGIN:LISTING MESSAGES $model = new Default_Model_Messages(); $select = $model->getMapper()->getDbTable()->select(); $select->from(array('u' => 'messages'), array('u.id', 'u.idUserFrom', 'u.idUserTo', 'u.subject', 'u.created'))->where('u.idUserTo = ?', Zend_Registry::get('user')->getId())->where('NOT u.deletedTo')->where('NOT u.trashedTo'); $select->order('u.created DESC')->setIntegrityCheck(false); // pagination $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginator->setItemCountPerPage(10); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setPageRange(5); Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $filters)); $this->view->inboxNr = Needs_Messages::getInboxMessagesNumber(); $this->view->result = $paginator; $this->view->itemCountPerPage = $paginator->getItemCountPerPage(); $this->view->totalItemCount = $paginator->getTotalItemCount(); //END:LISTING MESSAGES //BEGIN:LISTING LATEST EXPENSES / INCOME $model = new Default_Model_Expenses(); $select = $model->getMapper()->getDbTable()->select(); $select->from(array('u' => 'expenses'), array('u.id', 'u.name', 'u.price', 'u.date', 'u.type'))->where('u.idMember = ?', Zend_Registry::get('user')->getId())->where('NOT u.deleted'); $select->order('u.date DESC'); // pagination $paginatorLatest = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginatorLatest->setItemCountPerPage(10); $paginatorLatest->setCurrentPageNumber($this->_getParam('page')); $paginatorLatest->setPageRange(5); Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $filters)); $this->view->resultLatest = $paginatorLatest; $this->view->itemCountPerPageLatest = $paginatorLatest->getItemCountPerPage(); $this->view->totalItemCountLatest = $paginatorLatest->getTotalItemCount(); //END:LISTING LATEST EXPENSES / INCOME //START: Expenses PIE $groups = new Default_Model_Groups(); $select = $groups->getMapper()->getDbTable()->select()->from(array('g' => 'groups'), array('g.id', 'g.name', 'g.color', 'g.created', 'g.deleted'))->joinLeft(array('pg' => 'product_groups'), 'g.id = pg.idGroup', array())->joinLeft(array('p' => 'expenses'), 'p.id = pg.idProduct', array('price' => 'SUM(p.price)'))->where('NOT g.deleted')->where('p.type=?', 0)->where('p.date>=?', date('Y-m-01'))->group('g.id')->setIntegrityCheck(false); $resultPieExpenses = $groups->fetchAll($select); $this->view->resultPieExpenses = $resultPieExpenses; //END: Expenses PIE //START: Income PIE $groups2 = new Default_Model_Groups(); $select2 = $groups2->getMapper()->getDbTable()->select()->from(array('g' => 'groups'), array('g.id', 'g.name', 'g.color', 'g.created', 'g.deleted'))->joinLeft(array('pg' => 'product_groups'), 'g.id = pg.idGroup', array())->joinLeft(array('p' => 'expenses'), 'p.id = pg.idProduct', array('price' => 'SUM(p.price)'))->where('NOT g.deleted')->where('p.type=?', 1)->where('p.date>=?', date('Y-m-01'))->group('g.id')->setIntegrityCheck(false); $resultPieIncome = $groups2->fetchAll($select2); $this->view->resultPieIncome = $resultPieIncome; //END: Income PIE $date = date('Y-m-d'); $thisWeekStartDate = Needs_Tools::getWeekDaysByDate($date, $type = 'start'); $thisWeekEndDay = Needs_Tools::getWeekDaysByDate($date, $type = 'end'); $this->view->dateFrom = $thisWeekStartDate; $this->view->dateTo = $thisWeekEndDay; // $resultInfo= Needs_Tools::showProjectedDashboard($thisWeekStartDate,$thisWeekEndDay); // if ($resultInfo){ // $this->view->foodCost=$resultInfo["foodCost"]; // $this->view->laborCost=$resultInfo["laborCost"]; // $this->view->idShop=$resultInfo["idShop"]; // }else{ // $this->view->foodCost=''; // $this->view->laborCost=''; // $this->view->idShop=''; // } $resultIncomeExpense = Needs_Tools::showIncomeExpensesDashboard(date('Y'), date('m')); if ($resultIncomeExpense) { $value = array(); foreach ($resultIncomeExpense as $values) { $value[] = $values->getPrice(); } $this->view->incomeAmount = isset($value[1]) ? $value[1] : 0; $this->view->expensesAmount = isset($value[0]) ? $value[0] : 0; } else { $this->view->incomeAmount = 0; $this->view->expensesAmount = 0; } $date = date('Y-m-d'); $day = date('d', strtotime($date)); $feb = date('L', strtotime($date)) ? 29 : 28; //an bisect $days = array(0, 31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31); //nr zile pe luna //$month=array(1,2,3,4,5,6,7,8,9,10,11,12); $newdate = strtotime('-' . $days[date('n', strtotime($date))] . ' days', strtotime($date)); $resultIncomeExpenseLastMonth = Needs_Tools::showIncomeExpensesDashboard(date('Y', $newdate), date('m', $newdate)); if ($resultIncomeExpenseLastMonth) { $value = array(); foreach ($resultIncomeExpenseLastMonth as $values) { $value[] = $values->getPrice(); } $this->view->incomeAmountLastMonth = isset($value[1]) ? $value[1] : 0; $this->view->expensesAmountLastMonth = isset($value[0]) ? $value[0] : 0; } else { $this->view->incomeAmountLastMonth = 0; $this->view->expensesAmountLastMonth = 0; } $this->view->newdate = $newdate; //$this->view->form = $form; }
public function indexAction() { $auth = Zend_Auth::getInstance(); $authAccount = $auth->getStorage()->read(); $params = array(); $conditions = array(); if ($this->getRequest()->getParam('nameSearch')) { $params['nameSearch'] = $this->getRequest()->getParam('nameSearch'); } if ($this->getRequest()->getParam('idGroupSearch')) { $params['idGroupSearch'] = $this->getRequest()->getParam('idGroupSearch'); } if ($this->getRequest()->getParam('fromDate')) { $params['fromDate'] = date("Y-m-d", strtotime($this->getRequest()->getParam('fromDate'))); } if ($this->getRequest()->getParam('toDate')) { $params['toDate'] = date("Y-m-d", strtotime($this->getRequest()->getParam('toDate'))); } //BEGIN:SELECT EXPENSES $conditions['pagination'] = true; $expenses = new Default_Model_RecurrentExpenses(); $select = $expenses->getMapper()->getDbTable()->select()->from(array('p' => 'recurrent_expenses'), array('p.id', 'p.name', 'p.price', 'p.date', 'p.created', 'p.deleted'))->where('p.type=?', 0)->where('NOT p.deleted')->where('idMember=?', Zend_Registry::get('user')->getId()); if (!empty($params['nameSearch'])) { $select->where('p.name LIKE ?', '%' . $params['nameSearch'] . '%'); } if (!empty($params['idGroupSearch'])) { $select->where('p.idGroup = ?', $params['idGroupSearch']); } if (!empty($params['fromDate'])) { $select->where('p.date >= ?', $params['fromDate']); } if (!empty($params['toDate'])) { $select->where('p.date <= ?', $params['toDate']); } $select->joinLeft(array('uf' => 'uploaded_files'), 'p.`id` = uf.`idMessage`', array('ufiles' => 'uf.id', 'recurrent' => 'uf.idUser'))->setIntegrityCheck(false); $select->order(array('date DESC')); $resultExpense = Needs_Tools::showRecurrentExpensesDashboardbyDate(!empty($params['fromDate']) ? $params['fromDate'] : date('Y-m-01'), !empty($params['toDate']) ? $params['toDate'] : date('Y-m-d')); $this->view->resultExpense = $resultExpense; //END:SELECT PROJECTS $form = new Default_Form_RecurrentExpenses(); $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/recurrent-expenses/add-expense.phtml')))); $this->view->form = $form; if ($this->getRequest()->isPost() && $this->getRequest()->getParam('control') == 'addExpense') { if ($form->isValid($this->getRequest()->getPost())) { $post = $this->getRequest()->getPost(); $model = new Default_Model_RecurrentExpenses(); $model->setOptions($form->getValues()); $model->setDate(date("Y-m-d", strtotime($post["date"]))); $model->setType('0'); $idGroup = $this->getRequest()->getParam('idGroup'); $model->setIdGroup($idGroup); if ($expenseId = $model->save()) { if (!empty($post['galleryFiles']) && is_array($post['galleryFiles'])) { foreach ($post['galleryFiles'] as $valuesGallery) { $tmpFiles = new Default_Model_TempFiles(); if ($tmpFiles->find($valuesGallery)) { $post = $this->getRequest()->getPost(); $gallery = new Default_Model_FileManager(); $gallery->setOptions($form->getValues()); $gallery->setType($tmpFiles->getFileType()); $gallery->setSize($tmpFiles->getFileSize()); $gallery->setModule('sharedfiles'); $gallery->setIdMessage($expenseId); $gallery->setIdUser(1); $gallery->setName($tmpFiles->getFileName()); $savedId = $gallery->save(); if ($savedId) { $shared = new Default_Model_SharedList(); $shared->setIdUser(Zend_Registry::get('user')->getId()); $shared->setIdFile($savedId); $shared->save(); } //copy picture and crop $tempFile = APPLICATION_PUBLIC_PATH . '/media/temps/' . $tmpFiles->getFileName(); $targetFile = APPLICATION_PUBLIC_PATH . '/media/files/' . $tmpFiles->getFileName(); @copy($tempFile, $targetFile); @unlink($tempFile); $tmpFiles->delete(); } } //END:SAVE ATTACHMENTS } $idGroup = $this->getRequest()->getParam('idGroup'); $modelGroup = new Default_Model_ProductGroups(); $modelGroup->setIdProduct($expenseId); $modelGroup->setIdGroup($idGroup); $modelGroup->setRepeated(1); $modelGroup->save(); //mesaj de succes $this->_flashMessenger->addMessage("<div class='success canhide'><p>Recurrent expense was added successfully<a href='javascript:;'></a><p></div>"); } else { //mesaj de eroare $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Recurrent expense was not added<a href='javascript:;'></a><p></div>"); } //redirect $this->_redirect(WEBROOT . 'recurrent-expenses'); } } $formsearch = new Default_Form_RecurrentExpenseSearch(); $formsearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/recurrent-expenses/expense-search.phtml')))); $this->view->formsearch = $formsearch; $this->view->search = $params; // pagination $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginator->setItemCountPerPage(15); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setPageRange(5); Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $params)); $this->view->result = $paginator; $this->view->itemCountPerPage = $paginator->getItemCountPerPage(); $this->view->totalItemCount = $paginator->getTotalItemCount(); }
public function indexAction() { // BEGIN:FILTERS $filters = array(); //array with variables to send to pagination (filters) $type = $this->getRequest()->getParam('type'); //can be 'sent','trash' or empty (inbox) $this->view->type = $type; if (!empty($type)) { $filters['type'] = $type; } $searchTxt = $this->getRequest()->getParam('searchTxt'); if (!empty($searchTxt)) { $filters['searchTxt'] = $searchTxt; } $this->view->search = $filters; // END:FILTERS //BEGIN:SEARCH FORM $formSearch = new Default_Form_MessagesSearch(); $formSearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/messages-search.phtml')))); $this->view->formSearch = $formSearch; //END:SEARCH FORM //BEGIN:FORM ADD $replyId = $this->getRequest()->getParam('replyId'); $form = new Default_Form_Messages(); $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/messages.phtml')))); if (!empty($replyId)) { $model = new Default_Model_Messages(); $model->find($replyId); if ($model->getIdUserTo() == Zend_Registry::get('user')->getId()) { $form->reply($model); } } $this->view->form = $form; if ($this->getRequest()->isPost()) { $post = $this->getRequest()->getPost(); if (!empty($post['action']) && $post['action'] == 'add') { //if is valid save message if ($form->isValid($this->getRequest()->getPost())) { //save message $model = new Default_Model_Messages(); $model->setOptions($form->getValues()); $model->setIdUserFrom(Zend_Registry::get('user')->getId()); $savedId = $model->save(); if ($savedId) { //BEGIN:SAVE ATTACHMENTS if (!empty($post['galleryFiles']) && is_array($post['galleryFiles'])) { foreach ($post['galleryFiles'] as $valuesGallery) { $tmpFiles = new Default_Model_TempFiles(); if ($tmpFiles->find($valuesGallery)) { $gallery = new Default_Model_UploadedFiles(); $gallery->setIdMessage($savedId); $gallery->setType($tmpFiles->getFileType()); $gallery->setIdUser(Zend_Registry::get('user')->getId()); $gallery->setModule('messages'); $gallery->setName($tmpFiles->getFileName()); $gallery->save(); //copy picture and crop $tempFile = APPLICATION_PUBLIC_PATH . '/media/temps/' . $tmpFiles->getFileName(); $targetFile = APPLICATION_PUBLIC_PATH . '/media/files/' . $tmpFiles->getFileName(); @copy($tempFile, $targetFile); @unlink($tempFile); $tmpFiles->delete(); } } } //END:SAVE ATTACHMENTS $this->_flashMessenger->addMessage("<div class='success canhide'><p>Your message was succesfully sent.</p><a href='javascript:;'></a></div>"); } else { $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Error sending message!</p><a href='javascript:;'></a></div>"); } $this->_redirect(WEBROOT . 'messages'); } } } //END:FORM ADD //BEGIN:LISTING $model = new Default_Model_Messages(); $select = $model->getMapper()->getDbTable()->select(); if (!empty($type) && $type == 'sent') { //sent $select->from(array('u' => 'messages'), array('u.id', 'idUserFrom' => 'u.idUserTo', 'u.subject', 'u.created'))->where('u.idUserFrom = ?', Zend_Registry::get('user')->getId())->where('NOT u.deletedFrom')->where('NOT u.trashedFrom'); } elseif (!empty($type) && $type == 'trash') { //trash $select->from(array('u' => 'messages'), array('u.id', 'u.idUserFrom', 'u.idUserTo', 'u.subject', 'u.created'))->where("" . "(u.idUserTo = '" . Zend_Registry::get('user')->getId() . "' AND u.trashedTo = 1 AND NOT u.deletedTo) " . "OR " . "(u.idUserFrom = '" . Zend_Registry::get('user')->getId() . "' AND u.trashedFrom = 1 AND NOT u.deletedFrom)"); } else { //inbox $select->from(array('u' => 'messages'), array('u.id', 'u.idUserFrom', 'u.idUserTo', 'u.subject', 'u.created'))->where('u.idUserTo = ?', Zend_Registry::get('user')->getId())->where('NOT u.deletedTo')->where('NOT u.trashedTo'); } if (!empty($searchTxt)) { $select->where("u.subject LIKE ('%" . $searchTxt . "%') OR u.message LIKE ('%" . $searchTxt . "%')"); } $select->order('u.created DESC')->setIntegrityCheck(false); // pagination $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginator->setItemCountPerPage(10); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setPageRange(5); Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $filters)); $this->view->inboxNr = Needs_Messages::getInboxMessagesNumber(); $this->view->sentNr = Needs_Messages::getSentMessagesNumber(); $this->view->trashNr = Needs_Messages::getTrashMessagesNumber(); $this->view->result = $paginator; $this->view->itemCountPerPage = $paginator->getItemCountPerPage(); $this->view->totalItemCount = $paginator->getTotalItemCount(); //END:LISTING }
/** * Get the array of records satisfying the criteria specified in the parameter $options using Zend_Paginator * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array Default_Model_DbTable_BlogPost objects */ public static function GetPaginatorPosts($db, $options = array()) { $arrResult = array(); $_config = Zend_Registry::get('config'); $itemCountPerPage = (int) $_config['paginator']['itemCountPerPage']; $pagesInRange = (int) $_config['paginator']['pagesInRange']; //--------------------------------------------------------- // инициализация опций $defaults = array('itemCountPerPage' => $itemCountPerPage, 'pagesInRange' => $pagesInRange, 'page' => 1, 'offset' => 0, 'limit' => 0, 'order' => 'p.ts_created', 'sort' => true); foreach ($defaults as $k => $v) { $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v; } $select = self::_GetBaseQuery($db, $options); // установим поля таблицы для запроса $select->from(null, 'p.*'); // set the offset, limit, and ordering of results if ($options['limit'] > 0) { $select->limit($options['limit'], $options['offset']); } // Установим параметры сортировки для таблицы if ($options['sort']) { $select = self::GetSelectForSort($select, $options); } //------ Создадим обьект Zend_Paginator --------- $strSelect = $select->__toString(); $adapter = new Zend_Paginator_Adapter_DbSelect($select); $count = self::GetPostsCount($db, $options); $adapter->setRowCount($count); $paginator = new Zend_Paginator($adapter); // Установим максимальное количество отображаемых на странице элементов $paginator->setItemCountPerPage($options['itemCountPerPage']); // Установи массив страниц, возвращенный текущим стилем прокрутки $paginator->setPageRange($options['pagesInRange']); // Установим текущую страницу $paginator->setCurrentPageNumber($options['page']); //----- Конфигурирование кеша для Paginator ----- $pgCache = Default_Plugin_SysBox::getCache('paginator'); if ($pgCache->getOption('caching')) { // Установим кеш для Paginator Zend_Paginator::setCache($pgCache); // Очищение кеша if (Default_Plugin_SysBox::isCleanCache()) { $paginator->clearPageItemCache(); } } // получим данные в виде массива обьектов Default_Model_DbTable_BlogPost $posts = self::BuildMultiple($db, __CLASS__, $paginator); $post_ids = array_keys($posts); if (count($post_ids) == 0) { return array(); } // получим данные о загруженных сообщениях $profiles = Default_Model_Profile::BuildMultiple($db, 'Default_Model_DbTable_BlogPostProfile', array($post_ids)); foreach ($posts as $post_id => $post) { if (array_key_exists($post_id, $profiles) && $profiles[$post_id] instanceof Default_Model_DbTable_BlogPostProfile) { $posts[$post_id]->profile = $profiles[$post_id]; } else { $posts[$post_id]->profile->setPostId($post_id); } //!!!!------ Начало установки признака сортировки -----!!!!! if (isset($options['sortColumn'])) { $posts[$post_id]->sortColumn = $options['sortColumn']; } if (isset($options['ascDescFlg'])) { $posts[$post_id]->ascDescFlg = $options['ascDescFlg']; } //!!!!------ Конец установки признака сортировки -----!!!!! } // load the images for each post $options = array('post_id' => $post_ids); $images = Default_Model_DbTable_BlogPostImage::GetImages($db, $options); foreach ($images as $image) { $posts[$image->post_id]->images[$image->getId()] = $image; } // load the locations for each post $locations = Default_Model_DbTable_BlogPostLocation::GetLocations($db, $options); foreach ($locations as $l) { $posts[$l->post_id]->locations[$l->getId()] = $l; } // load the audio for each post $audios = Default_Model_DbTable_BlogPostAudio::GetAudio($db, $options); foreach ($audios as $audio) { $posts[$audio->post_id]->audio[$audio->getId()] = $audio; } // load the video for each post $videos = Default_Model_DbTable_BlogPostVideo::GetVideo($db, $options); foreach ($videos as $video) { $posts[$video->post_id]->video[$video->getId()] = $video; } // load the comments for each post $comments = Default_Model_DbTable_BlogPostComment::GetComments($db, $options); foreach ($comments as $comment) { $posts[$comment->post_id]->comments[$comment->getId()] = $comment; } $arrResult['pages'] = $paginator->getPages(); $arrResult['items'] = $posts; return $arrResult; }
/** * @param Object_BlogEntry_List $list * @param integer $page * @param integer $perPage * @return Zend_Paginator */ protected function _paginate(Object_BlogEntry_List $list, $page, $perPage) { $paginator = new Zend_Paginator($list); $paginator->setItemCountPerPage((int) $perPage); $paginator->setCurrentPageNumber((int) $page); $paginator->setPageRange(5); return $paginator; }
public function indexAction() { $auth = Zend_Auth::getInstance(); $authAccount = $auth->getStorage()->read(); $params = array(); $conditions = array(); if ($this->getRequest()->getParam('nameSearch')) { $params['nameSearch'] = $this->getRequest()->getParam('nameSearch'); } //BEGIN:SELECT GROUPS $conditions['pagination'] = true; $groups = new Default_Model_Groups(); $select = $groups->getMapper()->getDbTable()->select()->from(array('g' => 'groups'), array('g.id', 'g.name', 'g.created', 'g.deleted'))->joinLeft(array('pg' => 'product_groups'), 'g.id = pg.idGroup', array('productsNr' => 'COUNT(pg.id)'))->where('NOT g.deleted'); if (!empty($params['nameSearch'])) { $select->where('name LIKE ?', '%' . $params['nameSearch'] . '%'); } $select->group('g.id'); $select->setIntegrityCheck(false); $select->order(array('name ASC')); //END:SELECT GROUPS $form = new Default_Form_Groups(); $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/groups/add-group.phtml')))); $this->view->form = $form; $this->view->color = "#fff"; //$this->view->search=$params; if ($this->getRequest()->getParam('idGroup')) { $id = $this->getRequest()->getParam('idGroup'); $model = new Default_Model_Groups(); if ($model->find($id)) { $form = new Default_Form_Groups(); $form->edit($model); $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/groups/edit-group.phtml')))); $this->view->form = $form; $this->view->color = $model->getColor(); $this->view->idGroup = $model->getId(); if ($this->getRequest()->isPost()) { if ($this->getRequest()->getPost('submit')) { if ($form->isValid($this->getRequest()->getPost())) { $model->setOptions($form->getValues()); if ($groupId = $model->save()) { //mesaj de succes $this->_flashMessenger->addMessage("<div class='success canhide'><p>Group was modified successfully<a href='javascript:;'></a></p></div>"); } else { $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Group was not modified<a href='javascript:;'></a></p></div>"); } $this->_redirect(WEBROOT . 'groups'); } } } } } elseif ($this->getRequest()->isPost()) { // && $this->getRequest()->getParam('action') == 'add' if ($form->isValid($this->getRequest()->getPost())) { $post = $this->getRequest()->getPost(); $model = new Default_Model_Groups(); $model->setOptions($form->getValues()); if ($groupId = $model->save()) { //mesaj de succes $this->_flashMessenger->addMessage("<div class='success canhide'><p>Group was added successfully<a href='javascript:;'></a><p></div>"); } else { //mesaj de eroare $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Group was not added<a href='javascript:;'></a><p></div>"); } //redirect $this->_redirect(WEBROOT . 'groups'); } } $formsearch = new Default_Form_GroupSearch(); $formsearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/groups/group-search.phtml')))); $this->view->formsearch = $formsearch; $this->view->search = $params; // pagination $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginator->setItemCountPerPage(20); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setPageRange(5); Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', array())); $this->view->result = $paginator; $this->view->itemCountPerPage = $paginator->getItemCountPerPage(); $this->view->totalItemCount = $paginator->getTotalItemCount(); }
/** * Constructor * * Registers form view helper as decorator * * @param mixed $options * @return void */ public function __construct($select, $tables, $field_list, $options = null) { $this->_db = Zend_registry::get('db'); $_frontController = Zend_Controller_Front::getInstance(); $this->_request = $_frontController->getRequest(); if (null === $this->_view) { require_once 'Zend/Controller/Action/HelperBroker.php'; $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $this->_view = $viewRenderer->view; } if (!empty($options['actionKey'])) { $this->_view->actionKey = $options['actionKey']; } if (!empty($options['commands'])) { $this->_view->assign('commands', $options['commands']); } if (!empty($options['to-excel-action'])) { $this->_view->assign('to_excel_action', $options['to-excel-action']); } else { $this->_view->assign('to_excel_action', 'to-excel'); } if (!empty($options['disable-export-to-excel'])) { $this->_view->assign('disable_export_to_excel', $options['disable-export-to-excel']); } else { $this->_view->assign('disable_export_to_excel', 'false'); } if (!empty($options['enable-print'])) { $this->_view->assign('enable_print', $options['enable-print']); $this->_view->headScript()->appendFile($this->_view->locateFile('jquery.printElement.min.js')); } else { $this->_view->assign('enable_print', 'false'); } if (!empty($options['filters'])) { $this->_view->assign('filters', $options['filters']); foreach ($options['filters'] as $key => $filter) { $filter_val = $this->_request->getParam($key); if (!empty($filter_val)) { if ($filter['associatedTo'] != '') { if (!empty($filter['kindOfFilter']) && $filter['kindOfFilter'] == 'list') { $select->where("{$filter['associatedTo']} = '{$filter_val}'\r\n OR {$filter['associatedTo']} like '%{$filter_val}%'\r\n OR {$filter['associatedTo']} like '%,{$filter_val}'\r\n OR {$filter['associatedTo']} like '{$filter_val},%'\r\n OR {$filter['associatedTo']} like '%,{$filter_val},%'\r\n "); } else { $select->where("{$filter['associatedTo']} = ?", $filter_val); } } } } } else { $this->_view->assign('filters', array()); } if (!empty($options['action_panel'])) { if (!empty($options['action_panel'])) { $field_list['action_panel'] = $options['action_panel']; } if (!empty($options['action_panel']['actions'])) { $this->_view->assign('action_links', $options['action_panel']['actions']); } } $this->_view->assign('field_list', $field_list); if ($this->_request->getParam('order')) { if (in_array($this->_request->getParam('order'), array_keys($field_list))) { $direction = 'ASC'; if (in_array($this->_request->getParam('order-direction'), array('ASC', 'DESC'))) { $direction = $this->_request->getParam('order-direction'); } $select->order("{$this->_request->getParam('order')} {$direction}"); $this->_view->assign('order', $this->_request->getParam('order')); $this->_view->assign('order_direction', $this->_request->getParam('order-direction')); } } $searchfor = $this->_request->getParam('searchfor'); if ($searchfor) { $searching_on = array(); $search_keywords = explode(' ', $searchfor); foreach ($tables as $table => $columns) { foreach ($columns as $column) { $doSearch = true; if (isset($options['onlyColumns'])) { if (!in_array($column, $options['onlyColumns'])) { $doSearch = false; } } else { if (isset($options['excludedColums'])) { if (in_array($column, $options['excludedColums'])) { $doSearch = false; } } } if ($doSearch == true) { array_push($searching_on, $this->_db->quoteInto("{$table}.{$column} LIKE ?", "%{$searchfor}%")); foreach ($search_keywords as $keyword) { array_push($searching_on, $this->_db->quoteInto("{$table}.{$column} LIKE ?", "%{$keyword}%")); } } } } if (!empty($searching_on)) { $select->where(implode(' OR ', $searching_on)); } } $this->_view->assign('searchfor', $searchfor); $adapter = new Zend_Paginator_Adapter_DbSelect($select); $paginator = new Zend_Paginator($adapter); $_config = Zend_Registry::get('config'); $itemPerPage = 10; if (!empty($_config->lists->itemPerPage)) { $itemPerPage = $_config->lists->itemPerPage; } if (!empty($options['list_options']['perPage'])) { $itemPerPage = $options['list_options']['perPage']; } if ($this->_request->getParam('perPage')) { $itemPerPage = $this->_request->getParam('perPage') == 'all' ? $paginator->getTotalItemCount() : $this->_request->getParam('perPage'); } $pageRange = 5; if (!empty($_config->lists->pageRange)) { $pageRange = $_config->lists->pageRange; } $paginator->setItemCountPerPage($itemPerPage); $paginator->setCurrentPageNumber($this->_request->getParam('page')); $paginator->setPageRange($pageRange); $this->_view->assign('paginator', $paginator); }
function fun_paginator($ArrData) { $pager = new Zend_Paginator(new Zend_Paginator_Adapter_Array($ArrData)); $currentPage = isset($_GET['p']) ? (int) htmlentities($_GET['p']) : 1; $pager->setCurrentPageNumber($currentPage); $itemsPerPage = 12; $pager->setItemCountPerPage($itemsPerPage); $pager->setPageRange(10); $pages = $pager->getPages(); $pageLinks = array(); $separator = ' | '; //$this->view->separator=$separator; if ($pages->pageCount > 1) { if ($pages->current == $pages->first) { $pageLinks[] = "<li >First</li>"; $pageLinks[] = "<li >Privious</li>"; } else { $previous = $pages->current - 1; $first = $pages->first; $pageLinks[] = "<li ><a href=\"?p={$first}\">First</a></li>"; $pageLinks[] = "<li><a href=\"?p={$previous}\">Privious</a></li>"; } for ($x = $pages->firstPageInRange; $x <= $pages->lastPageInRange; $x++) { if ($x == $pages->current) { $pageLinks[] = "<li>" . $x . "</li>"; } else { $q = http_build_query(array('p' => $x)); $pageLinks[] = "<li><a href=\"?{$q}\">{$x}</a></li>"; } } if ($pages->current == $pages->last) { $pageLinks[] = "<li>Next</li>"; $pageLinks[] = "<li>Last</li>"; } else { $last = $pages->last; $next = $pages->current + 1; $pageLinks[] = "<li><a href=\"?p={$next}\">Next</a></li>"; $pageLinks[] = "<li><a href=\"?p={$last}\">Last</a></li>"; } } $pagedata['pageLinks'] = $pageLinks; $pagedata['pagingdata'] = $pager->getCurrentItems(); return $pagedata; }