Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Contact_Page_DedupeRules extends CRM_Core_Page_Basic { | |
36 | ||
37 | /** | |
fe482240 | 38 | * The action links that we need to display for the browse screen. |
6a488035 TO |
39 | * |
40 | * @var array | |
6a488035 TO |
41 | */ |
42 | static $_links = NULL; | |
43 | ||
44 | /** | |
fe482240 | 45 | * Get BAO Name. |
6a488035 | 46 | * |
a6c01b45 CW |
47 | * @return string |
48 | * Classname of BAO. | |
6a488035 | 49 | */ |
00be9182 | 50 | public function getBAOName() { |
6a488035 TO |
51 | return 'CRM_Dedupe_BAO_RuleGroup'; |
52 | } | |
53 | ||
54 | /** | |
fe482240 | 55 | * Get action Links. |
6a488035 | 56 | * |
a6c01b45 CW |
57 | * @return array |
58 | * (reference) of action links | |
6a488035 | 59 | */ |
00be9182 | 60 | public function &links() { |
6a488035 TO |
61 | if (!(self::$_links)) { |
62 | $deleteExtra = ts('Are you sure you want to delete this Rule?'); | |
63 | ||
64 | // helper variable for nicer formatting | |
65 | $links = array(); | |
66 | ||
67 | if (CRM_Core_Permission::check('merge duplicate contacts')) { | |
68 | $links[CRM_Core_Action::VIEW] = array( | |
69 | 'name' => ts('Use Rule'), | |
70 | 'url' => 'civicrm/contact/dedupefind', | |
71 | 'qs' => 'reset=1&rgid=%%id%%&action=preview', | |
72 | 'title' => ts('Use DedupeRule'), | |
73 | ); | |
74 | } | |
75 | if (CRM_Core_Permission::check('administer dedupe rules')) { | |
76 | $links[CRM_Core_Action::UPDATE] = array( | |
77 | 'name' => ts('Edit Rule'), | |
78 | 'url' => 'civicrm/contact/deduperules', | |
79 | 'qs' => 'action=update&id=%%id%%', | |
80 | 'title' => ts('Edit DedupeRule'), | |
81 | ); | |
82 | $links[CRM_Core_Action::DELETE] = array( | |
83 | 'name' => ts('Delete'), | |
84 | 'url' => 'civicrm/contact/deduperules', | |
85 | 'qs' => 'action=delete&id=%%id%%', | |
86 | 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"', | |
87 | 'title' => ts('Delete DedupeRule'), | |
88 | ); | |
89 | } | |
90 | ||
91 | self::$_links = $links; | |
92 | } | |
93 | return self::$_links; | |
94 | } | |
95 | ||
96 | /** | |
fe482240 | 97 | * Run the page. |
6a488035 TO |
98 | * |
99 | * This method is called after the page is created. It checks for the type | |
100 | * of action and executes that action. Finally it calls the parent's run | |
101 | * method. | |
102 | * | |
103 | * @return void | |
6a488035 | 104 | */ |
00be9182 | 105 | public function run() { |
6a488035 TO |
106 | // get the requested action, default to 'browse' |
107 | $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); | |
108 | ||
109 | // assign vars to templates | |
110 | $this->assign('action', $action); | |
111 | $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); | |
112 | ||
113 | $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE); | |
114 | if ($context == 'nonDupe') { | |
115 | CRM_Core_Session::setStatus(ts('Selected contacts have been marked as not duplicates'), ts('Changes Saved'), 'success'); | |
116 | } | |
117 | ||
118 | // assign permissions vars to template | |
119 | $this->assign('hasperm_administer_dedupe_rules', CRM_Core_Permission::check('administer dedupe rules')); | |
120 | $this->assign('hasperm_merge_duplicate_contacts', CRM_Core_Permission::check('merge duplicate contacts')); | |
121 | ||
122 | // which action to take? | |
123 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { | |
124 | $this->edit($action, $id); | |
125 | } | |
126 | if ($action & CRM_Core_Action::DELETE) { | |
127 | $this->delete($id); | |
128 | } | |
129 | ||
130 | // browse the rules | |
131 | $this->browse(); | |
132 | ||
133 | // parent run | |
134 | return parent::run(); | |
135 | } | |
136 | ||
137 | /** | |
fe482240 | 138 | * Browse all rule groups. |
6a488035 TO |
139 | * |
140 | * @return void | |
6a488035 | 141 | */ |
00be9182 | 142 | public function browse() { |
6a488035 TO |
143 | // get all rule groups |
144 | $ruleGroups = array(); | |
145 | $dao = new CRM_Dedupe_DAO_RuleGroup(); | |
146 | $dao->orderBy('contact_type,used ASC'); | |
147 | $dao->find(); | |
148 | ||
77d0b1f8 | 149 | $dedupeRuleTypes = CRM_Core_SelectValues::getDedupeRuleTypes(); |
6a488035 TO |
150 | while ($dao->fetch()) { |
151 | $ruleGroups[$dao->contact_type][$dao->id] = array(); | |
152 | CRM_Core_DAO::storeValues($dao, $ruleGroups[$dao->contact_type][$dao->id]); | |
153 | ||
154 | // form all action links | |
155 | $action = array_sum(array_keys($this->links())); | |
156 | $links = self::links(); | |
157 | /* if ($dao->is_default) { | |
e70a7fc0 TO |
158 | unset($links[CRM_Core_Action::MAP]); |
159 | unset($links[CRM_Core_Action::DELETE]); | |
160 | }*/ | |
6a488035 TO |
161 | |
162 | if ($dao->is_reserved) { | |
163 | unset($links[CRM_Core_Action::DELETE]); | |
164 | } | |
165 | ||
87dab4a4 AH |
166 | $ruleGroups[$dao->contact_type][$dao->id]['action'] = CRM_Core_Action::formLink( |
167 | $links, | |
168 | $action, | |
169 | array('id' => $dao->id), | |
170 | ts('more'), | |
171 | FALSE, | |
172 | 'dedupeRule.manage.action', | |
173 | 'DedupeRule', | |
174 | $dao->id | |
175 | ); | |
6a488035 | 176 | |
77d0b1f8 | 177 | $ruleGroups[$dao->contact_type][$dao->id]['used_display'] = $dedupeRuleTypes[$ruleGroups[$dao->contact_type][$dao->id]['used']]; |
178 | } | |
6a488035 TO |
179 | $this->assign('brows', $ruleGroups); |
180 | } | |
181 | ||
182 | /** | |
fe482240 | 183 | * Get name of edit form. |
6a488035 | 184 | * |
a6c01b45 CW |
185 | * @return string |
186 | * classname of edit form | |
6a488035 | 187 | */ |
00be9182 | 188 | public function editForm() { |
6a488035 TO |
189 | return 'CRM_Contact_Form_DedupeRules'; |
190 | } | |
191 | ||
192 | /** | |
fe482240 | 193 | * Get edit form name. |
6a488035 | 194 | * |
a6c01b45 CW |
195 | * @return string |
196 | * name of this page | |
6a488035 | 197 | */ |
00be9182 | 198 | public function editName() { |
6a488035 TO |
199 | return 'DedupeRules'; |
200 | } | |
201 | ||
202 | /** | |
fe482240 | 203 | * Get user context. |
6a488035 | 204 | * |
da6b46f4 EM |
205 | * @param null $mode |
206 | * | |
a6c01b45 CW |
207 | * @return string |
208 | * user context | |
6a488035 | 209 | */ |
00be9182 | 210 | public function userContext($mode = NULL) { |
6a488035 TO |
211 | return 'civicrm/contact/deduperules'; |
212 | } | |
213 | ||
4319322b | 214 | /** |
100fef9d | 215 | * @param int $id |
4319322b | 216 | */ |
00be9182 | 217 | public function delete($id) { |
6a488035 TO |
218 | $ruleDao = new CRM_Dedupe_DAO_Rule(); |
219 | $ruleDao->dedupe_rule_group_id = $id; | |
220 | $ruleDao->delete(); | |
221 | ||
222 | $rgDao = new CRM_Dedupe_DAO_RuleGroup(); | |
223 | $rgDao->id = $id; | |
224 | $rgDao->delete(); | |
225 | } | |
96025800 | 226 | |
6a488035 | 227 | } |