Merge pull request #15933 from civicrm/5.20
[civicrm-core.git] / CRM / Group / Form / Search.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 * $Id$
17 *
18 */
19class CRM_Group_Form_Search extends CRM_Core_Form {
20
21 public function preProcess() {
22 parent::preProcess();
9c854386
CW
23
24 CRM_Core_Resources::singleton()->addPermissions('edit groups');
6a488035
TO
25 }
26
e0ef6999
EM
27 /**
28 * @return array
29 */
00be9182 30 public function setDefaultValues() {
be2fb01f 31 $defaults = [];
6a488035
TO
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
7042abca 51 $this->addCheckBox('group_type_search',
6a488035
TO
52 ts('Type'),
53 $groupTypes,
54 NULL, NULL, NULL, NULL, '&nbsp;&nbsp;&nbsp;'
55 );
56
57 $this->add('select', 'visibility', ts('Visibility'),
be2fb01f 58 ['' => ts('- any visibility -')] + CRM_Core_SelectValues::ufVisibility(TRUE)
6a488035
TO
59 );
60
be2fb01f 61 $groupStatuses = [ts('Enabled') => 1, ts('Disabled') => 2];
6a488035
TO
62 $this->addCheckBox('group_status',
63 ts('Status'),
64 $groupStatuses,
65 NULL, NULL, NULL, NULL, '&nbsp;&nbsp;&nbsp;'
66 );
67
fecb40f5
MW
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,
be2fb01f 75 ['class' => 'crm-select2']
fecb40f5
MW
76 );
77 }
78
be2fb01f
CW
79 $this->addButtons([
80 [
353ffa53
TO
81 'type' => 'refresh',
82 'name' => ts('Search'),
83 'isDefault' => TRUE,
be2fb01f
CW
84 ],
85 ]);
6a488035
TO
86
87 parent::buildQuickForm();
88 $this->assign('suppressForm', TRUE);
89 }
90
00be9182 91 public function postProcess() {
6a488035
TO
92 $params = $this->controller->exportValues($this->_name);
93 $parent = $this->controller->getParent();
94 if (!empty($params)) {
be2fb01f 95 $fields = ['title', 'created_by', 'group_type', 'visibility', 'active_status', 'inactive_status', 'component_mode'];
6a488035
TO
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 }
96025800 108
6a488035 109}