Makes createLog function store authorName.

This commit is contained in:
Maxi Redigonda 2019-11-08 10:08:14 -03:00
parent f5f78a549c
commit bedf55d1ad

View File

@ -22,13 +22,24 @@ class Log extends DataStore {
'authorUser', 'authorUser',
'authorStaff', 'authorStaff',
'to', '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) { if($author === null) {
$author = Controller::getLoggedUser(); $author = Controller::getLoggedUser();
if(!$author->isNull()) $authorName = $author->name;
} }
$log = new Log(); $log = new Log();
@ -36,7 +47,8 @@ class Log extends DataStore {
$log->setProperties(array( $log->setProperties(array(
'type' => $type, 'type' => $type,
'to' => $to, 'to' => $to,
'date' => Date::getCurrentDate() 'date' => Date::getCurrentDate(),
'authorName' => $authorName
)); ));
if($author instanceof User) { if($author instanceof User) {
@ -55,8 +67,8 @@ class Log extends DataStore {
'type' => $this->type, 'type' => $this->type,
'to' => $this->to, 'to' => $this->to,
'author' => [ 'author' => [
'name' => $author->name, 'name' => $this->authorName,
'id' => $author->id, 'id' => !$author->isNull() ? $author->id : null,
'staff' => $author instanceof Staff 'staff' => $author instanceof Staff
], ],
'date' => $this->date 'date' => $this->date