3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Contact_Page_DedupeRules
extends CRM_Core_Page_Basic
{
38 * The action links that we need to display for the browse screen
43 static $_links = NULL;
48 * @return string Classname of BAO.
50 public function getBAOName() {
51 return 'CRM_Dedupe_BAO_RuleGroup';
57 * @return array (reference) of action links
59 public function &links() {
60 if (!(self
::$_links)) {
61 $deleteExtra = ts('Are you sure you want to delete this Rule?');
63 // helper variable for nicer formatting
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'),
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'),
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'),
90 self
::$_links = $links;
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
105 public function run() {
106 // get the requested action, default to 'browse'
107 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
109 // assign vars to templates
110 $this->assign('action', $action);
111 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, 0);
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');
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'));
122 // which action to take?
123 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
124 $this->edit($action, $id);
126 if ($action & CRM_Core_Action
::DELETE
) {
134 return parent
::run();
138 * Browse all rule groups
142 public function browse() {
143 // get all rule groups
144 $ruleGroups = array();
145 $dao = new CRM_Dedupe_DAO_RuleGroup();
146 $dao->orderBy('contact_type,used ASC');
149 $dedupeRuleTypes = CRM_Core_SelectValues
::getDedupeRuleTypes();
150 while ($dao->fetch()) {
151 $ruleGroups[$dao->contact_type
][$dao->id
] = array();
152 CRM_Core_DAO
::storeValues($dao, $ruleGroups[$dao->contact_type
][$dao->id
]);
154 // form all action links
155 $action = array_sum(array_keys($this->links()));
156 $links = self
::links();
157 /* if ($dao->is_default) {
158 unset($links[CRM_Core_Action::MAP]);
159 unset($links[CRM_Core_Action::DELETE]);
162 if ($dao->is_reserved
) {
163 unset($links[CRM_Core_Action
::DELETE
]);
166 $ruleGroups[$dao->contact_type
][$dao->id
]['action'] = CRM_Core_Action
::formLink(
169 array('id' => $dao->id
),
172 'dedupeRule.manage.action',
177 $ruleGroups[$dao->contact_type
][$dao->id
]['used_display'] = $dedupeRuleTypes[$ruleGroups[$dao->contact_type
][$dao->id
]['used']];
179 $this->assign('brows', $ruleGroups);
183 * Get name of edit form
185 * @return string classname of edit form
187 public function editForm() {
188 return 'CRM_Contact_Form_DedupeRules';
194 * @return string name of this page
196 public function editName() {
197 return 'DedupeRules';
205 * @return string user context
207 public function userContext($mode = NULL) {
208 return 'civicrm/contact/deduperules';
214 public function delete($id) {
215 $ruleDao = new CRM_Dedupe_DAO_Rule();
216 $ruleDao->dedupe_rule_group_id
= $id;
219 $rgDao = new CRM_Dedupe_DAO_RuleGroup();