'low', 'unread' => false, 'unreadStaff' => true, 'ticketNumber' => $this->generateUniqueTicketNumber() ); } public function store() { parent::store(); } public function generateUniqueTicketNumber() { $linearCongruentialGenerator = new LinearCongruentialGenerator(); $ticketQuantity = Ticket::count(); if ($ticketQuantity === 0) { $ticketNumber = Setting::getSetting('ticket-first-number')->value; } else { $linearCongruentialGenerator->setGap(Setting::getSetting('ticket-gap')->value); $linearCongruentialGenerator->setFirst(Setting::getSetting('ticket-first-number')->value); $ticketNumber = $linearCongruentialGenerator->generate($ticketQuantity); } return $ticketNumber; } public function toArray() { return [ 'ticketNumber' => $this->ticketNumber, 'title' => $this->title, 'content' => $this->content, 'department' => [ 'id' => $this->department->id, 'name' => $this->department->name ], 'date' => $this->date, 'file' => $this->file, 'language' => $this->language, 'unread' => !!$this->unread, 'unreadStaff' => !!$this->unreadStaff, 'closed' => !!$this->closed, 'priority' => $this->priority, 'author' => $this->authorToArray(), 'owner' => $this->ownerToArray(), 'events' => $this->eventsToArray() ]; } public function authorToArray() { $author = $this->author; if ($author && !$author->isNull()) { return [ 'id' => $author->id, 'name' => $author->name, 'email' => $author->email ]; } else { return [ 'name' => $this->authorName, 'email' => $this->authorEmail ]; } } public function ownerToArray() { $owner = $this->owner; if ($owner && !$owner->isNull()) { return [ 'id' => $owner->id, 'name' => $owner->name, 'email' => $owner->email ]; } else { return null; } } public function eventsToArray() { $events = []; foreach ($this->ownTicketeventList as $ticketEvent) { $event = [ 'type' => $ticketEvent->type, 'content'=> $ticketEvent->content, 'author' => [], 'date'=> $ticketEvent->date, 'file'=> $ticketEvent->file ]; $author = $ticketEvent->getAuthor(); if(!$author->isNull()) { $event['author'] = [ 'id'=> $author->id, 'name' => $author->name, 'email' =>$author->email, 'profilePic' => ($author instanceof Staff) ? $author->profilePic : null, 'staff' => $author instanceof Staff ]; } $events[] = $event; } return $events; } public function addEvent(Ticketevent $event) { $this->ownTicketeventList->add($event); } }