Add Redis caching, Slack notifications, and booking logic.
Implemented Redis caching for improved department and customer data retrieval. Added Slack integration to send department notifications. Enhanced booking features and status handling, including parsing logic and wash certificate processing.
This commit is contained in:
@@ -20,4 +20,92 @@ class redis implements redis_i
|
||||
$this->redis_database = $REDIS_CONFIG['database'];
|
||||
$this->redis_password = $REDIS_CONFIG['password'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function cache_department_booking_count(int $department_id, int $count): redis_i
|
||||
{
|
||||
// Cache the department booking count
|
||||
$this->set('department_booking_count_' . $department_id, $count);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get_department_booking_count(int $department_id): int|null
|
||||
{
|
||||
// Get the department booking count
|
||||
return $this->get('department_booking_count_' . $department_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function clear_department_booking_count(int $department_id): redis_i
|
||||
{
|
||||
// Clear the department booking count
|
||||
$this->delete('department_booking_count_' . $department_id);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function cache_economic_customer_name(int $customer_number, string $customer_name): self
|
||||
{
|
||||
// Cache the economic customer name
|
||||
$this->set('economic_customer_name_' . $customer_number, $customer_name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get_economic_customer_name(int $customer_number): string|null
|
||||
{
|
||||
// Get the economic customer name
|
||||
return $this->get('economic_customer_name_' . $customer_number);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function clear_economic_customer_name(int $customer_number): self
|
||||
{
|
||||
// Clear the economic customer name
|
||||
$this->delete('economic_customer_name_' . $customer_number);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function cache_department_webhook(int $department_id, string $webhook): self
|
||||
{
|
||||
// Cache the department webhook
|
||||
$this->set('department_webhook_' . $department_id, $webhook);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get_department_webhook(int $department_id): string|null
|
||||
{
|
||||
// Get the department webhook
|
||||
return $this->get('department_webhook_' . $department_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function clear_department_webhook(int $department_id): self
|
||||
{
|
||||
// Clear the department webhook
|
||||
$this->delete('department_webhook_' . $department_id);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace classes;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use interfaces\notification_i;
|
||||
use objects\departments_o;
|
||||
use traits\notification_t;
|
||||
|
||||
|
||||
class slack implements notification_i
|
||||
{
|
||||
use notification_t;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send_department_booking_notification(int $department_id, $message): self
|
||||
{
|
||||
// Get the departments webhook
|
||||
$webhook = self::get_department_webhook($department_id);
|
||||
// Check if the webhook is empty
|
||||
if (empty($webhook)) {
|
||||
throw new \Exception('Department webhook is empty');
|
||||
}
|
||||
// Send the notification to the department
|
||||
self::add_log(self::send_webhook_message($message, $webhook));
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function get_department_webhook(int $department_id): string
|
||||
{
|
||||
// Check if the department webhook is cached
|
||||
$webhook = redis->get_department_webhook($department_id);
|
||||
// If the department webhook is not cached, get it from the database
|
||||
if ($webhook === null) {
|
||||
$department = new departments_o();
|
||||
$department->id = $department_id;
|
||||
$department->getObjectProperties();
|
||||
$webhook = $department->slack_webhook->value();
|
||||
// Cache the department webhook
|
||||
redis->cache_department_webhook($department_id, $webhook);
|
||||
}
|
||||
return redis->get_department_webhook($department_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a slack webhook
|
||||
* @param string $message
|
||||
* @param string $webhook
|
||||
* @return string The response from the webhook, unparsed
|
||||
*/
|
||||
protected function send_webhook_message(string $message, string $webhook): string
|
||||
{
|
||||
global $DEBUG;
|
||||
try {
|
||||
// Initialize Guzzle client
|
||||
$client = new Client();
|
||||
|
||||
// Prepare the payload for the webhook
|
||||
$payload = [
|
||||
'text' => $message
|
||||
];
|
||||
|
||||
// Send POST request to the webhook
|
||||
$response = $client->post($webhook, [
|
||||
'headers' => ['Content-Type' => 'application/json'],
|
||||
'body' => json_encode($payload),
|
||||
'verify' => ($DEBUG === false) // Disable SSL verification (Only in development)
|
||||
]);
|
||||
|
||||
// Return success message
|
||||
return 'Message sent successfully. Response: ' . $response->getBody();
|
||||
} catch (\Exception $e) {
|
||||
// Handle any errors that occur
|
||||
return 'Failed to send message: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,14 @@ if ($args[1] === 'run') {
|
||||
echo "Running the redis test script";
|
||||
require_once 'tests/redis/redisTest.php';
|
||||
break;
|
||||
case 'bookingModule-test':
|
||||
echo "Running the bookingModule test script";
|
||||
require_once 'tests/bookingModule/bookingModuleTest.php';
|
||||
break;
|
||||
case 'slackModule-test':
|
||||
echo "Running the slack test script";
|
||||
require_once 'tests/slackModule/SlackModuleTest.php';
|
||||
break;
|
||||
default:
|
||||
echo "Invalid script name";
|
||||
break;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php global $DEBUG, $CONFIG_DB, $ENCRYPTION_KEY, $CORS, $WD, $db, $response, $request, $router;
|
||||
<?php global $DEBUG, $CONFIG_DB, $ENCRYPTION_KEY, $CORS, $WD, $db, $response, $request, $router, $redis;
|
||||
/**
|
||||
* This is the main entry point to the Truck Wash API.
|
||||
*/
|
||||
@@ -38,6 +38,7 @@ require_once 'classes/request.php';
|
||||
require_once 'classes/ratelimit.php';
|
||||
require_once 'classes/wash_certificate_store.php';
|
||||
require_once 'classes/redis.php';
|
||||
require_once 'classes/slack.php';
|
||||
|
||||
/**
|
||||
* Modules
|
||||
@@ -50,6 +51,7 @@ require_once 'modules/economic/invoices/draft/economicInvoicesDrafts.php';
|
||||
require_once 'modules/economic/invoices/draft/economic_invoice_draft_mo.php';
|
||||
|
||||
use classes\db;
|
||||
use classes\redis;
|
||||
use classes\request;
|
||||
use classes\response;
|
||||
use classes\router;
|
||||
@@ -59,6 +61,11 @@ $router = new router();
|
||||
$response = new response();
|
||||
$request = new request();
|
||||
$db = new db($CONFIG_DB);
|
||||
try {
|
||||
define("redis", (new redis())->connect());
|
||||
} catch (Exception $e) {
|
||||
$response->error($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
// Connect to the database, and ensure the connection is successful
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace interfaces;
|
||||
|
||||
interface notification_i
|
||||
{
|
||||
|
||||
}
|
||||
@@ -4,4 +4,69 @@ namespace interfaces;
|
||||
|
||||
interface redis_i
|
||||
{
|
||||
/**
|
||||
* Cache a departments booking count (cached)
|
||||
* @param int $department_id
|
||||
* @param int $count
|
||||
* @return self
|
||||
*/
|
||||
public function cache_department_booking_count(int $department_id, int $count): self;
|
||||
|
||||
/**
|
||||
* Get a departments booking count (cached)
|
||||
* @param int $department_id
|
||||
* @return int|null
|
||||
*/
|
||||
public function get_department_booking_count(int $department_id): int|null;
|
||||
|
||||
/**
|
||||
* Clear a departments booking count (cached)
|
||||
* @param int $department_id
|
||||
* @return self
|
||||
*/
|
||||
public function clear_department_booking_count(int $department_id): self;
|
||||
|
||||
/**
|
||||
* Cache a economic customer name
|
||||
* @param int $customer_number
|
||||
* @param string $customer_name
|
||||
* @return self
|
||||
*/
|
||||
public function cache_economic_customer_name(int $customer_number, string $customer_name): self;
|
||||
|
||||
/**
|
||||
* Get a economic customer name
|
||||
* @param int $customer_number
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_economic_customer_name(int $customer_number): string|null;
|
||||
|
||||
/**
|
||||
* Clear a economic customer name
|
||||
* @param int $customer_number
|
||||
* @return self
|
||||
*/
|
||||
public function clear_economic_customer_name(int $customer_number): self;
|
||||
|
||||
/**
|
||||
* Cache a department webhook
|
||||
* @param int $department_id
|
||||
* @param string $webhook
|
||||
* @return self
|
||||
*/
|
||||
public function cache_department_webhook(int $department_id, string $webhook): self;
|
||||
|
||||
/**
|
||||
* Get a department webhook
|
||||
* @param int $department_id
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_department_webhook(int $department_id): string|null;
|
||||
|
||||
/**
|
||||
* Clear a department webhook
|
||||
* @param int $department_id
|
||||
* @return self
|
||||
*/
|
||||
public function clear_department_webhook(int $department_id): self;
|
||||
}
|
||||
@@ -6,15 +6,6 @@ use economic_m;
|
||||
|
||||
class economicCustomers extends economic_m
|
||||
{
|
||||
public function getCustomerId(int $customerNumber): array|bool
|
||||
{
|
||||
// Check if the customer exists
|
||||
$url = '/customers?filter=customerNumber$eq:' . $customerNumber;
|
||||
$response = $this->send_request($url, 'GET', '');
|
||||
$response = json_decode($response);
|
||||
return $response->collection;
|
||||
}
|
||||
|
||||
public function searchCustomers(string|int $search, string $filter, int $limit = 10, int $page = 1): object
|
||||
{
|
||||
// Make sure the search string is ready for the API
|
||||
@@ -24,4 +15,29 @@ class economicCustomers extends economic_m
|
||||
$response = $this->send_request($url, 'GET', '');
|
||||
return json_decode($response);
|
||||
}
|
||||
|
||||
public function getCustomerName(int $customer_number): string|null
|
||||
{
|
||||
// Check if the customer name is cached
|
||||
if (redis->get_economic_customer_name($customer_number)) {
|
||||
return redis->get_economic_customer_name($customer_number);
|
||||
}
|
||||
// Get the customer name from the economic system
|
||||
$customer = $this->getCustomerId($customer_number);
|
||||
if (count($customer) > 0) {
|
||||
$customer = $customer[0];
|
||||
redis->cache_economic_customer_name($customer_number, $customer->name);
|
||||
return $customer->name;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getCustomerId(int $customerNumber): array|bool
|
||||
{
|
||||
// Check if the customer exists
|
||||
$url = '/customers?filter=customerNumber$eq:' . $customerNumber;
|
||||
$response = $this->send_request($url, 'GET', '');
|
||||
$response = json_decode($response);
|
||||
return $response->collection;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class economic_customer_mo
|
||||
public null|string $mobilePhone;
|
||||
public null|string $currency;
|
||||
public null|string $country;
|
||||
|
||||
public function getCustomerByCustomerNumber(int $customer_number): static
|
||||
{
|
||||
// Get the customer from the economic system
|
||||
@@ -40,6 +41,8 @@ class economic_customer_mo
|
||||
$this->mobilePhone = ($customer->mobilePhone ?? null);
|
||||
$this->currency = ($customer->currency ?? null);
|
||||
$this->country = ($customer->country ?? null);
|
||||
// Cache the customer name
|
||||
redis->cache_economic_customer_name($this->customer_number, $this->name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ require_once '../../traits/minio_t.php';
|
||||
require_once '../../classes/wash_certificate_store.php';
|
||||
|
||||
use classes\wash_certificate_store;
|
||||
use objects\bookings_o;
|
||||
|
||||
global $WORDPRESS_STATIC_TOKEN;
|
||||
// Validate the token was loaded from the config file
|
||||
@@ -128,7 +129,15 @@ $wash_certificate_store->uploadFile($generatedCertificateName, dirname(__FILE__)
|
||||
// Delete the local copy of the certificate
|
||||
//unlink(dirname(__FILE__) . '/' . $generatedCertificatePath);
|
||||
|
||||
// Set the status of the booking to completed
|
||||
$booking = new bookings_o();
|
||||
$booking->id = $_GET['bookingId'];
|
||||
$booking->getObjectProperties();
|
||||
$booking->status->set('completed');
|
||||
$booking->washCertificateUrl->set('Protected URL');
|
||||
$booking->washCertificateStatus->set('completed');
|
||||
|
||||
// Return the generated certificate object download URL
|
||||
$wash_certificate_store->getWashCertificateDownload($_GET['bookingId']);
|
||||
echo $wash_certificate_store->getWashCertificateDownload($_GET['bookingId']);
|
||||
// Exit the script
|
||||
exit;
|
||||
+33
-1
@@ -51,6 +51,8 @@ class bookings_o extends db
|
||||
// Create a new record in the database ( Replace the code, if an entry already exists )
|
||||
$sql = "INSERT INTO $this->table (customer_number, wash_type, contact_email, reference_number, regNrTraekker, regNrTrailer, washCertificateEmail, date, department, pickup_bool, notes, washCertificateStatus, washCertificateUrl, status) VALUES ($customer_number, '$wash_type', '$contact_email', '$reference_number', '$regNrTraekker', '$regNrTrailer', '$washCertificateEmail', '$date', '$department', $pickup_bool, '$notes', '$washCertificateStatus', '$washCertificateUrl', '$status')";
|
||||
$db->query($sql);
|
||||
// Clear the cache
|
||||
redis->clear_department_booking_count($department);
|
||||
|
||||
// Get the id of the new record
|
||||
$this->id = $db->insert_id();
|
||||
@@ -90,6 +92,8 @@ class bookings_o extends db
|
||||
// Create a new record in the database ( Replace the code, if an entry already exists )
|
||||
$sql = "INSERT INTO $this->table (id, customer_number, wash_type, contact_email, reference_number, regNrTraekker, regNrTrailer, washCertificateEmail, date, department, pickup_bool, notes, washCertificateStatus, washCertificateUrl, status) VALUES ($id, $customer_number, '$wash_type', '$contact_email', '$reference_number', '$regNrTraekker', '$regNrTrailer', '$washCertificateEmail', '$date', '$department', $pickup_bool, '$notes', '$washCertificateStatus', '$washCertificateUrl', '$status') ON DUPLICATE KEY UPDATE customer_number = $customer_number, wash_type = '$wash_type', contact_email = '$contact_email', reference_number = '$reference_number', regNrTraekker = '$regNrTraekker', regNrTrailer = '$regNrTrailer', washCertificateEmail = '$washCertificateEmail', date = '$date', department = '$department', pickup_bool = $pickup_bool, notes = '$notes', washCertificateStatus = '$washCertificateStatus', washCertificateUrl = '$washCertificateUrl', status = '$status'";
|
||||
$db->query($sql);
|
||||
// Clear the cache
|
||||
redis->clear_department_booking_count($department);
|
||||
}
|
||||
|
||||
public function getCustomerBookingsPaginated(int $customer_number, int $page = 1, int $limit = 10, array $order = ['id' => 'DESC'], string $search = null, array $filters = null): array
|
||||
@@ -108,10 +112,18 @@ class bookings_o extends db
|
||||
|
||||
public function getDepartmentBookingsUnfulfilledCount(int $department_id): int
|
||||
{
|
||||
global $db;
|
||||
global /** @var response $response */
|
||||
$db, $response;
|
||||
// Check if the count is cached
|
||||
if (redis->get_department_booking_count($department_id)) {
|
||||
$response->add_meta('cached', true);
|
||||
return redis->get_department_booking_count($department_id);
|
||||
}
|
||||
$sql = "SELECT COUNT(*) as count FROM $this->table WHERE department = $department_id AND status = 'pending'";
|
||||
$result = $db->query($sql);
|
||||
$row = $db->fetch_assoc($result);
|
||||
// Cache the count
|
||||
redis->cache_department_booking_count($department_id, $row['count']);
|
||||
return $row['count'];
|
||||
}
|
||||
|
||||
@@ -119,7 +131,10 @@ class bookings_o extends db
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->getObjectProperties();
|
||||
// Set the status to cancelled
|
||||
$this->status->set('cancelled');
|
||||
// Remove the cache
|
||||
redis->clear_department_booking_count($this->department->value());
|
||||
}
|
||||
|
||||
public function getObjectProperties(): void
|
||||
@@ -139,4 +154,21 @@ class bookings_o extends db
|
||||
$this->washCertificateUrl = new object_property($this->table, $this->id, 'washCertificateUrl', 'string', true);
|
||||
$this->status = new object_property($this->table, $this->id, 'status', 'string', true);
|
||||
}
|
||||
|
||||
public function parseBookings(array $listObjectsWithPaginationIfSet): array
|
||||
{
|
||||
// Parse the customer numbers
|
||||
$bookings = $this->parseCustomerNumbers($listObjectsWithPaginationIfSet);
|
||||
return $bookings;
|
||||
}
|
||||
|
||||
public function parseCustomerNumbers(array $listObjectsWithPaginationIfSet): array
|
||||
{
|
||||
// Parse the customer numbers
|
||||
foreach ( $listObjectsWithPaginationIfSet as $key => $value ) {
|
||||
$listObjectsWithPaginationIfSet[$key]['customer_name'] = redis->get_economic_customer_name($value['customer_number']) ?? (new users_o())->getCustomerName($value['customer_number']);
|
||||
}
|
||||
return $listObjectsWithPaginationIfSet;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ class departments_o extends db
|
||||
public object_property $name;
|
||||
public object_property $description;
|
||||
public object_property $economic_department_id; // The id of the department in the economic system (Can be null)
|
||||
public object_property $slack_webhook; // The slack webhook for the department
|
||||
|
||||
public function structure(): void
|
||||
{
|
||||
@@ -41,6 +42,7 @@ class departments_o extends db
|
||||
$this->name = new object_property($this->table, $this->id, 'name', 'string', true);
|
||||
$this->description = new object_property($this->table, $this->id, 'description', 'string', false);
|
||||
$this->economic_department_id = new object_property($this->table, $this->id, 'economic_department_id', 'int', false);
|
||||
$this->slack_webhook = new object_property($this->table, $this->id, 'slack_webhook', 'string', false);
|
||||
}
|
||||
|
||||
public function edit(int $id, string $name, string $description, int $economic_department_id): void
|
||||
@@ -62,12 +64,24 @@ class departments_o extends db
|
||||
$this->getObjectProperties();
|
||||
}
|
||||
|
||||
public function list(): array
|
||||
public function list($superUser = false): array
|
||||
{
|
||||
global $db;
|
||||
$sql = "SELECT * FROM $this->table";
|
||||
$result = $db->query($sql);
|
||||
return $db->fetch_all($result);
|
||||
$result = $db->fetch_all($result);
|
||||
// Only show the name, description and id if the user isn't a super user
|
||||
if (!$superUser) {
|
||||
$result = array_map(function ($department) {
|
||||
return [
|
||||
'name' => $department['name'],
|
||||
'description' => $department['description'],
|
||||
'id' => $department['id']
|
||||
];
|
||||
}, $result);
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getDepartmentById(int $id): array
|
||||
|
||||
@@ -641,4 +641,18 @@ class users_o extends db
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getCustomerName(int $customer_number): string|null
|
||||
{
|
||||
// Check if the customer name is cached
|
||||
if (redis->get_economic_customer_name($customer_number)) {
|
||||
return redis->get_economic_customer_name($customer_number);
|
||||
}
|
||||
// Get the customer name from the external source
|
||||
$economic = new economicCustomers();
|
||||
$customer_name = $economic->getCustomerName($customer_number);
|
||||
// Cache the customer name
|
||||
redis->cache_economic_customer_name($customer_number, $customer_name);
|
||||
return $customer_name;
|
||||
}
|
||||
}
|
||||
@@ -34,9 +34,10 @@ class bookingsRoute
|
||||
if ($user->hasPermission('issue_wash_certificates')) {
|
||||
$response->add_meta('wash_certificate_token', $EMAIL_WASH_CERTIFICATE_TOKEN);
|
||||
}
|
||||
$bookings_o = new bookings_o();
|
||||
// Return the list of bookings
|
||||
$response->success(
|
||||
(new bookings_o())->listObjectsWithPaginationIfSet()
|
||||
$bookings_o->parseBookings($bookings_o->listObjectsWithPaginationIfSet())
|
||||
);
|
||||
} else {
|
||||
// Log the incident
|
||||
@@ -128,7 +129,8 @@ class bookingsRoute
|
||||
// Get a departments unfulfilled bookings (count) for the day
|
||||
$this->get('/admin/bookings/department/count', function () {
|
||||
// Require the user to be logged in
|
||||
global $response;
|
||||
global /** @var response $response */
|
||||
$response;
|
||||
$this->requirePermission('list_department_bookings_count');
|
||||
// Get the user object
|
||||
$user = (new authentication())->get_user();
|
||||
@@ -142,6 +144,13 @@ class bookingsRoute
|
||||
if (!is_numeric($this->fromRequest('department_id'))) {
|
||||
$response->error('Department ID must be a number', 400);
|
||||
}
|
||||
// Check if the result is cached, if so, we don't need to query the database
|
||||
if (redis->get_department_booking_count((int)$this->fromRequest('department_id'))) {
|
||||
$response->add_meta('cached', true);
|
||||
$response->success(
|
||||
redis->get_department_booking_count((int)$this->fromRequest('department_id'))
|
||||
);
|
||||
}
|
||||
// Check if the department exists
|
||||
if (!(new departments_o())->selectId((int)$this->fromRequest('department_id'))->exists()) {
|
||||
$response->error('Department not found', 404);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
// prevent direct access
|
||||
if (!defined('WD')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function warn($message): void
|
||||
{
|
||||
echo "\n\033[33m$message\033[0m\n";
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// prevent direct access
|
||||
if (!defined('WD')) {
|
||||
exit;
|
||||
};
|
||||
|
||||
function warn($message): void
|
||||
{
|
||||
echo "\n\033[33m$message\033[0m\n";
|
||||
}
|
||||
|
||||
$slack = new \classes\slack();
|
||||
|
||||
$department_id = 4;
|
||||
|
||||
try {
|
||||
$response = $slack->send_department_booking_notification($department_id, 'Slack Module Test Message');
|
||||
} catch (Exception $e) {
|
||||
warn($e->getMessage());
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
echo redis->get_department_webhook($department_id);
|
||||
var_dump($slack->get_log());
|
||||
+18
-9
@@ -49,15 +49,6 @@ trait db_object_t
|
||||
return $db->fetch_assoc($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the table of the objects in the database
|
||||
* @param string $table The table of the objects in the database
|
||||
*/
|
||||
public function setTable(string $table): void
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* List objects with pagination (if set)
|
||||
* @return array The list of objects in the table
|
||||
@@ -313,4 +304,22 @@ trait db_object_t
|
||||
$result = $db->query($sql);
|
||||
return $result->num_rows > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the table of the objects in the database
|
||||
* @returns string
|
||||
*/
|
||||
public function getTable(): string
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the table of the objects in the database
|
||||
* @param string $table The table of the objects in the database
|
||||
*/
|
||||
public function setTable(string $table): void
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace traits;
|
||||
|
||||
trait notification_t
|
||||
{
|
||||
protected array $log = [];
|
||||
|
||||
/**
|
||||
* Send department booking notification
|
||||
* @param int $department_id
|
||||
* @param string $message
|
||||
*/
|
||||
abstract public function send_department_booking_notification(int $department_id, string $message): self;
|
||||
|
||||
public function add_log(mixed $data): void
|
||||
{
|
||||
$this->log[] = [
|
||||
'timestamp' => time(),
|
||||
'data' => $data
|
||||
];
|
||||
}
|
||||
|
||||
public function get_log(): array
|
||||
{
|
||||
return $this->log;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user