3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
35 * Base Search / View form for *all* listing of multiple contacts.
37 class CRM_Contact_Form_Search_Basic
extends CRM_Contact_Form_Search
{
40 * csv - common search values
44 public static $csv = ['contact_type', 'group', 'tag'];
47 * Build the form object.
49 public function buildQuickForm() {
50 $this->addSortNameField();
52 $searchOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
53 'advanced_search_options'
56 if (!empty($searchOptions['contactType'])) {
57 $contactTypes = ['' => ts('- any contact type -')] + CRM_Contact_BAO_ContactType
::getSelectElements();
58 $this->add('select', 'contact_type',
62 ['class' => 'crm-select2']
66 // add select for groups
67 // Get hierarchical listing of groups, respecting ACLs for CRM-16836.
68 $groupHierarchy = CRM_Contact_BAO_Group
::getGroupsHierarchy($this->_group
, NULL, ' ', TRUE);
69 if (!empty($searchOptions['groups'])) {
70 $this->addField('group', [
71 'entity' => 'group_contact',
73 'placeholder' => ts('- any group -'),
74 'options' => $groupHierarchy,
78 if (!empty($searchOptions['tags'])) {
80 if (!empty($this->_tag
)) {
81 $this->addField('tag', [
82 'entity' => 'entity_tag',
83 'label' => ts('with'),
84 'placeholder' => ts('- any tag -'),
89 parent
::buildQuickForm();
93 * Set the default form values.
97 * the default array reference
99 public function setDefaultValues() {
102 $defaults['sort_name'] = CRM_Utils_Array
::value('sort_name', $this->_formValues
);
103 foreach (self
::$csv as $v) {
104 if (!empty($this->_formValues
[$v]) && is_array($this->_formValues
[$v])) {
105 $tmpArray = array_keys($this->_formValues
[$v]);
106 $defaults[$v] = array_pop($tmpArray);
113 if ($this->_context
=== 'amtg') {
114 $defaults['task'] = CRM_Contact_Task
::GROUP_ADD
;
117 if ($this->_context
=== 'smog') {
118 $defaults['group_contact_status[Added]'] = TRUE;
125 * Add local and global form rules.
127 public function addRules() {
128 $this->addFormRule(['CRM_Contact_Form_Search_Basic', 'formRule']);
132 * Processing needed for buildForm and later.
134 public function preProcess() {
135 $this->set('searchFormName', 'Basic');
137 parent
::preProcess();
143 public function &getFormValues() {
144 return $this->_formValues
;
148 * This method is called for processing a submitted search form.
150 public function postProcess() {
151 $this->set('isAdvanced', '0');
152 $this->set('isSearchBuilder', '0');
154 // get user submitted values
155 // get it from controller only if form has been submitted, else preProcess has set this
156 if (!empty($_POST)) {
157 $this->_formValues
= $this->controller
->exportValues($this->_name
);
160 if (isset($this->_groupID
) && empty($this->_formValues
['group'])) {
161 $this->_formValues
['group'] = $this->_groupID
;
163 elseif (isset($this->_ssID
) && empty($_POST)) {
164 // if we are editing / running a saved search and the form has not been posted
165 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
168 if (CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID
, 'mapping_id')) {
169 $this->_params
= CRM_Contact_BAO_SavedSearch
::getSearchParams($this->_ssID
);
173 // we dont want to store the sortByCharacter in the formValue, it is more like
174 // a filter on the result set
175 // this filter is reset if we click on the search button
176 if ($this->_sortByCharacter
!== NULL && empty($_POST)) {
177 if (strtolower($this->_sortByCharacter
) == 'all') {
178 $this->_formValues
['sortByCharacter'] = NULL;
181 $this->_formValues
['sortByCharacter'] = $this->_sortByCharacter
;
185 $this->_sortByCharacter
= NULL;
188 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
189 $this->_returnProperties
= &$this->returnProperties();
191 parent
::postProcess();
195 * Add a form rule for this form.
197 * If Go is pressed then we must select some checkboxes and an action.
199 * @param array $fields
200 * @param array $files
201 * @param object $form
205 public static function formRule($fields, $files, $form) {
206 // check actionName and if next, then do not repeat a search, since we are going to the next page
207 if (array_key_exists('_qf_Search_next', $fields)) {
208 if (empty($fields['task'])) {
209 return ['task' => 'Please select a valid action.'];
212 if (CRM_Utils_Array
::value('task', $fields) == CRM_Contact_Task
::SAVE_SEARCH
) {
213 // dont need to check for selection of contacts for saving search
217 // if the all contact option is selected, ignore the contact checkbox validation
218 if ($fields['radio_ts'] == 'ts_all') {
222 foreach ($fields as $name => $dontCare) {
223 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
227 return ['task' => 'Please select one or more checkboxes to perform the action on.'];
233 * Return a descriptive name for the page, used in wizard header
241 public function getTitle() {
242 return ts('Find Contacts');