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