opensupports/server/models/Staff.php

66 lines
2.1 KiB
PHP
Raw Normal View History

2016-09-24 21:26:37 +02:00
<?php
2017-04-21 05:34:20 +02:00
/**
* @api {OBJECT} Staff Staff
* @apiVersion 4.1.0
2017-04-21 05:34:20 +02:00
* @apiGroup Data Structures
2017-05-11 21:37:03 +02:00
* @apiParam {String} name Name of the staff member.
* @apiParam {String} email Email of the staff member.
* @apiParam {String} profilePic profilePic url of the staff member.
* @apiParam {Number} level Level of the staff member.
* @apiParam {Object[]} departments The departments the staff member has assigned.
* @apiParam {[Ticket](#api-Data_Structures-ObjectTicket)[]} tickets The tickets the staff member has assigned.
* @apiParam {Number} lastLogin The last login of the staff member.
* @apiParam {Boolean} sendEmailOnNewTicket Indicates the staff member receives a mail when a ticket is created.
2017-04-21 05:34:20 +02:00
*/
2016-09-24 21:26:37 +02:00
class Staff extends DataStore {
const TABLE = 'staff';
public static function authenticate($userEmail, $userPassword) {
$user = Staff::getUser($userEmail, 'email');
return ($user && Hashing::verifyPassword($userPassword, $user->password)) ? $user : new NullDataStore();
}
2016-09-24 21:26:37 +02:00
public static function getProps() {
return [
'name',
'email',
'password',
'profilePic',
'level',
'sharedDepartmentList',
'sharedTicketList',
'lastLogin',
'ownStatList',
'sendEmailOnNewTicket'
2016-09-24 21:26:37 +02:00
];
}
public function getDefaultProps() {
return [
'level' => 1,
'ownStatList' => new DataStoreList(),
'sendEmailOnNewTicket' => 0
2016-09-24 21:26:37 +02:00
];
}
public static function getUser($value, $property = 'id') {
return parent::getDataStore($value, $property);
}
2016-12-08 18:30:19 +01:00
public function toArray() {
return [
2016-12-08 18:30:19 +01:00
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'profilePic' => $this->profilePic,
'level' => $this->level,
'departments' => $this->sharedDepartmentList->toArray(),
'tickets' => $this->sharedTicketList->toArray(),
'lastLogin' => $this->lastLogin ,
'sendEmailOnNewTicket' => $this->sendEmailOnNewTicket
];
}
2016-09-24 21:26:37 +02:00
}