Standard   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 174
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 174
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A search() 0 12 1
A save() 0 7 1
A render() 0 24 1
A getSubClientNames() 0 3 1
A getSubClient() 0 73 1
1
<?php
2
3
/**
4
 * @copyright Aimeos GmbH (aimeos.com), 2022-2026
5
 * @package Admin
6
 * @subpackage JQAdm
7
 */
8
9
10
namespace Aimeos\Admin\JQAdm\Settings\Theme;
11
12
sprintf( 'theme' ); // for translation
13
14
15
/**
16
 * Default implementation of settings theme JQAdm client.
17
 *
18
 * @package Admin
19
 * @subpackage JQAdm
20
 */
21
class Standard
22
	extends \Aimeos\Admin\JQAdm\Common\Admin\Factory\Base
23
	implements \Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface
24
{
25
	/** admin/jqadm/settings/theme/name
26
	 * Name of the theme subpart used by the JQAdm settings implementation
27
	 *
28
	 * Use "Myname" if your class is named "\Aimeos\Admin\Jqadm\Settings\Theme\Myname".
29
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
30
	 *
31
	 * @param string Last part of the JQAdm class name
32
	 * @since 2022.10
33
	 */
34
35
36
	/**
37
	 * Saves the data
38
	 *
39
	 * @return string|null HTML output
40
	 */
41
	public function save() : ?string
42
	{
43
		$context = $this->context();
44
		$site = $context->locale()->getSiteItem();
45
		$site->setConfigValue( 'theme', $this->view()->param( 'theme', [] ) );
46
47
		return null;
48
	}
49
50
51
	/**
52
	 * Returns the resource
53
	 *
54
	 * @return string|null HTML output
55
	 */
56
	public function search() : ?string
57
	{
58
		$context = $this->context();
59
		$site = $context->locale()->getSiteItem();
60
61
		$themeData = $context->config()->get( 'client/html/theme-presets', [] );
62
		$themeData = array_replace_recursive( $themeData, $site->getConfigValue( 'theme', [] ) );
63
64
		$view = $this->object()->data( $this->view() );
65
		$view->themeData = $themeData;
66
67
		return $this->render( $view );
68
	}
69
70
71
	/**
72
	 * Returns the sub-client given by its name.
73
	 *
74
	 * @param string $type Name of the client type
75
	 * @param string|null $name Name of the sub-client (Default if null)
76
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
77
	 */
78
	public function getSubClient( string $type, ?string $name = null ) : \Aimeos\Admin\JQAdm\Iface
79
	{
80
		/** admin/jqadm/settings/theme/decorators/excludes
81
		 * Excludes decorators added by the "common" option from the settings JQAdm client
82
		 *
83
		 * Decorators extend the functionality of a class by adding new aspects
84
		 * (e.g. log what is currently done), executing the methods of the underlying
85
		 * class only in certain conditions (e.g. only for logged in users) or
86
		 * modify what is returned to the caller.
87
		 *
88
		 * This option allows you to remove a decorator added via
89
		 * "admin/jqadm/common/decorators/default" before they are wrapped
90
		 * around the JQAdm client.
91
		 *
92
		 *  admin/jqadm/settings/theme/decorators/excludes = array( 'decorator1' )
93
		 *
94
		 * This would remove the decorator named "decorator1" from the list of
95
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
96
		 * "admin/jqadm/common/decorators/default" to the JQAdm client.
97
		 *
98
		 * @param array List of decorator names
99
		 * @since 2022.10
100
		 * @see admin/jqadm/common/decorators/default
101
		 * @see admin/jqadm/settings/theme/decorators/global
102
		 * @see admin/jqadm/settings/theme/decorators/local
103
		 */
104
105
		/** admin/jqadm/settings/theme/decorators/global
106
		 * Adds a list of globally available decorators only to the settings JQAdm client
107
		 *
108
		 * Decorators extend the functionality of a class by adding new aspects
109
		 * (e.g. log what is currently done), executing the methods of the underlying
110
		 * class only in certain conditions (e.g. only for logged in users) or
111
		 * modify what is returned to the caller.
112
		 *
113
		 * This option allows you to wrap global decorators
114
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
115
		 *
116
		 *  admin/jqadm/settings/theme/decorators/global = array( 'decorator1' )
117
		 *
118
		 * This would add the decorator named "decorator1" defined by
119
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
120
		 *
121
		 * @param array List of decorator names
122
		 * @since 2022.10
123
		 * @see admin/jqadm/common/decorators/default
124
		 * @see admin/jqadm/settings/theme/decorators/excludes
125
		 * @see admin/jqadm/settings/theme/decorators/local
126
		 */
127
128
		/** admin/jqadm/settings/theme/decorators/local
129
		 * Adds a list of local decorators only to the settings JQAdm client
130
		 *
131
		 * Decorators extend the functionality of a class by adding new aspects
132
		 * (e.g. log what is currently done), executing the methods of the underlying
133
		 * class only in certain conditions (e.g. only for logged in users) or
134
		 * modify what is returned to the caller.
135
		 *
136
		 * This option allows you to wrap local decorators
137
		 * ("\Aimeos\Admin\JQAdm\Settings\Decorator\*") around the JQAdm client.
138
		 *
139
		 *  admin/jqadm/settings/theme/decorators/local = array( 'decorator2' )
140
		 *
141
		 * This would add the decorator named "decorator2" defined by
142
		 * "\Aimeos\Admin\JQAdm\Settings\Decorator\Decorator2" only to the JQAdm client.
143
		 *
144
		 * @param array List of decorator names
145
		 * @since 2022.10
146
		 * @see admin/jqadm/common/decorators/default
147
		 * @see admin/jqadm/settings/theme/decorators/excludes
148
		 * @see admin/jqadm/settings/theme/decorators/global
149
		 */
150
		return $this->createSubClient( 'settings/theme/' . $type, $name );
151
	}
152
153
154
	/**
155
	 * Returns the list of sub-client names configured for the client.
156
	 *
157
	 * @return array List of JQAdm client names
158
	 */
159
	protected function getSubClientNames() : array
160
	{
161
		return $this->context()->config()->get( 'admin/jqadm/settings/theme/subparts', [] );
162
	}
163
164
165
	/**
166
	 * Returns the rendered template including the view data
167
	 *
168
	 * @param \Aimeos\Base\View\Iface $view View object with data assigned
169
	 * @return string HTML output
170
	 */
171
	protected function render( \Aimeos\Base\View\Iface $view ) : string
172
	{
173
		/** admin/jqadm/settings/theme/template-item
174
		 * Relative path to the HTML body template of the theme subpart for settings.
175
		 *
176
		 * The template file contains the HTML code and processing instructions
177
		 * to generate the result shown in the body of the frontend. The
178
		 * configuration string is the path to the template file relative
179
		 * to the templates directory (usually in templates/admin/jqadm).
180
		 *
181
		 * You can overwrite the template file configuration in extensions and
182
		 * provide alternative templates. These alternative templates should be
183
		 * named like the default one but with the string "default" replaced by
184
		 * an unique name. You may use the name of your project for this. If
185
		 * you've implemented an alternative client class as well, "default"
186
		 * should be replaced by the name of the new class.
187
		 *
188
		 * @param string Relative path to the template creating the HTML code
189
		 * @since 2016.04
190
		 */
191
		$tplconf = 'admin/jqadm/settings/theme/template-item';
192
		$default = 'settings/item-theme';
193
194
		return $view->render( $view->config( $tplconf, $default ) );
195
	}
196
}
197