~fabiocbalbuquerque/sahana-agasti/web-services

« back to all changes in this revision

Viewing changes to apps/frontend/lib/actions/actions.class.php

  • Committer: Fabio Albuquerque
  • Date: 2011-08-08 22:10:34 UTC
  • mfrom: (1.26.1 push-trunk)
  • Revision ID: fabiocbalbuquerque@gmail.com-20110808221034-vfr4ggsbxsdllq82
Merges from CUNY SPS

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
  {
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');
26
26
    }
27
27
  }
28
28
 
29
29
  public function executeSearch(sfWebRequest $request)
30
30
  {
31
 
 
32
 
    self::doSearch($request->getParameter('query'));
 
31
    $this->targetAction = 'search';
 
32
    $string = $request->getParameter('query');
 
33
    $pattern = "/\W/";
 
34
    $replace = " ";
 
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');
35
41
  }
62
68
    return $this->renderText($status);
63
69
  }
64
70
 
65
 
  public function doSearch($searchquery, $isFuzzy = TRUE, $widget = NULL)
 
71
  public function doSearch($searchquery, $currentPage, $isFuzzy = TRUE, $widget = NULL)
66
72
  {
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);
71
77
 
78
84
    $this->results = $query->getRecords();
79
85
    $this->hits = $query->getHits();
80
86
    $this->widget = $widget;
81
 
    $this->limit = null;
82
 
    $resultArray = array();
83
 
 
84
 
    $this->pager = new agArrayPager(null, 10);
85
87
 
86
88
    $searchResult = $query->getRecords(); //agStaff should be $models
87
89
    // TODO
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'){
91
 
 
92
 
    if (count($searchResult) > 0) {
93
 
      if (isset($searchResult['agStaff'])) {
94
 
        $this->target_module = 'staff';
 
92
 
 
93
    $resultsPerPage = agGlobal::getParam('search_list_results_per_page');
 
94
 
 
95
    if ($models[0] == 'agStaff')
 
96
    {
 
97
      $staff_ids = array();
 
98
      $this->targetModule = 'staff';
 
99
      if ( (isset($searchResult['agStaff']) || ($models[0] == 'agStaff')) && (count($searchResult) != 0) )
 
100
      {
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();
 
103
      }
 
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) )
 
109
      {
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
104
 
      } else {
105
 
        //$resultArray = array();
106
 
      }
 
111
        $facility_ids = $facilityCollection->getKeys();
 
112
      }
 
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) )
 
118
      {
 
119
        $organizationCollection = $searchResult['agOrganization'];
 
120
        $organization_ids = $organizationCollection->getKeys();
 
121
      }
 
122
      list($this->displayColumns, $pagerQuery) = agListHelper::getOrganizationList($organization_ids);
 
123
    } else {
 
124
      $this->forward404("Search Module Undefined.");
107
125
    }
108
126
 
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);
113
129
  }
114
130
 
115
131
  public function getSearchedModels()