Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | class CRM_Contact_Page_DedupeRules extends CRM_Core_Page_Basic { | |
34 | ||
35 | /** | |
fe482240 | 36 | * The action links that we need to display for the browse screen. |
6a488035 TO |
37 | * |
38 | * @var array | |
6a488035 TO |
39 | */ |
40 | static $_links = NULL; | |
41 | ||
42 | /** | |
fe482240 | 43 | * Get BAO Name. |
6a488035 | 44 | * |
a6c01b45 CW |
45 | * @return string |
46 | * Classname of BAO. | |
6a488035 | 47 | */ |
00be9182 | 48 | public function getBAOName() { |
6a488035 TO |
49 | return 'CRM_Dedupe_BAO_RuleGroup'; |
50 | } | |
51 | ||
52 | /** | |
fe482240 | 53 | * Get action Links. |
6a488035 | 54 | * |
a6c01b45 CW |
55 | * @return array |
56 | * (reference) of action links | |
6a488035 | 57 | */ |
00be9182 | 58 | public function &links() { |
6a488035 TO |
59 | if (!(self::$_links)) { |
60 | $deleteExtra = ts('Are you sure you want to delete this Rule?'); | |
61 | ||
62 | // helper variable for nicer formatting | |
63 | $links = array(); | |
64 | ||
65 | if (CRM_Core_Permission::check('merge duplicate contacts')) { | |
66 | $links[CRM_Core_Action::VIEW] = array( | |
67 | 'name' => ts('Use Rule'), | |
68 | 'url' => 'civicrm/contact/dedupefind', | |
69 | 'qs' => 'reset=1&rgid=%%id%%&action=preview', | |
70 | 'title' => ts('Use DedupeRule'), | |
71 | ); | |
72 | } | |
73 | if (CRM_Core_Permission::check('administer dedupe rules')) { | |
74 | $links[CRM_Core_Action::UPDATE] = array( | |
75 | 'name' => ts('Edit Rule'), | |
76 | 'url' => 'civicrm/contact/deduperules', | |
77 | 'qs' => 'action=update&id=%%id%%', | |
78 | 'title' => ts('Edit DedupeRule'), | |
79 | ); | |
80 | $links[CRM_Core_Action::DELETE] = array( | |
81 | 'name' => ts('Delete'), | |
82 | 'url' => 'civicrm/contact/deduperules', | |
83 | 'qs' => 'action=delete&id=%%id%%', | |
84 | 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"', | |
85 | 'title' => ts('Delete DedupeRule'), | |
86 | ); | |
87 | } | |
88 | ||
89 | self::$_links = $links; | |
90 | } | |
91 | return self::$_links; | |
92 | } | |
93 | ||
94 | /** | |
fe482240 | 95 | * Run the page. |
6a488035 TO |
96 | * |
97 | * This method is called after the page is created. It checks for the type | |
98 | * of action and executes that action. Finally it calls the parent's run | |
99 | * method. | |
6a488035 | 100 | */ |
00be9182 | 101 | public function run() { |
5d6d0104 | 102 | $id = $this->getIdAndAction(); |
6a488035 | 103 | |
edc80cda | 104 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE); |
6a488035 TO |
105 | if ($context == 'nonDupe') { |
106 | CRM_Core_Session::setStatus(ts('Selected contacts have been marked as not duplicates'), ts('Changes Saved'), 'success'); | |
107 | } | |
108 | ||
109 | // assign permissions vars to template | |
110 | $this->assign('hasperm_administer_dedupe_rules', CRM_Core_Permission::check('administer dedupe rules')); | |
111 | $this->assign('hasperm_merge_duplicate_contacts', CRM_Core_Permission::check('merge duplicate contacts')); | |
112 | ||
113 | // which action to take? | |
5d6d0104 AH |
114 | if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { |
115 | $this->edit($this->_action, $id); | |
6a488035 | 116 | } |
5d6d0104 | 117 | if ($this->_action & CRM_Core_Action::DELETE) { |
6a488035 TO |
118 | $this->delete($id); |
119 | } | |
120 | ||
121 | // browse the rules | |
122 | $this->browse(); | |
123 | ||
5d6d0104 AH |
124 | // This replaces parent run, but do parent's parent run |
125 | return CRM_Core_Page::run(); | |
6a488035 TO |
126 | } |
127 | ||
128 | /** | |
fe482240 | 129 | * Browse all rule groups. |
6a488035 | 130 | */ |
00be9182 | 131 | public function browse() { |
6a488035 TO |
132 | // get all rule groups |
133 | $ruleGroups = array(); | |
134 | $dao = new CRM_Dedupe_DAO_RuleGroup(); | |
52e87955 | 135 | $dao->orderBy('contact_type ASC, used ASC, title ASC'); |
6a488035 TO |
136 | $dao->find(); |
137 | ||
77d0b1f8 | 138 | $dedupeRuleTypes = CRM_Core_SelectValues::getDedupeRuleTypes(); |
6a488035 TO |
139 | while ($dao->fetch()) { |
140 | $ruleGroups[$dao->contact_type][$dao->id] = array(); | |
141 | CRM_Core_DAO::storeValues($dao, $ruleGroups[$dao->contact_type][$dao->id]); | |
142 | ||
143 | // form all action links | |
144 | $action = array_sum(array_keys($this->links())); | |
145 | $links = self::links(); | |
146 | /* if ($dao->is_default) { | |
e70a7fc0 TO |
147 | unset($links[CRM_Core_Action::MAP]); |
148 | unset($links[CRM_Core_Action::DELETE]); | |
149 | }*/ | |
6a488035 TO |
150 | |
151 | if ($dao->is_reserved) { | |
152 | unset($links[CRM_Core_Action::DELETE]); | |
153 | } | |
154 | ||
87dab4a4 AH |
155 | $ruleGroups[$dao->contact_type][$dao->id]['action'] = CRM_Core_Action::formLink( |
156 | $links, | |
157 | $action, | |
158 | array('id' => $dao->id), | |
159 | ts('more'), | |
160 | FALSE, | |
161 | 'dedupeRule.manage.action', | |
162 | 'DedupeRule', | |
163 | $dao->id | |
164 | ); | |
6a488035 | 165 | |
77d0b1f8 | 166 | $ruleGroups[$dao->contact_type][$dao->id]['used_display'] = $dedupeRuleTypes[$ruleGroups[$dao->contact_type][$dao->id]['used']]; |
167 | } | |
6a488035 TO |
168 | $this->assign('brows', $ruleGroups); |
169 | } | |
170 | ||
171 | /** | |
fe482240 | 172 | * Get name of edit form. |
6a488035 | 173 | * |
a6c01b45 CW |
174 | * @return string |
175 | * classname of edit form | |
6a488035 | 176 | */ |
00be9182 | 177 | public function editForm() { |
6a488035 TO |
178 | return 'CRM_Contact_Form_DedupeRules'; |
179 | } | |
180 | ||
181 | /** | |
fe482240 | 182 | * Get edit form name. |
6a488035 | 183 | * |
a6c01b45 CW |
184 | * @return string |
185 | * name of this page | |
6a488035 | 186 | */ |
00be9182 | 187 | public function editName() { |
6a488035 TO |
188 | return 'DedupeRules'; |
189 | } | |
190 | ||
191 | /** | |
fe482240 | 192 | * Get user context. |
6a488035 | 193 | * |
da6b46f4 EM |
194 | * @param null $mode |
195 | * | |
a6c01b45 CW |
196 | * @return string |
197 | * user context | |
6a488035 | 198 | */ |
00be9182 | 199 | public function userContext($mode = NULL) { |
6a488035 TO |
200 | return 'civicrm/contact/deduperules'; |
201 | } | |
202 | ||
4319322b | 203 | /** |
100fef9d | 204 | * @param int $id |
4319322b | 205 | */ |
00be9182 | 206 | public function delete($id) { |
6a488035 TO |
207 | $ruleDao = new CRM_Dedupe_DAO_Rule(); |
208 | $ruleDao->dedupe_rule_group_id = $id; | |
209 | $ruleDao->delete(); | |
210 | ||
211 | $rgDao = new CRM_Dedupe_DAO_RuleGroup(); | |
212 | $rgDao->id = $id; | |
cbd404b9 | 213 | if ($rgDao->find(TRUE)) { |
214 | $rgDao->delete(); | |
215 | CRM_Core_Session::setStatus(ts("The rule '%1' has been deleted.", array(1 => $rgDao->title)), ts('Rule Deleted'), 'success'); | |
216 | CRM_Utils_System::redirect(CRM_Utils_System::url($this->userContext(), 'reset=1')); | |
217 | } | |
6a488035 | 218 | } |
96025800 | 219 | |
6a488035 | 220 | } |