Completed
Push — master ( 03fc7e...44f12a )
by Henry
15:26
created

includes/Admin/Controller/Common.php (30 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Admin\Controller;
3
4
use Redaxscript\Admin;
5
6
/**
7
 * children class to handle common
8
 *
9
 * @since 4.0.0
10
 *
11
 * @package Redaxscript
12
 * @category Controller
13
 * @author Henry Ruhs
14
 */
15
16
class Common extends ControllerAbstract
17
{
18
	/**
19
	 * process the class
20
	 *
21
	 * @since 4.0.0
22
	 *
23
	 * @param string $action action to process
24
	 *
25
	 * @return string
26
	 */
27
28
	public function process(string $action = null) : string
29
	{
30
		$table = $this->_registry->get('tableParameter');
31
		$id = $this->_registry->get('idParameter');
32
		$alias = $this->_registry->get('aliasParameter');
33
34
		/* handle publish */
35
36
		if ($action === 'publish')
37
		{
38
			if ($this->_publish($table, $id))
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_publish() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $id defined by $this->_registry->get('idParameter') on line 31 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_publish() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
39
			{
40
				return $this->_success(
41
				[
42
					'route' => $this->_getRoute($table, $id),
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $id defined by $this->_registry->get('idParameter') on line 31 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
43
					'timeout' => 0
44
				]);
45
			};
46
		}
47
48
		/* handle unpublish */
49
50
		if ($action === 'unpublish')
51
		{
52
			if ($this->_unpublish($table, $id))
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_unpublish() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $id defined by $this->_registry->get('idParameter') on line 31 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_unpublish() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
53
			{
54
				return $this->_success(
55
				[
56
					'route' => $this->_getRoute($table, $id),
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $id defined by $this->_registry->get('idParameter') on line 31 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
57
					'timeout' => 0
58
				]);
59
			};
60
		}
61
62
		/* handle enable */
63
64
		if ($action === 'enable')
65
		{
66
			if ($this->_enable($table, $id))
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_enable() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $id defined by $this->_registry->get('idParameter') on line 31 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_enable() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
67
			{
68
				return $this->_success(
69
				[
70
					'route' => $this->_getRoute($table, $id),
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $id defined by $this->_registry->get('idParameter') on line 31 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
71
					'timeout' => 0
72
				]);
73
			};
74
		}
75
76
		/* handle disable */
77
78
		if ($action === 'disable')
79
		{
80
			if ($this->_disable($table, $id))
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_disable() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $id defined by $this->_registry->get('idParameter') on line 31 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_disable() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
81
			{
82
				return $this->_success(
83
				[
84
					'route' => $this->_getRoute($table, $id),
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $id defined by $this->_registry->get('idParameter') on line 31 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
85
					'timeout' => 0
86
				]);
87
			};
88
		}
89
90
		/* handle install */
91
92
		if ($action === 'install')
93
		{
94
			if ($this->_install($table, $alias))
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_install() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $alias defined by $this->_registry->get('aliasParameter') on line 32 can also be of type array; however, Redaxscript\Admin\Controller\Common::_install() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
95
			{
96
				return $this->_success(
97
				[
98
					'route' => $this->_getRoute($table),
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
99
					'timeout' => 0
100
				]);
101
			};
102
		}
103
104
		/* handle uninstall */
105
106
		if ($action === 'uninstall')
107
		{
108
			if ($this->_uninstall($table, $alias))
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_uninstall() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $alias defined by $this->_registry->get('aliasParameter') on line 32 can also be of type array; however, Redaxscript\Admin\Controller\Common::_uninstall() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
109
			{
110
				return $this->_success(
111
				[
112
					'route' => $this->_getRoute($table),
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
113
					'timeout' => 0
114
				]);
115
			};
116
		}
117
118
		/* handle delete */
119
120
		if ($action === 'delete')
121
		{
122
			if ($this->_delete($table, $id))
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_delete() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $id defined by $this->_registry->get('idParameter') on line 31 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_delete() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
123
			{
124
				return $this->_success(
125
				[
126
					'route' => $this->_getRoute($table, $id),
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $id defined by $this->_registry->get('idParameter') on line 31 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
127
					'timeout' => 0
128
				]);
129
			};
130
		}
131
132
		/* handle error */
133
134
		return $this->_error(
135
		[
136
			'route' => $this->_getRoute($table, $id)
0 ignored issues
show
It seems like $table defined by $this->_registry->get('tableParameter') on line 30 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $id defined by $this->_registry->get('idParameter') on line 31 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
137
		]);
138
	}
139
140
	/**
141
	 * publish the item
142
	 *
143
	 * @since 4.0.0
144
	 *
145
	 * @param string $table name of the table
146
	 * @param int $id identifier of the item
147
	 *
148
	 * @return bool
149
	 */
150
151
	public function _publish(string $table = null, int $id = null) : bool
152
	{
153
		if ($table === 'categories')
154
		{
155
			$categoryModel = new Admin\Model\Category();
156
			return $categoryModel->publishById($id);
157
		}
158
		if ($table === 'articles')
159
		{
160
			$articleModel = new Admin\Model\Article();
161
			return $articleModel->publishById($id);
162
		}
163
		if ($table === 'extras')
164
		{
165
			$extraModel = new Admin\Model\Extra();
166
			return $extraModel->publishById($id);
167
		}
168
		if ($table === 'comments')
169
		{
170
			$commentModel = new Admin\Model\Comment();
171
			return $commentModel->publishById($id);
172
		}
173
		return false;
174
	}
175
176
	/**
177
	 * unpublish the item
178
	 *
179
	 * @since 4.0.0
180
	 *
181
	 * @param string $table name of the table
182
	 * @param int $id identifier of the item
183
	 *
184
	 * @return bool
185
	 */
186
187
	public function _unpublish(string $table = null, int $id = null) : bool
188
	{
189
		if ($table === 'categories')
190
		{
191
			$categoryModel = new Admin\Model\Category();
192
			return $categoryModel->unpublishById($id);
193
		}
194
		if ($table === 'articles')
195
		{
196
			$articleModel = new Admin\Model\Article();
197
			return $articleModel->unpublishById($id);
198
		}
199
		if ($table === 'extras')
200
		{
201
			$extraModel = new Admin\Model\Extra();
202
			return $extraModel->unpublishById($id);
203
		}
204
		if ($table === 'comments')
205
		{
206
			$commentModel = new Admin\Model\Comment();
207
			return $commentModel->unpublishById($id);
208
		}
209
		return false;
210
	}
211
212
	/**
213
	 * enable the item
214
	 *
215
	 * @since 4.0.0
216
	 *
217
	 * @param string $table name of the table
218
	 * @param int $id identifier of the item
219
	 *
220
	 * @return bool
221
	 */
222
223
	public function _enable(string $table = null, int $id = null) : bool
224
	{
225
		if ($table === 'groups')
226
		{
227
			$groupModel = new Admin\Model\Group();
228
			return $groupModel->enableById($id);
229
		}
230
		if ($table === 'users')
231
		{
232
			$userModel = new Admin\Model\User();
233
			return $userModel->enableById($id);
234
		}
235
		if ($table === 'modules')
236
		{
237
			$moduleModel = new Admin\Model\Module();
238
			return $moduleModel->enableById($id);
239
		}
240
		return false;
241
	}
242
243
	/**
244
	 * disable the item
245
	 *
246
	 * @since 4.0.0
247
	 *
248
	 * @param string $table name of the table
249
	 * @param int $id identifier of the item
250
	 *
251
	 * @return bool
252
	 */
253
254
	public function _disable(string $table = null, int $id = null) : bool
255
	{
256
		if ($table === 'groups')
257
		{
258
			$groupModel = new Admin\Model\Group();
259
			return $groupModel->disableById($id);
260
		}
261
		if ($table === 'users')
262
		{
263
			$userModel = new Admin\Model\User();
264
			return $userModel->disableById($id);
265
		}
266
		if ($table === 'modules')
267
		{
268
			$moduleModel = new Admin\Model\Module();
269
			return $moduleModel->disableById($id);
270
		}
271
		return false;
272
	}
273
274
	/**
275
	 * install the item
276
	 *
277
	 * @since 4.0.0
278
	 *
279
	 * @param string $table name of the table
280
	 * @param string $alias alias of the item
281
	 *
282
	 * @return bool
283
	 */
284
285
	public function _install(string $table = null, string $alias = null) : bool
286
	{
287
		if ($table === 'modules')
288
		{
289
			$moduleClass = 'Redaxscript\Modules\\' . $alias . '\\' . $alias;
290
			$module = new $moduleClass($this->_registry, $this->_request, $this->_language, $this->_config);
291
			return $module->install();
292
		}
293
		return false;
294
	}
295
296
	/**
297
	 * uninstall the item
298
	 *
299
	 * @since 4.0.0
300
	 *
301
	 * @param string $table name of the table
302
	 * @param string $alias alias of the item
303
	 *
304
	 * @return bool
305
	 */
306
307
	public function _uninstall(string $table = null, string $alias = null) : bool
308
	{
309
		if ($table === 'modules')
310
		{
311
			$moduleClass = 'Redaxscript\Modules\\' . $alias . '\\' . $alias;
312
			$module = new $moduleClass($this->_registry, $this->_request, $this->_language, $this->_config);
313
			return $module->uninstall();
314
		}
315
		return false;
316
	}
317
318
	/**
319
	 * delete the item
320
	 *
321
	 * @since 4.0.0
322
	 *
323
	 * @param string $table name of the table
324
	 * @param int $id identifier of the item
325
	 *
326
	 * @return bool
327
	 */
328
329
	public function _delete(string $table = null, int $id = null) : bool
330
	{
331
		if ($table === 'categories')
332
		{
333
			$categoryModel = new Admin\Model\Category();
334
			return $categoryModel->deleteById($id);
335
		}
336
		if ($table === 'articles')
337
		{
338
			$articleModel = new Admin\Model\Article();
339
			return $articleModel->deleteById($id);
340
		}
341
		if ($table === 'extras')
342
		{
343
			$extraModel = new Admin\Model\Extra();
344
			return $extraModel->deleteById($id);
345
		}
346
		if ($table === 'comments')
347
		{
348
			$commentModel = new Admin\Model\Comment();
349
			return $commentModel->deleteById($id);
350
		}
351
		if ($table === 'groups')
352
		{
353
			$groupModel = new Admin\Model\Group();
354
			return $groupModel->deleteById($id);
355
		}
356
		if ($table === 'users')
357
		{
358
			$userModel = new Admin\Model\User();
359
			return $userModel->deleteById($id);
360
		}
361
		return false;
362
	}
363
364
	/**
365
	 * get route
366
	 *
367
	 * @since 4.0.0
368
	 *
369
	 * @param string $table name of the table
370
	 * @param int $id identifier of the item
371
	 *
372
	 * @return string
373
	 */
374
375
	public function _getRoute(string $table = null, int $id = null) : string
376
	{
377
		if ($this->_registry->get($table . 'Edit'))
378
		{
379
			if ($id)
0 ignored issues
show
Bug Best Practice introduced by
The expression $id of type null|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
380
			{
381
				return 'admin/view/' . $table . '#row-' . $id;
382
			}
383
			if ($table)
0 ignored issues
show
Bug Best Practice introduced by
The expression $table of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
384
			{
385
				return 'admin/view/' . $table;
386
			}
387
		}
388
		return 'admin';
389
	}
390
}
391