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

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

Labels
Severity

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 extra model
8
 *
9
 * @since 4.0.0
10
 *
11
 * @package Redaxscript
12
 * @category Model
13
 * @author Henry Ruhs
14
 */
15
16
class Extra extends BaseModel\Extra
17
{
18
	/**
19
	 * is unique by id and alias
20
	 *
21
	 * @since 4.0.0
22
	 *
23
	 * @param int $extraId identifier of the extra
24
	 * @param string $extraAlias alias of the extra
25
	 *
26
	 * @return bool
27
	 */
28
29
	public function isUniqueByIdAndAlias(int $extraId = null, string $extraAlias = null) : bool
30
	{
31
		return !$this->getByAlias($extraAlias)?->id || $this->getByAlias($extraAlias)?->id === $this->getById($extraId)?->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...
32
	}
33
34
	/**
35
	 * create the extra by array
36
	 *
37
	 * @since 4.0.0
38
	 *
39
	 * @param array $createArray array of the create
40
	 *
41
	 * @return bool
42
	 */
43
44
	public function createByArray(array $createArray = []) : bool
45
	{
46
		return $this
47
			->query()
48
			->create()
49
			->set($createArray)
50
			->save();
51
	}
52
53
	/**
54
	 * update the extra by id and array
55
	 *
56
	 * @since 4.0.0
57
	 *
58
	 * @param int $extraId identifier of the extra
59
	 * @param array $updateArray array of the update
60
	 *
61
	 * @return bool
62
	 */
63
64
	public function updateByIdAndArray(int $extraId = null, array $updateArray = []) : bool
65
	{
66
		return $this
67
			->query()
68
			->whereIdIs($extraId)
69
			->findOne()
70
			->set($updateArray)
71
			->save();
72
	}
73
74
	/**
75
	 * publish the extra by id
76
	 *
77
	 * @since 4.0.0
78
	 *
79
	 * @param int $extraId identifier of the extra
80
	 *
81
	 * @return bool
82
	 */
83
84
	public function publishById(int $extraId = null) : bool
85
	{
86
		return (bool)$this
87
			->query()
88
			->whereAnyIs(
89
			[
90
				[
91
					'id' =>	$extraId
92
				],
93
				[
94
					'sibling' => $extraId
95
				]
96
			])
97
			->findMany()
98
			->set('status', 1)
99
			->save();
100
	}
101
102
	/**
103
	 * unpublish the extra by id
104
	 *
105
	 * @since 4.0.0
106
	 *
107
	 * @param int $extraId identifier of the extra
108
	 *
109
	 * @return bool
110
	 */
111
112
	public function unpublishById(int $extraId = null) : bool
113
	{
114
		return (bool)$this
115
			->query()
116
			->whereAnyIs(
117
			[
118
				[
119
					'id' =>	$extraId
120
				],
121
				[
122
					'sibling' => $extraId
123
				]
124
			])
125
			->findMany()
126
			->set('status', 0)
127
			->save();
128
	}
129
130
	/**
131
	 * delete the extra by id
132
	 *
133
	 * @since 4.0.0
134
	 *
135
	 * @param int $extraId identifier of the extra
136
	 *
137
	 * @return bool
138
	 */
139
140
	public function deleteById(int $extraId = null) : bool
141
	{
142
		return $this
143
			->query()
144
			->whereAnyIs(
145
			[
146
				[
147
					'id' =>	$extraId
148
				],
149
				[
150
					'sibling' => $extraId
151
				]
152
			])
153
			->deleteMany();
154
	}
155
}
156