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

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

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 user model
8
 *
9
 * @since 4.0.0
10
 *
11
 * @package Redaxscript
12
 * @category Model
13
 * @author Henry Ruhs
14
 */
15
16
class User extends BaseModel\User
17
{
18
	/**
19
	 * is unique by id and user
20
	 *
21
	 * @since 4.5.0
22
	 *
23
	 * @param int $userId identifier of the user
24
	 * @param string $userUser user of the user
25
	 *
26
	 * @return bool
27
	 */
28
29
	public function isUniqueByIdAndUser(int $userId = null, string $userUser = null) : bool
30
	{
31
		return !$this->getByUser($userUser)?->id || $this->getByUser($userUser)?->id === $this->getById($userId)?->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
	 * update the user by id and array
36
	 *
37
	 * @since 4.0.0
38
	 *
39
	 * @param int $userId identifier of the user
40
	 * @param array $updateArray array of the update
41
	 *
42
	 * @return bool
43
	 */
44
45
	public function updateByIdAndArray(int $userId = null, array $updateArray = []) : bool
46
	{
47
		return $this
48
			->query()
49
			->whereIdIs($userId)
50
			->findOne()
51
			->set($updateArray)
52
			->save();
53
	}
54
55
	/**
56
	 * update last by id
57
	 *
58
	 * @since 4.0.0
59
	 *
60
	 * @param int $userId id of the user
61
	 * @param int $date timestamp of the date
62
	 *
63
	 * @return bool
64
	 */
65
66
	public function updateLastById(int $userId = null, int $date = null) : bool
67
	{
68
		return $this
69
			->query()
70
			->whereIdIs($userId)
71
			->findOne()
72
			->set('last', $date)
73
			->save();
74
	}
75
76
	/**
77
	 * enable the user by id
78
	 *
79
	 * @since 4.0.0
80
	 *
81
	 * @param int $userId identifier of the user
82
	 *
83
	 * @return bool
84
	 */
85
86
	public function enableById(int $userId = null) : bool
87
	{
88
		return $this
89
			->query()
90
			->whereIdIs($userId)
91
			->findOne()
92
			->set('status', 1)
93
			->save();
94
	}
95
96
	/**
97
	 * disable the user by id
98
	 *
99
	 * @since 4.0.0
100
	 *
101
	 * @param int $userId identifier of the user
102
	 *
103
	 * @return bool
104
	 */
105
106
	public function disableById(int $userId = null) : bool
107
	{
108
		return $this
109
			->query()
110
			->whereIdIs($userId)
111
			->findOne()
112
			->set('status', 0)
113
			->save();
114
	}
115
116
	/**
117
	 * delete the user by id
118
	 *
119
	 * @since 4.0.0
120
	 *
121
	 * @param int $userId identifier of the user
122
	 *
123
	 * @return bool
124
	 */
125
126
	public function deleteById(int $userId = null) : bool
127
	{
128
		return $this
129
			->query()
130
			->whereIdIs($userId)
131
			->deleteMany();
132
	}
133
}
134