public function executeMyLoans() { /**/ $this->pagerSlidingSize = intval(sfConfig::get('dw_pagerSlidingSize')); $query = Doctrine::getTable('Loans')->getMyLoans($this->getUser()->getId()); $count_q = clone $query; $count_q = $count_q->select('count(*)')->removeDqlQueryPart('orderby')->limit(0); $counted = new DoctrineCounted(); $counted->count_query = $count_q; $pager = new DarwinPager($query, $this->getRequestParameter('page', 1), 5); $pager->setCountQuery($counted); $this->pagerLayout = new PagerLayoutWithArrows($pager, new Doctrine_Pager_Range_Sliding(array('chunk' => $this->pagerSlidingSize)), $this->getController()->genUrl('widgets/reloadContent?category=board&widget=myLoans') . '/page/{%page_number}'); $this->pagerLayout->setTemplate('<li><a href="{%url}">{%page}</a></li>'); $this->pagerLayout->setSelectedTemplate('<li>{%page}</li>'); $this->pagerLayout->setSeparatorTemplate('<span class="pager_separator">::</span>'); if (!$this->pagerLayout->getPager()->getExecuted()) { $this->loans = $this->pagerLayout->execute(); } $this->myTotalLoans = $this->pagerLayout->getPager()->getNumResults(); $this->rights = Doctrine::getTable('LoanRights')->getEncodingRightsForUser($this->getUser()->getId()); if (count($this->loans)) { $ids = array(); foreach ($this->loans as $loan) { $ids[] = $loan->getId(); } if (!empty($ids)) { $this->status = Doctrine::getTable('LoanStatus')->getFromLoans($ids); } } }
/** * Method executed when searching an expedition - trigger by the click on the search button * @param SearchExpeditionForm $form The search expedition form instantiated that will be binded with the data contained in request * @param sfWebRequest $request Request coming from browser * @var int $pagerSlidingSize: Get the config value to define the range size of pager to be displayed in numbers (i.e.: with a value of 5, it will give this: << < 1 2 3 4 5 > >>) */ protected function searchResults(IgsSearchFormFilter $form, sfWebRequest $request) { if ($request->getParameter('searchExpeditionIgs', '') !== '') { // Bind form with data contained in searchExpedition array $form->bind($request->getParameter('searchExpeditionIgs')); // Modify the s_url to call the searchResult action when on result page and playing with pager $this->s_url = 'expeditionsIgs/search?is_choose=false'; // Test that the form binded is still valid (no errors) if ($form->isValid()) { // Define all properties that will be either used by the data query or by the pager // They take their values from the request. If not present, a default value is defined $query = $form->getQuery()->orderby($this->orderBy . ' ' . $this->orderDir); $pager = new DarwinPager($query, $this->currentPage, $this->form->getValue('rec_per_page')); // Replace the count query triggered by the Pager to get the number of records retrieved $count_q = clone $query; // Remove from query the group by and order by clauses $count_q = $count_q->select('count( distinct expedition_ref, ig_ref)')->removeDqlQueryPart('groupby')->removeDqlQueryPart('orderby'); // Initialize an empty count query $counted = new DoctrineCounted(); // Define the correct select count() of the count query $counted->count_query = $count_q; // And replace the one of the pager with this new one $pager->setCountQuery($counted); $this->pagerLayout = new PagerLayoutWithArrows($pager, new Doctrine_Pager_Range_Sliding(array('chunk' => $this->pagerSlidingSize)), $this->getController()->genUrl($this->s_url . $this->o_url) . '/page/{%page_number}'); // Sets the Pager Layout templates $this->setDefaultPaggingLayout($this->pagerLayout); // If pager not yet executed, this means the query has to be executed for data loading if (!$this->pagerLayout->getPager()->getExecuted()) { $this->expeditions = $this->pagerLayout->execute(); } } } }
public function executeSearch(sfWebRequest $request) { // Initialize the order by and paging values: order by collection_name here $this->setCommonValues('search', 'collection_name', $request); $this->form = new PublicSearchFormFilter(); // If the search has been triggered by clicking on the search button or with pinned specimens if ($request->getParameter('specimen_search_filters', '') !== '') { $this->form->bind($request->getParameter('specimen_search_filters')); } if ($this->form->isBound() && $this->form->isValid() && !$request->hasParameter('criteria')) { // Get the generated query from the filter and add order criterion to the query $query = $this->form->getWithOrderCriteria(); // Define the pager $pager = new DarwinPager($query, $this->form->getValue('current_page'), $this->form->getValue('rec_per_page')); // Replace the count query triggered by the Pager to get the number of records retrieved $count_q = clone $query; // Remove from query the group by and order by clauses $count_q = $count_q->select('count(*)')->removeDqlQueryPart('orderby')->limit(0); // Initialize an empty count query $counted = new DoctrineCounted(); // Define the correct select count() of the count query $counted->count_query = $count_q; // And replace the one of the pager with this new one $pager->setCountQuery($counted); // Define in one line a pager Layout based on a pagerLayoutWithArrows object // This pager layout is based on a Doctrine_Pager, itself based on a customed Doctrine_Query object (call to the getExpLike method of ExpeditionTable class) $params = $request->isMethod('post') ? $request->getPostParameters() : $request->getGetParameters(); unset($params['specimen_search_filters']['current_page']); $this->pagerLayout = new PagerLayoutWithArrows($pager, new Doctrine_Pager_Range_Sliding(array('chunk' => $this->pagerSlidingSize)), 'search/search?specimen_search_filters[current_page]={%page_number}&' . http_build_query($params)); // Sets the Pager Layout templates $this->setDefaultPaggingLayout($this->pagerLayout); $this->pagerLayout->setTemplate('<li data-page="{%page_number}"><a href="{%url}">{%page}</a></li>'); // If pager not yet executed, this means the query has to be executed for data loading if (!$this->pagerLayout->getPager()->getExecuted()) { $this->search = $this->pagerLayout->execute(); } $this->field_to_show = $this->getVisibleColumns($this->form); $this->defineFields(); $ids = $this->FecthIdForCommonNames(); $this->common_names = Doctrine::getTable('VernacularNames')->findAllCommonNames($ids); if (!count($this->common_names)) { $this->common_names = array('taxonomy' => array(), 'chronostratigraphy' => array(), 'lithostratigraphy' => array(), 'lithology' => array(), 'mineralogy' => array()); } return; } if ($this->form->isBound() && $this->form->getValue('search_type', 'zoo') != 'zoo') { $this->setTemplate('searchGeo'); } else { $this->setTemplate('index'); } }
public function executeSearch(sfWebRequest $request) { $this->forward404Unless($request->isMethod('post')); $this->setCommonValues('loan', 'from_date', $request); $this->form = new LoansFormFilter(null, array('user' => $this->getUser())); $this->is_choose = $request->getParameter('is_choose', '') == '' ? 0 : intval($request->getParameter('is_choose')); if ($request->getParameter('loans_filters', '') !== '') { $this->form->bind($request->getParameter('loans_filters')); if ($this->form->isValid()) { $query = $this->form->getQuery()->orderBy($this->orderBy . ' ' . $this->orderDir); $pager = new DarwinPager($query, $this->currentPage, $this->form->getValue('rec_per_page')); $count_q = clone $query; $count_q = $count_q->select('count(*)')->removeDqlQueryPart('orderby')->limit(0); $counted = new DoctrineCounted(); $counted->count_query = $count_q; // And replace the one of the pager with this new one $pager->setCountQuery($counted); $this->pagerLayout = new PagerLayoutWithArrows($pager, new Doctrine_Pager_Range_Sliding(array('chunk' => $this->pagerSlidingSize)), $this->getController()->genUrl($this->s_url . $this->o_url) . '/page/{%page_number}'); // Sets the Pager Layout templates $this->setDefaultPaggingLayout($this->pagerLayout); // If pager not yet executed, this means the query has to be executed for data loading if (!$this->pagerLayout->getPager()->getExecuted()) { $this->items = $this->pagerLayout->execute(); } $this->rights = Doctrine::getTable('loanRights')->getEncodingRightsForUser($this->getUser()->getId()); $loan_list = array(); foreach ($this->items as $loan) { $loan_list[] = $loan->getId(); } $this->printable = Doctrine::getTable('Loans')->getPrintableLoans($loan_list, $this->getUser()); $status = Doctrine::getTable('LoanStatus')->getStatusRelatedArray($loan_list); $this->status = array(); foreach ($status as $sta) { $this->status[$sta->getLoanRef()] = $sta; } } } }
/** * Action executed when searching a specimen - trigger by the click on the search button * It's also the same action that is used to open a saved search reopened, a list of pinned specimens * or when clicking on the back to criterias button * @param sfWebRequest $request Request coming from browser */ public function executeSearch(sfWebRequest $request) { $this->is_specimen_search = false; // Initialize the order by and paging values: order by collection_name here $this->setCommonValues('specimensearch', 'collection_name', $request); // Modify the s_url to call the searchResult action when on result page and playing with pager $this->s_url = 'specimensearch/search' . '?is_choose=' . $this->is_choose; // Initialize filter $this->form = new SpecimensFormFilter(null, array('user' => $this->getUser())); // If the search has been triggered by clicking on the search button or with pinned specimens if ($request->isMethod('post') && $request->getParameter('specimen_search_filters', '') !== '' || $request->hasParameter('pinned')) { // Store all post parameters $criterias = $request->getPostParameters(); // If pinned specimens called if ($request->hasParameter('pinned')) { // Get all ids pinned $ids = implode(',', $this->getUser()->getAllPinned('specimen')); if ($ids == '') { $ids = '0'; } $this->is_pinned_only_search = true; // Set the list of ids as criteria $criterias['specimen_search_filters']['spec_ids'] = $ids; } elseif ($request->hasParameter('spec_search')) { // Get the saved search concerned $saved_search = Doctrine::getTable('MySavedSearches')->getSavedSearchByKey($request->getParameter('spec_search'), $this->getUser()->getId()); // Forward 404 if we don't get the search requested $this->forward404Unless($saved_search); $criterias['specimen_search_filters']['spec_ids'] = $saved_search->getSearchedIdString(); if ($criterias['specimen_search_filters']['spec_ids'] == '') { $criterias['specimen_search_filters']['spec_ids'] = '0'; } $this->is_specimen_search = $saved_search->getId(); } $this->form->bind($criterias['specimen_search_filters']); } elseif ($request->getParameter('search_id', '') != '') { // Get the saved search asked $saved_search = Doctrine::getTable('MySavedSearches')->getSavedSearchByKey($request->getParameter('search_id'), $this->getUser()->getId()); // If not available, not found -> forward on 404 page $this->forward404Unless($saved_search); if ($saved_search->getIsOnlyId()) { $this->is_specimen_search = $saved_search->getId(); } // Get all search criterias from DB $criterias = $saved_search->getUnserialRequest(); // Transform all visible fields stored as a string with | as separator and store it into col_fields field $criterias['specimen_search_filters']['col_fields'] = implode('|', $saved_search->getVisibleFieldsInResult()); // If data were set, in other terms specimen_search_filters array is available... if (isset($criterias['specimen_search_filters'])) { // Bring all the required/necessary widgets on page Doctrine::getTable('Specimens')->getRequiredWidget($criterias['specimen_search_filters'], $this->getUser()->getId(), 'specimensearch_widget'); if ($saved_search->getisOnlyId() && $criterias['specimen_search_filters']['spec_ids'] == '') { $criterias['specimen_search_filters']['spec_ids'] = '0'; } $this->form->bind($criterias['specimen_search_filters']); } } if ($this->form->isBound()) { if ($this->form->isValid()) { $this->getUser()->storeRecPerPage($this->form->getValue('rec_per_page')); // When criteria parameter is given, it means we go back to criterias if ($request->hasParameter('criteria')) { $this->setTemplate('index'); // Bring all the required/necessary widgets on page Doctrine::getTable('Specimens')->getRequiredWidget($criterias['specimen_search_filters'], $this->getUser()->getId(), 'specimensearch_widget'); $this->loadWidgets(); return; } else { $this->spec_lists = Doctrine::getTable('MySavedSearches')->getListFor($this->getUser()->getId(), 'specimen'); $query = $this->form->getQuery()->orderby($this->orderBy . ' ' . $this->orderDir . ', id'); //If export is defined export it! $this->field_to_show = $this->getVisibleColumns($this->getUser(), $this->form); if ($request->getParameter('export', '') != '') { $this->specimensearch = $query->limit(1000)->execute(); $this->setLayout(false); $this->loadRelated(); $this->getResponse()->setHttpHeader('Pragma: private', true); $this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename="export.csv"'); $this->getResponse()->setContentType("application/force-download text/csv"); $this->setTemplate('exportCsv'); return; } // Define in one line a pager Layout based on a pagerLayoutWithArrows object // This pager layout is based on a Doctrine_Pager, itself based on a customed Doctrine_Query object (call to the getExpLike method of ExpeditionTable class) $pager = new DarwinPager($query, $this->currentPage, $this->form->getValue('rec_per_page')); // Replace the count query triggered by the Pager to get the number of records retrieved $count_q = clone $query; // Remove from query the group by and order by clauses $count_q = $count_q->select('count(s.id)')->removeDqlQueryPart('orderby')->limit(0); if ($this->form->with_group) { $count_q->select('count(distinct s.id)')->removeDqlQueryPart('groupby'); } // Initialize an empty count query $counted = new DoctrineCounted(); // Define the correct select count() of the count query $counted->count_query = $count_q; // And replace the one of the pager with this new one $pager->setCountQuery($counted); $this->pagerLayout = new PagerLayoutWithArrows($pager, new Doctrine_Pager_Range_Sliding(array('chunk' => $this->pagerSlidingSize)), $this->getController()->genUrl($this->s_url . $this->o_url) . '/page/{%page_number}'); // Sets the Pager Layout templates $this->setDefaultPaggingLayout($this->pagerLayout); // If pager not yet executed, this means the query has to be executed for data loading if (!$this->pagerLayout->getPager()->getExecuted()) { $this->specimensearch = $this->pagerLayout->execute(); } //Load Codes and Loans and related for each item $this->loadRelated(); $this->field_to_show = $this->getVisibleColumns($this->getUser(), $this->form); $this->defineFields($this->source); return $request->isXmlHttpRequest() ? $this->renderPartial('searchSuccess') : null; } } } $this->setTemplate('index'); if (isset($criterias['specimen_search_filters'])) { Doctrine::getTable('Specimens')->getRequiredWidget($criterias['specimen_search_filters'], $this->getUser()->getId(), 'specimensearch_widget'); } $this->loadWidgets(); }
protected function searchResults($form, $request) { if ($request->getParameter('searchCatalogue', '') !== '') { $form->bind($request->getParameter('searchCatalogue')); if ($form->isValid()) { $query = $form->getQuery()->orderBy($this->orderBy . ' ' . $this->orderDir); $pager = new DarwinPager($query, $this->currentPage, $form->getValue('rec_per_page')); // Replace the count query triggered by the Pager to get the number of records retrieved $count_q = clone $query; // Remove from query the group by and order by clauses $count_q = $count_q->select('count(id)')->removeDqlQueryPart('groupby')->removeDqlQueryPart('orderby')->removeDqlQueryPart('join'); // Initialize an empty count query $counted = new DoctrineCounted(); // Define the correct select count() of the count query $counted->count_query = $count_q; // And replace the one of the pager with this new one $pager->setCountQuery($counted); $this->pagerLayout = new PagerLayoutWithArrows($pager, new Doctrine_Pager_Range_Sliding(array('chunk' => $this->pagerSlidingSize)), $this->getController()->genUrl($this->s_url . $this->o_url) . '/page/{%page_number}'); // Sets the Pager Layout templates $this->setDefaultPaggingLayout($this->pagerLayout); // If pager not yet executed, this means the query has to be executed for data loading if (!$this->pagerLayout->getPager()->getExecuted()) { $this->items = $this->pagerLayout->execute(); } } } }