23
23
parent::__construct($context, $moduleName, $actionName);
24
24
if (empty($this->_searchedModels)) {
25
$this->_searchedModels = array('agStaff', 'agFacility');
25
$this->_searchedModels = array('agStaff', 'agFacility', 'agOrganization');
29
29
public function executeSearch(sfWebRequest $request)
32
self::doSearch($request->getParameter('query'));
31
$this->targetAction = 'search';
32
$string = $request->getParameter('query');
35
$this->params = '?query=' . urlencode(trim(preg_replace($pattern, $replace, $string), '+'));
36
// $this->params = '?query=' . $request->getParameter('query');
37
$currentPage = ($request->hasParameter('page')) ? $request->getParameter('page') : 1;
38
self::doSearch($request->getParameter('query'), $currentPage);
33
39
$this->setTemplate(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . 'modules/search/templates/search');
34
40
//$this->setTemplate('global/search');
62
68
return $this->renderText($status);
65
public function doSearch($searchquery, $isFuzzy = TRUE, $widget = NULL)
71
public function doSearch($searchquery, $currentPage, $isFuzzy = TRUE, $widget = NULL)
67
73
$models = $this->getSearchedModels();
68
$this->target_module = 'staff';
74
$this->targetModule = 'staff';
69
75
$this->searchquery = $searchquery;
70
76
$this->getResponse()->setTitle('Search results for: ' . $this->searchquery);
78
84
$this->results = $query->getRecords();
79
85
$this->hits = $query->getHits();
80
86
$this->widget = $widget;
82
$resultArray = array();
84
$this->pager = new agArrayPager(null, 10);
86
88
$searchResult = $query->getRecords(); //agStaff should be $models
88
90
//a) we can return the results hydrated as scalar
89
91
// (only get the PK's[person,entity,staff,facility,etc])
90
//if($models == 'agStaff'){
92
if (count($searchResult) > 0) {
93
if (isset($searchResult['agStaff'])) {
94
$this->target_module = 'staff';
93
$resultsPerPage = agGlobal::getParam('search_list_results_per_page');
95
if ($models[0] == 'agStaff')
98
$this->targetModule = 'staff';
99
if ( (isset($searchResult['agStaff']) || ($models[0] == 'agStaff')) && (count($searchResult) != 0) )
95
101
$staffCollection = $searchResult['agStaff'];
96
$staff_ids = $staffCollection->getKeys(); // toArray();
97
$resultArray = agListHelper::getStaffList($staff_ids);
98
} elseif (isset($searchResult['agFacility'])) {
99
$this->target_module = 'facility';
102
$staff_ids = $staffCollection->getKeys();
104
list($this->displayColumns, $pagerQuery) = agListHelper::getStaffList($staff_ids);
105
} elseif ($models[0] == 'agFacility') {
106
$facility_ids = array();
107
$this->targetModule = 'facility';
108
if ( (isset($searchResult['agFacility']) || ($models[0] == 'agFacility')) && (count($searchResult) != 0) )
100
110
$facilityCollection = $searchResult['agFacility'];
101
$facility_ids = $facilityCollection->getKeys(); // toArray();
102
$resultArray = agListHelper::getFacilityList($facility_ids);
103
// @todo change the above to use a FacilityList return
105
//$resultArray = array();
111
$facility_ids = $facilityCollection->getKeys();
113
list($this->displayColumns, $pagerQuery) = agListHelper::getFacilityList($facility_ids);
114
} elseif($models[0] == 'agOrganization') {
115
$organization_ids = array();
116
$this->targetModule = 'organization';
117
if ( (isset($searchResult['agOrganization']) || ($models[0] == 'agOrganization')) && (count($searchResult) != 0) )
119
$organizationCollection = $searchResult['agOrganization'];
120
$organization_ids = $organizationCollection->getKeys();
122
list($this->displayColumns, $pagerQuery) = agListHelper::getOrganizationList($organization_ids);
124
$this->forward404("Search Module Undefined.");
109
$this->pager->setResultArray($resultArray);
110
// $this->pager->setResultArray($staffArray);
111
$this->pager->setPage($this->getRequestParameter('page', 1));
112
$this->pager->init();
127
$this->pager = new Doctrine_Pager($pagerQuery, $currentPage, $resultsPerPage);
128
$this->data = $this->pager->execute(array(), Doctrine_Core::HYDRATE_SCALAR);
115
131
public function getSearchedModels()