[REF] Minor simplification on input
[civicrm-core.git] / CRM / Contact / Form / DedupeFind.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 for DedupeRules.
20 */
21 class CRM_Contact_Form_DedupeFind extends CRM_Admin_Form {
22
23 /**
24 * Indicate if this form should warn users of unsaved changes
25 * @var bool
26 */
27 protected $unsavedChangesWarn = FALSE;
28
29 /**
30 * Pre processing.
31 */
32 public function preProcess() {
33 $this->rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE, 0);
34 }
35
36 /**
37 * Build the form object.
38 */
39 public function buildQuickForm() {
40
41 $groupList = ['' => ts('- All Contacts -')] + CRM_Core_PseudoConstant::nestedGroup();
42
43 $this->add('select', 'group_id', ts('Select Group'), $groupList, FALSE, ['class' => 'crm-select2 huge']);
44 $this->add('text', 'limit', ts('No of contacts to find matches for '));
45
46 // To improve usability for smaller sites, we don't show the limit field unless a default limit has been set.
47 $this->assign('limitShown', (bool) Civi::settings()->get('dedupe_default_limit'));
48
49 $this->addButtons([
50 [
51 'type' => 'next',
52 'name' => ts('Continue'),
53 'isDefault' => TRUE,
54 ],
55 //hack to support cancel button functionality
56 [
57 'type' => 'submit',
58 'class' => 'cancel',
59 'icon' => 'fa-times',
60 'name' => ts('Cancel'),
61 ],
62 ]);
63 }
64
65 /**
66 * Set the default values for the form.
67 *
68 * @return array
69 */
70 public function setDefaultValues() {
71 $this->_defaults['limit'] = Civi::settings()->get('dedupe_default_limit');
72 return $this->_defaults;
73 }
74
75 /**
76 * Process the form submission.
77 */
78 public function postProcess() {
79 $values = $this->exportValues();
80 if (!empty($_POST['_qf_DedupeFind_submit'])) {
81 //used for cancel button
82 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/deduperules', 'reset=1'));
83 return;
84 }
85 $url = CRM_Utils_System::url('civicrm/contact/dedupefind', "reset=1&action=update&rgid={$this->rgid}");
86 if ($values['group_id']) {
87 $url .= "&gid={$values['group_id']}";
88 }
89
90 if (!empty($values['limit'])) {
91 $url .= '&limit=' . $values['limit'];
92 }
93
94 CRM_Utils_System::redirect($url);
95 }
96
97 }