/** * Loads ticket selected with page slug */ public function onRun() { $hash = $this->property('slug'); $creator = \Auth::getUser(); $ticket = Ticket::where('hash_id', $hash)->where('creator_id', $creator->id)->first(); $ticketFiles = TicketAttachment::where('ticket_id', $ticket->id)->get(); $this->page['ticket'] = $ticket; $this->page['ticket_files'] = $ticketFiles; }
/** * @return mixed */ public function index_onDelete() { if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) { $allvalues = array(); foreach ($checkedIds as $postId) { if (!($file = TicketAttachment::find($postId)) || !$file->canEdit($this->user)) { continue; } $unlink = unlink($_SERVER['DOCUMENT_ROOT'] . $file->file_path); $allvalues[] = $unlink; if ($unlink) { $file->delete(); } } if (count(array_unique($allvalues)) === 1 && end($allvalues) === true) { Flash::success('Successfully deleted those files.'); } else { Flash::error('Some files could not be deleted.'); } } return $this->listRefresh(); }
/** * Puts file entry in the database * * @param string $fileName * @param string $filePath * @param integer $tid * @param array $file * * @return TicketAttachment * @throws \Exception */ private function createAttachment($fileName, $filePath, $tid, $file) { DB::beginTransaction(); try { $attachment = new TicketAttachment(); $attachment->file_name = $fileName; $attachment->file_path = $filePath; $attachment->ticket_id = $tid; $attachment->file_size = $file['size']; $attachment->content_type = $file['type']; $attachment->user_id = $tid; $attachment->save(); } catch (\Exception $e) { DB::rollback(); throw new \Exception($e); //todo } DB::commit(); return $attachment; //todo think if necessary }