|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Services; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* User service |
|
8
|
|
|
*/ |
|
9
|
|
|
class UserService extends BaseService |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Returns Role ID of logged user |
|
14
|
|
|
* |
|
15
|
|
|
* @param void |
|
16
|
|
|
* @return type |
|
17
|
|
|
*/ |
|
18
|
|
|
public function getRoleId() |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->skautis->getRoleId(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Returns all SkautIS roles |
|
26
|
|
|
* |
|
27
|
|
|
* @param bool $activeOnly only active roles |
|
28
|
|
|
* @return array all roles of logged user |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getAllSkautISRoles($activeOnly = true) |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->skautis->user->UserRoleAll(array("ID_User" => $this->getUserDetail()->ID, "IsActive" => $activeOnly)); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Gets user detail |
|
38
|
|
|
* |
|
39
|
|
|
* @param void |
|
40
|
|
|
* @return res |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getUserDetail() |
|
43
|
|
|
{ |
|
44
|
|
|
$id = __FUNCTION__; |
|
45
|
|
|
// cache by the request |
|
46
|
|
|
if (!($res = $this->load($id))) { |
|
47
|
|
|
$res = $this->save($id, $this->skautis->user->UserDetail()); |
|
48
|
|
|
} |
|
49
|
|
|
return $res; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Changes the loggeed user SkautIS role |
|
55
|
|
|
* |
|
56
|
|
|
* @param ID_Role $id |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
|
|
public function updateSkautISRole($id) |
|
60
|
|
|
{ |
|
61
|
|
|
$unitId = $this->skautis->user->LoginUpdate(array("ID_UserRole" => $id, "ID" => $this->skautis->getToken())); |
|
|
|
|
|
|
62
|
|
|
if ($unitId) { |
|
63
|
|
|
$this->skautis->setRoleId($id); |
|
64
|
|
|
$this->skautis->setUnitId($unitId->ID_Unit); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Returns complete list of information about logged user |
|
71
|
|
|
* |
|
72
|
|
|
* @param void |
|
73
|
|
|
* @return type |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getPersonalDetail($personId = null) |
|
76
|
|
|
{ |
|
77
|
|
|
if(!$personId) { |
|
78
|
|
|
$personId = $this->getUserDetail()->ID_Person; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $this->skautis->org->personDetail((["ID" => $personId])); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Returns complete list of information about logged user unit |
|
86
|
|
|
* |
|
87
|
|
|
* @param void |
|
88
|
|
|
* @return type |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getParentUnitDetail($unitId) |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->skautis->org->unitAll((array("ID_UnitChild" => $unitId))); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Returns complete list of information about logged user unit |
|
97
|
|
|
* |
|
98
|
|
|
* @param void |
|
99
|
|
|
* @return type |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getUnitDetail($unitId) |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->skautis->org->unitDetail((array("ID" => $unitId))); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Returns complete list of information about logged user unit |
|
108
|
|
|
* |
|
109
|
|
|
* @param void |
|
110
|
|
|
* @return type |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getPersonUnitDetail($personId) |
|
113
|
|
|
{ |
|
114
|
|
|
$membership = $this->skautis->org->membershipAllPerson((array('ID_Person' => $personId, "ID_MembershipType" => "radne"))); |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
return $membership->MembershipAllOutput; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Check if login session is still valid |
|
121
|
|
|
* |
|
122
|
|
|
* @param void |
|
123
|
|
|
* @return type |
|
124
|
|
|
*/ |
|
125
|
|
|
public function isLoggedIn() |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->skautis->getUser()->isLoggedIn(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Resets login data |
|
133
|
|
|
* |
|
134
|
|
|
* @param void |
|
135
|
|
|
* @return void |
|
136
|
|
|
*/ |
|
137
|
|
|
public function resetLoginData() |
|
138
|
|
|
{ |
|
139
|
|
|
$this->skautis->resetLoginData(); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Verify action |
|
145
|
|
|
* |
|
146
|
|
|
* @param type $table např. ID_EventGeneral, NULL = oveření nad celou tabulkou |
|
147
|
|
|
* @param type $id id ověřované akce - např EV_EventGeneral_UPDATE |
|
148
|
|
|
* @param type $ID_Action tabulka v DB skautisu |
|
149
|
|
|
* @return BOOL|stdClass|array |
|
150
|
|
|
*/ |
|
151
|
|
|
public function actionVerify($table, $id = NULL, $ID_Action = NULL) |
|
|
|
|
|
|
152
|
|
|
{ |
|
153
|
|
|
$res = $this->skautis->user->ActionVerify(array( |
|
154
|
|
|
"ID" => $id, |
|
|
|
|
|
|
155
|
|
|
"ID_Table" => $table, |
|
|
|
|
|
|
156
|
|
|
"ID_Action" => $ID_Action, |
|
|
|
|
|
|
157
|
|
|
)); |
|
158
|
|
|
|
|
159
|
|
|
// returns boolean if certain function for verifying is set |
|
160
|
|
|
if ($ID_Action !== NULL) { |
|
161
|
|
|
if ($res instanceof stdClass) { |
|
|
|
|
|
|
162
|
|
|
return false; |
|
163
|
|
|
} |
|
164
|
|
|
if (is_array($res)) { |
|
165
|
|
|
return true; |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
if (is_array($res)) { |
|
169
|
|
|
$tmp = array(); |
|
170
|
|
|
foreach ($res as $v) { |
|
171
|
|
|
$tmp[$v->ID] = $v; |
|
172
|
|
|
} |
|
173
|
|
|
return $tmp; |
|
174
|
|
|
} |
|
175
|
|
|
return $res; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
} |
|
179
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'or with double quotes"literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\') and the backslash (\\). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is ValueIf your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.