Merge pull request #16008 from civicrm/5.20
[civicrm-core.git] / CRM / Group / 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 * $Id$
17 *
18 */
19 class CRM_Group_Form_Search extends CRM_Core_Form {
20
21 public function preProcess() {
22 parent::preProcess();
23
24 CRM_Core_Resources::singleton()->addPermissions('edit groups');
25 }
26
27 /**
28 * @return array
29 */
30 public function setDefaultValues() {
31 $defaults = [];
32 $defaults['group_status[1]'] = 1;
33 return $defaults;
34 }
35
36 public function buildQuickForm() {
37 $this->add('text', 'title', ts('Find'),
38 CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title')
39 );
40
41 $this->add('text', 'created_by', ts('Created By'),
42 CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title')
43 );
44
45 $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE);
46 $config = CRM_Core_Config::singleton();
47 if ($config->userFramework == 'Joomla') {
48 unset($groupTypes['Access Control']);
49 }
50
51 $this->addCheckBox('group_type_search',
52 ts('Type'),
53 $groupTypes,
54 NULL, NULL, NULL, NULL, '&nbsp;&nbsp;&nbsp;'
55 );
56
57 $this->add('select', 'visibility', ts('Visibility'),
58 ['' => ts('- any visibility -')] + CRM_Core_SelectValues::ufVisibility(TRUE)
59 );
60
61 $groupStatuses = [ts('Enabled') => 1, ts('Disabled') => 2];
62 $this->addCheckBox('group_status',
63 ts('Status'),
64 $groupStatuses,
65 NULL, NULL, NULL, NULL, '&nbsp;&nbsp;&nbsp;'
66 );
67
68 $componentModes = CRM_Contact_Form_Search::getModeSelect();
69 if (count($componentModes) > 1) {
70 $this->add('select',
71 'component_mode',
72 ts('View Results As'),
73 $componentModes,
74 FALSE,
75 ['class' => 'crm-select2']
76 );
77 }
78
79 $this->addButtons([
80 [
81 'type' => 'refresh',
82 'name' => ts('Search'),
83 'isDefault' => TRUE,
84 ],
85 ]);
86
87 parent::buildQuickForm();
88 $this->assign('suppressForm', TRUE);
89 }
90
91 public function postProcess() {
92 $params = $this->controller->exportValues($this->_name);
93 $parent = $this->controller->getParent();
94 if (!empty($params)) {
95 $fields = ['title', 'created_by', 'group_type', 'visibility', 'active_status', 'inactive_status', 'component_mode'];
96 foreach ($fields as $field) {
97 if (isset($params[$field]) &&
98 !CRM_Utils_System::isNull($params[$field])
99 ) {
100 $parent->set($field, $params[$field]);
101 }
102 else {
103 $parent->set($field, NULL);
104 }
105 }
106 }
107 }
108
109 }