Completed
Push — master ( 4e146b...a6625c )
by Henry
08:17
created

includes/Admin/Model/Category.php (1 issue)

unparsable_code_with_line

Bug Critical

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\Model;
3
4
use Redaxscript\Model as BaseModel;
5
6
/**
7
 * parent class to provide the admin category model
8
 *
9
 * @since 4.0.0
10
 *
11
 * @package Redaxscript
12
 * @category Model
13
 * @author Henry Ruhs
14
 */
15
16
class Category extends BaseModel\Category
17
{
18
	/**
19
	 * is unique by id and alias
20
	 *
21
	 * @since 4.0.0
22
	 *
23
	 * @param int $categoryId identifier of the category
24
	 * @param string $categoryAlias alias of the category
25
	 *
26
	 * @return bool
27
	 */
28
29
	public function isUniqueByIdAndAlias(int $categoryId = null, string $categoryAlias = null) : bool
30
	{
31
		$articleModel = new Article();
32
		return !$articleModel->getByAlias($categoryAlias)?->id && (!$this->getByAlias($categoryAlias)?->id || $this->getByAlias($categoryAlias)?->id === $this->getById($categoryId)?->id);
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_OBJECT_OPERATOR
Loading history...
33
	}
34
35
	/**
36
	 * create the category by array
37
	 *
38
	 * @since 4.0.0
39
	 *
40
	 * @param array $createArray array of the create
41
	 *
42
	 * @return bool
43
	 */
44
45
	public function createByArray(array $createArray = []) : bool
46
	{
47
		return $this
48
			->query()
49
			->create()
50
			->set($createArray)
51
			->save();
52
	}
53
54
	/**
55
	 * update the category by id and array
56
	 *
57
	 * @since 4.0.0
58
	 *
59
	 * @param int $categoryId identifier of the category
60
	 * @param array $updateArray array of the update
61
	 *
62
	 * @return bool
63
	 */
64
65
	public function updateByIdAndArray(int $categoryId = null, array $updateArray = []) : bool
66
	{
67
		return $this
68
			->query()
69
			->whereIdIs($categoryId)
70
			->findOne()
71
			->set($updateArray)
72
			->save();
73
	}
74
75
	/**
76
	 * publish the category by id
77
	 *
78
	 * @since 4.0.0
79
	 *
80
	 * @param int $categoryId identifier of the category
81
	 *
82
	 * @return bool
83
	 */
84
85
	public function publishById(int $categoryId = null) : bool
86
	{
87
		return (bool)$this
88
			->query()
89
			->whereAnyIs(
90
			[
91
				[
92
					'id' =>	$categoryId
93
				],
94
				[
95
					'parent' => $categoryId
96
				],
97
				[
98
					'sibling' => $categoryId
99
				]
100
			])
101
			->findMany()
102
			->set('status', 1)
103
			->save();
104
	}
105
106
	/**
107
	 * unpublish the category by id
108
	 *
109
	 * @since 4.0.0
110
	 *
111
	 * @param int $categoryId identifier of the category
112
	 *
113
	 * @return bool
114
	 */
115
116
	public function unpublishById(int $categoryId = null) : bool
117
	{
118
		return (bool)$this
119
			->query()
120
			->whereAnyIs(
121
			[
122
				[
123
					'id' =>	$categoryId
124
				],
125
				[
126
					'parent' => $categoryId
127
				],
128
				[
129
					'sibling' => $categoryId
130
				]
131
			])
132
			->findMany()
133
			->set('status', 0)
134
			->save();
135
	}
136
137
	/**
138
	 * delete the category by id
139
	 *
140
	 * @since 4.0.0
141
	 *
142
	 * @param int $categoryId identifier of the category
143
	 *
144
	 * @return bool
145
	 */
146
147
	public function deleteById(int $categoryId = null) : bool
148
	{
149
		return $this
150
		->query()
151
		->whereAnyIs(
152
		[
153
			[
154
				'id' =>	$categoryId
155
			],
156
			[
157
				'parent' => $categoryId
158
			],
159
			[
160
				'sibling' => $categoryId
161
			]
162
		])
163
		->deleteMany();
164
	}
165
}
166