Remove unused local variables
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / cache / builder / TemplateListenerCodeCacheBuilder.class.php
CommitLineData
11ade432 1<?php
a9229942 2
ef875357 3namespace wcf\system\cache\builder;
a9229942 4
11ade432 5use wcf\data\template\listener\TemplateListenerList;
11ade432
AE
6
7/**
b401cd0d 8 * Caches the template listener code for a certain environment.
a9229942
TD
9 *
10 * @author Alexander Ebert
11 * @copyright 2001-2019 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\System\Cache\Builder
11ade432 14 */
a9229942
TD
15class TemplateListenerCodeCacheBuilder extends AbstractCacheBuilder
16{
17 /**
18 * @inheritDoc
19 */
20 public function rebuild(array $parameters)
21 {
22 // get template codes for specified template
23 $templateListenerList = new TemplateListenerList();
24 $templateListenerList->getConditionBuilder()->add(
25 "template_listener.environment = ?",
26 [$parameters['environment']]
27 );
28 $templateListenerList->sqlOrderBy = 'template_listener.niceValue ASC, template_listener.listenerID ASC';
29 $templateListenerList->readObjects();
30
31 $data = [];
32 foreach ($templateListenerList->getObjects() as $templateListener) {
33 if (!isset($data[$templateListener->templateName])) {
34 $data[$templateListener->templateName] = [];
35 }
36
37 $templateCode = $templateListener->templateCode;
38 // wrap template listener code in if condition for options
39 // and permissions check
40 if ($templateListener->options || $templateListener->permissions) {
41 $templateCode = '{if ';
42
13b11e4c 43 $options = [];
a9229942
TD
44 if ($templateListener->options) {
45 $options = \explode(',', \strtoupper($templateListener->options));
46
47 $options = \array_map(static function ($value) {
48 return "('" . $value . "'|defined && '" . $value . "'|constant)";
49 }, $options);
50
51 $templateCode .= '(' . \implode(' || ', $options) . ')';
52 }
53 if ($templateListener->permissions) {
54 $permissions = \explode(',', $templateListener->permissions);
55
56 $permissions = \array_map(static function ($value) {
57 return "\$__wcf->session->getPermission('" . $value . "')";
58 }, $permissions);
59
60 if (!empty($options)) {
61 $templateCode .= " && ";
62 }
63
64 $templateCode .= '(' . \implode(' || ', $permissions) . ')';
65 }
66
67 $templateCode .= '}' . $templateListener->templateCode . '{/if}';
68 }
69
70 $data[$templateListener->templateName][$templateListener->eventName][] = $templateCode;
71 }
72
73 return $data;
74 }
11ade432 75}