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
50 protected $_queryParams;
53 * Are we restricting ourselves to a single contact
58 protected $_single = FALSE;
61 * Are we restricting ourselves to a single contact
66 protected $_limit = NULL;
69 * Prefix for the controller
72 protected $_prefix = "activity_";
77 * The saved search ID retrieved from the GET vars
85 * Processing needed for buildForm and later
90 function preProcess() {
91 $this->set('searchFormName', 'Search');
93 // set the button names
94 $this->_searchButtonName
= $this->getButtonName('refresh');
95 $this->_actionButtonName
= $this->getButtonName('next', 'action');
98 $this->defaults
= array();
100 // we allow the controller to set force/reset externally, useful when we are being
101 // driven by the wizard framework
102 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
103 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
104 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
105 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
107 $this->assign("context", $this->_context
);
109 // get user submitted values
110 // get it from controller only if form has been submitted, else preProcess has set this
111 if (!empty($_POST) && !$this->controller
->isModal()) {
112 $this->_formValues
= $this->controller
->exportValues($this->_name
);
115 $this->_formValues
= $this->get('formValues');
118 if (empty($this->_formValues
)) {
119 if (isset($this->_ssID
)) {
120 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
125 $this->postProcess();
126 $this->set('force', 0);
130 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
131 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
132 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
136 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
137 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
145 if ($this->_context
== 'user') {
146 $prefix = $this->_prefix
;
149 $this->assign("{$prefix}limit", $this->_limit
);
150 $this->assign("{$prefix}single", $this->_single
);
152 $controller = new CRM_Core_Selector_Controller($selector,
153 $this->get(CRM_Utils_Pager
::PAGE_ID
),
155 CRM_Core_Action
::VIEW
,
157 CRM_Core_Selector_Controller
::TRANSFER
,
160 $controller->setEmbedded(TRUE);
161 $controller->moveFromSessionToTemplate();
163 $this->assign('summary', $this->get('summary'));
167 * Build the form object
173 function buildQuickForm() {
174 parent
::buildQuickForm();
175 $this->addElement('text', 'sort_name', ts('Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
177 CRM_Activity_BAO_Query
::buildSearchForm($this);
179 $rows = $this->get('rows');
180 if (is_array($rows)) {
181 if (!$this->_single
) {
182 $this->addRowSelectors($rows);
185 $permission = CRM_Core_Permission
::getPermission();
187 $this->addTaskMenu(CRM_Activity_Task
::permissionedTaskTitles($permission));
193 * The post processing of the form gets done here.
195 * Key things done during post processing are
196 * - check for reset or next request. if present, skip post procesing.
197 * - now check if user requested running a saved search, if so, then
198 * the form values associated with the saved search are used for searching.
199 * - if user has done a submit with new values the regular post submissing is
201 * The processing consists of using a Selector / Controller framework for getting the
209 function postProcess() {
216 if (!empty($_POST)) {
217 $this->_formValues
= $this->controller
->exportValues($this->_name
);
220 $this->fixFormValues();
222 if (isset($this->_ssID
) && empty($_POST)) {
223 // if we are editing / running a saved search and the form has not been posted
224 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
227 // We don't show test records in summaries or dashboards
228 if (empty($this->_formValues
['activity_test']) && $this->_force
) {
229 $this->_formValues
["activity_test"] = 0;
232 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
234 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
236 $this->set('formValues', $this->_formValues
);
237 $this->set('queryParams', $this->_queryParams
);
239 $buttonName = $this->controller
->getButtonName();
240 if ($buttonName == $this->_actionButtonName
) {
241 // check actionName and if next, then do not repeat a search, since we are going to the next page
242 // hack, make sure we reset the task values
243 $stateMachine = $this->controller
->getStateMachine();
244 $formName = $stateMachine->getTaskFormName();
245 $this->controller
->resetPage($formName);
250 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
251 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
252 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
256 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
258 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
265 $selector->setKey($this->controller
->_key
);
268 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
269 $prefix = $this->_prefix
;
272 $controller = new CRM_Core_Selector_Controller($selector,
273 $this->get(CRM_Utils_Pager
::PAGE_ID
),
275 CRM_Core_Action
::VIEW
,
277 CRM_Core_Selector_Controller
::SESSION
,
280 $controller->setEmbedded(TRUE);
281 $query = &$selector->getQuery();
283 if ($this->_context
== 'user') {
284 $query->setSkipPermission(TRUE);
289 function fixFormValues() {
290 if (!$this->_force
) {
294 $status = CRM_Utils_Request
::retrieve('status', 'String', $this);
296 $this->_formValues
['activity_status'] = $status;
297 $this->_defaults
['activity_status'] = $status;
300 $survey = CRM_Utils_Request
::retrieve('survey', 'Positive', CRM_Core_DAO
::$_nullObject);
303 $this->_formValues
['activity_survey_id'] = $this->_defaults
['activity_survey_id'] = $survey;
304 $sid = CRM_Utils_Array
::value('activity_survey_id', $this->_formValues
);
305 $activity_type_id = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
307 $this->_formValues
['activity_type_id'][$activity_type_id] = 1;
308 $this->_defaults
['activity_type_id'][$activity_type_id] = 1;
310 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
313 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
315 $this->_formValues
['contact_id'] = $cid;
317 $activity_role = CRM_Utils_Request
::retrieve('activity_role', 'Positive', $this);
319 if ($activity_role) {
320 $this->_formValues
['activity_role'] = $activity_role;
323 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
325 // also assign individual mode to the template
326 $this->_single
= TRUE;
330 // Added for membership search
332 $signupType = CRM_Utils_Request
::retrieve('signupType', 'Positive',
333 CRM_Core_DAO
::$_nullObject
337 //$this->_formValues['activity_type_id'] = array();
338 $this->_formValues
['activity_role'] = 1;
339 $this->_defaults
['activity_role'] = 1;
340 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, FALSE, FALSE, 'name');
342 $renew = CRM_Utils_Array
::key('Membership Renewal', $activityTypes);
343 $signup = CRM_Utils_Array
::key('Membership Signup', $activityTypes);
345 switch ($signupType) {
346 case 3: // signups and renewals
347 $this->_formValues
['activity_type_id'][$renew] = 1;
348 $this->_defaults
['activity_type_id'][$renew] = 1;
349 case 1: // signups only
350 $this->_formValues
['activity_type_id'][$signup] = 1;
351 $this->_defaults
['activity_type_id'][$signup] = 1;
354 case 2: // renewals only
355 $this->_formValues
['activity_type_id'][$renew] = 1;
356 $this->_defaults
['activity_type_id'][$renew] = 1;
361 $dateLow = CRM_Utils_Request
::retrieve('dateLow', 'String',
362 CRM_Core_DAO
::$_nullObject
366 $dateLow = date('m/d/Y', strtotime($dateLow));
367 $this->_formValues
['activity_date_relative'] = 0;
368 $this->_defaults
['activity_date_relative'] = 0;
369 $this->_formValues
['activity_date_low'] = $dateLow;
370 $this->_defaults
['activity_date_low'] = $dateLow;
373 $dateHigh = CRM_Utils_Request
::retrieve('dateHigh', 'String',
374 CRM_Core_DAO
::$_nullObject
378 // Activity date time assumes midnight at the beginning of the date
379 // This sets it to almost midnight at the end of the date
380 /* if ($dateHigh <= 99999999) {
381 $dateHigh = 1000000 * $dateHigh + 235959;
383 $dateHigh = date('m/d/Y', strtotime($dateHigh));
384 $this->_formValues
['activity_date_relative'] = 0;
385 $this->_defaults
['activity_date_relative'] = 0;
386 $this->_formValues
['activity_date_high'] = $dateHigh;
387 $this->_defaults
['activity_date_high'] = $dateHigh;
390 if (!empty($this->_defaults
)) {
391 $this->setDefaults($this->_defaults
);
398 function getFormValues() {
403 * Return a descriptive name for the page, used in wizard header
408 public function getTitle() {
409 return ts('Find Activities');