3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
41 * This file is for activity search
43 class CRM_Activity_Form_Search
extends CRM_Core_Form_Search
{
46 * The params that are sent to the query.
50 protected $_queryParams;
53 * Are we restricting ourselves to a single contact.
57 protected $_single = FALSE;
60 * Are we restricting ourselves to a single contact.
64 protected $_limit = NULL;
67 * Prefix for the controller.
69 protected $_prefix = "activity_";
74 * The saved search ID retrieved from the GET vars.
81 * Processing needed for buildForm and later.
85 public function preProcess() {
86 $this->set('searchFormName', 'Search');
88 // set the button names
89 $this->_searchButtonName
= $this->getButtonName('refresh');
90 $this->_actionButtonName
= $this->getButtonName('next', 'action');
93 $this->defaults
= array();
95 // we allow the controller to set force/reset externally, useful when we are being
96 // driven by the wizard framework
97 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
98 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
99 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
100 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
102 $this->assign("context", $this->_context
);
104 // get user submitted values
105 // get it from controller only if form has been submitted, else preProcess has set this
106 if (!empty($_POST) && !$this->controller
->isModal()) {
107 $this->_formValues
= $this->controller
->exportValues($this->_name
);
110 $this->_formValues
= $this->get('formValues');
113 if (empty($this->_formValues
)) {
114 if (isset($this->_ssID
)) {
115 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
120 $this->postProcess();
121 $this->set('force', 0);
125 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
126 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
127 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
131 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
132 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
140 if ($this->_context
== 'user') {
141 $prefix = $this->_prefix
;
144 $this->assign("{$prefix}limit", $this->_limit
);
145 $this->assign("{$prefix}single", $this->_single
);
147 $controller = new CRM_Core_Selector_Controller($selector,
148 $this->get(CRM_Utils_Pager
::PAGE_ID
),
150 CRM_Core_Action
::VIEW
,
152 CRM_Core_Selector_Controller
::TRANSFER
,
155 $controller->setEmbedded(TRUE);
156 $controller->moveFromSessionToTemplate();
158 $this->assign('summary', $this->get('summary'));
162 * Build the form object.
167 public function buildQuickForm() {
168 parent
::buildQuickForm();
169 $this->addElement('text', 'sort_name', ts('Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
171 CRM_Activity_BAO_Query
::buildSearchForm($this);
173 $rows = $this->get('rows');
174 if (is_array($rows)) {
175 if (!$this->_single
) {
176 $this->addRowSelectors($rows);
179 $permission = CRM_Core_Permission
::getPermission();
181 $this->addTaskMenu(CRM_Activity_Task
::permissionedTaskTitles($permission));
187 * The post processing of the form gets done here.
189 * Key things done during post processing are
190 * - check for reset or next request. if present, skip post procesing.
191 * - now check if user requested running a saved search, if so, then
192 * the form values associated with the saved search are used for searching.
193 * - if user has done a submit with new values the regular post submissing is
196 * The processing consists of using a Selector / Controller framework for getting the
199 public function postProcess() {
206 if (!empty($_POST)) {
207 $this->_formValues
= $this->controller
->exportValues($this->_name
);
208 foreach (array('activity_type_id', 'status_id', 'activity_subject') as $element) {
209 $value = CRM_Utils_Array
::value($element, $this->_formValues
);
211 if (is_array($value)) {
212 if ($element == 'status_id') {
213 unset($this->_formValues
[$element]);
214 $element = 'activity_' . $element;
216 $this->_formValues
[$element] = array('IN' => $value);
219 $this->_formValues
[$element] = array('LIKE' => "%$value%");
225 $this->fixFormValues();
227 if (isset($this->_ssID
) && empty($_POST)) {
228 // if we are editing / running a saved search and the form has not been posted
229 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
232 // We don't show test records in summaries or dashboards
233 if (empty($this->_formValues
['activity_test']) && $this->_force
) {
234 $this->_formValues
["activity_test"] = 0;
237 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
239 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
241 $this->set('formValues', $this->_formValues
);
242 $this->set('queryParams', $this->_queryParams
);
244 $buttonName = $this->controller
->getButtonName();
245 if ($buttonName == $this->_actionButtonName
) {
246 // check actionName and if next, then do not repeat a search, since we are going to the next page
247 // hack, make sure we reset the task values
248 $stateMachine = $this->controller
->getStateMachine();
249 $formName = $stateMachine->getTaskFormName();
250 $this->controller
->resetPage($formName);
255 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
256 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
257 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
261 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
263 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
270 $selector->setKey($this->controller
->_key
);
273 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
274 $prefix = $this->_prefix
;
277 $controller = new CRM_Core_Selector_Controller($selector,
278 $this->get(CRM_Utils_Pager
::PAGE_ID
),
280 CRM_Core_Action
::VIEW
,
282 CRM_Core_Selector_Controller
::SESSION
,
285 $controller->setEmbedded(TRUE);
286 $query = &$selector->getQuery();
288 if ($this->_context
== 'user') {
289 $query->setSkipPermission(TRUE);
294 public function fixFormValues() {
295 if (!$this->_force
) {
299 $status = CRM_Utils_Request
::retrieve('status', 'String', $this);
301 $this->_formValues
['activity_status_id'] = $status;
302 $this->_defaults
['activity_status_id'] = $status;
305 $survey = CRM_Utils_Request
::retrieve('survey', 'Positive', CRM_Core_DAO
::$_nullObject);
308 $this->_formValues
['activity_survey_id'] = $this->_defaults
['activity_survey_id'] = $survey;
309 $sid = CRM_Utils_Array
::value('activity_survey_id', $this->_formValues
);
310 $activity_type_id = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
312 // since checkbox are replaced by multiple select option
313 $this->_formValues
['activity_type_id'] = $activity_type_id;
314 $this->_defaults
['activity_type_id'] = $activity_type_id;
316 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
319 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
321 $this->_formValues
['contact_id'] = $cid;
323 $activity_role = CRM_Utils_Request
::retrieve('activity_role', 'Positive', $this);
325 if ($activity_role) {
326 $this->_formValues
['activity_role'] = $activity_role;
329 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
331 // also assign individual mode to the template
332 $this->_single
= TRUE;
336 // Added for membership search
338 $signupType = CRM_Utils_Request
::retrieve('signupType', 'Positive',
339 CRM_Core_DAO
::$_nullObject
343 //$this->_formValues['activity_type_id'] = array();
344 $this->_formValues
['activity_role'] = 1;
345 $this->_defaults
['activity_role'] = 1;
346 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, FALSE, FALSE, 'name');
348 $renew = CRM_Utils_Array
::key('Membership Renewal', $activityTypes);
349 $signup = CRM_Utils_Array
::key('Membership Signup', $activityTypes);
351 switch ($signupType) {
352 case 3: // signups and renewals
353 $this->_formValues
['activity_type_id'][$renew] = 1;
354 $this->_defaults
['activity_type_id'][$renew] = 1;
355 case 1: // signups only
356 $this->_formValues
['activity_type_id'][$signup] = 1;
357 $this->_defaults
['activity_type_id'][$signup] = 1;
360 case 2: // renewals only
361 $this->_formValues
['activity_type_id'][$renew] = 1;
362 $this->_defaults
['activity_type_id'][$renew] = 1;
367 $dateLow = CRM_Utils_Request
::retrieve('dateLow', 'String',
368 CRM_Core_DAO
::$_nullObject
372 $dateLow = date('m/d/Y', strtotime($dateLow));
373 $this->_formValues
['activity_date_relative'] = 0;
374 $this->_defaults
['activity_date_relative'] = 0;
375 $this->_formValues
['activity_date_low'] = $dateLow;
376 $this->_defaults
['activity_date_low'] = $dateLow;
379 $dateHigh = CRM_Utils_Request
::retrieve('dateHigh', 'String',
380 CRM_Core_DAO
::$_nullObject
384 // Activity date time assumes midnight at the beginning of the date
385 // This sets it to almost midnight at the end of the date
386 /* if ($dateHigh <= 99999999) {
387 $dateHigh = 1000000 * $dateHigh + 235959;
389 $dateHigh = date('m/d/Y', strtotime($dateHigh));
390 $this->_formValues
['activity_date_relative'] = 0;
391 $this->_defaults
['activity_date_relative'] = 0;
392 $this->_formValues
['activity_date_high'] = $dateHigh;
393 $this->_defaults
['activity_date_high'] = $dateHigh;
396 if (!empty($this->_defaults
)) {
397 $this->setDefaults($this->_defaults
);
404 public function getFormValues() {
409 * Return a descriptive name for the page, used in wizard header
413 public function getTitle() {
414 return ts('Find Activities');