Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions controllers/ChatController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?php

namespace app\controllers;

use app\core\Application;
use app\core\Controller;
use app\core\Request;
use app\models\Chat;
use app\models\Customer;
use app\models\Technician;

class ChatController extends Controller
{
public function loadCustomerList()
{
$tech_id = Application::$app->session->get('technician');
$model = new Chat();

// Get customer chat list
$customers = $model->getCustomerChatList($tech_id);

$this->setLayout('auth');
return $this->render('/technician/components/load-user-list', [
'customers' => $customers
]);
}

public function loadTechnicianList()
{
$cus_id = Application::$app->session->get('customer');
$model = new Chat();

// Get customer chat list
$technicians = $model->getTechnicianChatList($cus_id);

$this->setLayout('auth');
return $this->render('/customer/components/load-user-list', [
'technicians' => $technicians
]);
}

public function viewCustomerMessages($id)
{
$chatModel = new Chat();
$customerId = intval($id[0]);

$tech_id = Application::$app->session->get('technician');

$customer = $chatModel->findCustomerById($customerId);
$customers = $chatModel->getCustomerChatList($tech_id);
$this->setLayout('auth');
if (!$customer) {
return $this->render('_404');
}

$messages = $chatModel->customerChatMessages($customerId, $tech_id);
return $this->render('/technician/customer-messages', [
'customers' => $customers,
'customer' => $customer,
'messages' => $messages
]);
}

public function viewTechnicianMessages($id)
{
$chatModel = new Chat();
$technicianId = intval($id[0]);

$cus_id = Application::$app->session->get('customer');

$technician = $chatModel->findTechnicianById($technicianId);
$technicians = $chatModel->getTechnicianChatList($cus_id);
$this->setLayout('auth');
if (!$technician) {
return $this->render('_404');
}

$messages = $chatModel->technicianChatMessages($technicianId, $cus_id);
return $this->render('/customer/technician-messages', [
'technicians' => $technicians,
'technician' => $technician,
'messages' => $messages
]);
}

public function loadCustomerMessages($id)
{
$chatModel = new Chat();
// echo json_encode($id);
// $id is an array, we need only the first element of that array
$tech_id = Application::$app->session->get('technician');

$customer = (new Customer())->findById(intval($id[0]));
$this->setLayout('auth');
if (!$customer) {
return $this->render('_404');
}

$messages = $chatModel->customerChatMessages(intval($id[0]), $tech_id);
return $this->render('/technician/components/load-messages', [
'customer' => $customer,
'messages' => $messages
]);
}

public function loadTechnicianMessages($id)
{
$chatModel = new Chat();
// echo json_encode($id);
// $id is an array, we need only the first element of that array
$cus_id = Application::$app->session->get('customer');

$technician = (new Technician())->findById(intval($id[0]));
$this->setLayout('auth');
if (!$technician) {
return $this->render('_404');
}

$messages = $chatModel->technicianChatMessages(intval($id[0]), $cus_id);
return $this->render('/customer/components/load-messages', [
'technician' => $technician,
'messages' => $messages
]);
}

public function technicianSendMessage()
{
header('Content-type: application/json');

try {
$jsonData = file_get_contents('php://input');
$data = json_decode($jsonData, true);

$outgoingMsgId = $data['outgoing_msg_id'];
$incomingMsgId = $data['incoming_msg_id'];
$message = $data['message'];

if (!$incomingMsgId || !$outgoingMsgId) {
Application::$app->response->setStatusCode(400);
return json_encode(['success' => false, 'error' => 'Missing the required parameter customerId, technicianId']);
exit;
}

$chatModel = new Chat();
$res = $chatModel->technicianSaveMessage($outgoingMsgId, $incomingMsgId, $message);
return json_encode($res);

} catch (\Exception $e) {
Application::$app->response->setStatusCode(500);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
}

public function customerSendMessage()
{
header('Content-type: application/json');

try {
$jsonData = file_get_contents('php://input');
$data = json_decode($jsonData, true);

$outgoingMsgId = $data['outgoing_msg_id'];
$incomingMsgId = $data['incoming_msg_id'];
$message = $data['message'];

if (!$incomingMsgId || !$outgoingMsgId) {
Application::$app->response->setStatusCode(400);
return json_encode(['success' => false, 'error' => 'Missing the required parameter customerId, technicianId']);
exit;
}

$chatModel = new Chat();
$res = $chatModel->customerSaveMessage($outgoingMsgId, $incomingMsgId, $message);
return json_encode($res);

} catch (\Exception $e) {
Application::$app->response->setStatusCode(500);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
}
}
10 changes: 9 additions & 1 deletion controllers/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use app\core\Controller;
use app\core\Request;
use app\core\Response;
use app\models\Chat;
use app\models\Comment;
use app\models\Customer;
use app\models\Post;
Expand Down Expand Up @@ -180,8 +181,15 @@ public function fixmeCommunity()

public function customerMessages()
{
$cus_id = Application::$app->session->get('customer');
$model = new Chat();

// Get customer chat list
$technicians = $model->getTechnicianChatList($cus_id);
$this->setLayout('auth');
return $this->render('/customer/customer-messages');
return $this->render('/customer/customer-messages', [
'technicians' => $technicians
]);
}

public function customerVehicleIssue()
Expand Down
22 changes: 20 additions & 2 deletions controllers/TechnicianController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use app\models\Post;
use app\models\Technician;
use app\models\TechnicianRequest;
use app\models\Chat;

class TechnicianController extends Controller
{
Expand Down Expand Up @@ -41,8 +42,16 @@ public function technicianMap()

public function technicianMessages()
{
$tech_id = Application::$app->session->get('technician');
$model = new Chat();

// Get customer chat list
$customers = $model->getCustomerChatList($tech_id);

$this->setLayout('auth');
return $this->render('/technician/technician-messages');
return $this->render('/technician/technician-messages', [
'customers' => $customers
]);
}

public function technicianSettings()
Expand Down Expand Up @@ -115,7 +124,7 @@ public function viewTechnicianProfile($id)
if (!$technician) {
return $this->render('_404');
}
// show($technician['fname']);
// show($technician['fname']);
$postModel = new Post();
$posts = $postModel->getPostsByTechnicianId(intval($id[0]));

Expand Down Expand Up @@ -165,5 +174,14 @@ public function technicianPaymentDetails()
return $this->render('/technician/technician-payment-details');
}

public function viewCustomerRequest($id)
{
$customer = (new Customer())->findById(intval($id[0]));

$this->setLayout('auth');
return $this->render('/technician/customer-request', [
'customer' => $customer
]);
}
}

3 changes: 2 additions & 1 deletion core/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ public function renderContent($viewContent)
protected function layoutContent()
{
$layout = Application::$app->layout;
if (Application::$app->controller) {
if (Application::$app->controller && Application::$app->controller->layout) {
$layout = Application::$app->controller->layout;
}
ob_start();
include_once Application::$ROOT_DIR . "/views/layouts/$layout.php";
return ob_get_clean();
}


protected function renderOnlyView($view, $params)
{
foreach ($params as $key => $value) {
Expand Down
Loading