Makes createLog function store authorName.

This commit is contained in:
Maxi Redigonda 2019-11-08 10:08:14 -03:00
parent f5f78a549c
commit bedf55d1ad
1 changed files with 17 additions and 5 deletions

View File

@ -22,13 +22,24 @@ class Log extends DataStore {
'authorUser',
'authorStaff',
'to',
'date'
'date',
'authorName'
];
}
public static function createLog($type,$to, $author = null) {
public static function createLog($type, $to, $author = null) {
$session = Session::getInstance();
$authorName = '';
if($session->isTicketSession()) {
$ticketNumber = $session->getTicketNumber();
$ticket = Ticket::getByTicketNumber($ticketNumber);
$authorName = $ticket->authorToArray()['name'];
}
if($author === null) {
$author = Controller::getLoggedUser();
if(!$author->isNull()) $authorName = $author->name;
}
$log = new Log();
@ -36,7 +47,8 @@ class Log extends DataStore {
$log->setProperties(array(
'type' => $type,
'to' => $to,
'date' => Date::getCurrentDate()
'date' => Date::getCurrentDate(),
'authorName' => $authorName
));
if($author instanceof User) {
@ -55,8 +67,8 @@ class Log extends DataStore {
'type' => $this->type,
'to' => $this->to,
'author' => [
'name' => $author->name,
'id' => $author->id,
'name' => $this->authorName,
'id' => !$author->isNull() ? $author->id : null,
'staff' => $author instanceof Staff
],
'date' => $this->date