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 (empty($this->_formValues
)) {
104 if (isset($this->_ssID
)) {
105 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
110 $this->postProcess();
111 $this->set('force', 0);
115 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
116 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
117 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
121 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
122 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
130 if ($this->_context
== 'user') {
131 $prefix = $this->_prefix
;
134 $this->assign("{$prefix}limit", $this->_limit
);
135 $this->assign("{$prefix}single", $this->_single
);
137 $controller = new CRM_Core_Selector_Controller($selector,
138 $this->get(CRM_Utils_Pager
::PAGE_ID
),
140 CRM_Core_Action
::VIEW
,
142 CRM_Core_Selector_Controller
::TRANSFER
,
145 $controller->setEmbedded(TRUE);
146 $controller->moveFromSessionToTemplate();
148 $this->assign('summary', $this->get('summary'));
152 * Build the form object.
154 public function buildQuickForm() {
155 parent
::buildQuickForm();
156 $this->addSortNameField();
158 CRM_Activity_BAO_Query
::buildSearchForm($this);
160 $rows = $this->get('rows');
161 if (is_array($rows)) {
162 if (!$this->_single
) {
163 $this->addRowSelectors($rows);
166 $permission = CRM_Core_Permission
::getPermission();
168 $this->addTaskMenu(CRM_Activity_Task
::permissionedTaskTitles($permission));
174 * The post processing of the form gets done here.
176 * Key things done during post processing are
177 * - check for reset or next request. if present, skip post procesing.
178 * - now check if user requested running a saved search, if so, then
179 * the form values associated with the saved search are used for searching.
180 * - if user has done a submit with new values the regular post submissing is
183 * The processing consists of using a Selector / Controller framework for getting the
186 public function postProcess() {
193 if (!empty($_POST)) {
194 $this->_formValues
= $this->controller
->exportValues($this->_name
);
195 $specialParams = array(
201 $changeNames = array(
202 'status_id' => 'activity_status_id',
203 'priority_id' => 'activity_priority_id',
206 CRM_Contact_BAO_Query
::processSpecialFormValue($this->_formValues
, $specialParams, $changeNames);
209 $this->fixFormValues();
211 if (isset($this->_ssID
) && empty($_POST)) {
212 // if we are editing / running a saved search and the form has not been posted
213 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
216 // We don't show test records in summaries or dashboards
217 if (empty($this->_formValues
['activity_test']) && $this->_force
) {
218 $this->_formValues
["activity_test"] = 0;
221 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($this->_formValues
);
223 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
225 $this->set('formValues', $this->_formValues
);
226 $this->set('queryParams', $this->_queryParams
);
228 $buttonName = $this->controller
->getButtonName();
229 if ($buttonName == $this->_actionButtonName
) {
230 // check actionName and if next, then do not repeat a search, since we are going to the next page
231 // hack, make sure we reset the task values
232 $stateMachine = $this->controller
->getStateMachine();
233 $formName = $stateMachine->getTaskFormName();
234 $this->controller
->resetPage($formName);
239 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
240 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
241 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
245 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
247 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
254 $selector->setKey($this->controller
->_key
);
257 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
258 $prefix = $this->_prefix
;
261 $controller = new CRM_Core_Selector_Controller($selector,
262 $this->get(CRM_Utils_Pager
::PAGE_ID
),
264 CRM_Core_Action
::VIEW
,
266 CRM_Core_Selector_Controller
::SESSION
,
269 $controller->setEmbedded(TRUE);
270 $query = &$selector->getQuery();
272 if ($this->_context
== 'user') {
273 $query->setSkipPermission(TRUE);
278 public function fixFormValues() {
279 if (!$this->_force
) {
283 $status = CRM_Utils_Request
::retrieve('status', 'String', $this);
285 $this->_formValues
['activity_status_id'] = $status;
286 $this->_defaults
['activity_status_id'] = $status;
289 $survey = CRM_Utils_Request
::retrieve('survey', 'Positive');
292 $this->_formValues
['activity_survey_id'] = $this->_defaults
['activity_survey_id'] = $survey;
293 $sid = CRM_Utils_Array
::value('activity_survey_id', $this->_formValues
);
294 $activity_type_id = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
296 // since checkbox are replaced by multiple select option
297 $this->_formValues
['activity_type_id'] = $activity_type_id;
298 $this->_defaults
['activity_type_id'] = $activity_type_id;
300 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
303 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
305 $this->_formValues
['contact_id'] = $cid;
307 $activity_role = CRM_Utils_Request
::retrieve('activity_role', 'Positive', $this);
309 if ($activity_role) {
310 $this->_formValues
['activity_role'] = $activity_role;
313 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
315 // also assign individual mode to the template
316 $this->_single
= TRUE;
320 // Added for membership search
322 $signupType = CRM_Utils_Request
::retrieve('signupType', 'Positive');
325 $this->_formValues
['activity_role'] = 1;
326 $this->_defaults
['activity_role'] = 1;
327 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, FALSE, FALSE, 'name');
329 $renew = CRM_Utils_Array
::key('Membership Renewal', $activityTypes);
330 $signup = CRM_Utils_Array
::key('Membership Signup', $activityTypes);
332 switch ($signupType) {
333 case 3: // signups and renewals
334 $this->_formValues
['activity_type_id'][$renew] = 1;
335 $this->_defaults
['activity_type_id'][$renew] = 1;
336 case 1: // signups only
337 $this->_formValues
['activity_type_id'][$signup] = 1;
338 $this->_defaults
['activity_type_id'][$signup] = 1;
341 case 2: // renewals only
342 $this->_formValues
['activity_type_id'][$renew] = 1;
343 $this->_defaults
['activity_type_id'][$renew] = 1;
348 $dateLow = CRM_Utils_Request
::retrieve('dateLow', 'String');
351 $dateLow = date('m/d/Y', strtotime($dateLow));
352 $this->_formValues
['activity_date_relative'] = 0;
353 $this->_defaults
['activity_date_relative'] = 0;
354 $this->_formValues
['activity_date_low'] = $dateLow;
355 $this->_defaults
['activity_date_low'] = $dateLow;
358 $dateHigh = CRM_Utils_Request
::retrieve('dateHigh', 'String');
361 // Activity date time assumes midnight at the beginning of the date
362 // This sets it to almost midnight at the end of the date
363 /* if ($dateHigh <= 99999999) {
364 $dateHigh = 1000000 * $dateHigh + 235959;
366 $dateHigh = date('m/d/Y', strtotime($dateHigh));
367 $this->_formValues
['activity_date_relative'] = 0;
368 $this->_defaults
['activity_date_relative'] = 0;
369 $this->_formValues
['activity_date_high'] = $dateHigh;
370 $this->_defaults
['activity_date_high'] = $dateHigh;
373 // Enable search activity by custom value
374 $requestParams = CRM_Utils_Request
::exportValues();
375 foreach (array_keys($requestParams) as $key) {
376 if (substr($key, 0, 7) != 'custom_') {
379 elseif (empty($requestParams[$key])) {
382 $customValue = CRM_Utils_Request
::retrieve($key, 'String', $this);
384 $this->_formValues
[$key] = $customValue;
385 $this->_defaults
[$key] = $customValue;
389 if (!empty($this->_defaults
)) {
390 $this->setDefaults($this->_defaults
);
397 public function getFormValues() {
402 * Return a descriptive name for the page, used in wizard header
406 public function getTitle() {
407 return ts('Find Activities');