2016-12-29 01:55:00 +01:00
|
|
|
<?php
|
|
|
|
use RedBeanPHP\Facade as RedBean;
|
|
|
|
|
|
|
|
class Log extends DataStore {
|
|
|
|
const TABLE = 'log';
|
|
|
|
|
|
|
|
public static function getProps() {
|
|
|
|
return [
|
|
|
|
'type',
|
2016-12-29 06:04:35 +01:00
|
|
|
'authorUser',
|
2016-12-29 01:55:00 +01:00
|
|
|
'authorStaff',
|
|
|
|
'to'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
public static function createLog($type,$to, $author = null) {
|
|
|
|
if($author === null) {
|
|
|
|
$author = Controller::getLoggedUser();
|
|
|
|
}
|
|
|
|
$log = new Log();
|
|
|
|
|
|
|
|
$log->setProperties(array(
|
|
|
|
'type' => $type,
|
2016-12-29 06:04:35 +01:00
|
|
|
'authorUser' => (!$author->isNull() && !$author->staff) ? $author : null,
|
2016-12-29 01:55:00 +01:00
|
|
|
'authorStaff' => (!$author->isNull() && $author->staff) ? $author : null,
|
|
|
|
'to' => $to,
|
|
|
|
));
|
|
|
|
$log->store();
|
|
|
|
}
|
2016-12-29 06:04:35 +01:00
|
|
|
public function toArray() {
|
|
|
|
return [
|
|
|
|
'type' => $this->type,
|
|
|
|
'to' => $this->to,
|
|
|
|
'author' => ($this->authorUser) ? $this->authorUser->toArray() : $this->authorStaff->toArray()
|
|
|
|
];
|
|
|
|
}
|
2016-12-29 01:55:00 +01:00
|
|
|
}
|