~fabiocbalbuquerque/sahana-agasti/web-services

1.1.162 by charles wisniewski
abstracted actions.class and created generic templates and components for search
1
<?php
2
3
/**
4
 * extends sfActions for common functionality
5
 *
1.1.625 by Chad Heuschober
Committing first-pass of the license change.
6
 * PHP Version 5.3
1.1.162 by charles wisniewski
abstracted actions.class and created generic templates and components for search
7
 *
1.1.625 by Chad Heuschober
Committing first-pass of the license change.
8
 * LICENSE: This source file is subject to LGPLv2.1 license
1.1.162 by charles wisniewski
abstracted actions.class and created generic templates and components for search
9
 * that is available through the world-wide-web at the following URI:
1.1.629 by Chad Heuschober
Added links to the correct LGPL license in the project files.
10
 * http://www.gnu.org/licenses/lgpl-2.1.html
1.1.162 by charles wisniewski
abstracted actions.class and created generic templates and components for search
11
 *
1.1.528 by charles wisniewski
cleaned up a lot of comments, admin/list now works and a number of extra pages have been removed
12
 * @author Charles Wisniewski, CUNY SPS
1.1.162 by charles wisniewski
abstracted actions.class and created generic templates and components for search
13
 *
14
 * Copyright of the Sahana Software Foundation, sahanafoundation.org
15
 */
16
class agActions extends sfActions
17
{
1.1.260 by charles wisniewski
staff pools now save ag_scenario_staff_resources
18
1.1.679 by Nils Stolpe
Getting rid of some coding violations in agActions.
19
  protected $_searchedModels;
1.1.222 by Usman Akeju
- removes auth file (and updates .bzrignore)
20
21
  public function __construct($context, $moduleName, $actionName)
22
  {
23
    parent::__construct($context, $moduleName, $actionName);
1.1.679 by Nils Stolpe
Getting rid of some coding violations in agActions.
24
    if (empty($this->_searchedModels)) {
1.22.7 by Shirley Chan
Making organization lucene searchable
25
      $this->_searchedModels = array('agStaff', 'agFacility', 'agOrganization');
1.1.226 by charles wisniewski
modified agActions to not initialize searchedModels as an array, allows for overloading
26
    }
1.1.222 by Usman Akeju
- removes auth file (and updates .bzrignore)
27
  }
1.1.167 by Usman Akeju
- adds initial work toward allowing search of multiple models
28
1.1.162 by charles wisniewski
abstracted actions.class and created generic templates and components for search
29
  public function executeSearch(sfWebRequest $request)
30
  {
1.19.57 by Shirley Chan
Converting all array_pager to doctrine_pager, making returns of large data set more efficient and within reasonable time
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);
1.1.704 by Darlene E McCullough
cleaning up code formatting for client stubs
39
    $this->setTemplate(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . 'modules/search/templates/search');
1.1.173 by charles wisniewski
modified search actions, added search result functionality to staff pool
40
    //$this->setTemplate('global/search');
41
  }
42
1.1.1136 by Usman Akeju
- more import batching + event polling work
43
  public function executeStatus(sfWebRequest $request)
44
  {
1.1.1225 by Usman Akeju
- more cleanup and logic fixes for import stuff
45
    ////TODO: module_ACTION_status instead? -UA
46
    //$statusId = implode('_', array($this->moduleName, 'status'));
1.1.1164 by Usman Akeju
- more import batching work
47
    //$context = $this->getContext();
1.1.1206 by Usman Akeju
- more staff import fixes and status stuff
48
    ////$context = sfContext::getInstance();
49
    //$status = $context->has($statusId) ? $this->getContext()->get($statusId) : $statusId/*array(0, 0, 0)*/;
1.1.1218 by Usman Akeju
- adds status update mechanism
50
1.1.1206 by Usman Akeju
- more staff import fixes and status stuff
51
    //TODO: get import data directory root info from global param
52
    $importDataRoot = sfConfig::get('sf_upload_dir');
1.1.1218 by Usman Akeju
- adds status update mechanism
53
    $importDir = $importDataRoot . DIRECTORY_SEPARATOR . $this->moduleName;
54
    $statusFile = $importDir . DIRECTORY_SEPARATOR . 'status.yml';
1.1.1225 by Usman Akeju
- more cleanup and logic fixes for import stuff
55
    $status = is_readable($statusFile) ? sfYaml::load($statusFile) : array()/* array(0, 0, 0) */;
1.1.1152 by Usman Akeju
- more work on polling, import batching, related routing
56
    $format = $request->getRequestFormat();
57
    if ('json' == $format) {
1.1.1136 by Usman Akeju
- more import batching + event polling work
58
      $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
1.1.1164 by Usman Akeju
- more import batching work
59
      $status = json_encode($status);
1.1.1136 by Usman Akeju
- more import batching + event polling work
60
    }
1.1.1152 by Usman Akeju
- more work on polling, import batching, related routing
61
    //TODO: else, use partial instead of returning?
1.1.1159 by Usman Akeju
- more import work
62
    //TODO: the else block below is for testing -- remove when finished
63
    else {
64
      $this->getResponse()->setHttpHeader('Content-Type', 'text/plain; charset=utf-8');
1.1.1164 by Usman Akeju
- more import batching work
65
      $status = json_encode($status);
1.1.1159 by Usman Akeju
- more import work
66
    }
1.1.1206 by Usman Akeju
- more staff import fixes and status stuff
67
1.1.1164 by Usman Akeju
- more import batching work
68
    return $this->renderText($status);
1.1.1130 by charles wisniewski
added event status polling function in global actions. added jquery caller to poll for event status. added agmessageresponsehandler for message responses
69
  }
70
1.19.57 by Shirley Chan
Converting all array_pager to doctrine_pager, making returns of large data set more efficient and within reasonable time
71
  public function doSearch($searchquery, $currentPage, $isFuzzy = TRUE, $widget = NULL)
1.1.173 by charles wisniewski
modified search actions, added search result functionality to staff pool
72
  {
1.1.222 by Usman Akeju
- removes auth file (and updates .bzrignore)
73
    $models = $this->getSearchedModels();
1.19.57 by Shirley Chan
Converting all array_pager to doctrine_pager, making returns of large data set more efficient and within reasonable time
74
    $this->targetModule = 'staff';
1.1.173 by charles wisniewski
modified search actions, added search result functionality to staff pool
75
    $this->searchquery = $searchquery;
1.1.162 by charles wisniewski
abstracted actions.class and created generic templates and components for search
76
    $this->getResponse()->setTitle('Search results for: ' . $this->searchquery);
1.1.1068 by charles wisniewski
added calls to autoloader for search. search now works on alphanumerics
77
1.1.1097 by Usman Akeju
- secured upload directory
78
    Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
1.1.260 by charles wisniewski
staff pools now save ag_scenario_staff_resources
79
    $query = LuceneSearch::find($this->searchquery);
1.1.679 by Nils Stolpe
Getting rid of some coding violations in agActions.
80
    if ($isFuzzy == TRUE) {
1.1.260 by charles wisniewski
staff pools now save ag_scenario_staff_resources
81
      $query->fuzzy();
82
    }
83
    $query->in($models);
1.1.162 by charles wisniewski
abstracted actions.class and created generic templates and components for search
84
    $this->results = $query->getRecords();
85
    $this->hits = $query->getHits();
1.1.386 by charles wisniewski
added functionality to add staff to a shift
86
    $this->widget = $widget;
1.1.745 by charles wisniewski
when searching for a staff member real results are now returned
87
88
    $searchResult = $query->getRecords(); //agStaff should be $models
1.1.1124 by charles wisniewski
message response import work
89
    // TODO
90
    //a) we can return the results hydrated as scalar
91
    // (only get the PK's[person,entity,staff,facility,etc])
1.19.57 by Shirley Chan
Converting all array_pager to doctrine_pager, making returns of large data set more efficient and within reasonable time
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
      {
1.1.1123 by Usman Akeju
- fixed headers after import caused by weird context change
101
        $staffCollection = $searchResult['agStaff'];
1.19.57 by Shirley Chan
Converting all array_pager to doctrine_pager, making returns of large data set more efficient and within reasonable time
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
      {
1.1.1123 by Usman Akeju
- fixed headers after import caused by weird context change
110
        $facilityCollection = $searchResult['agFacility'];
1.19.57 by Shirley Chan
Converting all array_pager to doctrine_pager, making returns of large data set more efficient and within reasonable time
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
      {
1.22.7 by Shirley Chan
Making organization lucene searchable
119
        $organizationCollection = $searchResult['agOrganization'];
1.19.57 by Shirley Chan
Converting all array_pager to doctrine_pager, making returns of large data set more efficient and within reasonable time
120
        $organization_ids = $organizationCollection->getKeys();
1.1.867 by charles wisniewski
new staff list up, old staff list is still available via staff/oldlist
121
      }
1.19.57 by Shirley Chan
Converting all array_pager to doctrine_pager, making returns of large data set more efficient and within reasonable time
122
      list($this->displayColumns, $pagerQuery) = agListHelper::getOrganizationList($organization_ids);
123
    } else {
124
      $this->forward404("Search Module Undefined.");
1.1.754 by charles wisniewski
added tooltip stylesheet [to be refactored later] added tooltip entry to wiki, added javascript to support tooltips and added commented out code to show proper facility record search returns
125
    }
1.1.867 by charles wisniewski
new staff list up, old staff list is still available via staff/oldlist
126
1.19.57 by Shirley Chan
Converting all array_pager to doctrine_pager, making returns of large data set more efficient and within reasonable time
127
    $this->pager = new Doctrine_Pager($pagerQuery, $currentPage, $resultsPerPage);
128
    $this->data = $this->pager->execute(array(), Doctrine_Core::HYDRATE_SCALAR);
1.1.162 by charles wisniewski
abstracted actions.class and created generic templates and components for search
129
  }
130
1.1.222 by Usman Akeju
- removes auth file (and updates .bzrignore)
131
  public function getSearchedModels()
132
  {
1.1.679 by Nils Stolpe
Getting rid of some coding violations in agActions.
133
    return $this->_searchedModels;
1.1.222 by Usman Akeju
- removes auth file (and updates .bzrignore)
134
  }
135
1.1.162 by charles wisniewski
abstracted actions.class and created generic templates and components for search
136
}