Newer
Older
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief User Model
* @author dev@maarch.org
* @ingroup core
*/
namespace Core\Models;
require_once 'apps/maarch_entreprise/services/Table.php';
class UserModelAbstract extends \Apps_Table_Service
{
static::checkRequired($aArgs, ['userId']);
static::checkString($aArgs, ['userId']);
$aReturn = static::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['users'],
'where' => ['user_id = ?'],
'data' => [$aArgs['userId']],
static::checkRequired($aArgs, ['mail']);
static::checkString($aArgs, ['mail']);
$aReturn = static::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['users'],
'where' => ['mail = ? and status = ?'],
'data' => [$aArgs['mail'], 'OK'],
'limit' => 1,
public static function update(array $aArgs = [])
{
static::checkRequired($aArgs, ['user', 'userId']);
static::checkRequired($aArgs['user'], ['firstname', 'lastname']);
static::checkString($aArgs['user'], ['firstname', 'lastname', 'mail', 'initials', 'thumbprint', 'phone']);
'table' => 'users',
'set' => [
'firstname' => $aArgs['user']['firstname'],
'lastname' => $aArgs['user']['lastname'],
'mail' => $aArgs['user']['mail'],
'phone' => $aArgs['user']['phone'],
'initials' => $aArgs['user']['initials'],
'thumbprint' => $aArgs['user']['thumbprint']
],
'where' => ['user_id = ?'],
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
return $isUpdated;
}
public static function updatePassword(array $aArgs = [])
{
static::checkRequired($aArgs, ['userId', 'password']);
static::checkString($aArgs, ['userId', 'password']);
$isUpdated = parent::update([
'table' => 'users',
'set' => [
'password' => SecurityModel::getPasswordHash($aArgs['password'])
],
'where' => ['user_id = ?'],
'data' => [$aArgs['userId']]
]);
return $isUpdated;
}
public static function checkPassword(array $aArgs = [])
{
static::checkRequired($aArgs, ['userId', 'password']);
static::checkString($aArgs, ['userId', 'password']);
$aReturn = parent::select([
'select' => ['password'],
'table' => 'users',
'where' => ['user_id = ?'],
'data' => [$aArgs['userId']]
]);
if ($aReturn[0]['password'] === SecurityModel::getPasswordHash($aArgs['password'])) {
return true;
} else {
return false;
}
public static function getSignaturesById(array $aArgs = [])
{
static::checkRequired($aArgs, ['userId']);
static::checkString($aArgs, ['userId']);
$aReturn = static::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['user_signatures'],
'where' => ['user_id = ?'],
'data' => [$aArgs['userId']],
]);
if (!empty($aReturn)) {
$docserver = DocserverModel::getByTypeId(['docserver_type_id' => 'TEMPLATES', 'select' => ['path_template']]);
}
foreach($aReturn as $key => $value) {
$pathToSignature = $docserver[0]['path_template'] . str_replace('#', '/', $value['signature_path']) . $value['signature_file_name'];
$extension = explode('.', $pathToSignature);
$extension = $extension[count($extension) - 1];
$fileNameOnTmp = 'tmp_file_' . $_SESSION['user']['UserId'] . '_' . rand() . '.' . strtolower($extension);
$filePathOnTmp = $_SESSION['config']['tmppath'] . $fileNameOnTmp; // TODO No Session
if (copy($pathToSignature, $filePathOnTmp)) {
$aReturn[$key]['pathToSignatureOnTmp'] = $_SESSION['config']['businessappurl'] . '/tmp/' . $fileNameOnTmp;
} else {
$aReturn[$key]['pathToSignatureOnTmp'] = '';
}
}
return $aReturn;
}
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
public static function createSignature(array $aArgs = [])
{
static::checkRequired($aArgs, ['userId', 'signatureLabel', 'signaturePath', 'signatureFileName']);
static::checkString($aArgs, ['userId', 'signatureLabel', 'signaturePath', 'signatureFileName']);
parent::insertInto(
[
'user_id' => $aArgs['userId'],
'signature_label' => $aArgs['signatureLabel'],
'signature_path' => $aArgs['signaturePath'],
'signature_file_name' => $aArgs['signatureFileName']
],
'user_signatures'
);
return true;
}
public static function deleteSignature(array $aArgs = [])
{
static::checkRequired($aArgs, ['signatureId']);
static::checkNumeric($aArgs, ['signatureId']);
$where = ['id = ?'];
$data = [$aArgs['signatureId']];
if (!empty($aArgs['userId'])) {
$where[] = 'user_id = ?';
$data[] = $aArgs['userId'];
}
parent::deleteFrom([
'table' => 'user_signatures',
'where' => $where,
'data' => $data,
]);
return true;
}
public static function getEmailSignaturesById(array $aArgs = [])
{
static::checkRequired($aArgs, ['userId']);
static::checkString($aArgs, ['userId']);
$aReturn = static::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['users_email_signatures'],
'where' => ['user_id = ?'],
'data' => [$aArgs['userId']],
]);
return $aReturn;
}
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
public static function getLabelledUserById(array $aArgs = [])
{
static::checkRequired($aArgs, ['id']);
static::checkString($aArgs, ['id']);
$rawUser = self::getById(['userId' => $aArgs['id'], 'select' => ['firstname', 'lastname']]);
$labelledUser = '';
if (!empty($rawUser)) {
$labelledUser = $rawUser['firstname']. ' ' .$rawUser['lastname'];
}
return $labelledUser;
}
public static function getSignatureForCurrentUser()
{
//TODO No Session
if (empty($_SESSION['user']['pathToSignature'][0]) || !file_exists($_SESSION['user']['pathToSignature'][0])) {
return [];
}
$aSignature = [
'signaturePath' => $_SESSION['user']['signature_path'],
'signatureFileName' => $_SESSION['user']['signature_file_name'],
'pathToSignature' => $_SESSION['user']['pathToSignature'][0]
];
$extension = explode('.', $aSignature['pathToSignature']);
$extension = $extension[count($extension) - 1];
$fileNameOnTmp = 'tmp_file_' . $_SESSION['user']['UserId'] . '_' . rand() . '.' . strtolower($extension);
$filePathOnTmp = $_SESSION['config']['tmppath'] . $fileNameOnTmp;
if (!copy($aSignature['pathToSignature'], $filePathOnTmp)) {
return $aSignature;
}
$aSignature['pathToSignatureOnTmp'] = $_SESSION['config']['businessappurl'] . '/tmp/' . $fileNameOnTmp;
return $aSignature;
}
public static function getCurrentConsigneById(array $aArgs = [])
{
static::checkRequired($aArgs, ['resId']);
static::checkNumeric($aArgs, ['resId']);
$aReturn = static::select([
'select' => ['process_comment'],
'table' => ['listinstance'],
'where' => ['res_id = ?', 'process_date is null', 'item_mode in (?)'],
'data' => [$aArgs['resId'], ['visa', 'sign']],
'order_by' => 'listinstance_id ASC',
'limit' => 1
]);
if (empty($aReturn[0])) {
return '';
}
return $aReturn[0]['process_comment'];
}
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
public static function getGroupsById(array $aArgs = [])
{
static::checkRequired($aArgs, ['userId']);
static::checkString($aArgs, ['userId']);
$aGroups = static::select([
'select' => ['usergroup_content.group_id', 'usergroups.group_desc', 'usergroup_content.primary_group'],
'table' => ['usergroup_content, usergroups'],
'where' => ['usergroup_content.group_id = usergroups.group_id', 'usergroup_content.user_id = ?'],
'data' => [$aArgs['userId']]
]);
return $aGroups;
}
public static function getEntitiesById(array $aArgs = [])
{
static::checkRequired($aArgs, ['userId']);
static::checkString($aArgs, ['userId']);
$aEntities = static::select([
'select' => ['users_entities.entity_id', 'entities.entity_label', 'users_entities.primary_entity'],
'table' => ['users_entities, entities'],
'where' => ['users_entities.entity_id = entities.entity_id', 'users_entities.user_id = ?'],
'data' => [$aArgs['userId']]
]);
return $aEntities;
}