public function getPaginationReturnModule($query, $recordsperpage = 10, $pagenumber = 1, $api = null, $flag = null) { //echo "<b>api=$api</b><br>"; $obj_user = array(); $obj_create = new App_Model_Objcreation(); if ($query == "error") { $obj_user = $obj_create->createObjfalse(3); } else { if ($query == "invalid") { $obj_user = $obj_create->createObjfalse(4); } else { $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($query)); $paginator->setItemCountPerPage($recordsperpage)->setCurrentPageNumber($pagenumber); if ($paginator->getTotalItemCount()) { if ($api == "category") { $obj_user = $obj_create->createObjCategory($paginator); } else { if ($api == "subcategory") { $obj_user = $obj_create->createObjSubCategory($paginator); } else { if ($api == "dealdet") { $obj_user = $obj_create->createObjDealDetail($paginator, $flag); } else { $obj_user = $obj_create->createObj($paginator, $flag); } } } } else { $obj_user = $obj_create->createObjfalse(1); } } } //end of else of if($category_result=="error") return $obj_user; }
/** * Create the page object used in View - paginator method * @access public * @return object */ public function getPages() { $pages = new stdClass(); $pageCount = $this->_paginator->count(); $pages->pageCount = $pageCount; $pages->itemCountPerPage = $this->_itemCountPerPage; $pages->first = 1; $pages->current = (int) $this->_currentPage; $pages->last = $pageCount; // Previous and next if ($this->_currentPage - 1 > 0) { $pages->previous = $this->_currentPage - 1; } if ($this->_currentPage + 1 <= $pageCount) { $pages->next = $this->_currentPage + 1; } // Pages in range $pageRange = $this->_paginator->getPageRange(); if ($pageRange > $pageCount) { $pageRange = $pageCount; } $delta = ceil($pageRange / 2); if ($this->_currentPage - $delta > $pageCount - $pageRange) { $lowerBound = $pageCount - $pageRange + 1; $upperBound = $pageCount; } else { if ($this->_currentPage - $delta < 0) { $delta = $this->_currentPage; } $offset = $this->_currentPage - $delta; $lowerBound = $offset + 1; $upperBound = $offset + $pageRange; } $pages->pagesInRange = $this->_paginator->getPagesInRange($lowerBound, $upperBound); $pages->firstPageInRange = min($pages->pagesInRange); $pages->lastPageInRange = max($pages->pagesInRange); // Item numbers if ($this->_currentItems == null) { $this->getCurrentItems(); } if ($this->_currentItems !== null) { $pages->currentItemCount = $this->_paginator->getCurrentItemCount(); $pages->itemCountPerPage = $this->_paginator->getItemCountPerPage(); $pages->totalItemCount = $this->_paginator->getTotalItemCount(); $pages->firstItemNumber = ($this->_currentPage - 1) * $this->_paginator->getItemCountPerPage() + 1; $pages->lastItemNumber = $pages->firstItemNumber + $pages->currentItemCount - 1; } return $pages; }
/** * Returns a paginated list of all sites matching the given parameters. * * @param array $params * @return array */ public static function search(array $params) { $siteDb = Yadda_Db_Table::getInstance('site'); $select = $siteDb->select()->setIntegrityCheck(false)->from('site')->joinLeft('deal', 'site.id = deal.site_id', array('latest_deal' => 'MAX(deal.created)'))->where('site.status = ?', 'active')->group('site.id')->order('site.name'); // fetch $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginator->setCurrentPageNumber(isset($params['page']) ? (int) $params['page'] : 1); $paginator->setItemCountPerPage(isset($params['count']) ? (int) $params['count'] : 10); $return = array('params' => $params, 'total' => $paginator->getTotalItemCount(), 'page' => $paginator->getCurrentPageNumber(), 'pages' => $paginator->count(), 'results' => array()); $sites = new Zend_Db_Table_Rowset(array('table' => $siteDb, 'data' => (array) $paginator->getCurrentItems())); foreach ($sites as $site) { $return['results'][] = self::toArray($site); } return $return; }
public static function search($params) { // build query $subscriptionDb = Yadda_Db_Table::getInstance('subscription'); $select = $subscriptionDb->select()->setIntegrityCheck(false)->from('subscription')->joinLeft('user', 'subscription.user_id = user.id', array('user_email' => 'email'))->where('subscription.status = ?', 'active')->order('created DESC'); // fetch $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginator->setCurrentPageNumber(isset($params['page']) ? (int) $params['page'] : 1); $paginator->setItemCountPerPage(isset($params['count']) ? (int) $params['count'] : 10); $return = array('params' => $params, 'total' => $paginator->getTotalItemCount(), 'page' => $paginator->getCurrentPageNumber(), 'pages' => $paginator->count(), 'results' => array()); $subscriptions = new Zend_Db_Table_Rowset(array('table' => $subscriptionDb, 'data' => (array) $paginator->getCurrentItems())); foreach ($subscriptions as $subscription) { $return['results'][] = self::toArray($subscription); } return $return; }
/** * Returns a paginated list of regions matching the given parameters. * * @param array $params * @return array */ public static function search(array $params) { // build query $regionDb = Yadda_Db_Table::getInstance('region'); $select = $regionDb->select()->from('region')->where('status = ?', 'active')->order('name'); // fetch $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginator->setCurrentPageNumber(isset($params['page']) ? (int) $params['page'] : 1); $paginator->setItemCountPerPage(isset($params['count']) ? (int) $params['count'] : 10); $return = array('params' => $params, 'total' => $paginator->getTotalItemCount(), 'page' => $paginator->getCurrentPageNumber(), 'pages' => $paginator->count(), 'results' => array()); $regions = new Zend_Db_Table_Rowset(array('table' => $regionDb, 'data' => (array) $paginator->getCurrentItems())); foreach ($regions as $region) { $return['results'][] = self::toArray($region); } return $return; }
public function testPaginator() { $countries = My_ShantyMongo_Country::all(); $this->assertEquals(239, $countries->count()); $paginator = new Zend_Paginator(new Shanty_Paginator_Adapter_Mongo($countries)); $paginator->setItemCountPerPage(10); $paginator->setCurrentPageNumber(3); $this->assertEquals(24, $paginator->count()); // Count pages $this->assertEquals(239, $paginator->getTotalItemCount()); // count total items $this->assertEquals(10, $paginator->getCurrentItemCount()); // count items on this page $paginator->getCurrentItems()->rewind(); $firstItem = $paginator->getCurrentItems()->current(); $this->assertEquals($firstItem->code, 'BB'); $this->assertEquals($firstItem->name, 'Barbados'); }
/** * Consulta os cancelamentos solicitados pelos contribuintes */ public function consultarAction() { if ($this->getRequest()->isPost()) { parent::noTemplate(); $aSolicitacoes = array(); $aParametros = $this->getAllParams(); $iLimit = $aParametros['rows']; $iPage = $aParametros['page']; $aFiltros = array('rejeitado' => NULL, 'autorizado' => NULL); $aOrdem = array('dt_solicitacao' => 'DESC'); $aSolicatacoesCancelamento = Contribuinte_Model_SolicitacaoCancelamento::getByAttributes($aFiltros, $aOrdem); $oPaginatorAdapter = new DBSeller_Controller_PaginatorArray($aSolicatacoesCancelamento); $aResultado = new Zend_Paginator($oPaginatorAdapter); $aResultado->setItemCountPerPage($iLimit); $aResultado->setCurrentPageNumber($iPage); $iTotal = $aResultado->getTotalItemCount(); $iTotalPages = $aResultado->getPages()->pageCount; foreach ($aResultado as $oSolicatacaoCancelamento) { $sMotivo = $this->getMotivoDescricaoCancelamento($oSolicatacaoCancelamento->getMotivo()); $sData = $oSolicatacaoCancelamento->getDtSolicitacao()->format("d/m/Y"); $sRazaoSocial = $oSolicatacaoCancelamento->getNota()->getP_razao_social(); $sCpfCnpj = DBSeller_Helper_Number_Format::maskCPF_CNPJ($oSolicatacaoCancelamento->getNota()->getP_cnpjcpf()); $iNota = $oSolicatacaoCancelamento->getNota()->getNota(); // Montado objeto que será retorna à grid $oSolicitacao = new StdClass(); $oSolicitacao->id = $oSolicatacaoCancelamento->getId(); $oSolicitacao->motivo_label = is_string($sMotivo) ? $sMotivo : "-"; $oSolicitacao->dt_solicitacao = $sData; $oSolicitacao->nome_contribuinte = $sRazaoSocial; $oSolicitacao->nota = $iNota; $oSolicitacao->cnpj = $sCpfCnpj; $aSolicitacoes[] = $oSolicitacao; } /** * Parametros de retorno do AJAX */ $aRetornoJson = array('total' => $iTotalPages, 'page' => $iPage, 'records' => $iTotal, 'rows' => $aSolicitacoes); echo $this->getHelper('json')->sendJson($aRetornoJson); } }
/** * 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); }
/** * Action responsável por listar as contas */ public function listarContasAction() { if ($this->getRequest()->isPost()) { parent::noTemplate(); $aRecord = array(); $iLimit = $this->_request->getParam('rows'); $iPage = $this->_request->getParam('page'); $sSord = $this->_request->getParam('sord'); $oPaginatorAdapter = new DBSeller_Controller_Paginator(Contribuinte_Model_PlanoContaAbrasf::getQuery(), 'Contribuinte_Model_PlanoContaAbrasf', 'Contribuinte\\PlanoContaAbrasf'); /** * Ordena os registros */ $oPaginatorAdapter->orderBy("e.id, e.conta_abrasf", $sSord); /** * Monta a paginação do GridPanel */ $oResultado = new Zend_Paginator($oPaginatorAdapter); $oResultado->setItemCountPerPage($iLimit); $oResultado->setCurrentPageNumber($iPage); $iTotal = $oResultado->getTotalItemCount(); $iTotalPages = $iTotal > 0 && $iLimit > 0 ? ceil($iTotal / $iLimit) : 0; foreach ($oResultado as $oPlanoContaAbrasf) { $oDadosColuna = new StdClass(); $oDadosColuna->id = $oPlanoContaAbrasf->getId(); $oDadosColuna->conta_abrasf = $oPlanoContaAbrasf->getContaAbrasf(); $oDadosColuna->titulo_contabil_desc = $oPlanoContaAbrasf->getTituloContabilDesc(); $oDadosColuna->tributavel = $oPlanoContaAbrasf->getTributavel(); $oDadosColuna->obrigatorio = $oPlanoContaAbrasf->getObrigatorio(); $aRecord[] = $oDadosColuna; } /** * Parametros de retorno do AJAX */ $aRetornoJson = array('total' => $iTotalPages, 'page' => $iPage, 'records' => $iTotal, 'rows' => $aRecord); echo $this->getHelper('json')->sendJson($aRetornoJson); } }
/** * Create the grid data structure * * @return object */ protected function _createGridData(Zend_Controller_Request_Abstract $request) { // Instantiate Zend_Paginator with the required data source adaptor if (!$this->_paginator instanceof Zend_Paginator) { $this->_paginator = new Zend_Paginator($this->_adapter); $this->_paginator->setDefaultItemCountPerPage($request->getParam('rows', $this->_defaultItemCountPerPage)); } // Filter items by supplied search criteria if ($request->getParam('_search') == 'true') { $filter = $this->_getFilterParams($request); $this->_paginator->getAdapter()->filter($filter['field'], $filter['value'], $filter['expression'], $filter['options']); } // Sort items by the supplied column field if ($request->getParam('sidx')) { $this->_paginator->getAdapter()->sort($request->getParam('sidx'), $request->getParam('sord', 'asc')); } // Pass the current page number to paginator $this->_paginator->setCurrentPageNumber($request->getParam('page', 1)); // Fetch a row of items from the adapter $rows = $this->_paginator->getCurrentItems(); $grid = new stdClass(); $grid->page = $this->_paginator->getCurrentPageNumber(); $grid->total = $this->_paginator->getItemCountPerPage(); $grid->records = $this->_paginator->getTotalItemCount(); $grid->rows = array(); foreach ($rows as $k => $row) { if (isset($row['id'])) { $grid->rows[$k]['id'] = $row['id']; } $grid->rows[$k]['cell'] = array(); foreach ($this->_columns as $column) { array_push($grid->rows[$k]['cell'], $column->cellValue($row)); } } return $grid; }
/** * 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); }
/** * Método para retornar os dados das contas em formato json para a DBJqGrid * * @param array $aParametros * @param bool $bDetalhes * @return array */ protected function retornaContasGuiaDesif(array $aParametros, $bDetalhes = FALSE) { $aRecord = array(); $iLimit = $aParametros['rows']; $iPage = $aParametros['page']; $sSord = $aParametros['sord']; $oContribuinte = $this->_session->contribuinte; $sCodigosContribuintes = NULL; $oPaginatorAdapter = new DBSeller_Controller_Paginator(Contribuinte_Model_ImportacaoDesif::getQuery(), 'Contribuinte_Model_ImportacaoDesif', 'Contribuinte\\ImportacaoDesif'); foreach ($oContribuinte->getContribuintes() as $iIdContribuinte) { if ($sCodigosContribuintes == NULL) { $sCodigosContribuintes .= $iIdContribuinte; } else { $sCodigosContribuintes .= ',' . $iIdContribuinte; } } $oPaginatorAdapter->where("e.contribuinte in ({$sCodigosContribuintes})"); if (isset($aParametros['id'])) { $oPaginatorAdapter->andWhere("e.id = {$aParametros['id']}"); } $oPaginatorAdapter->orderBy("e.competencia_inicial, e.competencia_final", $sSord); /** * Monta a paginação do GridPanel */ $oResultado = new Zend_Paginator($oPaginatorAdapter); $oResultado->setItemCountPerPage($iLimit); $oResultado->setCurrentPageNumber($iPage); foreach ($oResultado as $oDesif) { $aValores = Contribuinte_Model_ImportacaoDesif::getTotalReceitasGuia($oDesif->getId(), $bDetalhes); /** * Verifica se for para exibir as aliquotas detalhadas */ if ($bDetalhes) { foreach ($aValores['aliquotas_issqn'] as $iAliqIssqn => $aReceitas) { $aRecord[] = array('id_importacao_desif' => $oDesif->getId(), 'aliq_issqn' => DBSeller_Helper_Number_Format::toFloat($iAliqIssqn), 'total_receita' => DBSeller_Helper_Number_Format::toMoney($aReceitas['total_receita'], 2, 'R$ '), 'total_iss' => DBSeller_Helper_Number_Format::toMoney($aReceitas['total_iss'], 2, 'R$ ')); } } else { if ($aValores['total_receita'] > 0 && $aValores['total_iss'] > 0) { $aRecord[] = array('id' => $oDesif->getId(), 'competencia_inicial' => $oDesif->getCompetenciaInicial(), 'competencia_final' => $oDesif->getCompetenciaFinal(), 'total_receita' => DBSeller_Helper_Number_Format::toMoney($aValores['total_receita'], 2, 'R$ '), 'total_iss' => DBSeller_Helper_Number_Format::toMoney($aValores['total_iss'], 2, 'R$ '), 'aValores' => $aValores); } } } $iTotal = $oResultado->getTotalItemCount(); $iTotalPages = $iTotal > 0 && $iLimit > 0 ? ceil($iTotal / $iLimit) : 0; /** * Parametros de retorno do AJAX */ $aRetornoJson = array('total' => $iTotalPages, 'page' => $iPage, 'records' => $iTotal, 'rows' => $aRecord); return $aRetornoJson; }
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 }
/** * Job basic for seo. * show all the jobs in the city. * @return unknown_type */ function businessAction() { //echo "jobs"; $this->view = $this->_setRequiredParamsToView($this->view); $this->view->category = $this->_busType; try { $this->view->business = $this->getBusiness(); $this->view->form = $this->getForm($this->view->business, $this->view->location); //$values['cat4'] = Location::getStateIdByName($this->view->location->getState()); // $values['cat5'] = Location::getCityIdByName($this->view->location->getCity()); $cat1 = $this->view->paramsHolder->cat1; $additonalData = $this->_getAdditionalData($this->view); $select = $this->view->business->search($this->view->location, $this->view->limit, $this->view->offset, $this->view->paramsHolder->query, $cat1, $this->view->paramsHolder->cat2, $this->view->paramsHolder->cat3, $this->view->paramsHolder->cat4, $this->view->paramsHolder->cat5, $additonalData); if (!empty($select)) { logfire('------select: ', $select->__toString()); $adapter = new Zend_Paginator_Adapter_DbTableSelect($select); $paginator = new Zend_Paginator($adapter); $paginator->setItemCountPerPage($this->view->limit); $paginator->setCurrentPageNumber($this->view->offset); Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial('sitetemplate/_pagination.phtml'); $this->view->currentItemCount = $paginator->getCurrentItemCount(); $this->view->itemCount = $paginator->getTotalItemCount(); //echo '------currentItemCoutn: ' . $this->view->currentItemCount; $paginator->setView($this->view); $this->view->postings = $paginator; /* foreach($this->view->postings as $key=>$value) { print_r($value);break; } */ } } catch (Exception $e) { echo $e; } //$this->renderScript('jobs/index.phtml'); // echo Tag::link('jobsbasic',$this->view->location->toStdClass(),'test'); }
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(); }
/** * Carrega as importações DES-IF na grid */ public function listarImportacaoDesifAction() { parent::noLayout(); $aParametro = $this->_request->getParam('form'); $oForm = new Contribuinte_Form_ConsultaImportacaoDesif(); $iCompetenciaInicial = null; if (!empty($aParametro['competencia_inicial'])) { $aCompetenciaInicial = explode('/', $aParametro['competencia_inicial']); $iCompetenciaInicial = $aCompetenciaInicial[1] . $aCompetenciaInicial[0]; } $iCompetenciaFinal = null; if (!empty($aParametro['competencia_final'])) { $aCompetenciaFinal = explode('/', $aParametro['competencia_final']); $iCompetenciaFinal = $aCompetenciaFinal[1] . $aCompetenciaFinal[0]; } $aRecord = array(); $iLimit = $this->_request->getParam('rows') ? $this->_request->getParam('rows') : 10; $iPage = $this->_request->getParam('page') ? $this->_request->getParam('page') : 0; $oContribuinte = $this->_session->contribuinte; $aIdContribuinte = $oContribuinte->getContribuintes(); $aImportacao = Contribuinte_Model_ImportacaoDesif::getImportacaoPorCompetencia($aIdContribuinte, $iCompetenciaInicial, $iCompetenciaFinal); $oPaginatorAdapter = new DBSeller_Controller_PaginatorArray($aImportacao); /** * Monta a paginação do GridPanel */ $oResultado = new Zend_Paginator($oPaginatorAdapter); $oResultado->setItemCountPerPage($iLimit); $oResultado->setCurrentPageNumber($iPage); $iTotal = $oResultado->getTotalItemCount(); $iTotalPages = $oResultado->getPages()->pageCount; $aRecord = array(); foreach ($oResultado as $oImportacaoDesif) { $sCompInicial = substr($oImportacaoDesif->getCompetenciaInicial(), 4, 2) . "/"; $sCompInicial .= substr($oImportacaoDesif->getCompetenciaInicial(), 0, 4); $sCompFinal = substr($oImportacaoDesif->getCompetenciaFinal(), 4, 2) . "/"; $sCompFinal .= substr($oImportacaoDesif->getCompetenciaFinal(), 0, 4); $oImportacaoRetorno = new StdClass(); $oImportacaoRetorno->id = $oImportacaoDesif->getId(); $oImportacaoRetorno->competencia_inicial = $sCompInicial; $oImportacaoRetorno->competencia_final = $sCompFinal; $oImportacaoRetorno->data_hora = $oImportacaoDesif->getDataImportacao()->format('d/m/Y H:i:s'); $aRecord[] = $oImportacaoRetorno; } /** * Parametros de retorno do AJAX */ $aRetornoJson = array('total' => $iTotalPages, 'page' => $iPage, 'records' => $iTotal, 'rows' => $aRecord); echo $this->getHelper('json')->sendJson($aRetornoJson); }
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(); }
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 }
public function listAction() { if ($this->_request->isXmlHttpRequest()) { $pageId = $this->_getParam('page', 1); $limit = $this->_getParam('limit', 10); $sortCol = $this->_getParam('sortCol', 1); $sortOrder = $this->_getParam('sortOrder', 'asc'); $whereParam = $this->_getParam('where', ''); $modelTable = $this->_getModel(); $modelTableName = $modelTable->info(Centurion_Db_Table_Abstract::NAME); $where = $this->_getSelect(); if (get_magic_quotes_gpc()) { $whereParam = stripslashes($whereParam); } $whereParam = (array) json_decode($whereParam); foreach ($whereParam as $param => $values) { if (isset($this->_filters[$param]['type']) && $this->_filters[$param]['type'] === self::FILTER_EXPR) { foreach ($values as $key => $value) { $where->filter($this->_filters[$param]['data'][$value]['expr']); } unset($whereParam[$param]); } if (isset($this->_filters[$param]) && $this->_filters[$param]['type'] === self::FILTER_CUSTOM && is_callable($this->_filters[$param]['callback'])) { $where = call_user_func($this->_filters[$param]['callback'], $where, $values, $param); unset($whereParam[$param]); } if (isset($this->_filters[$param]['method']) && is_callable($this->_filters[$param]['method'])) { call_user_func_array($this->_filters[$param]['method'], array($where, $values)); unset($whereParam[$param]); } } $where->filter($whereParam); $cols = array(); $naturals = $modelTable->info(Centurion_Db_Table_Abstract::COLS); $queryCols = $where->getColumnsName(); foreach ($this->_displays as $col => $value) { if (is_array($value)) { if ($value['expr'] instanceof Zend_Db_Expr) { $cols[] = $value['expr']; } } else { if (in_array($col, $naturals)) { if (!$where->isInQuery($col, $modelTableName)) { $cols[] = new Zend_Db_Expr(sprintf(sprintf('%s.%s', $modelTable->getAdapter()->quoteIdentifier($modelTableName), $modelTable->getAdapter()->quoteIdentifier($col)))); } } else { if (!in_array($col, $queryCols)) { $cols[] = new Zend_Db_Expr(sprintf('%s AS %s', $where->addRelated($col), $modelTable->getAdapter()->quoteIdentifier($col))); } } } } $where->columns($cols); if (in_array($sortCol, array_keys($this->_extras)) && method_exists($this, 'resolveCol' . ucfirst($sortCol))) { $sortCol = $this->{'resolveCol' . ucfirst($sortCol)}($where); $where->order(sprintf('%s %s', $sortCol, $sortOrder)); } else { if ($sortCol !== 1 && in_array($sortCol, array_keys($this->_displays))) { $where->order(sprintf('%s %s', $sortCol, $sortOrder)); } } $this->_preList(); $adapter = new Zend_Paginator_Adapter_DbTableSelect($where); $paginator = new Zend_Paginator($adapter); $paginator->setCurrentPageNumber($pageId)->setItemCountPerPage($limit); $result = array('pageId' => $paginator->getCurrentPageNumber(), 'nbPages' => $paginator->count(), 'nbRows' => $paginator->getTotalItemCount(), 'rows' => array()); foreach ($paginator->getCurrentItems() as $modelRow) { $tempArray = $modelRow->toArray(); foreach ($this->_extras as $key => $extra) { if (method_exists($this, $key)) { $tempArray[$key] = $this->{$key}($modelRow); } elseif (method_exists($modelRow, $key)) { $tempArray[$key] = call_user_func(array($modelRow, $key)); } else { $tempArray[$key] = $modelRow->{$key}; } } array_push($result['rows'], array('id' => $modelRow->pk, 'cell' => $tempArray)); } $result = $this->_postList($result); $json = Zend_Json::encode($result); $this->getResponse()->appendBody($json); } }
/** The lister function of all guardian articles * @access public */ public function indexAction() { $page = $this->getParam('page'); $key = md5('pas' . self::QUERY); if (!$this->getCache()->test($key)) { $guardian = self::GUARDIANAPI_URL . 'search?q=' . urlencode(self::QUERY) . '&page-size=50&order-by=newest&format=' . self::FORMAT . '&show-fields=all&show-tags=all&show-factboxes=all&show-references=all&api-key=' . $this->_apikey; $this->_curl->setUri($guardian); $this->_curl->getRequest(); $articles = $this->_curl->getJson(); $this->getCache()->save($articles); } else { $articles = $this->getCache()->load($key); } $results = array(); foreach ($articles->response->results as $article) { if (isset($article->fields->thumbnail)) { $image = $article->fields->thumbnail; } else { $image = null; } if (isset($article->fields->standfirst)) { $stand = $article->fields->standfirst; } else { $stand = null; } $tags = array(); foreach ($article->tags as $k => $v) { $tags[$k] = $v; } if (isset($article->fields->byline)) { $byline = $article->fields->byline; } else { $byline = null; } $results[] = array('id' => $article->id, 'headline' => $article->fields->headline, 'byline' => $byline, 'image' => $image, 'pubDate' => $article->webPublicationDate, 'content' => $article->fields->body, 'trailtext' => $article->fields->trailText, 'publication' => $article->fields->publication, 'sectionName' => $article->sectionName, 'linkText' => $article->webTitle, 'standfirst' => $stand, 'section' => $article->sectionName, 'url' => $article->webUrl, 'shortUrl' => $article->fields->shortUrl, 'publication' => $article->fields->publication, 'tags' => $tags); } $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($results)); Zend_Paginator::setCache($this->getCache()); if (isset($page) && $page != "") { $paginator->setCurrentPageNumber((int) $page); } $paginator->setItemCountPerPage(20)->setPageRange(10); if (in_array($this->_helper->contextSwitch()->getCurrentContext(), array('xml', 'json', 'rss', 'atom'))) { $paginated = array(); foreach ($paginator as $k => $v) { $paginated[$k] = $v; } $data = array('pageNumber' => $paginator->getCurrentPageNumber(), 'total' => number_format($paginator->getTotalItemCount(), 0), 'itemsReturned' => $paginator->getCurrentItemCount(), 'totalPages' => number_format($paginator->getTotalItemCount() / $paginator->getItemCountPerPage(), 0)); $this->view->data = $data; $this->view->guardianStories = array('guardianStory' => $paginated); } else { $this->view->data = $paginator; } }
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 searchajaxAction() { ini_set('max_execution_time', 300); global $mySession; $db = new Db(); $dbAdapter = Zend_Db_Table::getDefaultAdapter(); $this->_helper->layout->disableLayout(); /* Meta Tags ---------------------------------- */ $metaArr = $db->runQuery("select meta_title, meta_keyword, meta_description from " . META_INFO . " where meta_id = 2"); $Title = $metaArr[0]['meta_title']; $Description = $metaArr[0]['meta_description']; $this->view->country_id = $country_id = $mySession->country_id; $this->view->state_id = $state_id = $mySession->state_id; $this->view->city_id = $city_id = $mySession->city_id; $this->view->sub_area_id = $sub_area_id = $mySession->sub_area_id; $this->view->local_area_id = $local_area_id = $mySession->local_area_id; /* SEO changes made after ponky ----------------------------------------- */ $location['country'] = $mySession->country; $location['state'] = $mySession->state; $location['city'] = $mySession->city; $location['sub_area'] = $mySession->sub_area; $location['local_area'] = $mySession->local_area; $location = array_filter($location, "strlen"); switch (count($location)) { case 0: $this->view->headTitle(str_replace('[BREADCRUMB]', 'All', $Title))->offsetUnset(0); $pageTitle = ""; break; case 1: $lArr = $db->runQuery("select country_id from " . COUNTRIES . " where lower(country_name) = '" . strtolower($location['country']) . "' "); $this->view->country_id = $country_id = $lArr[0]['country_id']; //Meta title $this->view->headTitle(str_replace('[BREADCRUMB]', $location['country'], $Title))->offsetUnset(0); $pageTitle = $location['country'] . " has "; break; case 2: $lArr = $db->runQuery("select " . COUNTRIES . ".country_id, state_id from " . COUNTRIES . " \n\t\t\t\t\t\t\t\t\t\t\tinner join " . STATE . " on " . STATE . ".country_id = " . COUNTRIES . ".country_id\n\t\t\t\t\t\t\t\t\t\t\twhere lower(country_name) = '" . strtolower($location['country']) . "'\n\t\t\t\t\t\t\t\t\t\t\tand lower(state_name) = '" . strtolower($location['state']) . "' "); if (count($lArr) == 0) { $this->renderScript('/error/error.phtml'); } $this->view->country_id = $country_id = $lArr[0]['country_id']; $this->view->state_id = $state_id = $lArr[0]['state_id']; //Meta title $this->view->headTitle(str_replace('[BREADCRUMB]', $location['state'] . '>' . $location['country'], $Title))->offsetUnset(0); $pageTitle = $location['state'] . ", " . $location['country'] . " has "; break; case 3: $lArr = $db->runQuery("select " . COUNTRIES . ".country_id, " . STATE . ".state_id, " . CITIES . ".city_id from " . COUNTRIES . " \n\t\t\t\t\t\t\t\t\t\t\tinner join " . STATE . " on " . STATE . ".country_id = " . COUNTRIES . ".country_id\n\t\t\t\t\t\t\t\t\t\t\tinner join " . CITIES . " on " . CITIES . ".state_id = " . STATE . ".state_id\n\t\t\t\t\t\t\t\t\t\t\twhere lower(country_name) = '" . strtolower($location['country']) . "'\n\t\t\t\t\t\t\t\t\t\t\tand lower(state_name) = '" . strtolower($location['state']) . "' \n\t\t\t\t\t\t\t\t\t\t\tand lower(city_name) = '" . strtolower($location['city']) . "' "); if (count($lArr) == 0) { $this->renderScript('/error/error.phtml'); } //Meta title $this->view->headTitle(str_replace('[BREADCRUMB]', $location['city'] . '>' . $location['state'] . '>' . $location['country'], $Title))->offsetUnset(0); $this->view->country_id = $country_id = $lArr[0]['country_id']; $this->view->state_id = $state_id = $lArr[0]['state_id']; $this->view->city_id = $city_id = $lArr[0]['city_id']; $pageTitle = $location['city'] . ", " . $location['state'] . ", " . $location['country'] . " has "; break; case 4: $lArr = $db->runQuery("select " . COUNTRIES . ".country_id, " . STATE . ".state_id, " . CITIES . ".city_id, " . SUB_AREA . ".sub_area_id from " . COUNTRIES . " \n\t\t\t\t\t\t\t\t\t\t\tinner join " . STATE . " on " . STATE . ".country_id = " . COUNTRIES . ".country_id\n\t\t\t\t\t\t\t\t\t\t\tinner join " . CITIES . " on " . CITIES . ".state_id = " . STATE . ".state_id\n\t\t\t\t\t\t\t\t\t\t\tinner join " . SUB_AREA . " on " . CITIES . ".city_id = " . SUB_AREA . ".city_id\n\t\t\t\t\t\t\t\t\t\t\twhere lower(country_name) = '" . strtolower($location['country']) . "'\n\t\t\t\t\t\t\t\t\t\t\tand lower(state_name) = '" . strtolower($location['state']) . "' \n\t\t\t\t\t\t\t\t\t\t\tand lower(city_name) = '" . strtolower($location['city']) . "' \n\t\t\t\t\t\t\t\t\t\t\tand lower(sub_area_name) = '" . strtolower($location['sub_area']) . "' "); if (count($lArr) == 0) { $this->renderScript('/error/error.phtml'); } //Meta title $this->view->headTitle(str_replace('[BREADCRUMB]', $location['sub_area'] . '>' . $location['city'] . '>' . $location['state'] . '>' . $location['country'], $Title))->offsetUnset(0); $this->view->country_id = $country_id = $lArr[0]['country_id']; $this->view->state_id = $state_id = $lArr[0]['state_id']; $this->view->city_id = $city_id = $lArr[0]['city_id']; $this->view->sub_area_id = $sub_area_id = $lArr[0]['sub_area_id']; $pageTitle = $location['sub_area'] . ", " . $location['city'] . ", " . $location['state'] . " has "; break; case 5: $lArr = $db->runQuery("select " . COUNTRIES . ".country_id, " . STATE . ".state_id, " . CITIES . ".city_id, " . SUB_AREA . ".sub_area_id, " . LOCAL_AREA . ".local_area_id from " . COUNTRIES . " \n\t\t\t\t\t\t\t\t\t\t\tinner join " . STATE . " on " . STATE . ".country_id = " . COUNTRIES . ".country_id\n\t\t\t\t\t\t\t\t\t\t\tinner join " . CITIES . " on " . CITIES . ".state_id = " . STATE . ".state_id\n\t\t\t\t\t\t\t\t\t\t\tinner join " . SUB_AREA . " on " . CITIES . ".city_id = " . SUB_AREA . ".city_id\n\t\t\t\t\t\t\t\t\t\t\tinner join " . LOCAL_AREA . " on " . SUB_AREA . ".sub_area_id = " . LOCAL_AREA . ".sub_area_id\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\twhere lower(country_name) = '" . strtolower($location['country']) . "'\n\t\t\t\t\t\t\t\t\t\t\tand lower(state_name) = '" . strtolower($location['state']) . "' \n\t\t\t\t\t\t\t\t\t\t\tand lower(city_name) = '" . strtolower($location['city']) . "' \n\t\t\t\t\t\t\t\t\t\t\tand lower(sub_area_name) = '" . strtolower($location['sub_area']) . "' \n\t\t\t\t\t\t\t\t\t\t\tand lower(local_area_name) = '" . strtolower($location['local_area']) . "' \n\t\t\t\t\t\t\t\t\t\t\t"); if (count($lArr) == 0) { $this->renderScript('/error/error.phtml'); } //Meta title $this->view->headTitle(str_replace('[BREADCRUMB]', $location['local_area'] . '>' . $location['sub_area'] . '>' . $location['city'] . '>' . $location['state'] . '>' . $location['country'], $Title))->offsetUnset(0); $this->view->country_id = $country_id = $lArr[0]['country_id']; $this->view->state_id = $state_id = $lArr[0]['state_id']; $this->view->city_id = $city_id = $lArr[0]['city_id']; $this->view->sub_area_id = $sub_area_id = $lArr[0]['sub_area_id']; $this->view->local_area_id = $local_area_id = $lArr[0]['local_area_id']; $pageTitle = $location['local_area'] . ", " . $location['sub_area'] . ", " . $location['city'] . " has "; break; } //----------------------------------------- $specArr = $db->runQuery("select * from " . SPEC_CHILD . " "); $this->view->specArr = $specArr; $spclOffrArr = $db->runQuery("select * from " . SPCL_OFFER_TYPES . " where status = '1' "); $this->view->spclOfferArr = $spclOffrArr; $_spclOffr = $this->getRequest()->getParam("spcloffr"); $sarry = array(); if (count($_spclOffr) > 0) { $i = 0; foreach ($spclOffrArr as $srow) { if (in_array($srow['type_name'], $_spclOffr)) { $sarry[$i] = $srow['id']; $i++; } } } $_spclOffr = $sarry; $this->view->spclOffr = $_spclOffr; //$this->view->pageTitle="Customer Sign In"; $laterDate = $this->getRequest()->getParam("laterDate"); $this->view->laterDate = $laterDate; @($myform = new Form_Search($lArr[0])); $this->view->myform = $myform; $this->view->Datefrom = $datefrom = $this->getRequest()->getParam("Datefrom"); $dateto = $this->getRequest()->getParam("DateTo"); $this->view->Dateto = $dateto; if ($dateto != "") { $dateto = date('Y-m-d', strtotime($datefrom . '+' . ($dateto - 1) . ' days')); $this->view->dateto = $dateto; } $bedroom = $this->getRequest()->getParam("bedroom"); $bathroom = $this->getRequest()->getParam("bathroom"); $amenity = $this->getRequest()->getParam("amenityRow"); $swimming = $this->getRequest()->getParam("swimming"); $facilities = $this->getRequest()->getParam("facilities"); $themes = $this->getRequest()->getParam("themes"); $propertyname = $this->getRequest()->getParam("propertyname"); $propertiesstatus = $this->getRequest()->getParam("propertiesstatus"); $ptypeRow = $this->getRequest()->getParam("ptypeRow"); $pstarRow = $this->getRequest()->getParam("pstarRow"); $this->view->bedroom = $bedroom; $this->view->bathroom = $bathroom; $this->view->amenity = $amenity; $this->view->swimming = $swimming; $this->view->facilities = $facilities; $this->view->themes = $themes; $this->view->propertyname = $propertyname; $this->view->ptypeRow = $ptypeRow; $this->view->pstarRow = $pstarRow; if ($datefrom != "") { $datefrom = date('Y-m-d', strtotime($datefrom)); } $check_spec = 0; // variable used for finding out that the facilities has been selected //$where .= " and ".CAL_RATE.".date_from >= '".$datefrom."' and ".CAL_RATE.".date_to <= '".$dateto."' "; $where = ""; $where1 = ""; if ($propertiesstatus == 1) { $where .= " and " . PROPERTY . ".cal_default != '" . $propertiesstatus . "' "; } if ($country_id != "") { $where .= " and " . PROPERTY . ".country_id = '" . $country_id . "' "; } if ($state_id != "") { $where .= " and " . PROPERTY . ".state_id = '" . $state_id . "' "; } if ($city_id != "") { $where .= " and " . PROPERTY . ".city_id = '" . $city_id . "' "; } if ($sub_area_id != "") { $where .= " and " . PROPERTY . ".sub_area_id = '" . $sub_area_id . "' "; } if ($local_area_id != "") { $where .= " and " . PROPERTY . ".local_area_id = '" . $local_area_id . "' "; } // // $availablePptyArr = $db->runQuery(" select group_concat(" . CAL_AVAIL . ".property_id) as ppty_list from " . CAL_AVAIL . " where // ( // ( date_from <= '" . date('Y-m-d', strtotime($datefrom)) . "' and date_to >= '" . date('Y-m-d', strtotime($datefrom)) . "') // or // ( date_from <= '" . date('Y-m-d', strtotime($dateto)) . "' and date_to >= '" . date('Y-m-d', strtotime($dateto)) . "') // or // ( date_from >= '" . date('Y-m-d', strtotime($datefrom)) . "' and date_to <= '" . date('Y-m-d', strtotime($dateto)) . "') // ) // and // cal_status = '0' "); $availablePptyArr = $db->runQuery(" select " . CAL_AVAIL . ".property_id as ppty_list from " . CAL_AVAIL . " where\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t( date_from <= '" . date('Y-m-d', strtotime($datefrom)) . "' and date_to >= '" . date('Y-m-d', strtotime($datefrom)) . "')\n\t\t\t\t\t\t\tor\n\t\t\t\t\t\t\t( date_from <= '" . date('Y-m-d', strtotime($dateto)) . "' and date_to >= '" . date('Y-m-d', strtotime($dateto)) . "')\t\t\t\t\t\t\t\t\t\t\t\n or\n \t\t\t\t\t\t( date_from >= '" . date('Y-m-d', strtotime($datefrom)) . "' and date_to <= '" . date('Y-m-d', strtotime($dateto)) . "')\n\t\t\t\t\t\t)\n\t\t\t\t\t\tand\n\t\t\t\t\t\tcal_status = '0' "); foreach ($availablePptyArr as $_k => $_v) { $_availableArr[0]['ppty_list'][] = $_v['ppty_list']; } $availablePptyArr = array(); $availablePptyArr[0]['ppty_list'] = implode(",", $_availableArr[0]['ppty_list']); $availablePptyDb = $dbAdapter->select()->from(CAL_AVAIL, array(new Zend_Db_Expr("group_concat(" . CAL_AVAIL . ".property_id) as ppty_list")))->where("(( date_from <= '" . date('Y-m-d', strtotime($datefrom)) . "' and date_to >= '" . date('Y-m-d', strtotime($datefrom)) . "') or ( date_from <= '" . date('Y-m-d', strtotime($dateto)) . "' and date_to >= '" . date('Y-m-d', strtotime($dateto)) . "'))")->where("cal_status = '0'"); $ppty_list = rtrim($availablePptyArr[0]['ppty_list'], ','); if ($datefrom != "") { if ($ppty_list != "") { $where1 = "and " . PROPERTY . ".id not in (" . $ppty_list . ") "; } else { $where1 = ""; } } /*= property type =*/ if (count($ptypeRow) > 0 && $ptypeRow[0] != "") { $where .= " and ("; for ($i = 0; $i < count($ptypeRow); $i++) { if ($i == 0) { $where .= " " . PROPERTY . ".property_type = " . $ptypeRow[$i] . " "; } else { $where .= " or " . PROPERTY . ".property_type = " . $ptypeRow[$i] . " "; } } $where .= ")"; } if (count($pstarRow) > 0 && $pstarRow[0] != "") { $where .= " and ("; $i = 0; $starcon = ""; foreach ($pstarRow as $strow) { switch ($strow) { case 3: $starcon = "(star_rating < 4 ) "; break; case 4: $starcon = " (star_rating = 4 ) "; break; case 5: $starcon = " (star_rating = 5 )"; break; case 6: $starcon = " (star_rating = 6 ) "; break; } if ($i == 0) { $where .= " " . $starcon; } else { $where .= " or " . $starcon; } $i++; } $where .= ")"; } if (count($bedroom) > 0 && $bedroom[0] != "") { $where .= " and ("; for ($i = 0; $i < count($bedroom); $i++) { if ($i == 0) { if ($bedroom[$i] == '7') { $where .= " " . PROPERTY . ".bedrooms >= '" . $bedroom[$i] . "' "; } else { $where .= " " . PROPERTY . ".bedrooms = '" . $bedroom[$i] . "' "; } } else { if ($bedroom[$i] == '7') { $where .= " or " . PROPERTY . ".bedrooms >= '" . $bedroom[$i] . "' "; } else { $where .= " or " . PROPERTY . ".bedrooms = '" . $bedroom[$i] . "' "; } } } $where .= ")"; } if (count($bathroom) > 0 && $bathroom[0] != "") { $where .= " and ("; for ($i = 0; $i < count($bathroom); $i++) { if ($i == 0) { if ($bathroom[$i] == '4') { $where .= " " . PROPERTY . ".bathrooms >= '" . $bathroom[$i] . "' "; } else { $where .= " " . PROPERTY . ".bathrooms = '" . $bathroom[$i] . "' or " . PROPERTY . ".bathrooms = '" . $bathroom[$i] . ".5' "; } } else { if ($bathroom[$i] == '4') { $where .= " or " . PROPERTY . ".bathrooms >= '" . $bathroom[$i] . "' "; } else { $where .= " or " . PROPERTY . ".bathrooms = '" . $bathroom[$i] . "' or " . PROPERTY . ".bathrooms = '" . $bathroom[$i] . ".5' "; } } } $where .= ")"; } if (count($amenity) > 0) { for ($i = 0; $i < count($amenity); $i++) { //$where .= " and ".SPEC_ANS.".answer = '".$amenity[$i]."' "; $specSearch[] = $amenity[$i]; } $check_spec = 1; } if (count($swimming) > 0) { for ($i = 0; $i < count($swimming); $i++) { //$where .= " and ".SPEC_ANS.".answer = '".$swimming[$i]."' "; $specSearch[] = $swimming[$i]; } $check_spec = 1; } if (count($themes) > 0) { for ($i = 0; $i < count($themes); $i++) { //$where .= " and ".SPEC_ANS.".answer = '".$themes[$i]."' "; $specSearch[] = $themes[$i]; } $check_spec = 1; } $having = $Having = ""; if ($check_spec) { $specArr = implode(",", $specSearch); //$where .= " and " . SPEC_ANS . ".answer in (" . $specArr . ") "; $_specWhere .= " and " . SPEC_ANS . ".answer in (" . $specArr . ") "; //$having = " having count(distinct ppty.answer) = " . count($specSearch) . " "; $_specGroupby = " group by property_id "; $_specHaving = " having count(distinct answer) = " . count($specSearch) . " "; //$Having = " count(distinct ppty.answer) = " . count($specSearch) . " "; // $specQuery = $dbAdapter->select()->from(PROPERTY,array("id")) // ->join(SPEC_ANS,SPEC_ANS.".property_id = ".PROPERTY.".id",array()) // ->where(SPEC_ANS.".answer in ('$specArr')") // ->group(PROPERTY.".id") // ->having(" count(distinct ".SPEC_ANS.".answer ) = '".count($specSearch)."' ") // ; // $specQuery = $dbAdapter->select()->from(SPEC_ANS)->where(" answer in ({$specArr})")->group("property_id")->having(" count(distinct answer ) = '" . count($specSearch) . "' "); //prd($specQuery->__toString()); $specQuery = $specQuery->query()->fetchAll(); $_specProperty = array(); foreach ($specQuery as $ssK => $ssVal) { //$_specProperty[] = $ssVal['id']; $_specProperty[] = $ssVal['property_id']; } $_specProperty = implode(",", $_specProperty); if ($_specProperty) { $where .= " and " . PROPERTY . ".id in ({$_specProperty}) "; } else { $where .= " and 1=0 "; } } if (count($facilities) > 0) { for ($i = 0; $i < count($facilities); $i++) { //$where .= " and ".AMENITY_ANS.".amenity_id in (".$facilities[$i]."' and ".AMENITY_ANS.".amenity_value = '1' "; $amenitySearch[] = $facilities[$i]; } $check_amenity = 1; } if (@$check_amenity) { $specArr = implode(",", $amenitySearch); //$where .= " and " . AMENITY_ANS . ".amenity_id in (" . $specArr . ") and " . AMENITY_ANS . ".amenity_value = '1' "; $amenityQuery = $dbAdapter->select()->from(PROPERTY, array("id"))->join(AMENITY_ANS, AMENITY_ANS . ".property_id = " . PROPERTY . ".id", array("amenity_id"))->where(AMENITY_ANS . ".amenity_id in ({$specArr}) and " . AMENITY_ANS . ".amenity_value = '1' ")->group(PROPERTY . ".id")->having(" count(distinct " . AMENITY_ANS . ".amenity_id ) = '" . count($amenitySearch) . "' "); // echo '<pre>'; print_r($amenityQuery->__toString()); exit('Macro die'); $amenityQuery = $amenityQuery->query()->fetchAll(); $_amenityProperty = array(); foreach ($amenityQuery as $ssK => $ssVal) { $_amenityProperty[] = $ssVal['id']; } $_amenityProperty = implode(",", $_amenityProperty); if ($_amenityProperty) { $where .= " and " . PROPERTY . ".id in ({$_amenityProperty}) "; } else { $where .= " and 1=0 "; } // if ($check_spec) // { // $having .= " and count(distinct ppty.amenity_id ) = " . count($amenitySearch) . " "; // $Having .= " and count(distinct ppty.amenity_id ) = " . count($amenitySearch) . " "; // } // else // { // $having .= " having count(distinct ppty.amenity_id ) = " . count($amenitySearch) . " "; // $Having .= " count(distinct ppty.amenity_id ) = " . count($amenitySearch) . " "; // } } $sum_query = ""; if (!empty($_spclOffr)) { $spclArr = implode(",", $_spclOffr); $where .= " and ( " . PROPERTY . ".id in (select property_id from spcl_offers where offer_id in (" . $spclArr . ") and book_by > curdate() ) )"; //"and " . SPCL_OFFERS . ".book_by >= curdate() "; } $sumQuery = ""; if ($datefrom != "" && $dateto != "") { /* * ***************** latest query ends************************ */ $sum_query = " select " . CAL_RATE . ".*, " . CURRENCY . ".exchange_rate ,\n coalesce (sum(\n case when " . CAL_RATE . ".date_from >= '" . $datefrom . "' and " . CAL_RATE . ".date_to <= '" . $dateto . "' \n then (abs( datediff( " . CAL_RATE . ".date_from, " . CAL_RATE . ".date_to ))+1) * round(prate*exchange_rate) \n when " . CAL_RATE . ".date_from <= '" . $datefrom . "' and " . CAL_RATE . ".date_to >= '" . $dateto . "'\n then (abs( datediff( '" . $datefrom . "', '" . $dateto . "' ))+1) * round(prate*exchange_rate) \n when " . CAL_RATE . ".date_from <= '" . $datefrom . "' and " . CAL_RATE . ".date_to >= '" . $datefrom . "' and " . CAL_RATE . ".date_to <= '" . $dateto . "' \n then (abs( datediff( '" . $datefrom . "', " . CAL_RATE . ".date_to ))+1) * round(prate*exchange_rate) \n when " . CAL_RATE . ".date_to >= '" . $dateto . "' and " . CAL_RATE . ".date_from >= '" . $datefrom . "' and " . CAL_RATE . ".date_from <= '" . $dateto . "'\n then (abs( datediff( " . CAL_RATE . ".date_from, '" . $dateto . "' ))+1) * round(prate*exchange_rate) \n end),round(min(prate)*exchange_rate)*" . (dateDiff($datefrom, $dateto) + 1) . " ) \n\n AS total_amount from " . CAL_RATE . " \n inner join " . PROPERTY . " on " . PROPERTY . ".id = " . CAL_RATE . ".property_id \n left join " . CURRENCY . " on " . PROPERTY . ".currency_code = " . CURRENCY . ".currency_code \n group by " . CAL_RATE . ".property_id \n "; $sumQuery = $dbAdapter->select()->from(CAL_RATE, array(CURRENCY . ".exchange_rate", CAL_RATE . ".prate", CAL_RATE . ".property_id", CAL_RATE . ".nights", new Zend_Db_Expr(" coalesce (sum(\n case when " . CAL_RATE . ".date_from >= '" . $datefrom . "' and " . CAL_RATE . ".date_to <= '" . $dateto . "' \n then (abs( datediff( " . CAL_RATE . ".date_from, " . CAL_RATE . ".date_to ))+1) * ceil(prate*exchange_rate) \n when " . CAL_RATE . ".date_from <= '" . $datefrom . "' and " . CAL_RATE . ".date_to >= '" . $dateto . "'\n then (abs( datediff( '" . $datefrom . "', '" . $dateto . "' ))+1) * ceil(prate*exchange_rate) \n when " . CAL_RATE . ".date_from <= '" . $datefrom . "' and " . CAL_RATE . ".date_to >= '" . $datefrom . "' and " . CAL_RATE . ".date_to <= '" . $dateto . "' \n then (abs( datediff( '" . $datefrom . "', " . CAL_RATE . ".date_to ))+1) * ceil(prate*exchange_rate) \n when " . CAL_RATE . ".date_to >= '" . $dateto . "' and " . CAL_RATE . ".date_from >= '" . $datefrom . "' and " . CAL_RATE . ".date_from <= '" . $dateto . "'\n then (abs( datediff( " . CAL_RATE . ".date_from, '" . $dateto . "' ))+1) * ceil(prate*exchange_rate) \n end),ceil(min(prate)*exchange_rate)*" . (dateDiff($datefrom, $dateto) + 1) . " ) \n AS total_amount ")))->join(PROPERTY, PROPERTY . ".id = " . CAL_RATE . ".property_id", array())->joinLeft(CURRENCY, PROPERTY . ".currency_code = " . CURRENCY . ".currency_code", array())->group(CAL_RATE . ".property_id"); } if ($propertyname != "") { $propertyname = strtolower($propertyname); $where .= " and ( lower(" . PROPERTY . ".property_title) like '%" . $propertyname . "%' \n\t\t\t\t\t or lower(" . PROPERTY . ".property_name) like '%" . $propertyname . "%' \t\n\t\t\t\t\t or lower(" . COUNTRIES . ".country_name) like '%" . $propertyname . "%' \n\t\t\t\t\t or lower(" . STATE . ".state_name) like '%" . $propertyname . "%' \n\t\t\t\t\t or lower(" . CITIES . ".city_name) like '%" . $propertyname . "%' \n\t\t\t\t\t or lower(" . SUB_AREA . ".sub_area_name) like '%" . $propertyname . "%' \n\t\t\t\t\t or lower(" . LOCAL_AREA . ".local_area_name) like '%" . $propertyname . "%'\n\t\t\t\t\t or " . PROPERTY . ".propertycode like '%" . $propertyname . "%' )\n\t\t\t"; } $limit = 10; //5 records per page $start = $this->getRequest()->getParam("start"); $page = $this->getRequest()->getParam("start"); if (empty($start)) { $start = 1; $page = 0; } $page = $page - 1; $starti = ($start - 1) * 10; //code for converting an array to request params $nvp_string = ""; $nvp_string = addQueryString('start', $page + 1); if (!isset($mySession->gridType)) { $mySession->gridType = 1; } if ($this->getRequest()->isPost()) { switch ($_REQUEST['sorti']) { case '1': $order = $Order = ""; $mySession->order = '1'; break; case '2': if ($datefrom != "" && $dateto != "") { $order = "order by ppty.total_amount desc"; $Order = "ppty.total_amount desc"; } else { $order = "order by ppty.prate desc"; $Order = "order by ppty.prate desc"; } $mySession->order = '2'; break; case '3': $order = "order by ppty.bedrooms asc"; $Order = "ppty.bedrooms asc"; $mySession->order = '3'; break; case '4': $order = "order by ppty.bedrooms desc"; $Order = "ppty.bedrooms desc"; $mySession->order = '4'; break; } switch ($_REQUEST['grid']) { case '1': $mySession->gridType = '1'; break; case '2': $mySession->gridType = '2'; break; case '3': $mySession->gridType = '3'; break; } } if ($datefrom != "" && $dateto != "") { $order = "order by ppty.total_amount asc"; $Order = "ppty.total_amount asc"; } else { $order = "order by ppty.prate asc"; $Order = "ppty.prate asc"; } if (isset($mySession->order)) { switch ($mySession->order) { case '1': if ($datefrom != "" && $dateto != "") { $order = "order by ppty.total_amount asc"; $Order = "ppty.total_amount asc"; } else { $order = "order by prate asc"; $Order = "prate asc"; } break; case '2': if ($datefrom != "" && $dateto != "") { $order = "order by ppty.total_amount desc"; $Order = "ppty.total_amount desc"; } else { $order = "order by prate desc"; $Order = "prate desc"; } break; case '3': $order = "order by bedrooms asc"; $Order = "bedrooms asc"; break; case '4': $order = "order by bedrooms desc"; $Order = "bedrooms desc"; break; } } $no_date_query = "select * from \n\t\t\t\t\t\t (select property_id, date_from, date_to, nights, ceil(prate*exchange_rate) as prate from " . CAL_RATE . " \n\t\t\t\t\t\t inner join " . PROPERTY . " on " . CAL_RATE . ".property_id = " . PROPERTY . ".id \t\n\t\t\t\t\t\t inner join " . CURRENCY . " on " . PROPERTY . ".currency_code = " . CURRENCY . ".currency_code\n where " . CAL_RATE . ".date_from >= curdate()\n\t\t\t\t\t\t order by prate asc) as abc group by abc.property_id"; $noDateQuery = $dbAdapter->select()->from(array("abc" => $dbAdapter->select()->from(CAL_RATE, array('property_id', 'date_from', 'date_to', 'nights', 'ceil(prate*exchange_rate) as prate'))->join(PROPERTY, CAL_RATE . ".property_id = " . PROPERTY . ".id ", array())->join(CURRENCY, PROPERTY . ".currency_code = " . CURRENCY . ".currency_code", array())->where(CAL_RATE . ".date_to >= curdate()")->order("prate asc")))->group("abc.property_id"); $subProperty = $dbAdapter->select()->from(PROPERTY, array("property.id as pid", "cletitude", "clongitude", "propertycode", "(ptyle_name)", "property_title", CURRENCY . ".currency_code", "(country_name)", "(state_name)", "(city_name)", "(sub_area_name)", "(local_area_name)", "bedrooms", new Zend_Db_Expr('trim(trailing "." from trim(trailing 0 from ' . PROPERTY . '.bathrooms)) as bathrooms'), "(ptyle_url)", "en_bedrooms", "maximum_occupancy", "is_insured", "star_rating", "cal_default", "cal_availability.prate as prate", "cal_availability.nights", ($sumQuery == '' ? '' : 'cal_availability.total_amount') . ""))->join(array('pt' => PROPERTY_TYPE), "pt.ptyle_id = " . PROPERTY . ".property_type ", array())->join(COUNTRIES, COUNTRIES . ".country_id = " . PROPERTY . ".country_id", array())->join(STATE, STATE . ".state_id = " . PROPERTY . ".state_id", array())->join(CITIES, CITIES . ".city_id = " . PROPERTY . ".city_id", array())->join(CURRENCY, CURRENCY . ".currency_code = " . PROPERTY . ".currency_code", array())->joinLeft(SUB_AREA, SUB_AREA . ".sub_area_id = " . PROPERTY . ".sub_area_id", array())->joinLeft(LOCAL_AREA, LOCAL_AREA . ".local_area_id = " . PROPERTY . ".local_area_id", array()); if (!empty($sumQuery)) { $subProperty = $subProperty->joinLeft(array('cal_availability' => $sumQuery), "cal_availability.property_id = " . PROPERTY . ".id", array()); } else { $subProperty = $subProperty->joinLeft(array('cal_availability' => $noDateQuery), "cal_availability.property_id = " . PROPERTY . ".id", array()); } $subProperty = $subProperty->where(PROPERTY . ".status = '3'")->where("1 " . $where . " " . $where1); //prd($subProperty->__toString()); if (!empty($sumQuery)) { $subProperty = $subProperty->group("pid"); } $subProperty = $subProperty->order("cal_availability.prate asc"); $propertyDbAdapter = $dbAdapter->select()->from(array("ppty" => $subProperty))->group("ppty.pid"); if ($Having) { $propertyDbAdapter = $propertyDbAdapter->having($Having); } $propertyDbAdapter = $propertyDbAdapter->order($Order); //prd($propertyDbAdapter->__toString()); $adapter = new Zend_Paginator_Adapter_DbSelect($propertyDbAdapter); $paginator = new Zend_Paginator($adapter); $paginator->setItemCountPerPage(10); $paginator->setCurrentPageNumber($page + 1); //$paginator->setItemCountPerPage(10); $totalCount = $paginator->getTotalItemCount(); $this->view->paginator = $paginator; $propertyArr = $propertyDbAdapter->limitPage($page + 1, 10)->query()->fetchAll(); //prd($propertyArr); // $propertyArr = $db->runQuery("select * from // (select " . PROPERTY . ".id as pid, cletitude, clongitude, propertycode, ptyle_name, property_title, " . CURRENCY . ".currency_code, country_name, state_name, city_name, sub_area_name, local_area_name, // bedrooms, bathrooms, en_bedrooms, maximum_occupancy, star_rating, cal_default, amenity_id, " . SPEC_ANS . ".answer, cal_availability.prate as prate, cal_availability.nights // " . (($sum_query == '') ? '' : ', cal_availability.total_amount ') . " // from " . PROPERTY . " // inner join " . PROPERTY_TYPE . " as pt on pt.ptyle_id = " . PROPERTY . ".property_type // left join " . SPEC_ANS . " on " . SPEC_ANS . ".property_id = " . PROPERTY . ".id // left join " . AMENITY_ANS . " on " . AMENITY_ANS . ".property_id = " . PROPERTY . ".id // inner join " . COUNTRIES . " on " . COUNTRIES . ".country_id = " . PROPERTY . ".country_id // inner join " . STATE . " on " . STATE . ".state_id = " . PROPERTY . ".state_id // inner join " . CITIES . " on " . CITIES . ".city_id = " . PROPERTY . ".city_id // inner join " . CURRENCY . " on " . CURRENCY . ".currency_code = " . PROPERTY . ".currency_code // left join " . SUB_AREA . " on " . SUB_AREA . ".sub_area_id = " . PROPERTY . ".sub_area_id // left join " . LOCAL_AREA . " on " . LOCAL_AREA . ".local_area_id = " . PROPERTY . ".local_area_id // left join // " . (($sum_query == '') ? "(" . $no_date_query . ")" : "(" . $sum_query . ")") . " as cal_availability // on cal_availability.property_id = " . PROPERTY . ".id // where " . PROPERTY . ".status = '3' // $where // $where1 " . (($sum_query == '') ? '' : 'group by pid') . " order by cal_availability.prate asc) as ppty // where ppty.pid != '0' // group by ppty.pid // $having // $order // // "); //prd($propertyArr); /* * ************************* FINAL QUERY ENDS ****************************************** */ //prd($propertyArr[0]['__counti']); $propertyData = array(); $t = 0; $x = 0; $k = 0; foreach ($propertyArr as $key => $val) { //CODE FOR INSERTING IMAGE $imgArr = $db->runQuery("select * from " . GALLERY . " where property_id = " . $val['pid'] . " "); //prd("select answer from ".SPEC_ANS." where property_id = ".$val['pid']." $_specWhere "); $_specArr = $db->runQuery("select answer from " . SPEC_ANS . " where property_id = " . $val['pid'] . " "); $_amenityArr = $db->runQuery("select amenity_id from " . AMENITY_ANS . " where property_id = " . $val['pid'] . " "); $subpropertyData[$x]['image_name'] = $imgArr[0]['image_name']; $subpropertyData[$x]['image_title'] = $imgArr[0]['image_title']; $propertyData[$x]['image_name'] = $imgArr[0]['image_name']; $propertyData[$x]['image_title'] = $imgArr[0]['image_title']; $propertyData[$x]['amenity_id'] = $_amenityArr[0]['amenity_id']; foreach ($val as $keys => $values) { if ($_specWhere && count($_specArr) > 0 || !$specWhere) { $propertyData[$x][$keys] = $values; $subpropertyData[$x][$keys] = $values; } } $x++; } //prd($subpropertyData); /* $this->view->propertyData=$propertyData; */ $this->view->total = count($propertyData); $this->view->start = $start; $this->view->now = APPLICATION_URL . "search?" . $nvp_string; if (!empty($nvp_string)) { $this->view->queryString = "?" . $nvp_string; } else { $this->view->queryString = ""; } $this->view->limit = $limit; //prd($subpropertyData); if ($mySession->gridType != '3') { $Description = str_replace(array('[PROPERTY_NO_START]', '[PROPERTY_NO_END]'), array($subpropertyData[0]['propertycode'], $subpropertyData[count($subpropertyData) - 1]['propertycode']), $Description); $this->view->headMeta('description', $Description); $this->view->propertyData = $subpropertyData; } else { $Description = str_replace(array('[PROPERTY_NO_START]', '[PROPERTY_NO_END]'), array($propertyData[0]['propertycode'], $propertyData[count($propertyData) - 1]['propertycode']), $Description); $this->view->headMeta('description', $Description); $this->view->propertyData = $propertyData; } $pageTitle .= $totalCount . " Holiday Rentals"; $this->view->headlineText = $pageTitle; $this->view->gridType = $mySession->gridType; //amenity arr $amenityArr = $db->runQuery("select * from " . AMENITY . " where amenity_status = '1' "); $this->view->amenityArr = $amenityArr; $this->renderScript('search/searchajax.phtml'); }
public function membersAction() { $page = $this->_getParam('page'); if (!$this->_cache->test('members')) { $query = 'getMps'; $output = '&output=xml'; $key = '&key=' . self::TWFYAPIKEY; $twfy = self::TWFYURL . $query . $output . $key; $data = Zend_Json::fromXml($this->get($twfy), true); $data = json_decode($data); $this->_cache->save($data); } else { $data = $this->_cache->load('members'); } $data2 = array(); foreach ($data->twfy->match as $a) { if (in_array($a->constituency, $this->_remove)) { unset($a->name); unset($a->person_id); unset($a->party); unset($a->constituency); } if (isset($a->name)) { $data2[] = array('name' => $a->name, 'person_id' => $a->person_id, 'constituency' => $a->constituency, 'party' => $a->party); } } $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($data2)); if (isset($page) && $page != "") { $paginator->setCurrentPageNumber((int) $page); } $paginator->setItemCountPerPage(40)->setPageRange(10); if (in_array($this->_helper->contextSwitch()->getCurrentContext(), array('xml', 'json'))) { $data = array('pageNumber' => $paginator->getCurrentPageNumber(), 'total' => number_format($paginator->getTotalItemCount(), 0), 'itemsReturned' => $paginator->getCurrentItemCount(), 'totalPages' => number_format($paginator->getTotalItemCount() / $paginator->getItemCountPerPage(), 0)); $this->view->data = $data; $members = array(); foreach ($paginator as $k => $v) { $members[] = array(); $members[$k] = $v; } $this->view->members = $members; } else { $this->view->data = $paginator; } }