3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
35 * This file is for activity search.
37 class CRM_Activity_Form_Search
extends CRM_Core_Form_Search
{
40 * The params that are sent to the query.
44 protected $_queryParams;
47 * Are we restricting ourselves to a single contact.
51 protected $_single = FALSE;
54 * Are we restricting ourselves to a single contact.
58 protected $_limit = NULL;
61 * Prefix for the controller.
63 protected $_prefix = "activity_";
66 * The saved search ID retrieved from the GET vars.
73 * Processing needed for buildForm and later.
75 public function preProcess() {
76 $this->set('searchFormName', 'Search');
78 // set the button names
79 $this->_searchButtonName
= $this->getButtonName('refresh');
80 $this->_actionButtonName
= $this->getButtonName('next', 'action');
83 $this->defaults
= array();
85 // we allow the controller to set force/reset externally, useful when we are being
86 // driven by the wizard framework
87 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean');
88 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
89 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
90 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
92 $this->assign("context", $this->_context
);
94 // get user submitted values
95 // get it from controller only if form has been submitted, else preProcess has set this
96 if (!empty($_POST) && !$this->controller
->isModal()) {
97 $this->_formValues
= $this->controller
->exportValues($this->_name
);
100 $this->_formValues
= $this->get('formValues');
103 // If we force the search then merge form values with url values
104 // and set submit values to form values.
105 $this->_formValues
= array_merge((array) $this->_formValues
, CRM_Utils_Request
::exportValues());
106 $this->_submitValues
= $this->_formValues
;
110 if (empty($this->_formValues
)) {
111 if (isset($this->_ssID
)) {
112 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
117 $this->postProcess();
118 $this->set('force', 0);
122 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
123 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
124 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
128 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
129 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
137 if ($this->_context
== 'user') {
138 $prefix = $this->_prefix
;
141 $this->assign("{$prefix}limit", $this->_limit
);
142 $this->assign("{$prefix}single", $this->_single
);
144 $controller = new CRM_Core_Selector_Controller($selector,
145 $this->get(CRM_Utils_Pager
::PAGE_ID
),
147 CRM_Core_Action
::VIEW
,
149 CRM_Core_Selector_Controller
::TRANSFER
,
152 $controller->setEmbedded(TRUE);
153 $controller->moveFromSessionToTemplate();
155 $this->assign('summary', $this->get('summary'));
159 * Build the form object.
161 public function buildQuickForm() {
162 parent
::buildQuickForm();
163 $this->addSortNameField();
165 CRM_Activity_BAO_Query
::buildSearchForm($this);
167 $rows = $this->get('rows');
168 if (is_array($rows)) {
169 if (!$this->_single
) {
170 $this->addRowSelectors($rows);
173 $permission = CRM_Core_Permission
::getPermission();
175 $this->addTaskMenu(CRM_Activity_Task
::permissionedTaskTitles($permission));
181 * The post processing of the form gets done here.
183 * Key things done during post processing are
184 * - check for reset or next request. if present, skip post procesing.
185 * - now check if user requested running a saved search, if so, then
186 * the form values associated with the saved search are used for searching.
187 * - if user has done a submit with new values the regular post submissing is
190 * The processing consists of using a Selector / Controller framework for getting the
193 public function postProcess() {
200 if (!empty($_POST)) {
201 $this->_formValues
= $this->controller
->exportValues($this->_name
);
202 $specialParams = array(
208 $changeNames = array(
209 'status_id' => 'activity_status_id',
210 'priority_id' => 'activity_priority_id',
213 CRM_Contact_BAO_Query
::processSpecialFormValue($this->_formValues
, $specialParams, $changeNames);
216 $this->fixFormValues();
218 if (isset($this->_ssID
) && empty($_POST)) {
219 // if we are editing / running a saved search and the form has not been posted
220 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
223 // We don't show test records in summaries or dashboards
224 if (empty($this->_formValues
['activity_test']) && $this->_force
) {
225 $this->_formValues
["activity_test"] = 0;
228 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($this->_formValues
);
230 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
232 $this->set('formValues', $this->_formValues
);
233 $this->set('queryParams', $this->_queryParams
);
235 $buttonName = $this->controller
->getButtonName();
236 if ($buttonName == $this->_actionButtonName
) {
237 // check actionName and if next, then do not repeat a search, since we are going to the next page
238 // hack, make sure we reset the task values
239 $stateMachine = $this->controller
->getStateMachine();
240 $formName = $stateMachine->getTaskFormName();
241 $this->controller
->resetPage($formName);
246 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
247 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
248 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
252 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
254 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
261 $selector->setKey($this->controller
->_key
);
264 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
265 $prefix = $this->_prefix
;
268 $controller = new CRM_Core_Selector_Controller($selector,
269 $this->get(CRM_Utils_Pager
::PAGE_ID
),
271 CRM_Core_Action
::VIEW
,
273 CRM_Core_Selector_Controller
::SESSION
,
276 $controller->setEmbedded(TRUE);
277 $query = &$selector->getQuery();
279 if ($this->_context
== 'user') {
280 $query->setSkipPermission(TRUE);
285 public function fixFormValues() {
286 if (!$this->_force
) {
290 $status = CRM_Utils_Request
::retrieve('status', 'String', $this);
292 $this->_formValues
['activity_status_id'] = $status;
293 $this->_defaults
['activity_status_id'] = $status;
296 $survey = CRM_Utils_Request
::retrieve('survey', 'Positive');
299 $this->_formValues
['activity_survey_id'] = $this->_defaults
['activity_survey_id'] = $survey;
300 $sid = CRM_Utils_Array
::value('activity_survey_id', $this->_formValues
);
301 $activity_type_id = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
303 // since checkbox are replaced by multiple select option
304 $this->_formValues
['activity_type_id'] = $activity_type_id;
305 $this->_defaults
['activity_type_id'] = $activity_type_id;
307 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
310 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
312 $this->_formValues
['contact_id'] = $cid;
314 $activity_role = CRM_Utils_Request
::retrieve('activity_role', 'Positive', $this);
316 if ($activity_role) {
317 $this->_formValues
['activity_role'] = $activity_role;
320 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
322 // also assign individual mode to the template
323 $this->_single
= TRUE;
327 // Added for membership search
329 $signupType = CRM_Utils_Request
::retrieve('signupType', 'Positive');
332 $this->_formValues
['activity_role'] = 1;
333 $this->_defaults
['activity_role'] = 1;
334 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, FALSE, FALSE, 'name');
336 $renew = CRM_Utils_Array
::key('Membership Renewal', $activityTypes);
337 $signup = CRM_Utils_Array
::key('Membership Signup', $activityTypes);
339 switch ($signupType) {
340 case 3: // signups and renewals
341 $this->_formValues
['activity_type_id'][$renew] = 1;
342 $this->_defaults
['activity_type_id'][$renew] = 1;
343 case 1: // signups only
344 $this->_formValues
['activity_type_id'][$signup] = 1;
345 $this->_defaults
['activity_type_id'][$signup] = 1;
348 case 2: // renewals only
349 $this->_formValues
['activity_type_id'][$renew] = 1;
350 $this->_defaults
['activity_type_id'][$renew] = 1;
355 $dateLow = CRM_Utils_Request
::retrieve('dateLow', 'String');
358 $dateLow = date('m/d/Y', strtotime($dateLow));
359 $this->_formValues
['activity_date_relative'] = 0;
360 $this->_defaults
['activity_date_relative'] = 0;
361 $this->_formValues
['activity_date_low'] = $dateLow;
362 $this->_defaults
['activity_date_low'] = $dateLow;
365 $dateHigh = CRM_Utils_Request
::retrieve('dateHigh', 'String');
368 // Activity date time assumes midnight at the beginning of the date
369 // This sets it to almost midnight at the end of the date
370 /* if ($dateHigh <= 99999999) {
371 $dateHigh = 1000000 * $dateHigh + 235959;
373 $dateHigh = date('m/d/Y', strtotime($dateHigh));
374 $this->_formValues
['activity_date_relative'] = 0;
375 $this->_defaults
['activity_date_relative'] = 0;
376 $this->_formValues
['activity_date_high'] = $dateHigh;
377 $this->_defaults
['activity_date_high'] = $dateHigh;
380 // Enable search activity by custom value
381 $requestParams = CRM_Utils_Request
::exportValues();
382 foreach (array_keys($requestParams) as $key) {
383 if (substr($key, 0, 7) != 'custom_') {
386 elseif (empty($requestParams[$key])) {
389 $customValue = CRM_Utils_Request
::retrieve($key, 'String', $this);
391 $this->_formValues
[$key] = $customValue;
392 $this->_defaults
[$key] = $customValue;
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');