_id = NULL; } /** * Build the form - it consists of * - displaying the QILL (query in local language) * - displaying elements for saving the search * * @access public * * @return void */ function buildQuickForm() { CRM_Utils_System::setTitle(ts('Smart Group')); // get the qill $query = new CRM_Event_BAO_Query($this->get('formValues')); $qill = $query->qill(); // need to save qill for the smarty template $this->assign('qill', $qill); // the name and description are actually stored with the group and not the saved search $this->add('text', 'title', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE ); $this->addElement('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description') ); // get the group id for the saved search $groupId = NULL; if (isset($this->_id)) { $params = array('saved_search_id' => $this->_id); CRM_Contact_BAO_Group::retrieve($params, $values); $groupId = $values['id']; $this->addDefaultButtons(ts('Update Smart Group')); } else { $this->addDefaultButtons(ts('Save Smart Group')); } $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Group', $groupId, 'title') ); } /** * process the form after the input has been submitted and validated * * @access public * * @return void */ public function postProcess() { // saved search form values $formValues = $this->controller->exportValues(); $session = CRM_Core_Session::singleton(); //save the search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->form_values = serialize($this->get('formValues')); $savedSearch->mapping_id = $mappingId; $savedSearch->save(); $this->set('ssID', $savedSearch->id); CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Saved'), 'success'); // also create a group that is associated with this saved search only if new saved search $params = array(); $params['title'] = $formValues['title']; $params['description'] = $formValues['description']; $params['visibility'] = 'User and User Admin Only'; $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } $group = CRM_Contact_BAO_Group::create($params); } }