3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Contact_Page_DedupeRules
extends CRM_Core_Page_Basic
{
20 * The action links that we need to display for the browse screen.
24 public static $_links = NULL;
32 public function getBAOName() {
33 return 'CRM_Dedupe_BAO_RuleGroup';
40 * (reference) of action links
42 public function &links() {
43 if (!(self
::$_links)) {
44 $deleteExtra = ts('Are you sure you want to delete this Rule?');
46 // helper variable for nicer formatting
49 if (CRM_Core_Permission
::check('merge duplicate contacts')) {
50 $links[CRM_Core_Action
::VIEW
] = [
51 'name' => ts('Use Rule'),
52 'url' => 'civicrm/contact/dedupefind',
53 'qs' => 'reset=1&rgid=%%id%%&action=preview',
54 'title' => ts('Use DedupeRule'),
57 if (CRM_Core_Permission
::check('administer dedupe rules')) {
58 $links[CRM_Core_Action
::UPDATE
] = [
59 'name' => ts('Edit Rule'),
60 'url' => 'civicrm/contact/deduperules',
61 'qs' => 'action=update&id=%%id%%',
62 'title' => ts('Edit DedupeRule'),
64 $links[CRM_Core_Action
::DELETE
] = [
65 'name' => ts('Delete'),
66 'url' => 'civicrm/contact/deduperules',
67 'qs' => 'action=delete&id=%%id%%',
68 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
69 'title' => ts('Delete DedupeRule'),
73 self
::$_links = $links;
81 * This method is called after the page is created. It checks for the type
82 * of action and executes that action. Finally it calls the parent's run
85 public function run() {
86 $id = $this->getIdAndAction();
88 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this, FALSE);
89 if ($context == 'nonDupe') {
90 CRM_Core_Session
::setStatus(ts('Selected contacts have been marked as not duplicates'), ts('Changes Saved'), 'success');
93 // assign permissions vars to template
94 $this->assign('hasperm_administer_dedupe_rules', CRM_Core_Permission
::check('administer dedupe rules'));
95 $this->assign('hasperm_merge_duplicate_contacts', CRM_Core_Permission
::check('merge duplicate contacts'));
97 // which action to take?
98 if ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
99 $this->edit($this->_action
, $id);
101 if ($this->_action
& CRM_Core_Action
::DELETE
) {
108 // This replaces parent run, but do parent's parent run
109 return CRM_Core_Page
::run();
113 * Browse all rule groups.
115 public function browse() {
116 // get all rule groups
118 $dao = new CRM_Dedupe_DAO_RuleGroup();
119 $dao->orderBy('contact_type ASC, used ASC, title ASC');
122 $dedupeRuleTypes = CRM_Core_SelectValues
::getDedupeRuleTypes();
123 while ($dao->fetch()) {
124 $ruleGroups[$dao->contact_type
][$dao->id
] = [];
125 CRM_Core_DAO
::storeValues($dao, $ruleGroups[$dao->contact_type
][$dao->id
]);
127 // form all action links
128 $action = array_sum(array_keys($this->links()));
129 $links = self
::links();
130 /* if ($dao->is_default) {
131 unset($links[CRM_Core_Action::MAP]);
132 unset($links[CRM_Core_Action::DELETE]);
135 if ($dao->is_reserved
) {
136 unset($links[CRM_Core_Action
::DELETE
]);
139 $ruleGroups[$dao->contact_type
][$dao->id
]['action'] = CRM_Core_Action
::formLink(
145 'dedupeRule.manage.action',
150 $ruleGroups[$dao->contact_type
][$dao->id
]['used_display'] = $dedupeRuleTypes[$ruleGroups[$dao->contact_type
][$dao->id
]['used']];
152 $this->assign('brows', $ruleGroups);
156 * Get name of edit form.
159 * classname of edit form
161 public function editForm() {
162 return 'CRM_Contact_Form_DedupeRules';
166 * Get edit form name.
171 public function editName() {
172 return 'DedupeRules';
183 public function userContext($mode = NULL) {
184 return 'civicrm/contact/deduperules';
190 public function delete($id) {
191 $ruleDao = new CRM_Dedupe_DAO_Rule();
192 $ruleDao->dedupe_rule_group_id
= $id;
195 $rgDao = new CRM_Dedupe_DAO_RuleGroup();
197 if ($rgDao->find(TRUE)) {
199 CRM_Core_Session
::setStatus(ts("The rule '%1' has been deleted.", [1 => $rgDao->title
]), ts('Rule Deleted'), 'success');
200 CRM_Utils_System
::redirect(CRM_Utils_System
::url($this->userContext(), 'reset=1'));