3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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. |
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 along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2014
40 * This file is for activity search
42 class CRM_Activity_Form_Search
extends CRM_Core_Form_Search
{
45 * The params that are sent to the query.
49 protected $_queryParams;
52 * Are we restricting ourselves to a single contact.
56 protected $_single = FALSE;
59 * Are we restricting ourselves to a single contact.
63 protected $_limit = NULL;
66 * Prefix for the controller.
68 protected $_prefix = "activity_";
73 * The saved search ID retrieved from the GET vars.
80 * Processing needed for buildForm and later.
84 public function preProcess() {
85 $this->set('searchFormName', 'Search');
87 // set the button names
88 $this->_searchButtonName
= $this->getButtonName('refresh');
89 $this->_actionButtonName
= $this->getButtonName('next', 'action');
92 $this->defaults
= array();
94 // we allow the controller to set force/reset externally, useful when we are being
95 // driven by the wizard framework
96 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
97 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
98 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
99 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
101 $this->assign("context", $this->_context
);
103 // get user submitted values
104 // get it from controller only if form has been submitted, else preProcess has set this
105 if (!empty($_POST) && !$this->controller
->isModal()) {
106 $this->_formValues
= $this->controller
->exportValues($this->_name
);
109 $this->_formValues
= $this->get('formValues');
112 if (empty($this->_formValues
)) {
113 if (isset($this->_ssID
)) {
114 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
119 $this->postProcess();
120 $this->set('force', 0);
124 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
125 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
126 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
130 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
131 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
139 if ($this->_context
== 'user') {
140 $prefix = $this->_prefix
;
143 $this->assign("{$prefix}limit", $this->_limit
);
144 $this->assign("{$prefix}single", $this->_single
);
146 $controller = new CRM_Core_Selector_Controller($selector,
147 $this->get(CRM_Utils_Pager
::PAGE_ID
),
149 CRM_Core_Action
::VIEW
,
151 CRM_Core_Selector_Controller
::TRANSFER
,
154 $controller->setEmbedded(TRUE);
155 $controller->moveFromSessionToTemplate();
157 $this->assign('summary', $this->get('summary'));
161 * Build the form object.
166 public function buildQuickForm() {
167 parent
::buildQuickForm();
168 $this->addElement('text', 'sort_name', ts('Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
170 CRM_Activity_BAO_Query
::buildSearchForm($this);
172 $rows = $this->get('rows');
173 if (is_array($rows)) {
174 if (!$this->_single
) {
175 $this->addRowSelectors($rows);
178 $permission = CRM_Core_Permission
::getPermission();
180 $this->addTaskMenu(CRM_Activity_Task
::permissionedTaskTitles($permission));
186 * The post processing of the form gets done here.
188 * Key things done during post processing are
189 * - check for reset or next request. if present, skip post procesing.
190 * - now check if user requested running a saved search, if so, then
191 * the form values associated with the saved search are used for searching.
192 * - if user has done a submit with new values the regular post submissing is
195 * The processing consists of using a Selector / Controller framework for getting the
198 public function postProcess() {
205 if (!empty($_POST)) {
206 $this->_formValues
= $this->controller
->exportValues($this->_name
);
207 foreach (array('activity_type_id', 'status_id', 'activity_subject') as $element) {
208 $value = CRM_Utils_Array
::value($element, $this->_formValues
);
210 if (is_array($value)) {
211 if ($element == 'status_id') {
212 unset($this->_formValues
[$element]);
213 $element = 'activity_' . $element;
215 $this->_formValues
[$element] = array('IN' => $value);
218 $this->_formValues
[$element] = array('LIKE' => "%$value%");
224 $this->fixFormValues();
226 if (isset($this->_ssID
) && empty($_POST)) {
227 // if we are editing / running a saved search and the form has not been posted
228 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
231 // We don't show test records in summaries or dashboards
232 if (empty($this->_formValues
['activity_test']) && $this->_force
) {
233 $this->_formValues
["activity_test"] = 0;
236 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
238 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
240 $this->set('formValues', $this->_formValues
);
241 $this->set('queryParams', $this->_queryParams
);
243 $buttonName = $this->controller
->getButtonName();
244 if ($buttonName == $this->_actionButtonName
) {
245 // check actionName and if next, then do not repeat a search, since we are going to the next page
246 // hack, make sure we reset the task values
247 $stateMachine = $this->controller
->getStateMachine();
248 $formName = $stateMachine->getTaskFormName();
249 $this->controller
->resetPage($formName);
254 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
255 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
256 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
260 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
262 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
269 $selector->setKey($this->controller
->_key
);
272 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
273 $prefix = $this->_prefix
;
276 $controller = new CRM_Core_Selector_Controller($selector,
277 $this->get(CRM_Utils_Pager
::PAGE_ID
),
279 CRM_Core_Action
::VIEW
,
281 CRM_Core_Selector_Controller
::SESSION
,
284 $controller->setEmbedded(TRUE);
285 $query = &$selector->getQuery();
287 if ($this->_context
== 'user') {
288 $query->setSkipPermission(TRUE);
293 public function fixFormValues() {
294 if (!$this->_force
) {
298 $status = CRM_Utils_Request
::retrieve('status', 'String', $this);
300 $this->_formValues
['activity_status'] = $status;
301 $this->_defaults
['activity_status'] = $status;
304 $survey = CRM_Utils_Request
::retrieve('survey', 'Positive', CRM_Core_DAO
::$_nullObject);
307 $this->_formValues
['activity_survey_id'] = $this->_defaults
['activity_survey_id'] = $survey;
308 $sid = CRM_Utils_Array
::value('activity_survey_id', $this->_formValues
);
309 $activity_type_id = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
311 // since checkbox are replaced by multiple select option
312 $this->_formValues
['activity_type_id'] = $activity_type_id;
313 $this->_defaults
['activity_type_id'] = $activity_type_id;
315 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
318 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
320 $this->_formValues
['contact_id'] = $cid;
322 $activity_role = CRM_Utils_Request
::retrieve('activity_role', 'Positive', $this);
324 if ($activity_role) {
325 $this->_formValues
['activity_role'] = $activity_role;
328 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
330 // also assign individual mode to the template
331 $this->_single
= TRUE;
335 // Added for membership search
337 $signupType = CRM_Utils_Request
::retrieve('signupType', 'Positive',
338 CRM_Core_DAO
::$_nullObject
342 //$this->_formValues['activity_type_id'] = array();
343 $this->_formValues
['activity_role'] = 1;
344 $this->_defaults
['activity_role'] = 1;
345 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, FALSE, FALSE, 'name');
347 $renew = CRM_Utils_Array
::key('Membership Renewal', $activityTypes);
348 $signup = CRM_Utils_Array
::key('Membership Signup', $activityTypes);
350 switch ($signupType) {
351 case 3: // signups and renewals
352 $this->_formValues
['activity_type_id'][$renew] = 1;
353 $this->_defaults
['activity_type_id'][$renew] = 1;
354 case 1: // signups only
355 $this->_formValues
['activity_type_id'][$signup] = 1;
356 $this->_defaults
['activity_type_id'][$signup] = 1;
359 case 2: // renewals only
360 $this->_formValues
['activity_type_id'][$renew] = 1;
361 $this->_defaults
['activity_type_id'][$renew] = 1;
366 $dateLow = CRM_Utils_Request
::retrieve('dateLow', 'String',
367 CRM_Core_DAO
::$_nullObject
371 $dateLow = date('m/d/Y', strtotime($dateLow));
372 $this->_formValues
['activity_date_relative'] = 0;
373 $this->_defaults
['activity_date_relative'] = 0;
374 $this->_formValues
['activity_date_low'] = $dateLow;
375 $this->_defaults
['activity_date_low'] = $dateLow;
378 $dateHigh = CRM_Utils_Request
::retrieve('dateHigh', 'String',
379 CRM_Core_DAO
::$_nullObject
383 // Activity date time assumes midnight at the beginning of the date
384 // This sets it to almost midnight at the end of the date
385 /* if ($dateHigh <= 99999999) {
386 $dateHigh = 1000000 * $dateHigh + 235959;
388 $dateHigh = date('m/d/Y', strtotime($dateHigh));
389 $this->_formValues
['activity_date_relative'] = 0;
390 $this->_defaults
['activity_date_relative'] = 0;
391 $this->_formValues
['activity_date_high'] = $dateHigh;
392 $this->_defaults
['activity_date_high'] = $dateHigh;
395 if (!empty($this->_defaults
)) {
396 $this->setDefaults($this->_defaults
);
403 public function getFormValues() {
408 * Return a descriptive name for the page, used in wizard header
412 public function getTitle() {
413 return ts('Find Activities');