Merge pull request #15875 from civicrm/5.20
[civicrm-core.git] / CRM / Profile / Form / Search.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class generates form components generic to all the contact types.
20 *
21 * It delegates the work to lower level subclasses and integrates the changes
22 * back in. It also uses a lot of functionality with the CRM API's, so any change
23 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
24 */
25 class CRM_Profile_Form_Search extends CRM_Profile_Form {
26
27 /**
28 * Pre processing work done here.
29 */
30 public function preProcess() {
31 $this->_mode = CRM_Profile_Form::MODE_SEARCH;
32 parent::preProcess();
33 }
34
35 /**
36 * Set the default form values.
37 *
38 * @return array
39 * the default array reference
40 */
41 public function setDefaultValues() {
42 $defaults = [];
43 // note we intentionally overwrite value since we use it as defaults
44 // and its all pass by value
45 // we need to figure out the type, so we can either set an array element
46 // or a scalar -- FIX ME sometime please
47 foreach ($_GET as $key => $value) {
48 if (substr($key, 0, 7) == 'custom_' || $key == "preferred_communication_method") {
49 if (strpos($value, CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
50 $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
51 $value = [];
52 foreach ($v as $item) {
53 if ($item) {
54 $value[$item] = $item;
55 }
56 }
57 }
58 }
59 elseif ($key == 'group' || $key == 'tag') {
60 $v = explode(',', $value);
61 $value = [];
62 foreach ($v as $item) {
63 $value[$item] = 1;
64 }
65 }
66 elseif (in_array($key, [
67 'birth_date',
68 'deceased_date',
69 ])) {
70 list($value) = CRM_Utils_Date::setDateDefaults($value);
71 }
72
73 $defaults[$key] = $value;
74 }
75 return $defaults;
76 }
77
78 /**
79 * Build the form object.
80 */
81 public function buildQuickForm() {
82 // Is proximity search enabled for this profile?
83 $proxSearch = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup',
84 $this->get('gid'),
85 'is_proximity_search', 'id'
86 );
87 if ($proxSearch) {
88 CRM_Contact_Form_Task_ProximityCommon::buildQuickForm($this, $proxSearch);
89 }
90
91 $this->addButtons([
92 [
93 'type' => 'refresh',
94 'name' => ts('Search'),
95 'isDefault' => TRUE,
96 ],
97 ]);
98
99 parent::buildQuickForm();
100 }
101
102 /**
103 * Post process function.
104 */
105 public function postProcess() {
106 }
107
108 }