120 lines
3.0 KiB
PHP
120 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
|
|
use App\Models\ThzMasterModel;
|
|
use App\Models\ThzMasterNotesModel;
|
|
use App\ControllerCleaners\ThzControllerCleaner;
|
|
|
|
class ThzController extends BaseController
|
|
{
|
|
|
|
protected $thzMasterModel;
|
|
protected $thzMasterNotesModel;
|
|
|
|
protected $thzControllerCleaner;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->thzMasterModel = new ThzMasterModel();
|
|
$this->thzMasterNotesModel = new ThzMasterNotesModel();
|
|
$this->thzControllerCleaner = new ThzControllerCleaner();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
//
|
|
}
|
|
|
|
public function ticketCreation(){
|
|
|
|
$data = $this->request->getJSON(true);
|
|
|
|
$result = $this->thzMasterModel->insert($data);
|
|
|
|
return $this->response->setJSON((['status' => 'success', 'message' => 'Ticket created successfully']));
|
|
|
|
}
|
|
|
|
public function ticketList(){
|
|
|
|
$data = $this->request->getJson(true);
|
|
|
|
$id = $data['id'] ?? null;
|
|
|
|
if ( isset($id) && !empty($id) ) {
|
|
//Find Specific Ticket per id
|
|
$mobile = $data['mobile'] ?? null;
|
|
$result = $this->thzMasterModel->where('mobile',$mobile)->findAll();
|
|
}else{
|
|
// Find all the Ticket For the Manager who can see all the Tickets
|
|
$result = $this->thzMasterModel->findAll();
|
|
}
|
|
|
|
if(empty($result)){
|
|
return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']));
|
|
}
|
|
|
|
return $this->response->setJSON((['status' => 'success', 'data' => $result]));
|
|
|
|
}
|
|
|
|
|
|
public function ticketConversationSave(){
|
|
|
|
$data = $this->request->getJson(true);
|
|
|
|
$result = $this->thzMasterNotesModel->insert($data);
|
|
|
|
if(empty($result)){
|
|
return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']));
|
|
}
|
|
|
|
return $this->response->setJSON((['status' => 'success', 'data' => $result]));
|
|
|
|
|
|
}
|
|
|
|
public function conversationListPerTicket(){
|
|
|
|
$data = $this->request->getJson(true);
|
|
|
|
$thz_id = $data['thz_id'] ?? null;
|
|
|
|
$result = $this->thzMasterNotesModel->conversationListPerTicket($thz_id);
|
|
|
|
if(empty($result)){
|
|
return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']));
|
|
}
|
|
|
|
return $this->response->setJSON((['status' => 'success', 'data' => $result]));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************************************** PRIVATE FUNCTIONS ********************************************************/
|
|
|
|
|
|
private function checkGeneralUserOrEmployee($data){
|
|
|
|
if($data['empcode']){
|
|
return $data['empcode'];
|
|
} elseif ($data['mobile']) {
|
|
return $data['mobile'];
|
|
} elseif ($data['email']) {
|
|
return $data['email'];
|
|
} else {
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|