Merge pull request #15850 from civicrm/5.20
[civicrm-core.git] / CRM / Tag / Page / Tag.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Page for managing tags.
20 */
21 class CRM_Tag_Page_Tag extends CRM_Core_Page {
22
23 /**
24 * Run page
25 */
26 public function run() {
27 CRM_Core_Resources::singleton()
28 ->addScriptFile('civicrm', 'bower_components/jstree/dist/jstree.min.js', 0, 'html-header')
29 ->addStyleFile('civicrm', 'bower_components/jstree/dist/themes/default/style.min.css')
30 ->addPermissions(['administer reserved tags', 'administer Tagsets']);
31
32 $usedFor = $tagsets = [];
33
34 $result = civicrm_api3('OptionValue', 'get', [
35 'return' => ["value", "name"],
36 'option_group_id' => "tag_used_for",
37 ]);
38 foreach ($result['values'] as $value) {
39 $usedFor[$value['value']] = $value['name'];
40 }
41
42 $result = civicrm_api3('Tag', 'get', [
43 'return' => ["name", "used_for", "description", "created_id.display_name", "created_date", "is_reserved"],
44 'is_tagset' => 1,
45 'options' => ['limit' => 0],
46 ]);
47 foreach ($result['values'] as $id => $tagset) {
48 $used = explode(',', CRM_Utils_Array::value('used_for', $tagset, ''));
49 $tagset['used_for_label'] = array_values(array_intersect_key($usedFor, array_flip($used)));
50 if (isset($tagset['created_id.display_name'])) {
51 $tagset['display_name'] = $tagset['created_id.display_name'];
52 }
53 unset($tagset['created_id.display_name']);
54 $tagsets[$id] = $tagset;
55 }
56
57 $this->assign('usedFor', $usedFor);
58 $this->assign('tagsets', $tagsets);
59
60 return parent::run();
61 }
62
63 }