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 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
41 * Base Search / View form for *all* listing of multiple
44 class CRM_Contact_Form_Search_Basic
extends CRM_Contact_Form_Search
{
47 * csv - common search values
52 static $csv = array('contact_type', 'group', 'tag');
55 * Build the form object
60 public function buildQuickForm() {
61 // text for sort_name or email criteria
62 $config = CRM_Core_Config
::singleton();
63 $label = empty($config->includeEmailInName
) ?
ts('Name') : ts('Name or Email');
64 $this->add('text', 'sort_name', $label);
66 $searchOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
67 'advanced_search_options'
71 //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
72 // this is loaded onto then replace with something like '__' & test
73 $separator = CRM_Core_DAO
::VALUE_SEPARATOR
;
74 if (!empty($searchOptions['contactType'])) {
75 $contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType
::getSelectElements(FALSE, TRUE, $separator);
76 $this->add('select', 'contact_type',
80 array('class' => 'crm-select2')
84 // add select for groups
85 if (!empty($searchOptions['groups'])) {
86 $this->addSelect('group', array('entity' => 'group_contact', 'label' => ts('in'), 'context' => 'search', 'placeholder' => ts('- any group -')));
89 if (!empty($searchOptions['tags'])) {
91 if (!empty($this->_tag
)) {
92 $this->addSelect('tag', array('entity' => 'entity_tag', 'label' => ts('with'), 'context' => 'search', 'placeholder' => ts('- any tag -')));
96 parent
::buildQuickForm();
100 * Set the default form values
103 * @return array the default array reference
105 public function setDefaultValues() {
108 $defaults['sort_name'] = CRM_Utils_Array
::value('sort_name', $this->_formValues
);
109 foreach (self
::$csv as $v) {
110 if (!empty($this->_formValues
[$v]) && is_array($this->_formValues
[$v])) {
111 $tmpArray = array_keys($this->_formValues
[$v]);
112 $defaults[$v] = array_pop($tmpArray);
119 if ($this->_context
=== 'amtg') {
120 $defaults['task'] = CRM_Contact_Task
::GROUP_CONTACTS
;
123 if ($this->_context
=== 'smog') {
124 $defaults['group_contact_status[Added]'] = TRUE;
131 * Add local and global form rules
136 public function addRules() {
137 $this->addFormRule(array('CRM_Contact_Form_Search_Basic', 'formRule'));
141 * Processing needed for buildForm and later
145 public function preProcess() {
146 $this->set('searchFormName', 'Basic');
148 parent
::preProcess();
154 public function &getFormValues() {
155 return $this->_formValues
;
159 * This method is called for processing a submitted search form
163 public function postProcess() {
164 $this->set('isAdvanced', '0');
165 $this->set('isSearchBuilder', '0');
167 // get user submitted values
168 // get it from controller only if form has been submitted, else preProcess has set this
169 if (!empty($_POST)) {
170 $this->_formValues
= $this->controller
->exportValues($this->_name
);
171 $this->normalizeFormValues();
174 if (isset($this->_groupID
) && empty($this->_formValues
['group'])) {
175 $this->_formValues
['group'][$this->_groupID
] = 1;
177 elseif (isset($this->_ssID
) && empty($_POST)) {
178 // if we are editing / running a saved search and the form has not been posted
179 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
182 if (CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID
, 'mapping_id')) {
183 $this->_params
= CRM_Contact_BAO_SavedSearch
::getSearchParams($this->_ssID
);
187 // we dont want to store the sortByCharacter in the formValue, it is more like
188 // a filter on the result set
189 // this filter is reset if we click on the search button
190 if ($this->_sortByCharacter
!== NULL && empty($_POST)) {
191 if (strtolower($this->_sortByCharacter
) == 'all') {
192 $this->_formValues
['sortByCharacter'] = NULL;
195 $this->_formValues
['sortByCharacter'] = $this->_sortByCharacter
;
199 $this->_sortByCharacter
= NULL;
202 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
203 $this->_returnProperties
= &$this->returnProperties();
205 parent
::postProcess();
209 * Normalize the form values to make it look similar to the advanced form values
210 * this prevents a ton of work downstream and allows us to use the same code for
211 * multiple purposes (queries, save/edit etc)
215 public function normalizeFormValues() {
216 $contactType = CRM_Utils_Array
::value('contact_type', $this->_formValues
);
217 if ($contactType && !is_array($contactType)) {
218 unset($this->_formValues
['contact_type']);
219 $this->_formValues
['contact_type'][$contactType] = 1;
222 $config = CRM_Core_Config
::singleton();
224 $group = CRM_Utils_Array
::value('group', $this->_formValues
);
225 if ($group && !is_array($group)) {
226 unset($this->_formValues
['group']);
227 $this->_formValues
['group'][$group] = 1;
230 $tag = CRM_Utils_Array
::value('tag', $this->_formValues
);
231 if ($tag && !is_array($tag)) {
232 unset($this->_formValues
['tag']);
233 $this->_formValues
['tag'][$tag] = 1;
240 * Add a form rule for this form. If Go is pressed then we must select some checkboxes
243 public static function formRule($fields) {
244 // check actionName and if next, then do not repeat a search, since we are going to the next page
245 if (array_key_exists('_qf_Search_next', $fields)) {
246 if (empty($fields['task'])) {
247 return array('task' => 'Please select a valid action.');
250 if (CRM_Utils_Array
::value('task', $fields) == CRM_Contact_Task
::SAVE_SEARCH
) {
251 // dont need to check for selection of contacts for saving search
255 // if the all contact option is selected, ignore the contact checkbox validation
256 if ($fields['radio_ts'] == 'ts_all') {
260 foreach ($fields as $name => $dontCare) {
261 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
265 return array('task' => 'Please select one or more checkboxes to perform the action on.');
271 * Return a descriptive name for the page, used in wizard header
278 public function getTitle() {
279 return ts('Find Contacts');