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 | ||
36 | /** | |
37 | * Page for displaying list of categories | |
38 | */ | |
39 | class CRM_Admin_Page_Tag extends CRM_Core_Page_Basic { | |
40 | ||
96f50de2 CW |
41 | public $useLivePageJS = TRUE; |
42 | ||
6a488035 | 43 | /** |
eceb18cc | 44 | * The action links that we need to display for the browse screen. |
6a488035 TO |
45 | * |
46 | * @var array | |
6a488035 TO |
47 | */ |
48 | static $_links = NULL; | |
49 | ||
50 | /** | |
eceb18cc | 51 | * Get BAO. |
6a488035 | 52 | * |
a6c01b45 CW |
53 | * @return string |
54 | * Classname of BAO. | |
6a488035 | 55 | */ |
00be9182 | 56 | public function getBAOName() { |
6a488035 TO |
57 | return 'CRM_Core_BAO_Tag'; |
58 | } | |
59 | ||
60 | /** | |
eceb18cc | 61 | * Get action Links. |
6a488035 | 62 | * |
a6c01b45 CW |
63 | * @return array |
64 | * (reference) of action links | |
6a488035 | 65 | */ |
00be9182 | 66 | public function &links() { |
6a488035 TO |
67 | if (!(self::$_links)) { |
68 | self::$_links = array( | |
69 | CRM_Core_Action::UPDATE => array( | |
70 | 'name' => ts('Edit'), | |
71 | 'url' => 'civicrm/admin/tag', | |
72 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
73 | 'title' => ts('Edit Tag'), | |
74 | ), | |
75 | CRM_Core_Action::DELETE => array( | |
76 | 'name' => ts('Delete'), | |
77 | 'url' => 'civicrm/admin/tag', | |
78 | 'qs' => 'action=delete&id=%%id%%', | |
79 | 'title' => ts('Delete Tag'), | |
80 | ), | |
81 | CRM_Core_Action::FOLLOWUP => array( | |
82 | 'name' => ts('Merge'), | |
83 | 'class' => 'merge_tag', | |
6a488035 TO |
84 | 'title' => ts('Merge Tag'), |
85 | ), | |
86 | ); | |
87 | } | |
88 | return self::$_links; | |
89 | } | |
90 | ||
91 | /** | |
eceb18cc | 92 | * Get name of edit form. |
6a488035 | 93 | * |
a6c01b45 CW |
94 | * @return string |
95 | * Classname of edit form. | |
6a488035 | 96 | */ |
00be9182 | 97 | public function editForm() { |
6a488035 TO |
98 | return 'CRM_Admin_Form_Tag'; |
99 | } | |
100 | ||
101 | /** | |
eceb18cc | 102 | * Get form name for edit form. |
6a488035 | 103 | * |
a6c01b45 CW |
104 | * @return string |
105 | * name of this page. | |
6a488035 | 106 | */ |
00be9182 | 107 | public function editName() { |
6a488035 TO |
108 | return 'Tag'; |
109 | } | |
110 | ||
111 | /** | |
eceb18cc | 112 | * Get form name for delete form. |
6a488035 | 113 | * |
a6c01b45 CW |
114 | * @return string |
115 | * name of this page. | |
6a488035 | 116 | */ |
00be9182 | 117 | public function deleteName() { |
6a488035 TO |
118 | return 'Tag'; |
119 | } | |
120 | ||
121 | /** | |
122 | * Get user context. | |
123 | * | |
fd31fa4c EM |
124 | * @param null $mode |
125 | * | |
a6c01b45 CW |
126 | * @return string |
127 | * user context. | |
6a488035 | 128 | */ |
00be9182 | 129 | public function userContext($mode = NULL) { |
6a488035 TO |
130 | return 'civicrm/admin/tag'; |
131 | } | |
132 | ||
133 | /** | |
eceb18cc | 134 | * Get name of delete form. |
6a488035 | 135 | * |
a6c01b45 CW |
136 | * @return string |
137 | * Classname of delete form. | |
6a488035 | 138 | */ |
00be9182 | 139 | public function deleteForm() { |
6a488035 TO |
140 | return 'CRM_Admin_Form_Tag'; |
141 | } | |
142 | ||
143 | /** | |
100fef9d | 144 | * Override function browse() |
02fc859b | 145 | * |
100fef9d CW |
146 | * @param null $action |
147 | * @param null $sort | |
6a488035 | 148 | */ |
00be9182 | 149 | public function browse($action = NULL, $sort = NULL) { |
6a488035 TO |
150 | $adminTagSet = FALSE; |
151 | if (CRM_Core_Permission::check('administer Tagsets')) { | |
152 | $adminTagSet = TRUE; | |
153 | } | |
154 | $this->assign('adminTagSet', $adminTagSet); | |
155 | ||
156 | $reservedClause = !CRM_Core_Permission::check('administer reserved tags') ? "AND t1.is_reserved != 1" : ''; | |
157 | $query = "SELECT t1.name, t1.id | |
158 | FROM civicrm_tag t1 LEFT JOIN civicrm_tag t2 ON t1.id = t2.parent_id | |
159 | WHERE t2.id IS NULL {$reservedClause}"; | |
160 | $tag = CRM_Core_DAO::executeQuery($query); | |
161 | ||
162 | $mergeableTags = array(); | |
163 | while ($tag->fetch()) { | |
164 | $mergeableTags[$tag->id] = 1; | |
165 | } | |
166 | ||
167 | $usedFor = CRM_Core_OptionGroup::values('tag_used_for'); | |
168 | ||
169 | $query = "SELECT t1.name, t1.id, t2.name as parent, t1.description, t1.used_for, t1.is_tagset, | |
170 | t1.is_reserved, t1.parent_id, t1.used_for | |
171 | FROM civicrm_tag t1 LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id | |
172 | GROUP BY t1.parent_id, t1.id"; | |
173 | ||
174 | $tag = CRM_Core_DAO::executeQuery($query); | |
175 | $values = array(); | |
176 | ||
177 | $action = CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE; | |
178 | $permission = CRM_Core_Permission::EDIT; | |
179 | ||
180 | while ($tag->fetch()) { | |
181 | $values[$tag->id] = (array) $tag; | |
182 | ||
183 | $used = array(); | |
184 | if ($values[$tag->id]['used_for']) { | |
185 | $usedArray = explode(",", $values[$tag->id]['used_for']); | |
186 | foreach ($usedArray as $key => $value) { | |
187 | $used[$key] = $usedFor[$value]; | |
188 | } | |
189 | } | |
190 | ||
191 | if (!empty($used)) { | |
192 | $values[$tag->id]['used_for'] = implode(", ", $used); | |
193 | } | |
194 | ||
195 | $newAction = $action; | |
196 | if ($values[$tag->id]['is_reserved']) { | |
197 | $newAction = CRM_Core_Action::UPDATE; | |
198 | } | |
199 | ||
200 | if ($values[$tag->id]['is_tagset'] && !CRM_Core_Permission::check('administer Tagsets')) { | |
201 | $newAction = 0; | |
202 | } | |
203 | ||
204 | if (array_key_exists($tag->id, $mergeableTags)) { | |
205 | $newAction += CRM_Core_Action::FOLLOWUP; | |
206 | } | |
207 | ||
208 | // populate action links | |
209 | if ($newAction) { | |
210 | $this->action($tag, $newAction, $values[$tag->id], self::links(), $permission, TRUE); | |
211 | } | |
212 | else { | |
213 | $values[$tag->id]['action'] = ''; | |
214 | } | |
215 | } | |
216 | ||
217 | $this->assign('rows', $values); | |
218 | } | |
96025800 | 219 | |
6a488035 | 220 | } |