Apply fixes from StyleCI
This commit is contained in:

committed by
StyleCI Bot

parent
857d3004eb
commit
88f3df2180
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\v1;
|
||||
|
||||
use App\Http\Controllers\Agent\helpdesk\TicketController as CoreTicketController;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\helpdesk\TicketRequest;
|
||||
//use Illuminate\Support\Facades\Request as Value;
|
||||
use App\Http\Requests\helpdesk\TicketRequest;
|
||||
use App\Model\helpdesk\Agent\Department;
|
||||
use App\Model\helpdesk\Agent\Teams;
|
||||
use App\Model\helpdesk\Manage\Help_topic;
|
||||
@@ -20,7 +21,6 @@ use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use App\Http\Controllers\Agent\helpdesk\TicketController as CoreTicketController;
|
||||
|
||||
/**
|
||||
* -----------------------------------------------------------------------------
|
||||
@@ -34,8 +34,8 @@ use App\Http\Controllers\Agent\helpdesk\TicketController as CoreTicketController
|
||||
*
|
||||
* @version v1
|
||||
*/
|
||||
class ApiController extends Controller {
|
||||
|
||||
class ApiController extends Controller
|
||||
{
|
||||
public $user;
|
||||
public $request;
|
||||
public $ticket;
|
||||
@@ -55,7 +55,8 @@ class ApiController extends Controller {
|
||||
/**
|
||||
* @param Request $request
|
||||
*/
|
||||
public function __construct(Request $request) {
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
|
||||
$this->middleware('jwt.auth');
|
||||
@@ -64,9 +65,7 @@ class ApiController extends Controller {
|
||||
$user = \JWTAuth::parseToken()->authenticate();
|
||||
$this->user = $user;
|
||||
} catch (\Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
|
||||
|
||||
} catch (\Tymon\JWTAuth\Exceptions\JWTException $e) {
|
||||
|
||||
}
|
||||
|
||||
$ticket = new TicketController();
|
||||
@@ -121,7 +120,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function createTicket(\App\Http\Requests\helpdesk\CreateTicketRequest $request, \App\Model\helpdesk\Utility\CountryCode $code) {
|
||||
public function createTicket(\App\Http\Requests\helpdesk\CreateTicketRequest $request, \App\Model\helpdesk\Utility\CountryCode $code)
|
||||
{
|
||||
try {
|
||||
$user_id = $this->request->input('user_id');
|
||||
|
||||
@@ -148,7 +148,7 @@ class ApiController extends Controller {
|
||||
$PhpMailController = new \App\Http\Controllers\Common\PhpMailController();
|
||||
$NotificationController = new \App\Http\Controllers\Common\NotificationController();
|
||||
$core = new CoreTicketController($PhpMailController, $NotificationController);
|
||||
$response = $core->post_newticket($request, $code,true);
|
||||
$response = $core->post_newticket($request, $code, true);
|
||||
//$response = $this->ticket->createTicket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data, $attach);
|
||||
//return $response;
|
||||
/*
|
||||
@@ -179,11 +179,12 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function ticketReply() {
|
||||
public function ticketReply()
|
||||
{
|
||||
//dd($this->request->all());
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'ticket_ID' => 'required|exists:tickets,id',
|
||||
'ticket_ID' => 'required|exists:tickets,id',
|
||||
'reply_content' => 'required',
|
||||
]);
|
||||
if ($v->fails()) {
|
||||
@@ -193,9 +194,10 @@ class ApiController extends Controller {
|
||||
}
|
||||
$attach = $this->request->input('attachments');
|
||||
$result = $this->ticket->reply($this->thread, $this->request, $this->attach, $attach);
|
||||
$result = $result->join('users','ticket_thread.user_id','=','users.id')
|
||||
->select('ticket_thread.*','users.first_name as first_name')
|
||||
$result = $result->join('users', 'ticket_thread.user_id', '=', 'users.id')
|
||||
->select('ticket_thread.*', 'users.first_name as first_name')
|
||||
->first();
|
||||
|
||||
return response()->json(compact('result'));
|
||||
} catch (\Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
@@ -215,14 +217,15 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function editTicket() {
|
||||
public function editTicket()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'ticket_id' => 'required|exists:tickets,id',
|
||||
'subject' => 'required',
|
||||
'sla_plan' => 'required|exists:sla_plan,id',
|
||||
'help_topic' => 'required|exists:help_topic,id',
|
||||
'ticket_source' => 'required|exists:ticket_source,id',
|
||||
'ticket_id' => 'required|exists:tickets,id',
|
||||
'subject' => 'required',
|
||||
'sla_plan' => 'required|exists:sla_plan,id',
|
||||
'help_topic' => 'required|exists:help_topic,id',
|
||||
'ticket_source' => 'required|exists:ticket_source,id',
|
||||
'ticket_priority' => 'required|exists:ticket_priority,priority_id',
|
||||
]);
|
||||
if ($v->fails()) {
|
||||
@@ -252,7 +255,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function deleteTicket() {
|
||||
public function deleteTicket()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'ticket_id' => 'required|exists:tickets,id',
|
||||
@@ -285,15 +289,16 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function openedTickets() {
|
||||
public function openedTickets()
|
||||
{
|
||||
try {
|
||||
// $result = $this->model->where('status', '=', 1)->where('isanswered', '=', 0)->where('assigned_to', '=', null)->orderBy('id', 'DESC')->get();
|
||||
// return response()->json(compact('result'));
|
||||
|
||||
$result = $this->user->join('tickets', function ($join) {
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
->where('isanswered', '=', 0)->where('status', '=', 1)->whereNull('assigned_to');
|
||||
})
|
||||
})
|
||||
->join('department', 'department.id', '=', 'tickets.dept_id')
|
||||
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
|
||||
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
|
||||
@@ -329,16 +334,17 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function unassignedTickets() {
|
||||
public function unassignedTickets()
|
||||
{
|
||||
try {
|
||||
//dd('sdhjbc');
|
||||
// $result = $this->model->where('assigned_to', '=', null)->where('status', '1')->orderBy('id', 'DESC')->get();
|
||||
// return response()->json(compact('result'));
|
||||
$user = \JWTAuth::parseToken()->authenticate();
|
||||
$unassigned = $this->user->join('tickets', function ($join) {
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
->whereNull('assigned_to')->where('status', '=', 1);
|
||||
})
|
||||
})
|
||||
->join('department', 'department.id', '=', 'tickets.dept_id')
|
||||
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
|
||||
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
|
||||
@@ -349,7 +355,7 @@ class ApiController extends Controller {
|
||||
->whereNotNull('title');
|
||||
})
|
||||
->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
|
||||
->where(function($query) use($user) {
|
||||
->where(function ($query) use ($user) {
|
||||
if ($user->role != 'admin') {
|
||||
$query->where('tickets.dept_id', '=', $user->primary_dpt);
|
||||
}
|
||||
@@ -379,15 +385,16 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function closeTickets() {
|
||||
public function closeTickets()
|
||||
{
|
||||
try {
|
||||
// $result = $this->model->where('status', '>', 1)->where('status', '<', 4)->orderBy('id', 'DESC')->get();
|
||||
// return response()->json(compact('result'));
|
||||
$user = \JWTAuth::parseToken()->authenticate();
|
||||
$result = $this->user->join('tickets', function ($join) {
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
->where('status', '=', 3)->orWhere('status', '=', 2);
|
||||
})
|
||||
})
|
||||
->join('department', 'department.id', '=', 'tickets.dept_id')
|
||||
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
|
||||
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
|
||||
@@ -398,7 +405,7 @@ class ApiController extends Controller {
|
||||
->whereNotNull('title');
|
||||
})
|
||||
->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
|
||||
->where(function($query) use($user) {
|
||||
->where(function ($query) use ($user) {
|
||||
if ($user->role != 'admin') {
|
||||
$query->where('tickets.dept_id', '=', $user->primary_dpt);
|
||||
}
|
||||
@@ -428,7 +435,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function getAgents() {
|
||||
public function getAgents()
|
||||
{
|
||||
try {
|
||||
$result = $this->faveoUser->where('role', 'agent')->orWhere('role', 'admin')->where('active', 1)->get();
|
||||
|
||||
@@ -451,7 +459,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function getTeams() {
|
||||
public function getTeams()
|
||||
{
|
||||
try {
|
||||
$result = $this->team->get();
|
||||
|
||||
@@ -474,11 +483,12 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function assignTicket() {
|
||||
public function assignTicket()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'ticket_id' => 'required',
|
||||
'user' => 'required',
|
||||
'user' => 'required',
|
||||
]);
|
||||
if ($v->fails()) {
|
||||
$error = $v->errors();
|
||||
@@ -512,7 +522,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function getCustomers() {
|
||||
public function getCustomers()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'search' => 'required',
|
||||
@@ -523,7 +534,7 @@ class ApiController extends Controller {
|
||||
return response()->json(compact('error'));
|
||||
}
|
||||
$search = $this->request->input('search');
|
||||
$result = $this->faveoUser->where('first_name', 'like', '%' . $search . '%')->orWhere('last_name', 'like', '%' . $search . '%')->orWhere('user_name', 'like', '%' . $search . '%')->orWhere('email', 'like', '%' . $search . '%')->get();
|
||||
$result = $this->faveoUser->where('first_name', 'like', '%'.$search.'%')->orWhere('last_name', 'like', '%'.$search.'%')->orWhere('user_name', 'like', '%'.$search.'%')->orWhere('email', 'like', '%'.$search.'%')->get();
|
||||
|
||||
return response()->json(compact('result'))
|
||||
->header('X-Header-One', 'Header Value');
|
||||
@@ -546,7 +557,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function getCustomersWith() {
|
||||
public function getCustomersWith()
|
||||
{
|
||||
try {
|
||||
$users = $this->user
|
||||
->leftJoin('user_assign_organization', 'user_assign_organization.user_id', '=', 'users.id')
|
||||
@@ -577,7 +589,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function getCustomer() {
|
||||
public function getCustomer()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'user_id' => 'required',
|
||||
@@ -609,7 +622,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function searchTicket() {
|
||||
public function searchTicket()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'search' => 'required',
|
||||
@@ -620,7 +634,7 @@ class ApiController extends Controller {
|
||||
return response()->json(compact('error'));
|
||||
}
|
||||
$search = $this->request->input('search');
|
||||
$result = $this->thread->select('ticket_id')->where('title', 'like', '%' . $search . '%')->orWhere('body', 'like', '%' . $search . '%')->get();
|
||||
$result = $this->thread->select('ticket_id')->where('title', 'like', '%'.$search.'%')->orWhere('body', 'like', '%'.$search.'%')->get();
|
||||
|
||||
return response()->json(compact('result'));
|
||||
} catch (Exception $e) {
|
||||
@@ -641,7 +655,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function ticketThreads() {
|
||||
public function ticketThreads()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'id' => 'required',
|
||||
@@ -678,7 +693,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function checkUrl() {
|
||||
public function checkUrl()
|
||||
{
|
||||
//dd($this->request);
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
@@ -695,7 +711,7 @@ class ApiController extends Controller {
|
||||
$url = str_finish($url, '/');
|
||||
}
|
||||
|
||||
$url = $url . '/api/v1/helpdesk/check-url?api_key=' . $this->request->input('api_key') . '&token=' . \Config::get('app.token');
|
||||
$url = $url.'/api/v1/helpdesk/check-url?api_key='.$this->request->input('api_key').'&token='.\Config::get('app.token');
|
||||
$result = $this->CallGetApi($url);
|
||||
//dd($result);
|
||||
return response()->json(compact('result'));
|
||||
@@ -715,7 +731,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function urlResult() {
|
||||
public function urlResult()
|
||||
{
|
||||
return 'success';
|
||||
}
|
||||
|
||||
@@ -726,7 +743,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return type int|string|json
|
||||
*/
|
||||
public function callGetApi($url) {
|
||||
public function callGetApi($url)
|
||||
{
|
||||
$curl = curl_init($url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
@@ -735,7 +753,7 @@ class ApiController extends Controller {
|
||||
$response = curl_exec($curl);
|
||||
|
||||
if (curl_errno($curl)) {
|
||||
echo 'error:' . curl_error($curl);
|
||||
echo 'error:'.curl_error($curl);
|
||||
}
|
||||
|
||||
return $response;
|
||||
@@ -750,7 +768,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return type int|string|json
|
||||
*/
|
||||
public function callPostApi($url, $data) {
|
||||
public function callPostApi($url, $data)
|
||||
{
|
||||
$curl = curl_init($url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
@@ -760,7 +779,7 @@ class ApiController extends Controller {
|
||||
$response = curl_exec($curl);
|
||||
|
||||
if (curl_errno($curl)) {
|
||||
echo 'error:' . curl_error($curl);
|
||||
echo 'error:'.curl_error($curl);
|
||||
}
|
||||
|
||||
return $response;
|
||||
@@ -772,7 +791,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return type | json
|
||||
*/
|
||||
public function generateApiKey() {
|
||||
public function generateApiKey()
|
||||
{
|
||||
try {
|
||||
$set = $this->setting->where('id', '1')->first();
|
||||
//dd($set);
|
||||
@@ -806,7 +826,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function getHelpTopic() {
|
||||
public function getHelpTopic()
|
||||
{
|
||||
try {
|
||||
$result = $this->helptopic->get();
|
||||
|
||||
@@ -829,7 +850,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function getSlaPlan() {
|
||||
public function getSlaPlan()
|
||||
{
|
||||
try {
|
||||
$result = $this->slaPlan->get();
|
||||
|
||||
@@ -852,7 +874,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function getPriority() {
|
||||
public function getPriority()
|
||||
{
|
||||
try {
|
||||
$result = $this->priority->get();
|
||||
|
||||
@@ -875,7 +898,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function getDepartment() {
|
||||
public function getDepartment()
|
||||
{
|
||||
try {
|
||||
$result = $this->department->get();
|
||||
|
||||
@@ -898,7 +922,8 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return type json
|
||||
*/
|
||||
public function getTickets() {
|
||||
public function getTickets()
|
||||
{
|
||||
try {
|
||||
$tickets = $this->model->orderBy('created_at', 'desc')->paginate(10);
|
||||
$tickets->toJson();
|
||||
@@ -922,13 +947,14 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return type json
|
||||
*/
|
||||
public function inbox() {
|
||||
public function inbox()
|
||||
{
|
||||
try {
|
||||
$user = \JWTAuth::parseToken()->authenticate();
|
||||
$inbox = $this->user->join('tickets', function ($join) {
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
->where('status', '=', 1);
|
||||
})
|
||||
})
|
||||
->join('department', 'department.id', '=', 'tickets.dept_id')
|
||||
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
|
||||
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
|
||||
@@ -939,7 +965,7 @@ class ApiController extends Controller {
|
||||
->whereNotNull('ticket_thread.title');
|
||||
})
|
||||
->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'ticket_thread.title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name', 'department.id as department_id', 'users.primary_dpt as user_dpt')
|
||||
->where(function($query) use($user) {
|
||||
->where(function ($query) use ($user) {
|
||||
if ($user->role != 'admin') {
|
||||
$query->where('tickets.dept_id', '=', $user->primary_dpt);
|
||||
}
|
||||
@@ -949,6 +975,7 @@ class ApiController extends Controller {
|
||||
->distinct()
|
||||
->paginate(10)
|
||||
->toJson();
|
||||
|
||||
return $inbox;
|
||||
} catch (\Exception $ex) {
|
||||
$error = $ex->getMessage();
|
||||
@@ -968,12 +995,13 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return type json
|
||||
*/
|
||||
public function internalNote() {
|
||||
public function internalNote()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'userid' => 'required|exists:users,id',
|
||||
'userid' => 'required|exists:users,id',
|
||||
'ticketid' => 'required|exists:tickets,id',
|
||||
'body' => 'required',
|
||||
'body' => 'required',
|
||||
]);
|
||||
if ($v->fails()) {
|
||||
$error = $v->errors();
|
||||
@@ -1000,13 +1028,14 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function getTrash() {
|
||||
public function getTrash()
|
||||
{
|
||||
try {
|
||||
$user = \JWTAuth::parseToken()->authenticate();
|
||||
$trash = $this->user->join('tickets', function ($join) {
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
->where('status', '=', 5);
|
||||
})
|
||||
})
|
||||
->join('department', 'department.id', '=', 'tickets.dept_id')
|
||||
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
|
||||
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
|
||||
@@ -1017,7 +1046,7 @@ class ApiController extends Controller {
|
||||
->whereNotNull('title');
|
||||
})
|
||||
->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
|
||||
->where(function($query) use($user) {
|
||||
->where(function ($query) use ($user) {
|
||||
if ($user->role != 'admin') {
|
||||
$query->where('tickets.dept_id', '=', $user->primary_dpt);
|
||||
}
|
||||
@@ -1042,7 +1071,8 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function getMyTicketsAgent() {
|
||||
public function getMyTicketsAgent()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'user_id' => 'required|exists:users,id',
|
||||
@@ -1060,10 +1090,10 @@ class ApiController extends Controller {
|
||||
}
|
||||
//$user = \JWTAuth::parseToken()->authenticate();
|
||||
$result = $this->user->join('tickets', function ($join) use ($id) {
|
||||
$join->on('users.id', '=', 'tickets.assigned_to')
|
||||
$join->on('users.id', '=', 'tickets.assigned_to')
|
||||
->where('status', '=', 1);
|
||||
//->where('user_id', '=', $id);
|
||||
})
|
||||
})
|
||||
->join('department', 'department.id', '=', 'tickets.dept_id')
|
||||
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
|
||||
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
|
||||
@@ -1100,7 +1130,8 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function getMyTicketsUser() {
|
||||
public function getMyTicketsUser()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'user_id' => 'required|exists:users,id',
|
||||
@@ -1117,9 +1148,9 @@ class ApiController extends Controller {
|
||||
return response()->json(compact('error'));
|
||||
}
|
||||
$result = $this->user->join('tickets', function ($join) use ($id) {
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
->where('user_id', '=', $id);
|
||||
})
|
||||
})
|
||||
->join('department', 'department.id', '=', 'tickets.dept_id')
|
||||
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
|
||||
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
|
||||
@@ -1151,7 +1182,8 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function getTicketById() {
|
||||
public function getTicketById()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($this->request->all(), [
|
||||
'id' => 'required|exists:tickets,id',
|
||||
@@ -1163,7 +1195,7 @@ class ApiController extends Controller {
|
||||
}
|
||||
$id = $this->request->input('id');
|
||||
if (!$this->model->where('id', $id)->first()) {
|
||||
$error = 'There is no Ticket as ticket id: ' . $id;
|
||||
$error = 'There is no Ticket as ticket id: '.$id;
|
||||
|
||||
return response()->json(compact('error'));
|
||||
}
|
||||
@@ -1171,44 +1203,43 @@ class ApiController extends Controller {
|
||||
$join->on('users.id', '=', 'tickets.user_id')
|
||||
->where('tickets.id', '=', $id);
|
||||
});
|
||||
|
||||
|
||||
|
||||
$response = $this->differenciateHelpTopic($query)
|
||||
->leftJoin('department','tickets.dept_id','=',"department.id")
|
||||
->leftJoin('ticket_priority','tickets.priority_id','=','ticket_priority.priority_id')
|
||||
->leftJoin('ticket_status','tickets.status','=','ticket_status.id')
|
||||
->leftJoin('sla_plan','tickets.sla','=','sla_plan.id')
|
||||
->leftJoin('ticket_source','tickets.source','=','ticket_source.id');
|
||||
->leftJoin('department', 'tickets.dept_id', '=', 'department.id')
|
||||
->leftJoin('ticket_priority', 'tickets.priority_id', '=', 'ticket_priority.priority_id')
|
||||
->leftJoin('ticket_status', 'tickets.status', '=', 'ticket_status.id')
|
||||
->leftJoin('sla_plan', 'tickets.sla', '=', 'sla_plan.id')
|
||||
->leftJoin('ticket_source', 'tickets.source', '=', 'ticket_source.id');
|
||||
//$select = 'users.email','users.user_name','users.first_name','users.last_name','tickets.id','ticket_number','num_sequence','user_id','priority_id','sla','max_open_ticket','captcha','status','lock_by','lock_at','source','isoverdue','reopened','isanswered','is_deleted', 'closed','is_transfer','transfer_at','reopened_at','duedate','closed_at','last_message_at';
|
||||
|
||||
$result = $response->addSelect(
|
||||
'users.email',
|
||||
'users.user_name',
|
||||
'users.first_name',
|
||||
'users.last_name',
|
||||
'tickets.id',
|
||||
'ticket_number',
|
||||
'user_id',
|
||||
'users.email',
|
||||
'users.user_name',
|
||||
'users.first_name',
|
||||
'users.last_name',
|
||||
'tickets.id',
|
||||
'ticket_number',
|
||||
'user_id',
|
||||
'ticket_priority.priority_id',
|
||||
'ticket_priority.priority as priority_name',
|
||||
'department.name as dept_name',
|
||||
'ticket_status.name as status_name',
|
||||
'sla_plan.name as sla_name',
|
||||
'ticket_source.name as source_name',
|
||||
'sla_plan.id as sla',
|
||||
'ticket_status.id as status',
|
||||
'lock_by',
|
||||
'lock_at',
|
||||
'ticket_source.id as source',
|
||||
'isoverdue',
|
||||
'reopened',
|
||||
'isanswered',
|
||||
'is_deleted',
|
||||
'closed',
|
||||
'reopened_at',
|
||||
'duedate',
|
||||
'closed_at',
|
||||
'tickets.created_at',
|
||||
'sla_plan.id as sla',
|
||||
'ticket_status.id as status',
|
||||
'lock_by',
|
||||
'lock_at',
|
||||
'ticket_source.id as source',
|
||||
'isoverdue',
|
||||
'reopened',
|
||||
'isanswered',
|
||||
'is_deleted',
|
||||
'closed',
|
||||
'reopened_at',
|
||||
'duedate',
|
||||
'closed_at',
|
||||
'tickets.created_at',
|
||||
'tickets.updated_at')->first();
|
||||
|
||||
return response()->json(compact('result'));
|
||||
@@ -1225,7 +1256,8 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function createPagination($array, $perPage) {
|
||||
public function createPagination($array, $perPage)
|
||||
{
|
||||
try {
|
||||
//Get current page form url e.g. &page=6
|
||||
$currentPage = LengthAwarePaginator::resolveCurrentPage();
|
||||
@@ -1253,7 +1285,8 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function collaboratorSearch() {
|
||||
public function collaboratorSearch()
|
||||
{
|
||||
$this->validate($this->request, ['term' => 'required']);
|
||||
try {
|
||||
$emails = $this->ticket->autosearch();
|
||||
@@ -1263,7 +1296,7 @@ class ApiController extends Controller {
|
||||
foreach ($emails as $key => $email) {
|
||||
$user_model = $user->where('email', $email)->first();
|
||||
//return $user_model;
|
||||
$users[$key]['name'] = $user_model->first_name . ' ' . $user_model->last_name;
|
||||
$users[$key]['name'] = $user_model->first_name.' '.$user_model->last_name;
|
||||
$users[$key]['email'] = $email;
|
||||
$users[$key]['avatar'] = $this->avatarUrl($email);
|
||||
}
|
||||
@@ -1280,12 +1313,13 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function avatarUrl($email) {
|
||||
public function avatarUrl($email)
|
||||
{
|
||||
try {
|
||||
$user = new User();
|
||||
$user = $user->where('email', $email)->first();
|
||||
if ($user->profile_pic) {
|
||||
$url = url('uploads/profilepic/' . $user->profile_pic);
|
||||
$url = url('uploads/profilepic/'.$user->profile_pic);
|
||||
} else {
|
||||
$url = \Gravatar::src($email);
|
||||
}
|
||||
@@ -1297,10 +1331,11 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function addCollaboratorForTicket() {
|
||||
public function addCollaboratorForTicket()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make(\Input::get(), [
|
||||
'email' => 'required|email|unique:users',
|
||||
'email' => 'required|email|unique:users',
|
||||
'ticket_id' => 'required',
|
||||
]
|
||||
);
|
||||
@@ -1327,7 +1362,8 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function getCollaboratorForTicket() {
|
||||
public function getCollaboratorForTicket()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make(\Input::get(), [
|
||||
'ticket_id' => 'required',
|
||||
@@ -1356,11 +1392,12 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteCollaborator() {
|
||||
public function deleteCollaborator()
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make(\Input::get(), [
|
||||
'ticketid' => 'required',
|
||||
'email' => 'required',
|
||||
'email' => 'required',
|
||||
]
|
||||
);
|
||||
if ($v->fails()) {
|
||||
@@ -1380,7 +1417,8 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function dependency() {
|
||||
public function dependency()
|
||||
{
|
||||
try {
|
||||
$department = $this->department->select('name', 'id')->get()->toArray();
|
||||
$sla = $this->slaPlan->select('name', 'id')->get()->toArray();
|
||||
@@ -1391,7 +1429,7 @@ class ApiController extends Controller {
|
||||
$status = \DB::table('ticket_status')->select('name', 'id')->get();
|
||||
$source = \DB::table('ticket_source')->select('name', 'id')->get();
|
||||
$result = ['departments' => $department, 'sla' => $sla, 'staffs' => $staff, 'teams' => $team,
|
||||
'priorities' => $priority, 'helptopics' => $helptopic, 'status' => $status, 'sources' => $source,];
|
||||
'priorities' => $priority, 'helptopics' => $helptopic, 'status' => $status, 'sources' => $source, ];
|
||||
|
||||
return response()->json(compact('result'));
|
||||
} catch (\Exception $e) {
|
||||
@@ -1403,7 +1441,8 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function differenciateHelpTopic($query) {
|
||||
public function differenciateHelpTopic($query)
|
||||
{
|
||||
$ticket = $query->first();
|
||||
$check = 'department';
|
||||
if ($ticket) {
|
||||
@@ -1417,16 +1456,18 @@ class ApiController extends Controller {
|
||||
return $query->select('tickets.dept_id');
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getSystem($check, $query) {
|
||||
public function getSystem($check, $query)
|
||||
{
|
||||
switch ($check) {
|
||||
case 'department':
|
||||
return $query->select('tickets.dept_id');
|
||||
case 'helpTopic':
|
||||
return $query->select('tickets.help_topic_id');
|
||||
default :
|
||||
default:
|
||||
return $query->select('tickets.dept_id');
|
||||
}
|
||||
}
|
||||
@@ -1438,10 +1479,11 @@ class ApiController extends Controller {
|
||||
*
|
||||
* @return type json
|
||||
*/
|
||||
public function register(Request $request) {
|
||||
public function register(Request $request)
|
||||
{
|
||||
try {
|
||||
$v = \Validator::make($request->all(), [
|
||||
'email' => 'required|email|unique:users',
|
||||
'email' => 'required|email|unique:users',
|
||||
'password' => 'required|min:6',
|
||||
]);
|
||||
if ($v->fails()) {
|
||||
@@ -1455,7 +1497,7 @@ class ApiController extends Controller {
|
||||
$password = \Hash::make($request->input('password'));
|
||||
$role = $request->input('role');
|
||||
if ($auth->role == 'agent') {
|
||||
$role = "user";
|
||||
$role = 'user';
|
||||
}
|
||||
$user = new User();
|
||||
$user->password = $password;
|
||||
@@ -1463,6 +1505,7 @@ class ApiController extends Controller {
|
||||
$user->email = $email;
|
||||
$user->role = $role;
|
||||
$user->save();
|
||||
|
||||
return response()->json(compact('user'));
|
||||
} catch (\Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
@@ -1470,5 +1513,4 @@ class ApiController extends Controller {
|
||||
return response()->json(compact('error'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user