Attendize/app/Http/Controllers/Admin/HelpTicketCrudController.php

136 lines
4.7 KiB
PHP
Raw Normal View History

2020-04-29 11:48:01 +00:00
<?php
namespace App\Http\Controllers\Admin;
2020-05-06 15:53:50 +00:00
use App\Http\Requests\HelpTicketCommentRequest;
2020-05-05 10:59:31 +00:00
use App\Models\HelpTicket;
2020-05-06 15:53:50 +00:00
use App\Models\HelpTicketComment;
use App\Notifications\TicketCommented;
2020-04-29 11:48:01 +00:00
use Backpack\CRUD\app\Http\Controllers\CrudController;
// VALIDATION: change the requests to match your own file names if you need form validation
use App\Http\Requests\HelpTicketRequest as StoreRequest;
use App\Http\Requests\HelpTicketRequest as UpdateRequest;
use Backpack\CRUD\CrudPanel;
2020-05-06 15:53:50 +00:00
use Illuminate\Support\Facades\Notification;
2020-04-29 11:48:01 +00:00
/**
* Class HelpTicletCrudController
* @package App\Http\Controllers\Admin
* @property-read CrudPanel $crud
*/
class HelpTicketCrudController extends CrudController
{
public function setup()
{
/*
|--------------------------------------------------------------------------
| CrudPanel Basic Information
|--------------------------------------------------------------------------
*/
$this->crud->setModel('App\Models\HelpTicket');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/helpTicket');
$this->crud->setEntityNameStrings('help ticket', 'help tickets');
/*
|--------------------------------------------------------------------------
| CrudPanel Configuration
|--------------------------------------------------------------------------
*/
// TODO: remove setFromDb() and manually define Fields and Columns
2020-05-05 08:34:35 +00:00
// $this->crud->setFromDb();
2020-04-29 11:48:01 +00:00
2020-05-05 08:34:35 +00:00
$this->crud->setColumns([
['name'=>'code','type'=>'text','label'=>'Code'],
['name'=>'name','type'=>'text','label'=>'Name'],
['name'=>'phone','type'=>'text','label'=>'Phone'],
['name'=>'email','type'=>'email','label'=>'Email'],
['name'=>'subject','type'=>'text','label'=>'Subject'],
['name'=>'status','type'=>'text','label'=>'Status'],
2020-06-02 08:13:35 +00:00
['name'=>'updated_at','type'=>'datetime','Update']
2020-05-05 08:34:35 +00:00
]);
2020-04-29 11:48:01 +00:00
// add asterisk for fields that are required in HelpTicletRequest
2020-05-05 08:40:29 +00:00
// $this->crud->setRequiredFields(StoreRequest::class, 'create');
// $this->crud->setRequiredFields(UpdateRequest::class, 'edit');
2020-05-05 08:42:27 +00:00
$this->crud->denyAccess('create');
$this->crud->denyAccess('update');
2020-05-05 08:47:49 +00:00
$this->crud->allowAccess('show');
2020-05-05 08:58:50 +00:00
$this->crud->addButtonFromView('line', 'replay', 'replay', 'beginning');
2020-05-05 08:40:29 +00:00
2020-06-02 08:50:37 +00:00
$this->crud->addFilter([ // dropdown filter
'name' => 'status',
'type' => 'dropdown',
'label'=> 'Status'
], [
1 => 'pending',
2 => 'waiting replay',
3 => 'solved',
], function($value) { // if the filter is active
$this->crud->addClause('where', 'status', $value);
});
backpack_user()->unreadNotifications->markAsRead();
2020-04-29 11:48:01 +00:00
}
2020-05-05 09:10:15 +00:00
public function show($id)
{
$content = parent::show($id);
2020-05-05 10:42:02 +00:00
// $this->crud->addColumn([
// 'name' => 'table',
// 'label' => 'Table',
// 'type' => 'table',
// 'columns' => [
// 'code' => 'Code',
// 'name' => 'Name',
// 'phone' => 'Phone',
// ]
// ]);
2020-05-05 09:10:15 +00:00
return $content;
}
2020-04-29 11:48:01 +00:00
public function store(StoreRequest $request)
{
// your additional operations before save here
$redirect_location = parent::storeCrud($request);
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
public function update(UpdateRequest $request)
{
// your additional operations before save here
$redirect_location = parent::updateCrud($request);
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
2020-05-05 08:58:50 +00:00
public function replay($id){
2020-05-05 10:59:31 +00:00
$entry = HelpTicket::with(['comments','topic'])->findOrFail($id);
return view('admin.HelpDeskTicket')
->with('entry',$entry)
->with('crud',$this->crud);
2020-05-05 08:58:50 +00:00
}
2020-05-06 15:53:50 +00:00
public function replayPost(HelpTicketCommentRequest $request, $ticket_id){
$ticket = HelpTicket::findOrFail($ticket_id,['id','email','name']);
$comment = HelpTicketComment::create([
'help_ticket_id' => $ticket_id,
'text' => $request->text,
'name' => auth()->user()->full_name,
'user_id' => auth()->id()
]);
2020-05-15 08:20:04 +00:00
$ticket->update(['status'=>'waiting_replay']);
2020-05-08 10:54:00 +00:00
2020-05-06 15:53:50 +00:00
Notification::route('mail', $ticket->email)
->notify(new TicketCommented($comment));
return redirect()->route('ticket.replay',['id'=>$ticket_id]);
}
2020-04-29 11:48:01 +00:00
}