'user', 'authorStaff' => 'staff', ]; } 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(); $log->setProperties(array( 'type' => $type, 'to' => $to, 'date' => Date::getCurrentDate(), 'authorName' => $authorName )); if($author instanceof User) { $log->authorUser = $author; } else { $log->authorStaff = $author; } $log->store(); } public function toArray() { $author = ($this->authorUser instanceof User) ? $this->authorUser : $this->authorStaff; return [ 'type' => $this->type, 'to' => $this->to, 'author' => [ 'name' => $this->authorName, 'id' => ($author && !$author->isNull()) ? $author->id : null, 'staff' => $author instanceof Staff ], 'date' => $this->date ]; } }