nhance/app/Controllers/ThzController.php

169 lines
4.4 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);
$cleanedData = $this->thzControllerCleaner->ticketCreation($data);
if ($cleanedData === false) {
return $this->response->setJSON((['status' => 'error', 'message' => 'Invalid data given']));
}
$result = $this->thzMasterModel->insert($cleanedData);
return $this->response->setJSON((['status' => 'success', 'message' => 'Ticket created successfully']));
}
public function ticketList(){
$data = $this->request->getJson(true);
$cleanedData = $this->thzControllerCleaner->ticketList($data);
if( $cleanedData === false ) {
return $this->response->setJSON((['status' => 'error', 'message' => 'Invalid data given']));
}
$id = $cleanedData['id'] ?? null;
if (empty($id)) {
$result = $this->thzMasterModel->findAll();
}
$result = $this->thzMasterModel->where('id',$id)->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);
$cleanedData = $this->thzControllerCleaner->ticketList($data);
if( $cleanedData === false ) {
return $this->response->setJSON((['status' => 'error', 'message' => 'Invalid data given']));
}
$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 ticketListForUser(){
$data = $this->request->getJson(true);
$cleanedData = $this->thzControllerCleaner->ticketList($data);
if( $cleanedData === false ) {
return $this->response->setJSON((['status' => 'error', 'message' => 'Invalid data given']));
}
$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 conversationListForUserPerTicket(){
$data = $this->request->getJson(true);
$cleanedData = $this->thzControllerCleaner->ticketList($data);
if( $cleanedData === false ) {
return $this->response->setJSON((['status' => 'error', 'message' => 'Invalid data given']));
}
$thz_id = $cleanedData['thz_id'] ?? null;
$result = $this->thzMasterNotesModel->conversationListForUserPerTicket($thz_id);
if(empty($result)){
return $this->response->setJSON((['status' => 'error', 'message' => 'No tickets found']));
}
return $this->response->setJSON((['status' => 'success', 'data' => $result]));
}
public function ticketListForAssignedStaff(){
}
public function conversationListForAssignedStaffPerTicket(){
}
/************************************************** 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;
}
}
}