3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * Page for displaying list of categories
39 class CRM_Admin_Page_Tag
extends CRM_Core_Page_Basic
{
42 * The action links that we need to display for the browse screen
47 static $_links = NULL;
52 * @return string Classname of BAO.
54 function getBAOName() {
55 return 'CRM_Core_BAO_Tag';
61 * @return array (reference) of action links
64 if (!(self
::$_links)) {
65 self
::$_links = array(
66 CRM_Core_Action
::UPDATE
=> array(
68 'url' => 'civicrm/admin/tag',
69 'qs' => 'action=update&id=%%id%%&reset=1',
70 'title' => ts('Edit Tag'),
72 CRM_Core_Action
::DELETE
=> array(
73 'name' => ts('Delete'),
74 'url' => 'civicrm/admin/tag',
75 'qs' => 'action=delete&id=%%id%%',
76 'title' => ts('Delete Tag'),
78 CRM_Core_Action
::FOLLOWUP
=> array(
79 'name' => ts('Merge'),
80 'class' => 'merge_tag',
81 'url' => 'javascript:',
82 'title' => ts('Merge Tag'),
90 * Get name of edit form
92 * @return string Classname of edit form.
95 return 'CRM_Admin_Form_Tag';
99 * Get form name for edit form
101 * @return string name of this page.
103 function editName() {
108 * Get form name for delete form
110 * @return string name of this page.
112 function deleteName() {
119 * @return string user context.
121 function userContext($mode = NULL) {
122 return 'civicrm/admin/tag';
126 * Get name of delete form
128 * @return string Classname of delete form.
130 function deleteForm() {
131 return 'CRM_Admin_Form_Tag';
135 * override function browse()
137 function browse($action = NULL, $sort = NULL) {
138 $adminTagSet = FALSE;
139 if (CRM_Core_Permission
::check('administer Tagsets')) {
142 $this->assign('adminTagSet', $adminTagSet);
144 $reservedClause = !CRM_Core_Permission
::check('administer reserved tags') ?
"AND t1.is_reserved != 1" : '';
145 $query = "SELECT t1.name, t1.id
146 FROM civicrm_tag t1 LEFT JOIN civicrm_tag t2 ON t1.id = t2.parent_id
147 WHERE t2.id IS NULL {$reservedClause}";
148 $tag = CRM_Core_DAO
::executeQuery($query);
150 $mergeableTags = array();
151 while ($tag->fetch()) {
152 $mergeableTags[$tag->id
] = 1;
155 $usedFor = CRM_Core_OptionGroup
::values('tag_used_for');
157 $query = "SELECT t1.name, t1.id, t2.name as parent, t1.description, t1.used_for, t1.is_tagset,
158 t1.is_reserved, t1.parent_id, t1.used_for
159 FROM civicrm_tag t1 LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id
160 GROUP BY t1.parent_id, t1.id";
162 $tag = CRM_Core_DAO
::executeQuery($query);
165 $action = CRM_Core_Action
::UPDATE + CRM_Core_Action
::DELETE
;
166 $permission = CRM_Core_Permission
::EDIT
;
168 while ($tag->fetch()) {
169 $values[$tag->id
] = (array) $tag;
172 if ($values[$tag->id
]['used_for']) {
173 $usedArray = explode(",", $values[$tag->id
]['used_for']);
174 foreach ($usedArray as $key => $value) {
175 $used[$key] = $usedFor[$value];
180 $values[$tag->id
]['used_for'] = implode(", ", $used);
183 $newAction = $action;
184 if ($values[$tag->id
]['is_reserved']) {
185 $newAction = CRM_Core_Action
::UPDATE
;
188 if ($values[$tag->id
]['is_tagset'] && !CRM_Core_Permission
::check('administer Tagsets')) {
192 if (array_key_exists($tag->id
, $mergeableTags)) {
193 $newAction +
= CRM_Core_Action
::FOLLOWUP
;
196 // populate action links
198 $this->action($tag, $newAction, $values[$tag->id
], self
::links(), $permission, TRUE);
201 $values[$tag->id
]['action'] = '';
205 $this->assign('rows', $values);