Passed
Push — master ( 630e22...ef28d4 )
by Aimeos
03:58
created

Standard   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 167
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 167
rs 10
wmc 6

5 Methods

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