3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
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 public function preProcess() {
61 * Build the form object - it consists of
62 * - displaying the QILL (query in local language)
63 * - displaying elements for saving the search
68 public function buildQuickForm() {
69 CRM_Utils_System
::setTitle(ts('Smart Group'));
71 $query = new CRM_Event_BAO_Query($this->get('formValues'));
72 $qill = $query->qill();
74 // Values from the search form
75 $formValues = $this->controller
->exportValues();
77 // need to save qill for the smarty template
78 $this->assign('qill', $qill);
80 // the name and description are actually stored with the group and not the saved search
81 $this->add('text', 'title', ts('Name'),
82 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE
85 $this->addElement('text', 'description', ts('Description'),
86 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Group', 'description')
89 // get the group id for the saved search
91 if (isset($this->_id
)) {
92 $params = array('saved_search_id' => $this->_id
);
93 CRM_Contact_BAO_Group
::retrieve($params, $values);
94 $groupId = $values['id'];
96 $this->addDefaultButtons(ts('Update Smart Group'));
99 $this->addDefaultButtons(ts('Save Smart Group'));
100 $this->assign('partiallySelected', $formValues['radio_ts'] != 'ts_all');
103 $this->addRule('title', ts('Name already exists in Database.'),
104 'objectExists', array('CRM_Contact_DAO_Group', $groupId, 'title')
109 * Process the form after the input has been submitted and validated.
114 public function postProcess() {
115 // saved search form values
116 $formValues = $this->controller
->exportValues();
118 $session = CRM_Core_Session
::singleton();
121 $savedSearch = new CRM_Contact_BAO_SavedSearch();
122 $savedSearch->id
= $this->_id
;
123 $savedSearch->form_values
= serialize($this->get('formValues'));
124 $savedSearch->save();
125 $this->set('ssID', $savedSearch->id
);
126 CRM_Core_Session
::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Saved'), 'success');
128 // also create a group that is associated with this saved search only if new saved search
130 $params['title'] = $formValues['title'];
131 $params['description'] = $formValues['description'];
132 $params['visibility'] = 'User and User Admin Only';
133 $params['saved_search_id'] = $savedSearch->id
;
134 $params['is_active'] = 1;
137 $params['id'] = CRM_Contact_BAO_SavedSearch
::getName($this->_id
, 'id');
139 $group = CRM_Contact_BAO_Group
::create($params);