Implemented caching for department and customer names to improve performance. Added Slack notifications for new bookings with detailed formatting. Refactored related methods to streamline functionality and ensure better code clarity.
140 lines
3.5 KiB
PHP
140 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace classes;
|
|
|
|
use interfaces\redis_i;
|
|
|
|
class redis implements redis_i
|
|
{
|
|
use \traits\redis_t;
|
|
|
|
public function __construct()
|
|
{
|
|
global $REDIS_CONFIG;
|
|
// Make sure the Redis configuration is set
|
|
if (!isset($REDIS_CONFIG)) {
|
|
throw new \Exception('Redis configuration is not set');
|
|
}
|
|
// Apply the Redis configuration
|
|
$this->redis_host = $REDIS_CONFIG['host'];
|
|
$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;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function cache_department_name(int $department_id, string $department_name): self
|
|
{
|
|
// Cache the department name
|
|
$this->set('department_name_' . $department_id, $department_name);
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function get_department_name(int $department_id): string|null
|
|
{
|
|
// Get the department name
|
|
return $this->get('department_name_' . $department_id);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function clear_department_name(int $department_id): self
|
|
{
|
|
// Clear the department name
|
|
$this->delete('department_name_' . $department_id);
|
|
return $this;
|
|
}
|
|
} |