3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 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-2014
37 * This class provides the functionality to save a search
38 * Saved Searches are used for saving frequently used queries
39 * regarding the event participations
41 class CRM_Event_Form_Task_SaveSearch
extends CRM_Event_Form_Task
{
44 * saved search id if any
51 * build all the data structures needed to build the form
55 */ function preProcess() {
61 * Build the form - it consists of
62 * - displaying the QILL (query in local language)
63 * - displaying elements for saving the search
69 function buildQuickForm() {
70 CRM_Utils_System
::setTitle(ts('Smart Group'));
72 $query = new CRM_Event_BAO_Query($this->get('formValues'));
73 $qill = $query->qill();
75 // need to save qill for the smarty template
76 $this->assign('qill', $qill);
78 // the name and description are actually stored with the group and not the saved search
79 $this->add('text', 'title', ts('Name'),
80 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE
83 $this->addElement('text', 'description', ts('Description'),
84 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Group', 'description')
87 // get the group id for the saved search
89 if (isset($this->_id
)) {
90 $params = array('saved_search_id' => $this->_id
);
91 CRM_Contact_BAO_Group
::retrieve($params, $values);
92 $groupId = $values['id'];
94 $this->addDefaultButtons(ts('Update Smart Group'));
97 $this->addDefaultButtons(ts('Save Smart Group'));
100 $this->addRule('title', ts('Name already exists in Database.'),
101 'objectExists', array('CRM_Contact_DAO_Group', $groupId, 'title')
106 * process the form after the input has been submitted and validated
112 public function postProcess() {
113 // saved search form values
114 $formValues = $this->controller
->exportValues();
116 $session = CRM_Core_Session
::singleton();
119 $savedSearch = new CRM_Contact_BAO_SavedSearch();
120 $savedSearch->id
= $this->_id
;
121 $savedSearch->form_values
= serialize($this->get('formValues'));
122 $savedSearch->mapping_id
= $mappingId;
123 $savedSearch->save();
124 $this->set('ssID', $savedSearch->id
);
125 CRM_Core_Session
::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Saved'), 'success');
127 // also create a group that is associated with this saved search only if new saved search
129 $params['title'] = $formValues['title'];
130 $params['description'] = $formValues['description'];
131 $params['visibility'] = 'User and User Admin Only';
132 $params['saved_search_id'] = $savedSearch->id
;
133 $params['is_active'] = 1;
136 $params['id'] = CRM_Contact_BAO_SavedSearch
::getName($this->_id
, 'id');
138 $group = CRM_Contact_BAO_Group
::create($params);