938746037a3ef8e216f53c9a8f490feeeacf73b0
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
35 * Page for displaying list of categories.
37 class CRM_Admin_Page_Tag
extends CRM_Core_Page_Basic
{
39 public $useLivePageJS = TRUE;
42 * The action links that we need to display for the browse screen.
46 static $_links = NULL;
54 public function getBAOName() {
55 return 'CRM_Core_BAO_Tag';
62 * (reference) of action links
64 public function &links() {
65 if (!(self
::$_links)) {
66 self
::$_links = array(
67 CRM_Core_Action
::UPDATE
=> array(
69 'url' => 'civicrm/admin/tag',
70 'qs' => 'action=update&id=%%id%%&reset=1',
71 'title' => ts('Edit Tag'),
73 CRM_Core_Action
::DELETE
=> array(
74 'name' => ts('Delete'),
75 'url' => 'civicrm/admin/tag',
76 'qs' => 'action=delete&id=%%id%%',
77 'title' => ts('Delete Tag'),
79 CRM_Core_Action
::FOLLOWUP
=> array(
80 'name' => ts('Merge'),
81 'class' => 'merge_tag',
82 'title' => ts('Merge Tag'),
90 * Get name of edit form.
93 * Classname of edit form.
95 public function editForm() {
96 return 'CRM_Admin_Form_Tag';
100 * Get form name for edit form.
105 public function editName() {
110 * Get form name for delete form.
115 public function deleteName() {
127 public function userContext($mode = NULL) {
128 return 'civicrm/admin/tag';
132 * Get name of delete form.
135 * Classname of delete form.
137 public function deleteForm() {
138 return 'CRM_Admin_Form_Tag';
142 * Override function browse()
144 * @param null $action
147 public function browse($action = NULL, $sort = NULL) {
148 $adminTagSet = FALSE;
149 if (CRM_Core_Permission
::check('administer Tagsets')) {
152 $this->assign('adminTagSet', $adminTagSet);
154 $reservedClause = !CRM_Core_Permission
::check('administer reserved tags') ?
"AND t1.is_reserved != 1" : '';
155 $query = "SELECT t1.name, t1.id
156 FROM civicrm_tag t1 LEFT JOIN civicrm_tag t2 ON t1.id = t2.parent_id
157 WHERE t2.id IS NULL {$reservedClause}";
158 $tag = CRM_Core_DAO
::executeQuery($query);
160 $mergeableTags = array();
161 while ($tag->fetch()) {
162 $mergeableTags[$tag->id
] = 1;
165 $usedFor = CRM_Core_OptionGroup
::values('tag_used_for');
167 $query = "SELECT t1.name, t1.id, t2.name as parent, t1.description, t1.used_for, t1.is_tagset,
168 t1.is_reserved, t1.parent_id, t1.used_for
169 FROM civicrm_tag t1 LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id
170 GROUP BY t1.parent_id, t1.id";
172 $tag = CRM_Core_DAO
::executeQuery($query);
175 $action = CRM_Core_Action
::UPDATE + CRM_Core_Action
::DELETE
;
176 $permission = CRM_Core_Permission
::EDIT
;
178 while ($tag->fetch()) {
179 $values[$tag->id
] = (array) $tag;
182 if ($values[$tag->id
]['used_for']) {
183 $usedArray = explode(",", $values[$tag->id
]['used_for']);
184 foreach ($usedArray as $key => $value) {
185 $used[$key] = $usedFor[$value];
190 $values[$tag->id
]['used_for'] = implode(", ", $used);
193 $newAction = $action;
194 if ($values[$tag->id
]['is_reserved']) {
195 $newAction = CRM_Core_Action
::UPDATE
;
198 if ($values[$tag->id
]['is_tagset'] && !CRM_Core_Permission
::check('administer Tagsets')) {
202 if (array_key_exists($tag->id
, $mergeableTags)) {
203 $newAction +
= CRM_Core_Action
::FOLLOWUP
;
206 // populate action links
208 $this->action($tag, $newAction, $values[$tag->id
], self
::links(), $permission, TRUE);
211 $values[$tag->id
]['action'] = '';
215 $this->assign('rows', $values);