Revert renaming the service-categories to categories (for clarity)
This commit is contained in:
parent
ae76ad7385
commit
e9842a40bc
17 changed files with 773 additions and 614 deletions
|
@ -33,7 +33,7 @@ class Booking extends EA_Controller {
|
||||||
$this->load->model('providers_model');
|
$this->load->model('providers_model');
|
||||||
$this->load->model('admins_model');
|
$this->load->model('admins_model');
|
||||||
$this->load->model('secretaries_model');
|
$this->load->model('secretaries_model');
|
||||||
$this->load->model('categories_model');
|
$this->load->model('service_categories_model');
|
||||||
$this->load->model('services_model');
|
$this->load->model('services_model');
|
||||||
$this->load->model('customers_model');
|
$this->load->model('customers_model');
|
||||||
$this->load->model('settings_model');
|
$this->load->model('settings_model');
|
||||||
|
|
|
@ -12,21 +12,21 @@
|
||||||
* ---------------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Categories controller.
|
* Service-categories controller.
|
||||||
*
|
*
|
||||||
* Handles the categories related operations.
|
* Handles the service-categories related operations.
|
||||||
*
|
*
|
||||||
* @package Controllers
|
* @package Controllers
|
||||||
*/
|
*/
|
||||||
class Categories extends EA_Controller {
|
class Service_categories extends EA_Controller {
|
||||||
/**
|
/**
|
||||||
* Categories constructor.
|
* Service-categories constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->load->model('categories_model');
|
$this->load->model('service_categories_model');
|
||||||
$this->load->model('roles_model');
|
$this->load->model('roles_model');
|
||||||
|
|
||||||
$this->load->library('accounts');
|
$this->load->library('accounts');
|
||||||
|
@ -35,9 +35,9 @@ class Categories extends EA_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the backend categories page.
|
* Render the backend service-categories page.
|
||||||
*
|
*
|
||||||
* On this page admin users will be able to manage categories, which are eventually selected by customers during the
|
* On this page admin users will be able to manage service-categories, which are eventually selected by customers during the
|
||||||
* booking process.
|
* booking process.
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
|
@ -73,11 +73,11 @@ class Categories extends EA_Controller {
|
||||||
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
|
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->load->view('pages/categories');
|
$this->load->view('pages/service_categories');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter categories by the provided keyword.
|
* Filter service-categories by the provided keyword.
|
||||||
*/
|
*/
|
||||||
public function search()
|
public function search()
|
||||||
{
|
{
|
||||||
|
@ -96,9 +96,9 @@ class Categories extends EA_Controller {
|
||||||
|
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
|
|
||||||
$categories = $this->categories_model->search($keyword, $limit, $offset, $order_by);
|
$service_categories = $this->service_categories_model->search($keyword, $limit, $offset, $order_by);
|
||||||
|
|
||||||
json_response($categories);
|
json_response($service_categories);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
|
@ -107,7 +107,7 @@ class Categories extends EA_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a category.
|
* Create a service-category.
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
|
@ -118,22 +118,22 @@ class Categories extends EA_Controller {
|
||||||
abort(403, 'Forbidden');
|
abort(403, 'Forbidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
$category = request('category');
|
$service_category = request('service_category');
|
||||||
|
|
||||||
$this->categories_model->only($category, [
|
$this->service_categories_model->only($service_category, [
|
||||||
'name',
|
'name',
|
||||||
'description'
|
'description'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$category_id = $this->categories_model->save($category);
|
$service_category_id = $this->service_categories_model->save($service_category);
|
||||||
|
|
||||||
$category = $this->categories_model->find($category_id);
|
$service_category = $this->service_categories_model->find($service_category_id);
|
||||||
|
|
||||||
$this->webhooks_client->trigger(WEBHOOK_CATEGORY_SAVE, $category);
|
$this->webhooks_client->trigger(WEBHOOK_CATEGORY_SAVE, $service_category);
|
||||||
|
|
||||||
json_response([
|
json_response([
|
||||||
'success' => TRUE,
|
'success' => TRUE,
|
||||||
'id' => $category_id
|
'id' => $service_category_id
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
|
@ -143,7 +143,7 @@ class Categories extends EA_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a category.
|
* Update a service-category.
|
||||||
*/
|
*/
|
||||||
public function update()
|
public function update()
|
||||||
{
|
{
|
||||||
|
@ -154,23 +154,23 @@ class Categories extends EA_Controller {
|
||||||
abort(403, 'Forbidden');
|
abort(403, 'Forbidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
$category = request('category');
|
$service_category = request('service_category');
|
||||||
|
|
||||||
$this->categories_model->only($category, [
|
$this->service_categories_model->only($service_category, [
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
'description'
|
'description'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$category_id = $this->categories_model->save($category);
|
$service_category_id = $this->service_categories_model->save($service_category);
|
||||||
|
|
||||||
$category = $this->categories_model->find($category_id);
|
$service_category = $this->service_categories_model->find($service_category_id);
|
||||||
|
|
||||||
$this->webhooks_client->trigger(WEBHOOK_CATEGORY_SAVE, $category);
|
$this->webhooks_client->trigger(WEBHOOK_CATEGORY_SAVE, $service_category);
|
||||||
|
|
||||||
json_response([
|
json_response([
|
||||||
'success' => TRUE,
|
'success' => TRUE,
|
||||||
'id' => $category_id
|
'id' => $service_category_id
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
|
@ -180,7 +180,7 @@ class Categories extends EA_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a category.
|
* Remove a service-category.
|
||||||
*/
|
*/
|
||||||
public function destroy()
|
public function destroy()
|
||||||
{
|
{
|
||||||
|
@ -191,13 +191,13 @@ class Categories extends EA_Controller {
|
||||||
abort(403, 'Forbidden');
|
abort(403, 'Forbidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
$category_id = request('category_id');
|
$service_category_id = request('service_category_id');
|
||||||
|
|
||||||
$category = $this->categories_model->find($category_id);
|
$service_category = $this->service_categories_model->find($service_category_id);
|
||||||
|
|
||||||
$this->categories_model->delete($category_id);
|
$this->service_categories_model->delete($service_category_id);
|
||||||
|
|
||||||
$this->webhooks_client->trigger(WEBHOOK_CATEGORY_DELETE, $category);
|
$this->webhooks_client->trigger(WEBHOOK_CATEGORY_DELETE, $service_category);
|
||||||
|
|
||||||
json_response([
|
json_response([
|
||||||
'success' => TRUE,
|
'success' => TRUE,
|
||||||
|
@ -210,7 +210,7 @@ class Categories extends EA_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a category.
|
* Find a service-category.
|
||||||
*/
|
*/
|
||||||
public function find()
|
public function find()
|
||||||
{
|
{
|
||||||
|
@ -221,11 +221,11 @@ class Categories extends EA_Controller {
|
||||||
abort(403, 'Forbidden');
|
abort(403, 'Forbidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
$category_id = request('category_id');
|
$service_category_id = request('service_category_id');
|
||||||
|
|
||||||
$category = $this->categories_model->find($category_id);
|
$service_category = $this->service_categories_model->find($service_category_id);
|
||||||
|
|
||||||
json_response($category);
|
json_response($service_category);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
|
@ -12,13 +12,13 @@
|
||||||
* ---------------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Categories API v1 controller.
|
* Service-categories API v1 controller.
|
||||||
*
|
*
|
||||||
* @package Controllers
|
* @package Controllers
|
||||||
*/
|
*/
|
||||||
class Categories_api_v1 extends EA_Controller {
|
class Service_categories_api_v1 extends EA_Controller {
|
||||||
/**
|
/**
|
||||||
* Categories_api_v1 constructor.
|
* Service_categories_api_v1 constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -28,11 +28,11 @@ class Categories_api_v1 extends EA_Controller {
|
||||||
|
|
||||||
$this->api->auth();
|
$this->api->auth();
|
||||||
|
|
||||||
$this->api->model('categories_model');
|
$this->api->model('service_categories_model');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a category collection.
|
* Get a service-category collection.
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
@ -50,26 +50,26 @@ class Categories_api_v1 extends EA_Controller {
|
||||||
|
|
||||||
$with = $this->api->request_with();
|
$with = $this->api->request_with();
|
||||||
|
|
||||||
$categories = empty($keyword)
|
$service_categories = empty($keyword)
|
||||||
? $this->categories_model->get(NULL, $limit, $offset, $order_by)
|
? $this->service_categories_model->get(NULL, $limit, $offset, $order_by)
|
||||||
: $this->categories_model->search($keyword, $limit, $offset, $order_by);
|
: $this->service_categories_model->search($keyword, $limit, $offset, $order_by);
|
||||||
|
|
||||||
foreach ($categories as &$category)
|
foreach ($service_categories as &$service_category)
|
||||||
{
|
{
|
||||||
$this->categories_model->api_encode($category);
|
$this->service_categories_model->api_encode($service_category);
|
||||||
|
|
||||||
if ( ! empty($fields))
|
if ( ! empty($fields))
|
||||||
{
|
{
|
||||||
$this->categories_model->only($category, $fields);
|
$this->service_categories_model->only($service_category, $fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty($with))
|
if ( ! empty($with))
|
||||||
{
|
{
|
||||||
$this->categories_model->load($category, $with);
|
$this->service_categories_model->load($service_category, $with);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json_response($categories);
|
json_response($service_categories);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
|
@ -78,9 +78,9 @@ class Categories_api_v1 extends EA_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a single category.
|
* Get a single service-category.
|
||||||
*
|
*
|
||||||
* @param int|null $id Category ID.
|
* @param int|null $id Service-category ID.
|
||||||
*/
|
*/
|
||||||
public function show(int $id = NULL)
|
public function show(int $id = NULL)
|
||||||
{
|
{
|
||||||
|
@ -90,28 +90,28 @@ class Categories_api_v1 extends EA_Controller {
|
||||||
|
|
||||||
$with = $this->api->request_with();
|
$with = $this->api->request_with();
|
||||||
|
|
||||||
$category = $this->categories_model->find($id);
|
$service_category = $this->service_categories_model->find($id);
|
||||||
|
|
||||||
$this->categories_model->api_encode($category);
|
$this->service_categories_model->api_encode($service_category);
|
||||||
|
|
||||||
if ( ! empty($fields))
|
if ( ! empty($fields))
|
||||||
{
|
{
|
||||||
$this->categories_model->only($category, $fields);
|
$this->service_categories_model->only($service_category, $fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty($with))
|
if ( ! empty($with))
|
||||||
{
|
{
|
||||||
$this->categories_model->load($category, $with);
|
$this->service_categories_model->load($service_category, $with);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $category)
|
if ( ! $service_category)
|
||||||
{
|
{
|
||||||
response('', 404);
|
response('', 404);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_response($category);
|
json_response($service_category);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
|
@ -120,28 +120,28 @@ class Categories_api_v1 extends EA_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a category.
|
* Create a service-category.
|
||||||
*/
|
*/
|
||||||
public function store()
|
public function store()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$category = request();
|
$service_category = request();
|
||||||
|
|
||||||
$this->categories_model->api_decode($category);
|
$this->service_categories_model->api_decode($service_category);
|
||||||
|
|
||||||
if (array_key_exists('id', $category))
|
if (array_key_exists('id', $service_category))
|
||||||
{
|
{
|
||||||
unset($category['id']);
|
unset($service_category['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$category_id = $this->categories_model->save($category);
|
$service_category_id = $this->service_categories_model->save($service_category);
|
||||||
|
|
||||||
$created_category = $this->categories_model->find($category_id);
|
$created_service_category = $this->service_categories_model->find($service_category_id);
|
||||||
|
|
||||||
$this->categories_model->api_encode($created_category);
|
$this->service_categories_model->api_encode($created_service_category);
|
||||||
|
|
||||||
json_response($created_category, 201);
|
json_response($created_service_category, 201);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
|
@ -150,15 +150,15 @@ class Categories_api_v1 extends EA_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a category.
|
* Update a service-category.
|
||||||
*
|
*
|
||||||
* @param int $id Category ID.
|
* @param int $id Service-category ID.
|
||||||
*/
|
*/
|
||||||
public function update(int $id)
|
public function update(int $id)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$occurrences = $this->categories_model->get(['id' => $id]);
|
$occurrences = $this->service_categories_model->get(['id' => $id]);
|
||||||
|
|
||||||
if (empty($occurrences))
|
if (empty($occurrences))
|
||||||
{
|
{
|
||||||
|
@ -169,17 +169,17 @@ class Categories_api_v1 extends EA_Controller {
|
||||||
|
|
||||||
$original_category = $occurrences[0];
|
$original_category = $occurrences[0];
|
||||||
|
|
||||||
$category = request();
|
$service_category = request();
|
||||||
|
|
||||||
$this->categories_model->api_decode($category, $original_category);
|
$this->service_categories_model->api_decode($service_category, $original_category);
|
||||||
|
|
||||||
$category_id = $this->categories_model->save($category);
|
$service_category_id = $this->service_categories_model->save($service_category);
|
||||||
|
|
||||||
$updated_category = $this->categories_model->find($category_id);
|
$updated_service_category = $this->service_categories_model->find($service_category_id);
|
||||||
|
|
||||||
$this->categories_model->api_encode($updated_category);
|
$this->service_categories_model->api_encode($updated_service_category);
|
||||||
|
|
||||||
json_response($updated_category);
|
json_response($updated_service_category);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
|
@ -188,15 +188,15 @@ class Categories_api_v1 extends EA_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a category.
|
* Delete a service-category.
|
||||||
*
|
*
|
||||||
* @param int $id Category ID.
|
* @param int $id Service-category ID.
|
||||||
*/
|
*/
|
||||||
public function destroy(int $id)
|
public function destroy(int $id)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$occurrences = $this->categories_model->get(['id' => $id]);
|
$occurrences = $this->service_categories_model->get(['id' => $id]);
|
||||||
|
|
||||||
if (empty($occurrences))
|
if (empty($occurrences))
|
||||||
{
|
{
|
||||||
|
@ -205,7 +205,7 @@ class Categories_api_v1 extends EA_Controller {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->categories_model->delete($id);
|
$this->service_categories_model->delete($id);
|
||||||
|
|
||||||
response('', 204);
|
response('', 204);
|
||||||
}
|
}
|
|
@ -41,7 +41,7 @@
|
||||||
*
|
*
|
||||||
* @property Admins_model $admins_model
|
* @property Admins_model $admins_model
|
||||||
* @property Appointments_model $appointments_model
|
* @property Appointments_model $appointments_model
|
||||||
* @property Categories_model $categories_model
|
* @property Service_categories_model $service_categories_model
|
||||||
* @property Consents_model $consents_model
|
* @property Consents_model $consents_model
|
||||||
* @property Customers_model $customers_model
|
* @property Customers_model $customers_model
|
||||||
* @property Providers_model $providers_model
|
* @property Providers_model $providers_model
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Easy!Appointments - Online Appointment Scheduler
|
||||||
|
*
|
||||||
|
* @package EasyAppointments
|
||||||
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||||
|
* @copyright Copyright (c) Alex Tselegidis
|
||||||
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||||
|
* @link https://easyappointments.org
|
||||||
|
* @since v1.5.0
|
||||||
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
class Migration_Revert_rename_service_categories_table_to_categories extends EA_Migration {
|
||||||
|
/**
|
||||||
|
* Upgrade method.
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if ($this->db->table_exists('categories'))
|
||||||
|
{
|
||||||
|
$this->dbforge->rename_table('categories', 'service_categories');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downgrade method.
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
if ($this->db->table_exists('service_categories'))
|
||||||
|
{
|
||||||
|
$this->dbforge->rename_table('service_categories', 'categories');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Easy!Appointments - Online Appointment Scheduler
|
||||||
|
*
|
||||||
|
* @package EasyAppointments
|
||||||
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||||
|
* @copyright Copyright (c) Alex Tselegidis
|
||||||
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||||
|
* @link https://easyappointments.org
|
||||||
|
* @since v1.5.0
|
||||||
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
class Migration_Revert_rename_id_service_categories_column_of_services_table extends EA_Migration {
|
||||||
|
/**
|
||||||
|
* Upgrade method.
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if ($this->db->field_exists('id_categories', 'services'))
|
||||||
|
{
|
||||||
|
$this->db->query('ALTER TABLE `' . $this->db->dbprefix('services') . '` DROP FOREIGN KEY `services_categories`');
|
||||||
|
|
||||||
|
$fields = [
|
||||||
|
'id_categories' => [
|
||||||
|
'name' => 'id_service_categories',
|
||||||
|
'type' => 'INT',
|
||||||
|
'constraint' => '11'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->dbforge->modify_column('services', $fields);
|
||||||
|
|
||||||
|
$this->db->query('
|
||||||
|
ALTER TABLE `' . $this->db->dbprefix('services') . '`
|
||||||
|
ADD CONSTRAINT `services_service_categories` FOREIGN KEY (`id_service_categories`) REFERENCES `' . $this->db->dbprefix('service_categories') . '` (`id`)
|
||||||
|
ON DELETE SET NULL
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downgrade method.
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
if ($this->db->field_exists('id_service_categories', 'services'))
|
||||||
|
{
|
||||||
|
$this->db->query('ALTER TABLE `' . $this->db->dbprefix('services') . '` DROP FOREIGN KEY `services_service_categories`');
|
||||||
|
|
||||||
|
$fields = [
|
||||||
|
'id_service_categories' => [
|
||||||
|
'name' => 'id_categories',
|
||||||
|
'type' => 'INT',
|
||||||
|
'constraint' => '11'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->dbforge->modify_column('services', $fields);
|
||||||
|
|
||||||
|
$this->db->query('
|
||||||
|
ALTER TABLE `' . $this->db->dbprefix('services') . '`
|
||||||
|
ADD CONSTRAINT `services_categories` FOREIGN KEY (`id_categories`) REFERENCES `' . $this->db->dbprefix('categories') . '` (`id`)
|
||||||
|
ON DELETE SET NULL
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,343 +0,0 @@
|
||||||
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Easy!Appointments - Online Appointment Scheduler
|
|
||||||
*
|
|
||||||
* @package EasyAppointments
|
|
||||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
||||||
* @copyright Copyright (c) Alex Tselegidis
|
|
||||||
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
||||||
* @link https://easyappointments.org
|
|
||||||
* @since v1.0.0
|
|
||||||
* ---------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categories model.
|
|
||||||
*
|
|
||||||
* Handles all the database operations of the category resource.
|
|
||||||
*
|
|
||||||
* @package Models
|
|
||||||
*/
|
|
||||||
class Categories_model extends EA_Model {
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected array $casts = [
|
|
||||||
'id' => 'integer',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected array $api_resource = [
|
|
||||||
'id' => 'id',
|
|
||||||
'name' => 'name',
|
|
||||||
'description' => 'description',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save (insert or update) a category.
|
|
||||||
*
|
|
||||||
* @param array $category Associative array with the category data.
|
|
||||||
*
|
|
||||||
* @return int Returns the category ID.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function save(array $category): int
|
|
||||||
{
|
|
||||||
$this->validate($category);
|
|
||||||
|
|
||||||
if (empty($category['id']))
|
|
||||||
{
|
|
||||||
return $this->insert($category);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return $this->update($category);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the category data.
|
|
||||||
*
|
|
||||||
* @param array $category Associative array with the category data.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function validate(array $category)
|
|
||||||
{
|
|
||||||
// If a category ID is provided then check whether the record really exists in the database.
|
|
||||||
if ( ! empty($category['id']))
|
|
||||||
{
|
|
||||||
$count = $this->db->get_where('categories', ['id' => $category['id']])->num_rows();
|
|
||||||
|
|
||||||
if ( ! $count)
|
|
||||||
{
|
|
||||||
throw new InvalidArgumentException('The provided category ID does not exist in the database: ' . $category['id']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure all required fields are provided.
|
|
||||||
if (
|
|
||||||
empty($category['name'])
|
|
||||||
)
|
|
||||||
{
|
|
||||||
throw new InvalidArgumentException('Not all required fields are provided: ' . print_r($category, TRUE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert a new category into the database.
|
|
||||||
*
|
|
||||||
* @param array $category Associative array with the category data.
|
|
||||||
*
|
|
||||||
* @return int Returns the category ID.
|
|
||||||
*
|
|
||||||
* @throws RuntimeException
|
|
||||||
*/
|
|
||||||
protected function insert(array $category): int
|
|
||||||
{
|
|
||||||
$category['create_datetime'] = date('Y-m-d H:i:s');
|
|
||||||
$category['update_datetime'] = date('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
if ( ! $this->db->insert('categories', $category))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Could not insert category.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->db->insert_id();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update an existing category.
|
|
||||||
*
|
|
||||||
* @param array $category Associative array with the category data.
|
|
||||||
*
|
|
||||||
* @return int Returns the category ID.
|
|
||||||
*
|
|
||||||
* @throws RuntimeException
|
|
||||||
*/
|
|
||||||
protected function update(array $category): int
|
|
||||||
{
|
|
||||||
$category['update_datetime'] = date('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
if ( ! $this->db->update('categories', $category, ['id' => $category['id']]))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Could not update service categories.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $category['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove an existing category from the database.
|
|
||||||
*
|
|
||||||
* @param int $category_id Category ID.
|
|
||||||
*
|
|
||||||
* @throws RuntimeException
|
|
||||||
*/
|
|
||||||
public function delete(int $category_id): void
|
|
||||||
{
|
|
||||||
$this->db->delete('categories', ['id' => $category_id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a specific category from the database.
|
|
||||||
*
|
|
||||||
* @param int $category_id The ID of the record to be returned.
|
|
||||||
*
|
|
||||||
* @return array Returns an array with the category data.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function find(int $category_id): array
|
|
||||||
{
|
|
||||||
$category = $this->db->get_where('categories', ['id' => $category_id])->row_array();
|
|
||||||
|
|
||||||
if ( ! $category)
|
|
||||||
{
|
|
||||||
throw new InvalidArgumentException('The provided category ID was not found in the database: ' . $category_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->cast($category);
|
|
||||||
|
|
||||||
return $category;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a specific field value from the database.
|
|
||||||
*
|
|
||||||
* @param int $category_id Category ID.
|
|
||||||
* @param string $field Name of the value to be returned.
|
|
||||||
*
|
|
||||||
* @return mixed Returns the selected category value from the database.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function value(int $category_id, string $field): mixed
|
|
||||||
{
|
|
||||||
if (empty($field))
|
|
||||||
{
|
|
||||||
throw new InvalidArgumentException('The field argument is cannot be empty.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($category_id))
|
|
||||||
{
|
|
||||||
throw new InvalidArgumentException('The category ID argument cannot be empty.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether the service exists.
|
|
||||||
$query = $this->db->get_where('categories', ['id' => $category_id]);
|
|
||||||
|
|
||||||
if ( ! $query->num_rows())
|
|
||||||
{
|
|
||||||
throw new InvalidArgumentException('The provided category ID was not found in the database: ' . $category_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the required field is part of the category data.
|
|
||||||
$category = $query->row_array();
|
|
||||||
|
|
||||||
$this->cast($category);
|
|
||||||
|
|
||||||
if ( ! array_key_exists($field, $category))
|
|
||||||
{
|
|
||||||
throw new InvalidArgumentException('The requested field was not found in the category data: ' . $field);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $category[$field];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all services that match the provided criteria.
|
|
||||||
*
|
|
||||||
* @param array|string|null $where Where conditions
|
|
||||||
* @param int|null $limit Record limit.
|
|
||||||
* @param int|null $offset Record offset.
|
|
||||||
* @param string|null $order_by Order by.
|
|
||||||
*
|
|
||||||
* @return array Returns an array of service categories.
|
|
||||||
*/
|
|
||||||
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
|
||||||
{
|
|
||||||
if ($where !== NULL)
|
|
||||||
{
|
|
||||||
$this->db->where($where);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($order_by !== NULL)
|
|
||||||
{
|
|
||||||
$this->db->order_by($order_by);
|
|
||||||
}
|
|
||||||
|
|
||||||
$categories = $this->db->get('categories', $limit, $offset)->result_array();
|
|
||||||
|
|
||||||
foreach ($categories as &$category)
|
|
||||||
{
|
|
||||||
$this->cast($category);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $categories;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the query builder interface, configured for use with the service categories table.
|
|
||||||
*
|
|
||||||
* @return CI_DB_query_builder
|
|
||||||
*/
|
|
||||||
public function query(): CI_DB_query_builder
|
|
||||||
{
|
|
||||||
return $this->db->from('categories');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Search service categories by the provided keyword.
|
|
||||||
*
|
|
||||||
* @param string $keyword Search keyword.
|
|
||||||
* @param int|null $limit Record limit.
|
|
||||||
* @param int|null $offset Record offset.
|
|
||||||
* @param string|null $order_by Order by.
|
|
||||||
*
|
|
||||||
* @return array Returns an array of service categories.
|
|
||||||
*/
|
|
||||||
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
|
||||||
{
|
|
||||||
$categories = $this
|
|
||||||
->db
|
|
||||||
->select()
|
|
||||||
->from('categories')
|
|
||||||
->group_start()
|
|
||||||
->like('name', $keyword)
|
|
||||||
->or_like('description', $keyword)
|
|
||||||
->group_end()
|
|
||||||
->limit($limit)
|
|
||||||
->offset($offset)
|
|
||||||
->order_by($order_by)
|
|
||||||
->get()
|
|
||||||
->result_array();
|
|
||||||
|
|
||||||
foreach ($categories as &$category)
|
|
||||||
{
|
|
||||||
$this->cast($category);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $categories;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load related resources to a category.
|
|
||||||
*
|
|
||||||
* @param array $category Associative array with the category data.
|
|
||||||
* @param array $resources Resource names to be attached.
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function load(array &$category, array $resources)
|
|
||||||
{
|
|
||||||
// Service categories do not currently have any related resources.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the database category record to the equivalent API resource.
|
|
||||||
*
|
|
||||||
* @param array $category Category data.
|
|
||||||
*/
|
|
||||||
public function api_encode(array &$category)
|
|
||||||
{
|
|
||||||
$encoded_resource = [
|
|
||||||
'id' => array_key_exists('id', $category) ? (int)$category['id'] : NULL,
|
|
||||||
'name' => $category['name'],
|
|
||||||
'description' => array_key_exists('description', $category) ? $category['description'] : NULL
|
|
||||||
];
|
|
||||||
|
|
||||||
$category = $encoded_resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the API resource to the equivalent database category record.
|
|
||||||
*
|
|
||||||
* @param array $category API resource.
|
|
||||||
* @param array|null $base Base category data to be overwritten with the provided values (useful for updates).
|
|
||||||
*/
|
|
||||||
public function api_decode(array &$category, array $base = NULL)
|
|
||||||
{
|
|
||||||
$decoded_resource = $base ?: [];
|
|
||||||
|
|
||||||
if (array_key_exists('id', $category))
|
|
||||||
{
|
|
||||||
$decoded_resource['id'] = $category['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array_key_exists('name', $category))
|
|
||||||
{
|
|
||||||
$decoded_resource['name'] = $category['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array_key_exists('description', $category))
|
|
||||||
{
|
|
||||||
$decoded_resource['description'] = $category['description'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$category = $decoded_resource;
|
|
||||||
}
|
|
||||||
}
|
|
369
application/models/Service_categories_model.php
Normal file
369
application/models/Service_categories_model.php
Normal file
|
@ -0,0 +1,369 @@
|
||||||
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Easy!Appointments - Online Appointment Scheduler
|
||||||
|
*
|
||||||
|
* @package EasyAppointments
|
||||||
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||||
|
* @copyright Copyright (c) Alex Tselegidis
|
||||||
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||||
|
* @link https://easyappointments.org
|
||||||
|
* @since v1.0.0
|
||||||
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service-Categories model.
|
||||||
|
*
|
||||||
|
* Handles all the database operations of the service-category resource.
|
||||||
|
*
|
||||||
|
* @package Models
|
||||||
|
*/
|
||||||
|
class Service_categories_model extends EA_Model {
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected array $casts = [
|
||||||
|
'id' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected array $api_resource = [
|
||||||
|
'id' => 'id',
|
||||||
|
'name' => 'name',
|
||||||
|
'description' => 'description',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save (insert or update) a service-category.
|
||||||
|
*
|
||||||
|
* @param array $service_category Associative array with the service-category data.
|
||||||
|
*
|
||||||
|
* @return int Returns the service-category ID.
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function save(array $service_category): int
|
||||||
|
{
|
||||||
|
$this->validate($service_category);
|
||||||
|
|
||||||
|
if (empty($service_category['id']))
|
||||||
|
{
|
||||||
|
return $this->insert($service_category);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $this->update($service_category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the service-category data.
|
||||||
|
*
|
||||||
|
* @param array $service_category Associative array with the service-category data.
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function validate(array $service_category)
|
||||||
|
{
|
||||||
|
// If a service-category ID is provided then check whether the record really exists in the database.
|
||||||
|
if ( ! empty($service_category['id']))
|
||||||
|
{
|
||||||
|
$count = $this->db->get_where('service_categories', ['id' => $service_category['id']])->num_rows();
|
||||||
|
|
||||||
|
if ( ! $count)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The provided service-category ID does not exist in the database: ' . $service_category['id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure all required fields are provided.
|
||||||
|
if (
|
||||||
|
empty($service_category['name'])
|
||||||
|
)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('Not all required fields are provided: ' . print_r($service_category, TRUE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert a new service-category into the database.
|
||||||
|
*
|
||||||
|
* @param array $service_category Associative array with the service-category data.
|
||||||
|
*
|
||||||
|
* @return int Returns the service-category ID.
|
||||||
|
*
|
||||||
|
* @throws RuntimeException
|
||||||
|
*/
|
||||||
|
protected function insert(array $service_category): int
|
||||||
|
{
|
||||||
|
$service_category['create_datetime'] = date('Y-m-d H:i:s');
|
||||||
|
$service_category['update_datetime'] = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
if ( ! $this->db->insert('service_categories', $service_category))
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Could not insert service-category.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->db->insert_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing service-category.
|
||||||
|
*
|
||||||
|
* @param array $service_category Associative array with the service-category data.
|
||||||
|
*
|
||||||
|
* @return int Returns the service-category ID.
|
||||||
|
*
|
||||||
|
* @throws RuntimeException
|
||||||
|
*/
|
||||||
|
protected function update(array $service_category): int
|
||||||
|
{
|
||||||
|
$service_category['update_datetime'] = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
if ( ! $this->db->update('service_categories', $service_category, ['id' => $service_category['id']]))
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Could not update service categories.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $service_category['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an existing service-category from the database.
|
||||||
|
*
|
||||||
|
* @param int $category_id Category ID.
|
||||||
|
* @param bool $force_delete Override soft delete.
|
||||||
|
*
|
||||||
|
* @throws RuntimeException
|
||||||
|
*/
|
||||||
|
public function delete(int $category_id, bool $force_delete = FALSE)
|
||||||
|
{
|
||||||
|
if ($force_delete)
|
||||||
|
{
|
||||||
|
$this->db->delete('service_categories', ['id' => $category_id]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->update('service_categories', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $category_id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific service-category from the database.
|
||||||
|
*
|
||||||
|
* @param int $category_id The ID of the record to be returned.
|
||||||
|
* @param bool $with_trashed
|
||||||
|
*
|
||||||
|
* @return array Returns an array with the service-category data.
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function find(int $category_id, bool $with_trashed = FALSE): array
|
||||||
|
{
|
||||||
|
if ( ! $with_trashed)
|
||||||
|
{
|
||||||
|
$this->db->where('delete_datetime IS NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
$service_category = $this->db->get_where('service_categories', ['id' => $category_id])->row_array();
|
||||||
|
|
||||||
|
if ( ! $service_category)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The provided service-category ID was not found in the database: ' . $category_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cast($service_category);
|
||||||
|
|
||||||
|
return $service_category;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific field value from the database.
|
||||||
|
*
|
||||||
|
* @param int $category_id Category ID.
|
||||||
|
* @param string $field Name of the value to be returned.
|
||||||
|
*
|
||||||
|
* @return mixed Returns the selected service-category value from the database.
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function value(int $category_id, string $field): mixed
|
||||||
|
{
|
||||||
|
if (empty($field))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The field argument is cannot be empty.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($category_id))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The service-category ID argument cannot be empty.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check whether the service exists.
|
||||||
|
$query = $this->db->get_where('service_categories', ['id' => $category_id]);
|
||||||
|
|
||||||
|
if ( ! $query->num_rows())
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The provided service-category ID was not found in the database: ' . $category_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the required field is part of the service-category data.
|
||||||
|
$service_category = $query->row_array();
|
||||||
|
|
||||||
|
$this->cast($service_category);
|
||||||
|
|
||||||
|
if ( ! array_key_exists($field, $service_category))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The requested field was not found in the service-category data: ' . $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $service_category[$field];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all services that match the provided criteria.
|
||||||
|
*
|
||||||
|
* @param array|string|null $where Where conditions
|
||||||
|
* @param int|null $limit Record limit.
|
||||||
|
* @param int|null $offset Record offset.
|
||||||
|
* @param string|null $order_by Order by.
|
||||||
|
* @param bool $with_trashed
|
||||||
|
*
|
||||||
|
* @return array Returns an array of service categories.
|
||||||
|
*/
|
||||||
|
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||||
|
{
|
||||||
|
if ($where !== NULL)
|
||||||
|
{
|
||||||
|
$this->db->where($where);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($order_by !== NULL)
|
||||||
|
{
|
||||||
|
$this->db->order_by($order_by);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $with_trashed)
|
||||||
|
{
|
||||||
|
$this->db->where('delete_datetime IS NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
$service_categories = $this->db->get('service_categories', $limit, $offset)->result_array();
|
||||||
|
|
||||||
|
foreach ($service_categories as &$service_category)
|
||||||
|
{
|
||||||
|
$this->cast($service_category);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $service_categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the query builder interface, configured for use with the service categories table.
|
||||||
|
*
|
||||||
|
* @return CI_DB_query_builder
|
||||||
|
*/
|
||||||
|
public function query(): CI_DB_query_builder
|
||||||
|
{
|
||||||
|
return $this->db->from('service_categories');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search service categories by the provided keyword.
|
||||||
|
*
|
||||||
|
* @param string $keyword Search keyword.
|
||||||
|
* @param int|null $limit Record limit.
|
||||||
|
* @param int|null $offset Record offset.
|
||||||
|
* @param string|null $order_by Order by.
|
||||||
|
* @param bool $with_trashed
|
||||||
|
*
|
||||||
|
* @return array Returns an array of service categories.
|
||||||
|
*/
|
||||||
|
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||||
|
{
|
||||||
|
if ( ! $with_trashed)
|
||||||
|
{
|
||||||
|
$this->db->where('delete_datetime IS NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
$service_categories = $this
|
||||||
|
->db
|
||||||
|
->select()
|
||||||
|
->from('service_categories')
|
||||||
|
->group_start()
|
||||||
|
->like('name', $keyword)
|
||||||
|
->or_like('description', $keyword)
|
||||||
|
->group_end()
|
||||||
|
->limit($limit)
|
||||||
|
->offset($offset)
|
||||||
|
->order_by($order_by)
|
||||||
|
->get()
|
||||||
|
->result_array();
|
||||||
|
|
||||||
|
foreach ($service_categories as &$service_category)
|
||||||
|
{
|
||||||
|
$this->cast($service_category);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $service_categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load related resources to a service-category.
|
||||||
|
*
|
||||||
|
* @param array $service_category Associative array with the service-category data.
|
||||||
|
* @param array $resources Resource names to be attached.
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function load(array &$service_category, array $resources)
|
||||||
|
{
|
||||||
|
// Service categories do not currently have any related resources.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the database service-category record to the equivalent API resource.
|
||||||
|
*
|
||||||
|
* @param array $service_category Category data.
|
||||||
|
*/
|
||||||
|
public function api_encode(array &$service_category)
|
||||||
|
{
|
||||||
|
$encoded_resource = [
|
||||||
|
'id' => array_key_exists('id', $service_category) ? (int)$service_category['id'] : NULL,
|
||||||
|
'name' => $service_category['name'],
|
||||||
|
'description' => array_key_exists('description', $service_category) ? $service_category['description'] : NULL
|
||||||
|
];
|
||||||
|
|
||||||
|
$service_category = $encoded_resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the API resource to the equivalent database service-category record.
|
||||||
|
*
|
||||||
|
* @param array $service_category API resource.
|
||||||
|
* @param array|null $base Base service-category data to be overwritten with the provided values (useful for updates).
|
||||||
|
*/
|
||||||
|
public function api_decode(array &$service_category, array $base = NULL)
|
||||||
|
{
|
||||||
|
$decoded_resource = $base ?: [];
|
||||||
|
|
||||||
|
if (array_key_exists('id', $service_category))
|
||||||
|
{
|
||||||
|
$decoded_resource['id'] = $service_category['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('name', $service_category))
|
||||||
|
{
|
||||||
|
$decoded_resource['name'] = $service_category['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('description', $service_category))
|
||||||
|
{
|
||||||
|
$decoded_resource['description'] = $service_category['description'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$service_category = $decoded_resource;
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,7 +27,7 @@ class Services_model extends EA_Model {
|
||||||
'price' => 'float',
|
'price' => 'float',
|
||||||
'attendants_number' => 'integer',
|
'attendants_number' => 'integer',
|
||||||
'is_private' => 'boolean',
|
'is_private' => 'boolean',
|
||||||
'id_categories' => 'integer',
|
'id_service_categories' => 'integer',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,7 +45,7 @@ class Services_model extends EA_Model {
|
||||||
'availabilitiesType' => 'availabilities_type',
|
'availabilitiesType' => 'availabilities_type',
|
||||||
'attendantsNumber' => 'attendants_number',
|
'attendantsNumber' => 'attendants_number',
|
||||||
'isPrivate' => 'is_private',
|
'isPrivate' => 'is_private',
|
||||||
'categoryId' => 'id_categories',
|
'serviceCategoryId' => 'id_service_categories',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,18 +99,18 @@ class Services_model extends EA_Model {
|
||||||
throw new InvalidArgumentException('Not all required fields are provided: ' . print_r($service, TRUE));
|
throw new InvalidArgumentException('Not all required fields are provided: ' . print_r($service, TRUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a category was provided then make sure it really exists in the database.
|
// If a category was provided then make sure it really exists in the database.
|
||||||
if ( ! empty($service['id_categories']))
|
if ( ! empty($service['id_service_categories']))
|
||||||
{
|
{
|
||||||
$count = $this->db->get_where('categories', ['id' => $service['id_categories']])->num_rows();
|
$count = $this->db->get_where('categories', ['id' => $service['id_service_categories']])->num_rows();
|
||||||
|
|
||||||
if ( ! $count)
|
if ( ! $count)
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('The provided category ID was not found in the database: ' . $service['id_categories']);
|
throw new InvalidArgumentException('The provided category ID was not found in the database: ' . $service['id_service_categories']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the duration value is valid.
|
// Make sure the duration value is valid.
|
||||||
if ( ! empty($service['duration']))
|
if ( ! empty($service['duration']))
|
||||||
{
|
{
|
||||||
if ((int)$service['duration'] < EVENT_MINIMUM_DURATION)
|
if ((int)$service['duration'] < EVENT_MINIMUM_DURATION)
|
||||||
|
@ -136,7 +136,7 @@ class Services_model extends EA_Model {
|
||||||
throw new InvalidArgumentException('The provided availabilities type is invalid: ' . $service['availabilities_type']);
|
throw new InvalidArgumentException('The provided availabilities type is invalid: ' . $service['availabilities_type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the attendants number value.
|
// Validate the attendants number value.
|
||||||
if (empty($service['attendants_number']) || (int)$service['attendants_number'] < 1)
|
if (empty($service['attendants_number']) || (int)$service['attendants_number'] < 1)
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('The provided attendants number is invalid: ' . $service['attendants_number']);
|
throw new InvalidArgumentException('The provided attendants number is invalid: ' . $service['attendants_number']);
|
||||||
|
@ -190,25 +190,39 @@ class Services_model extends EA_Model {
|
||||||
* Remove an existing service from the database.
|
* Remove an existing service from the database.
|
||||||
*
|
*
|
||||||
* @param int $service_id Service ID.
|
* @param int $service_id Service ID.
|
||||||
|
* @param bool $force_delete Override soft delete.
|
||||||
*
|
*
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function delete(int $service_id): void
|
public function delete(int $service_id, bool $force_delete = FALSE)
|
||||||
{
|
{
|
||||||
$this->db->delete('services', ['id' => $service_id]);
|
if ($force_delete)
|
||||||
|
{
|
||||||
|
$this->db->delete('services', ['id' => $service_id]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->update('services', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $service_id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a specific service from the database.
|
* Get a specific service from the database.
|
||||||
*
|
*
|
||||||
* @param int $service_id The ID of the record to be returned.
|
* @param int $service_id The ID of the record to be returned.
|
||||||
|
* @param bool $with_trashed
|
||||||
*
|
*
|
||||||
* @return array Returns an array with the service data.
|
* @return array Returns an array with the service data.
|
||||||
*
|
*
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function find(int $service_id): array
|
public function find(int $service_id, bool $with_trashed = FALSE): array
|
||||||
{
|
{
|
||||||
|
if ( ! $with_trashed)
|
||||||
|
{
|
||||||
|
$this->db->where('delete_datetime IS NULL');
|
||||||
|
}
|
||||||
|
|
||||||
$service = $this->db->get_where('services', ['id' => $service_id])->row_array();
|
$service = $this->db->get_where('services', ['id' => $service_id])->row_array();
|
||||||
|
|
||||||
if ( ! $service)
|
if ( ! $service)
|
||||||
|
@ -271,10 +285,11 @@ class Services_model extends EA_Model {
|
||||||
* @param int|null $limit Record limit.
|
* @param int|null $limit Record limit.
|
||||||
* @param int|null $offset Record offset.
|
* @param int|null $offset Record offset.
|
||||||
* @param string|null $order_by Order by.
|
* @param string|null $order_by Order by.
|
||||||
|
* @param bool $with_trashed
|
||||||
*
|
*
|
||||||
* @return array Returns an array of services.
|
* @return array Returns an array of services.
|
||||||
*/
|
*/
|
||||||
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||||
{
|
{
|
||||||
if ($where !== NULL)
|
if ($where !== NULL)
|
||||||
{
|
{
|
||||||
|
@ -286,6 +301,11 @@ class Services_model extends EA_Model {
|
||||||
$this->db->order_by($order_by);
|
$this->db->order_by($order_by);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! $with_trashed)
|
||||||
|
{
|
||||||
|
$this->db->where('delete_datetime IS NULL');
|
||||||
|
}
|
||||||
|
|
||||||
$services = $this->db->get('services', $limit, $offset)->result_array();
|
$services = $this->db->get('services', $limit, $offset)->result_array();
|
||||||
|
|
||||||
foreach ($services as &$service)
|
foreach ($services as &$service)
|
||||||
|
@ -313,10 +333,11 @@ class Services_model extends EA_Model {
|
||||||
$services = $this
|
$services = $this
|
||||||
->db
|
->db
|
||||||
->distinct()
|
->distinct()
|
||||||
->select('services.*, categories.name AS category_name, categories.id AS category_id')
|
->select('services.*, service_categories.name AS service_category_name, service_categories.id AS service_category_id')
|
||||||
->from('services')
|
->from('services')
|
||||||
->join('services_providers', 'services_providers.id_services = services.id', 'inner')
|
->join('services_providers', 'services_providers.id_services = services.id', 'inner')
|
||||||
->join('categories', 'categories.id = services.id_categories', 'left')
|
->join('service_categories', 'service_categories.id = services.id_service_categories', 'left')
|
||||||
|
->where('services.delete_datetime IS NULL')
|
||||||
->order_by('name ASC')
|
->order_by('name ASC')
|
||||||
->get()
|
->get()
|
||||||
->result_array();
|
->result_array();
|
||||||
|
@ -346,11 +367,17 @@ class Services_model extends EA_Model {
|
||||||
* @param int|null $limit Record limit.
|
* @param int|null $limit Record limit.
|
||||||
* @param int|null $offset Record offset.
|
* @param int|null $offset Record offset.
|
||||||
* @param string|null $order_by Order by.
|
* @param string|null $order_by Order by.
|
||||||
|
* @param bool $with_trashed
|
||||||
*
|
*
|
||||||
* @return array Returns an array of services.
|
* @return array Returns an array of services.
|
||||||
*/
|
*/
|
||||||
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
|
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
|
||||||
{
|
{
|
||||||
|
if ( ! $with_trashed)
|
||||||
|
{
|
||||||
|
$this->db->where('delete_datetime IS NULL');
|
||||||
|
}
|
||||||
|
|
||||||
$services = $this
|
$services = $this
|
||||||
->db
|
->db
|
||||||
->select()
|
->select()
|
||||||
|
@ -395,7 +422,7 @@ class Services_model extends EA_Model {
|
||||||
'category' => $this
|
'category' => $this
|
||||||
->db
|
->db
|
||||||
->get_where('categories', [
|
->get_where('categories', [
|
||||||
'id' => $service['id_categories'] ?? $service['categoryId'] ?? NULL
|
'id' => $service['id_service_categories'] ?? $service['serviceCategoryId'] ?? NULL
|
||||||
])
|
])
|
||||||
->row_array(),
|
->row_array(),
|
||||||
default => throw new InvalidArgumentException('The requested appointment relation is not supported: ' . $resource),
|
default => throw new InvalidArgumentException('The requested appointment relation is not supported: ' . $resource),
|
||||||
|
@ -420,7 +447,7 @@ class Services_model extends EA_Model {
|
||||||
'location' => $service['location'],
|
'location' => $service['location'],
|
||||||
'availabilitiesType' => $service['availabilities_type'],
|
'availabilitiesType' => $service['availabilities_type'],
|
||||||
'attendantsNumber' => (int)$service['attendants_number'],
|
'attendantsNumber' => (int)$service['attendants_number'],
|
||||||
'categoryId' => $service['id_categories'] !== NULL ? (int)$service['id_categories'] : NULL
|
'serviceCategoryId' => $service['id_service_categories'] !== NULL ? (int)$service['id_service_categories'] : NULL
|
||||||
];
|
];
|
||||||
|
|
||||||
$service = $encoded_resource;
|
$service = $encoded_resource;
|
||||||
|
@ -481,9 +508,9 @@ class Services_model extends EA_Model {
|
||||||
$decoded_resource['attendants_number'] = $service['attendantsNumber'];
|
$decoded_resource['attendants_number'] = $service['attendantsNumber'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('categoryId', $service))
|
if (array_key_exists('serviceCategoryId', $service))
|
||||||
{
|
{
|
||||||
$decoded_resource['id_categories'] = $service['categoryId'];
|
$decoded_resource['id_service_categories'] = $service['serviceCategoryId'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$service = $decoded_resource;
|
$service = $decoded_resource;
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
<a class="dropdown-item" href="<?= site_url('services') ?>">
|
<a class="dropdown-item" href="<?= site_url('services') ?>">
|
||||||
<?= lang('services') ?>
|
<?= lang('services') ?>
|
||||||
</a>
|
</a>
|
||||||
<a class="dropdown-item" href="<?= site_url('categories') ?>">
|
<a class="dropdown-item" href="<?= site_url('service_categories') ?>">
|
||||||
<?= lang('categories') ?>
|
<?= lang('categories') ?>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
$has_category = FALSE;
|
$has_category = FALSE;
|
||||||
foreach ($available_services as $service)
|
foreach ($available_services as $service)
|
||||||
{
|
{
|
||||||
if ( ! empty($service['category_id']))
|
if ( ! empty($service['service_category_id']))
|
||||||
{
|
{
|
||||||
$has_category = TRUE;
|
$has_category = TRUE;
|
||||||
break;
|
break;
|
||||||
|
@ -36,14 +36,14 @@
|
||||||
|
|
||||||
foreach ($available_services as $service)
|
foreach ($available_services as $service)
|
||||||
{
|
{
|
||||||
if ( ! empty($service['category_id']))
|
if ( ! empty($service['service_category_id']))
|
||||||
{
|
{
|
||||||
if ( ! isset($grouped_services[$service['category_name']]))
|
if ( ! isset($grouped_services[$service['service_category_name']]))
|
||||||
{
|
{
|
||||||
$grouped_services[$service['category_name']] = [];
|
$grouped_services[$service['service_category_name']] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$grouped_services[$service['category_name']][] = $service;
|
$grouped_services[$service['service_category_name']][] = $service;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
$grouped_services['uncategorized'] = [];
|
$grouped_services['uncategorized'] = [];
|
||||||
foreach ($available_services as $service)
|
foreach ($available_services as $service)
|
||||||
{
|
{
|
||||||
if ($service['category_id'] == NULL)
|
if ($service['service_category_id'] == NULL)
|
||||||
{
|
{
|
||||||
$grouped_services['uncategorized'][] = $service;
|
$grouped_services['uncategorized'][] = $service;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
foreach ($grouped_services as $key => $group)
|
foreach ($grouped_services as $key => $group)
|
||||||
{
|
{
|
||||||
$group_label = $key !== 'uncategorized'
|
$group_label = $key !== 'uncategorized'
|
||||||
? $group[0]['category_name']
|
? $group[0]['service_category_name']
|
||||||
: 'Uncategorized';
|
: 'Uncategorized';
|
||||||
|
|
||||||
if (count($group) > 0)
|
if (count($group) > 0)
|
||||||
|
|
20
application/views/pages/categories.php → application/views/pages/service_categories.php
Executable file → Normal file
20
application/views/pages/categories.php → application/views/pages/service_categories.php
Executable file → Normal file
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
<div class="container-fluid backend-page" id="service-categories-page">
|
<div class="container-fluid backend-page" id="service-categories-page">
|
||||||
|
|
||||||
<div class="row" id="categories">
|
<div class="row" id="service-categories">
|
||||||
<div id="filter-categories" class="filter-records column col-12 col-md-5">
|
<div id="filter-service-categories" class="filter-records column col-12 col-md-5">
|
||||||
<form class="input-append mb-4">
|
<form class="input-append mb-4">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="text" class="key form-control">
|
<input type="text" class="key form-control">
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<h4 class="text-black-50 mb-3 fw-light">
|
<h4 class="text-black-50 mb-3 fw-light">
|
||||||
<?= lang('categories') ?>
|
<?= lang('service-categories') ?>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
<div class="results">
|
<div class="results">
|
||||||
|
@ -29,26 +29,26 @@
|
||||||
<div class="record-details col-12 col-md-5">
|
<div class="record-details col-12 col-md-5">
|
||||||
<div class="btn-toolbar mb-4">
|
<div class="btn-toolbar mb-4">
|
||||||
<div class="add-edit-delete-group btn-group">
|
<div class="add-edit-delete-group btn-group">
|
||||||
<button id="add-category" class="btn btn-primary">
|
<button id="add-service-category" class="btn btn-primary">
|
||||||
<i class="fas fa-plus-square me-2"></i>
|
<i class="fas fa-plus-square me-2"></i>
|
||||||
<?= lang('add') ?>
|
<?= lang('add') ?>
|
||||||
</button>
|
</button>
|
||||||
<button id="edit-category" class="btn btn-outline-secondary" disabled="disabled">
|
<button id="edit-service-category" class="btn btn-outline-secondary" disabled="disabled">
|
||||||
<i class="fas fa-edit me-2"></i>
|
<i class="fas fa-edit me-2"></i>
|
||||||
<?= lang('edit') ?>
|
<?= lang('edit') ?>
|
||||||
</button>
|
</button>
|
||||||
<button id="delete-category" class="btn btn-outline-secondary" disabled="disabled">
|
<button id="delete-service-category" class="btn btn-outline-secondary" disabled="disabled">
|
||||||
<i class="fas fa-trash-alt me-2"></i>
|
<i class="fas fa-trash-alt me-2"></i>
|
||||||
<?= lang('delete') ?>
|
<?= lang('delete') ?>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="save-cancel-group" style="display:none;">
|
<div class="save-cancel-group" style="display:none;">
|
||||||
<button id="save-category" class="btn btn-primary">
|
<button id="save-service-category" class="btn btn-primary">
|
||||||
<i class="fas fa-check-square me-2"></i>
|
<i class="fas fa-check-square me-2"></i>
|
||||||
<?= lang('save') ?>
|
<?= lang('save') ?>
|
||||||
</button>
|
</button>
|
||||||
<button id="cancel-category" class="btn btn-secondary">
|
<button id="cancel-service-category" class="btn btn-secondary">
|
||||||
<?= lang('cancel') ?>
|
<?= lang('cancel') ?>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -89,7 +89,7 @@
|
||||||
<script src="<?= asset_url('assets/js/utils/message.js') ?>"></script>
|
<script src="<?= asset_url('assets/js/utils/message.js') ?>"></script>
|
||||||
<script src="<?= asset_url('assets/js/utils/validation.js') ?>"></script>
|
<script src="<?= asset_url('assets/js/utils/validation.js') ?>"></script>
|
||||||
<script src="<?= asset_url('assets/js/utils/url.js') ?>"></script>
|
<script src="<?= asset_url('assets/js/utils/url.js') ?>"></script>
|
||||||
<script src="<?= asset_url('assets/js/http/categories_http_client.js') ?>"></script>
|
<script src="<?= asset_url('assets/js/http/service_categories_http_client.js') ?>"></script>
|
||||||
<script src="<?= asset_url('assets/js/pages/categories.js') ?>"></script>
|
<script src="<?= asset_url('assets/js/pages/service_categories.js') ?>"></script>
|
||||||
|
|
||||||
<?php end_section('scripts') ?>
|
<?php end_section('scripts') ?>
|
|
@ -94,10 +94,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label" for="category">
|
<label class="form-label" for="service-category-id">
|
||||||
<?= lang('category') ?>
|
<?= lang('category') ?>
|
||||||
</label>
|
</label>
|
||||||
<select id="category" class="form-control" disabled></select>
|
<select id="service-category-id" class="form-control" disabled></select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
|
@ -174,7 +174,7 @@
|
||||||
<script src="<?= asset_url('assets/js/utils/validation.js') ?>"></script>
|
<script src="<?= asset_url('assets/js/utils/validation.js') ?>"></script>
|
||||||
<script src="<?= asset_url('assets/js/utils/url.js') ?>"></script>
|
<script src="<?= asset_url('assets/js/utils/url.js') ?>"></script>
|
||||||
<script src="<?= asset_url('assets/js/http/services_http_client.js') ?>"></script>
|
<script src="<?= asset_url('assets/js/http/services_http_client.js') ?>"></script>
|
||||||
<script src="<?= asset_url('assets/js/http/categories_http_client.js') ?>"></script>
|
<script src="<?= asset_url('assets/js/http/service_categories_http_client.js') ?>"></script>
|
||||||
<script src="<?= asset_url('assets/js/pages/services.js') ?>"></script>
|
<script src="<?= asset_url('assets/js/pages/services.js') ?>"></script>
|
||||||
|
|
||||||
<?php end_section('scripts') ?>
|
<?php end_section('scripts') ?>
|
||||||
|
|
|
@ -10,78 +10,78 @@
|
||||||
* ---------------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Categories HTTP client.
|
* Service-categories HTTP client.
|
||||||
*
|
*
|
||||||
* This module implements the categories related HTTP requests.
|
* This module implements the service-categories related HTTP requests.
|
||||||
*/
|
*/
|
||||||
App.Http.Categories = (function () {
|
App.Http.ServiceCategories = (function () {
|
||||||
/**
|
/**
|
||||||
* Save (create or update) a category.
|
* Save (create or update) a service-category.
|
||||||
*
|
*
|
||||||
* @param {Object} category
|
* @param {Object} serviceCategory
|
||||||
*
|
*
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
function save(category) {
|
function save(serviceCategory) {
|
||||||
return category.id ? update(category) : create(category);
|
return serviceCategory.id ? update(serviceCategory) : create(serviceCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a category.
|
* Create a service-category.
|
||||||
*
|
*
|
||||||
* @param {Object} category
|
* @param {Object} serviceCategory
|
||||||
*
|
*
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
function create(category) {
|
function create(serviceCategory) {
|
||||||
const url = App.Utils.Url.siteUrl('categories/create');
|
const url = App.Utils.Url.siteUrl('service_categories/create');
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
csrf_token: vars('csrf_token'),
|
csrf_token: vars('csrf_token'),
|
||||||
category: category
|
service_category: serviceCategory
|
||||||
};
|
};
|
||||||
|
|
||||||
return $.post(url, data);
|
return $.post(url, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a category.
|
* Update a service-category.
|
||||||
*
|
*
|
||||||
* @param {Object} category
|
* @param {Object} serviceCategory
|
||||||
*
|
*
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
function update(category) {
|
function update(serviceCategory) {
|
||||||
const url = App.Utils.Url.siteUrl('categories/update');
|
const url = App.Utils.Url.siteUrl('service_categories/update');
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
csrf_token: vars('csrf_token'),
|
csrf_token: vars('csrf_token'),
|
||||||
category: category
|
service_category: serviceCategory
|
||||||
};
|
};
|
||||||
|
|
||||||
return $.post(url, data);
|
return $.post(url, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a category.
|
* Delete a service-category.
|
||||||
*
|
*
|
||||||
* @param {Number} categoryId
|
* @param {Number} serviceCategoryId
|
||||||
*
|
*
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
function destroy(categoryId) {
|
function destroy(serviceCategoryId) {
|
||||||
const url = App.Utils.Url.siteUrl('categories/destroy');
|
const url = App.Utils.Url.siteUrl('service_categories/destroy');
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
csrf_token: vars('csrf_token'),
|
csrf_token: vars('csrf_token'),
|
||||||
category_id: categoryId
|
service_category_id: serviceCategoryId
|
||||||
};
|
};
|
||||||
|
|
||||||
return $.post(url, data);
|
return $.post(url, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search categories by keyword.
|
* Search service-categories by keyword.
|
||||||
*
|
*
|
||||||
* @param {String} keyword
|
* @param {String} keyword
|
||||||
* @param {Number} [limit]
|
* @param {Number} [limit]
|
||||||
|
@ -91,7 +91,7 @@ App.Http.Categories = (function () {
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
function search(keyword, limit = null, offset = null, orderBy = null) {
|
function search(keyword, limit = null, offset = null, orderBy = null) {
|
||||||
const url = App.Utils.Url.siteUrl('categories/search');
|
const url = App.Utils.Url.siteUrl('service_categories/search');
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
csrf_token: vars('csrf_token'),
|
csrf_token: vars('csrf_token'),
|
||||||
|
@ -105,18 +105,18 @@ App.Http.Categories = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a category.
|
* Find a service-category.
|
||||||
*
|
*
|
||||||
* @param {Number} categoryId
|
* @param {Number} serviceCategoryId
|
||||||
*
|
*
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
function find(categoryId) {
|
function find(serviceCategoryId) {
|
||||||
const url = App.Utils.Url.siteUrl('categories/find');
|
const url = App.Utils.Url.siteUrl('service_categories/find');
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
csrf_token: vars('csrf_token'),
|
csrf_token: vars('csrf_token'),
|
||||||
category_id: categoryId
|
service_category_id: serviceCategoryId
|
||||||
};
|
};
|
||||||
|
|
||||||
return $.post(url, data);
|
return $.post(url, data);
|
|
@ -10,13 +10,13 @@
|
||||||
* ---------------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Categories page.
|
* Service-categories page.
|
||||||
*
|
*
|
||||||
* This module implements the functionality of the categories page.
|
* This module implements the functionality of the service-categories page.
|
||||||
*/
|
*/
|
||||||
App.Pages.Categories = (function () {
|
App.Pages.Categories = (function () {
|
||||||
const $categories = $('#categories');
|
const $serviceCategories = $('#service-categories');
|
||||||
const $filterCategories = $('#filter-categories');
|
const $filterCategories = $('#filter-service-categories');
|
||||||
const $id = $('#id');
|
const $id = $('#id');
|
||||||
const $name = $('#name');
|
const $name = $('#name');
|
||||||
const $description = $('#description');
|
const $description = $('#description');
|
||||||
|
@ -32,67 +32,67 @@ App.Pages.Categories = (function () {
|
||||||
*
|
*
|
||||||
* @param {jQuery.Event} event
|
* @param {jQuery.Event} event
|
||||||
*/
|
*/
|
||||||
$categories.on('submit', '#filter-categories form', (event) => {
|
$serviceCategories.on('submit', '#filter-service-categories form', (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const key = $('#filter-categories .key').val();
|
const key = $('#filter-service-categories .key').val();
|
||||||
$('.selected').removeClass('selected');
|
$('.selected').removeClass('selected');
|
||||||
resetForm();
|
resetForm();
|
||||||
filter(key);
|
filter(key);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event: Filter Categories Row "Click"
|
* Event: Filter Service-Categories Row "Click"
|
||||||
*
|
*
|
||||||
* Displays the selected row data on the right side of the page.
|
* Displays the selected row data on the right side of the page.
|
||||||
*
|
*
|
||||||
* @param {jQuery.Event} event
|
* @param {jQuery.Event} event
|
||||||
*/
|
*/
|
||||||
$categories.on('click', '.category-row', (event) => {
|
$serviceCategories.on('click', '.service-category-row', (event) => {
|
||||||
if ($('#filter-categories .filter').prop('disabled')) {
|
if ($('#filter-service-categories .filter').prop('disabled')) {
|
||||||
$('#filter-categories .results').css('color', '#AAA');
|
$('#filter-service-categories .results').css('color', '#AAA');
|
||||||
return; // exit because we are on edit mode
|
return; // exit because we are on edit mode
|
||||||
}
|
}
|
||||||
|
|
||||||
const categoryId = $(event.currentTarget).attr('data-id');
|
const serviceCategoryId = $(event.currentTarget).attr('data-id');
|
||||||
|
|
||||||
const category = filterResults.find((filterResult) => Number(filterResult.id) === Number(categoryId));
|
const serviceCategory = filterResults.find((filterResult) => Number(filterResult.id) === Number(serviceCategoryId));
|
||||||
|
|
||||||
display(category);
|
display(serviceCategory);
|
||||||
$('#filter-categories .selected').removeClass('selected');
|
$('#filter-service-categories .selected').removeClass('selected');
|
||||||
$(event.currentTarget).addClass('selected');
|
$(event.currentTarget).addClass('selected');
|
||||||
$('#edit-category, #delete-category').prop('disabled', false);
|
$('#edit-service-category, #delete-service-category').prop('disabled', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event: Add Category Button "Click"
|
* Event: Add Service-Category Button "Click"
|
||||||
*/
|
*/
|
||||||
$categories.on('click', '#add-category', () => {
|
$serviceCategories.on('click', '#add-service-category', () => {
|
||||||
resetForm();
|
resetForm();
|
||||||
$categories.find('.add-edit-delete-group').hide();
|
$serviceCategories.find('.add-edit-delete-group').hide();
|
||||||
$categories.find('.save-cancel-group').show();
|
$serviceCategories.find('.save-cancel-group').show();
|
||||||
$categories.find('.record-details').find('input, select, textarea').prop('disabled', false);
|
$serviceCategories.find('.record-details').find('input, select, textarea').prop('disabled', false);
|
||||||
$categories.find('.record-details .form-label span').prop('hidden', false);
|
$serviceCategories.find('.record-details .form-label span').prop('hidden', false);
|
||||||
$filterCategories.find('button').prop('disabled', true);
|
$filterCategories.find('button').prop('disabled', true);
|
||||||
$filterCategories.find('.results').css('color', '#AAA');
|
$filterCategories.find('.results').css('color', '#AAA');
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event: Edit Category Button "Click"
|
* Event: Edit Service-Category Button "Click"
|
||||||
*/
|
*/
|
||||||
$categories.on('click', '#edit-category', () => {
|
$serviceCategories.on('click', '#edit-service-category', () => {
|
||||||
$categories.find('.add-edit-delete-group').hide();
|
$serviceCategories.find('.add-edit-delete-group').hide();
|
||||||
$categories.find('.save-cancel-group').show();
|
$serviceCategories.find('.save-cancel-group').show();
|
||||||
$categories.find('.record-details').find('input, select, textarea').prop('disabled', false);
|
$serviceCategories.find('.record-details').find('input, select, textarea').prop('disabled', false);
|
||||||
$categories.find('.record-details .form-label span').prop('hidden', false);
|
$serviceCategories.find('.record-details .form-label span').prop('hidden', false);
|
||||||
$filterCategories.find('button').prop('disabled', true);
|
$filterCategories.find('button').prop('disabled', true);
|
||||||
$filterCategories.find('.results').css('color', '#AAA');
|
$filterCategories.find('.results').css('color', '#AAA');
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event: Delete Category Button "Click"
|
* Event: Delete Service-Category Button "Click"
|
||||||
*/
|
*/
|
||||||
$categories.on('click', '#delete-category', () => {
|
$serviceCategories.on('click', '#delete-service-category', () => {
|
||||||
const categoryId = $id.val();
|
const serviceCategoryId = $id.val();
|
||||||
|
|
||||||
const buttons = [
|
const buttons = [
|
||||||
{
|
{
|
||||||
|
@ -104,7 +104,7 @@ App.Pages.Categories = (function () {
|
||||||
{
|
{
|
||||||
text: lang('delete'),
|
text: lang('delete'),
|
||||||
click: (event, messageModal) => {
|
click: (event, messageModal) => {
|
||||||
remove(categoryId);
|
remove(serviceCategoryId);
|
||||||
messageModal.dispose();
|
messageModal.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,27 +116,27 @@ App.Pages.Categories = (function () {
|
||||||
/**
|
/**
|
||||||
* Event: Categories Save Button "Click"
|
* Event: Categories Save Button "Click"
|
||||||
*/
|
*/
|
||||||
$categories.on('click', '#save-category', () => {
|
$serviceCategories.on('click', '#save-service-category', () => {
|
||||||
const category = {
|
const serviceCategory = {
|
||||||
name: $name.val(),
|
name: $name.val(),
|
||||||
description: $description.val()
|
description: $description.val()
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($id.val() !== '') {
|
if ($id.val() !== '') {
|
||||||
category.id = $id.val();
|
serviceCategory.id = $id.val();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validate()) {
|
if (!validate()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
save(category);
|
save(serviceCategory);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event: Cancel Category Button "Click"
|
* Event: Cancel Service-Category Button "Click"
|
||||||
*/
|
*/
|
||||||
$categories.on('click', '#cancel-category', () => {
|
$serviceCategories.on('click', '#cancel-service-category', () => {
|
||||||
const id = $id.val();
|
const id = $id.val();
|
||||||
resetForm();
|
resetForm();
|
||||||
if (id !== '') {
|
if (id !== '') {
|
||||||
|
@ -148,23 +148,23 @@ App.Pages.Categories = (function () {
|
||||||
/**
|
/**
|
||||||
* Filter service categories records.
|
* Filter service categories records.
|
||||||
*
|
*
|
||||||
* @param {String} keyword This key string is used to filter the category records.
|
* @param {String} keyword This key string is used to filter the service-category records.
|
||||||
* @param {Number} selectId Optional, if set then after the filter operation the record with the given
|
* @param {Number} selectId Optional, if set then after the filter operation the record with the given
|
||||||
* ID will be selected (but not displayed).
|
* ID will be selected (but not displayed).
|
||||||
* @param {Boolean} show Optional (false), if true then the selected record will be displayed on the form.
|
* @param {Boolean} show Optional (false), if true then the selected record will be displayed on the form.
|
||||||
*/
|
*/
|
||||||
function filter(keyword, selectId = null, show = false) {
|
function filter(keyword, selectId = null, show = false) {
|
||||||
App.Http.Categories.search(keyword, filterLimit).then((response) => {
|
App.Http.ServiceCategories.search(keyword, filterLimit).then((response) => {
|
||||||
filterResults = response;
|
filterResults = response;
|
||||||
|
|
||||||
$('#filter-categories .results').empty();
|
$('#filter-service-categories .results').empty();
|
||||||
|
|
||||||
response.forEach((category) => {
|
response.forEach((serviceCategory) => {
|
||||||
$('#filter-categories .results').append(getFilterHtml(category)).append($('<hr/>'));
|
$('#filter-service-categories .results').append(getFilterHtml(serviceCategory)).append($('<hr/>'));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.length === 0) {
|
if (response.length === 0) {
|
||||||
$('#filter-categories .results').append(
|
$('#filter-service-categories .results').append(
|
||||||
$('<em/>', {
|
$('<em/>', {
|
||||||
'text': lang('no_records_found')
|
'text': lang('no_records_found')
|
||||||
})
|
})
|
||||||
|
@ -178,7 +178,7 @@ App.Pages.Categories = (function () {
|
||||||
filterLimit += 20;
|
filterLimit += 20;
|
||||||
filter(keyword, selectId, show);
|
filter(keyword, selectId, show);
|
||||||
}
|
}
|
||||||
}).appendTo('#filter-categories .results');
|
}).appendTo('#filter-service-categories .results');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectId) {
|
if (selectId) {
|
||||||
|
@ -188,13 +188,13 @@ App.Pages.Categories = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a category record to the database (via AJAX post).
|
* Save a service-category record to the database (via AJAX post).
|
||||||
*
|
*
|
||||||
* @param {Object} category Contains the category data.
|
* @param {Object} serviceCategory Contains the service-category data.
|
||||||
*/
|
*/
|
||||||
function save(category) {
|
function save(serviceCategory) {
|
||||||
App.Http.Categories.save(category).then((response) => {
|
App.Http.ServiceCategories.save(serviceCategory).then((response) => {
|
||||||
App.Layouts.Backend.displayNotification(lang('category_saved'));
|
App.Layouts.Backend.displayNotification(lang('service_category_saved'));
|
||||||
resetForm();
|
resetForm();
|
||||||
$filterCategories.find('.key').val('');
|
$filterCategories.find('.key').val('');
|
||||||
filter('', response.id, true);
|
filter('', response.id, true);
|
||||||
|
@ -202,42 +202,42 @@ App.Pages.Categories = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete category record.
|
* Delete service-category record.
|
||||||
*
|
*
|
||||||
* @param {Number} id Record ID to be deleted.
|
* @param {Number} id Record ID to be deleted.
|
||||||
*/
|
*/
|
||||||
function remove(id) {
|
function remove(id) {
|
||||||
App.Http.Categories.destroy(id).then(() => {
|
App.Http.ServiceCategories.destroy(id).then(() => {
|
||||||
App.Layouts.Backend.displayNotification(lang('category_deleted'));
|
App.Layouts.Backend.displayNotification(lang('category_deleted'));
|
||||||
resetForm();
|
resetForm();
|
||||||
filter($('#filter-categories .key').val());
|
filter($('#filter-service-categories .key').val());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a category record on the form.
|
* Display a service-category record on the form.
|
||||||
*
|
*
|
||||||
* @param {Object} category Contains the category data.
|
* @param {Object} serviceCategory Contains the service-category data.
|
||||||
*/
|
*/
|
||||||
function display(category) {
|
function display(serviceCategory) {
|
||||||
$id.val(category.id);
|
$id.val(serviceCategory.id);
|
||||||
$name.val(category.name);
|
$name.val(serviceCategory.name);
|
||||||
$description.val(category.description);
|
$description.val(serviceCategory.description);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate category data before save (insert or update).
|
* Validate service-category data before save (insert or update).
|
||||||
*
|
*
|
||||||
* @return {Boolean} Returns the validation result.
|
* @return {Boolean} Returns the validation result.
|
||||||
*/
|
*/
|
||||||
function validate() {
|
function validate() {
|
||||||
$categories.find('.is-invalid').removeClass('is-invalid');
|
$serviceCategories.find('.is-invalid').removeClass('is-invalid');
|
||||||
$categories.find('.form-message').removeClass('alert-danger').hide();
|
$serviceCategories.find('.form-message').removeClass('alert-danger').hide();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let missingRequired = false;
|
let missingRequired = false;
|
||||||
|
|
||||||
$categories.find('.required').each((index, fieldEl) => {
|
$serviceCategories.find('.required').each((index, fieldEl) => {
|
||||||
if (!$(fieldEl).val()) {
|
if (!$(fieldEl).val()) {
|
||||||
$(fieldEl).addClass('is-invalid');
|
$(fieldEl).addClass('is-invalid');
|
||||||
missingRequired = true;
|
missingRequired = true;
|
||||||
|
@ -250,43 +250,43 @@ App.Pages.Categories = (function () {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
$categories.find('.form-message').addClass('alert-danger').text(error.message).show();
|
$serviceCategories.find('.form-message').addClass('alert-danger').text(error.message).show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bring the category form back to its initial state.
|
* Bring the service-category form back to its initial state.
|
||||||
*/
|
*/
|
||||||
function resetForm() {
|
function resetForm() {
|
||||||
$filterCategories.find('.selected').removeClass('selected');
|
$filterCategories.find('.selected').removeClass('selected');
|
||||||
$filterCategories.find('button').prop('disabled', false);
|
$filterCategories.find('button').prop('disabled', false);
|
||||||
$filterCategories.find('.results').css('color', '');
|
$filterCategories.find('.results').css('color', '');
|
||||||
|
|
||||||
$categories.find('.add-edit-delete-group').show();
|
$serviceCategories.find('.add-edit-delete-group').show();
|
||||||
$categories.find('.save-cancel-group').hide();
|
$serviceCategories.find('.save-cancel-group').hide();
|
||||||
$categories.find('.record-details').find('input, select, textarea').val('').prop('disabled', true);
|
$serviceCategories.find('.record-details').find('input, select, textarea').val('').prop('disabled', true);
|
||||||
$categories.find('.record-details .form-label span').prop('hidden', true);
|
$serviceCategories.find('.record-details .form-label span').prop('hidden', true);
|
||||||
$('#edit-category, #delete-category').prop('disabled', true);
|
$('#edit-service-category, #delete-service-category').prop('disabled', true);
|
||||||
|
|
||||||
$categories.find('.record-details .is-invalid').removeClass('is-invalid');
|
$serviceCategories.find('.record-details .is-invalid').removeClass('is-invalid');
|
||||||
$categories.find('.record-details .form-message').hide();
|
$serviceCategories.find('.record-details .form-message').hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the filter results row HTML code.
|
* Get the filter results row HTML code.
|
||||||
*
|
*
|
||||||
* @param {Object} category Contains the category data.
|
* @param {Object} serviceCategory Contains the service-category data.
|
||||||
*
|
*
|
||||||
* @return {String} Returns the record HTML code.
|
* @return {String} Returns the record HTML code.
|
||||||
*/
|
*/
|
||||||
function getFilterHtml(category) {
|
function getFilterHtml(serviceCategory) {
|
||||||
return $('<div/>', {
|
return $('<div/>', {
|
||||||
'class': 'category-row entry',
|
'class': 'service-category-row entry',
|
||||||
'data-id': category.id,
|
'data-id': serviceCategory.id,
|
||||||
'html': [
|
'html': [
|
||||||
$('<strong/>', {
|
$('<strong/>', {
|
||||||
'text': category.name
|
'text': serviceCategory.name
|
||||||
}),
|
}),
|
||||||
$('<br/>')
|
$('<br/>')
|
||||||
]
|
]
|
||||||
|
@ -296,7 +296,7 @@ App.Pages.Categories = (function () {
|
||||||
/**
|
/**
|
||||||
* Select a specific record from the current filter results.
|
* Select a specific record from the current filter results.
|
||||||
*
|
*
|
||||||
* If the category ID does not exist in the list then no record will be selected.
|
* If the service-category ID does not exist in the list then no record will be selected.
|
||||||
*
|
*
|
||||||
* @param {Number} id The record ID to be selected from the filter results.
|
* @param {Number} id The record ID to be selected from the filter results.
|
||||||
* @param {Boolean} show Optional (false), if true then the method will display the record on the form.
|
* @param {Boolean} show Optional (false), if true then the method will display the record on the form.
|
||||||
|
@ -304,14 +304,14 @@ App.Pages.Categories = (function () {
|
||||||
function select(id, show = false) {
|
function select(id, show = false) {
|
||||||
$filterCategories.find('.selected').removeClass('selected');
|
$filterCategories.find('.selected').removeClass('selected');
|
||||||
|
|
||||||
$filterCategories.find('.category-row[data-id="' + id + '"]').addClass('selected');
|
$filterCategories.find('.service-category-row[data-id="' + id + '"]').addClass('selected');
|
||||||
|
|
||||||
if (show) {
|
if (show) {
|
||||||
const category = filterResults.find((category) => Number(category.id) === Number(id));
|
const serviceCategory = filterResults.find((serviceCategory) => Number(serviceCategory.id) === Number(id));
|
||||||
|
|
||||||
display(category);
|
display(serviceCategory);
|
||||||
|
|
||||||
$('#edit-category, #delete-category').prop('disabled', false);
|
$('#edit-service-category, #delete-service-category').prop('disabled', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ App.Pages.Services = (function () {
|
||||||
const $duration = $('#duration');
|
const $duration = $('#duration');
|
||||||
const $price = $('#price');
|
const $price = $('#price');
|
||||||
const $currency = $('#currency');
|
const $currency = $('#currency');
|
||||||
const $category = $('#category');
|
const $serviceCategoryId = $('#service-category-id');
|
||||||
const $availabilitiesType = $('#availabilities-type');
|
const $availabilitiesType = $('#availabilities-type');
|
||||||
const $attendantsNumber = $('#attendants-number');
|
const $attendantsNumber = $('#attendants-number');
|
||||||
const $isPrivate = $('#is-private');
|
const $isPrivate = $('#is-private');
|
||||||
|
@ -107,7 +107,7 @@ App.Pages.Services = (function () {
|
||||||
$duration.val('30');
|
$duration.val('30');
|
||||||
$price.val('0');
|
$price.val('0');
|
||||||
$currency.val('');
|
$currency.val('');
|
||||||
$category.val('');
|
$serviceCategoryId.val('');
|
||||||
$availabilitiesType.val('flexible');
|
$availabilitiesType.val('flexible');
|
||||||
$attendantsNumber.val('1');
|
$attendantsNumber.val('1');
|
||||||
});
|
});
|
||||||
|
@ -142,7 +142,7 @@ App.Pages.Services = (function () {
|
||||||
availabilities_type: $availabilitiesType.val(),
|
availabilities_type: $availabilitiesType.val(),
|
||||||
attendants_number: $attendantsNumber.val(),
|
attendants_number: $attendantsNumber.val(),
|
||||||
is_private: Number($isPrivate.prop('checked')),
|
is_private: Number($isPrivate.prop('checked')),
|
||||||
id_categories: $category.val() || undefined
|
id_service_categories: $serviceCategoryId.val() || undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($id.val() !== '') {
|
if ($id.val() !== '') {
|
||||||
|
@ -300,8 +300,8 @@ App.Pages.Services = (function () {
|
||||||
$isPrivate.prop('checked', service.is_private);
|
$isPrivate.prop('checked', service.is_private);
|
||||||
App.Components.ColorSelection.setColor($color, service.color);
|
App.Components.ColorSelection.setColor($color, service.color);
|
||||||
|
|
||||||
const categoryId = service.id_categories !== null ? service.id_categories : '';
|
const serviceCategoryId = service.id_service_categories !== null ? service.id_service_categories : '';
|
||||||
$category.val(categoryId);
|
$serviceCategoryId.val(serviceCategoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -399,19 +399,19 @@ App.Pages.Services = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the service category list box.
|
* Update the service-category list box.
|
||||||
*
|
*
|
||||||
* Use this method every time a change is made to the service categories db table.
|
* Use this method every time a change is made to the service categories db table.
|
||||||
*/
|
*/
|
||||||
function updateAvailableCategories() {
|
function updateAvailableServiceCategories() {
|
||||||
App.Http.Categories.search('', 999).then((response) => {
|
App.Http.ServiceCategories.search('', 999).then((response) => {
|
||||||
$category.empty();
|
$serviceCategoryId.empty();
|
||||||
|
|
||||||
response.forEach((category) => {
|
response.forEach((serviceCategory) => {
|
||||||
$category.append(new Option(category.name, category.id));
|
$serviceCategoryId.append(new Option(serviceCategory.name, serviceCategory.id));
|
||||||
});
|
});
|
||||||
|
|
||||||
$category.append(new Option('', '')).val('');
|
$serviceCategoryId.append(new Option('', '')).val('');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +422,7 @@ App.Pages.Services = (function () {
|
||||||
resetForm();
|
resetForm();
|
||||||
filter('');
|
filter('');
|
||||||
addEventListeners();
|
addEventListeners();
|
||||||
updateAvailableCategories();
|
updateAvailableServiceCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', initialize);
|
document.addEventListener('DOMContentLoaded', initialize);
|
||||||
|
|
58
openapi.yml
58
openapi.yml
|
@ -21,10 +21,10 @@ tags:
|
||||||
- name: admins
|
- name: admins
|
||||||
- name: appointments
|
- name: appointments
|
||||||
- name: availabilities
|
- name: availabilities
|
||||||
- name: categories
|
|
||||||
- name: customers
|
- name: customers
|
||||||
- name: providers
|
- name: providers
|
||||||
- name: secretaries
|
- name: secretaries
|
||||||
|
- name: service_categories
|
||||||
- name: services
|
- name: services
|
||||||
- name: settings
|
- name: settings
|
||||||
- name: unavailabilities
|
- name: unavailabilities
|
||||||
|
@ -776,11 +776,11 @@ paths:
|
||||||
security:
|
security:
|
||||||
- BearerToken: [ ]
|
- BearerToken: [ ]
|
||||||
- BasicAuth: [ ]
|
- BasicAuth: [ ]
|
||||||
/categories:
|
/service_categories:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
- categories
|
- service_categories
|
||||||
summary: Get all categories
|
summary: Get all service-categories
|
||||||
parameters:
|
parameters:
|
||||||
- name: page
|
- name: page
|
||||||
in: query
|
in: query
|
||||||
|
@ -812,7 +812,7 @@ paths:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/CategoryCollection'
|
$ref: '#/components/schemas/ServiceCategoryCollection'
|
||||||
'401':
|
'401':
|
||||||
description: Unauthorized
|
description: Unauthorized
|
||||||
'500':
|
'500':
|
||||||
|
@ -826,13 +826,13 @@ paths:
|
||||||
- BasicAuth: [ ]
|
- BasicAuth: [ ]
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- categories
|
- service_categories
|
||||||
summary: Create a category
|
summary: Create a service-category
|
||||||
requestBody:
|
requestBody:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/CategoryPayload'
|
$ref: '#/components/schemas/ServiceCategoryPayload'
|
||||||
required: true
|
required: true
|
||||||
responses:
|
responses:
|
||||||
'201':
|
'201':
|
||||||
|
@ -840,7 +840,7 @@ paths:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/CategoryRecord'
|
$ref: '#/components/schemas/ServiceCategoryRecord'
|
||||||
'401':
|
'401':
|
||||||
description: Unauthorized
|
description: Unauthorized
|
||||||
'500':
|
'500':
|
||||||
|
@ -853,13 +853,13 @@ paths:
|
||||||
security:
|
security:
|
||||||
- BearerToken: [ ]
|
- BearerToken: [ ]
|
||||||
- BasicAuth: [ ]
|
- BasicAuth: [ ]
|
||||||
/categories/{categoryId}:
|
/service_categories/{serviceCategoryId}:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
- categories
|
- service_categories
|
||||||
summary: Get a category
|
summary: Get a service-category
|
||||||
parameters:
|
parameters:
|
||||||
- name: categoryId
|
- name: serviceCategoryId
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
|
@ -870,7 +870,7 @@ paths:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/CategoryRecord'
|
$ref: '#/components/schemas/ServiceCategoryRecord'
|
||||||
'401':
|
'401':
|
||||||
description: Unauthorized
|
description: Unauthorized
|
||||||
'404':
|
'404':
|
||||||
|
@ -886,10 +886,10 @@ paths:
|
||||||
- BasicAuth: [ ]
|
- BasicAuth: [ ]
|
||||||
put:
|
put:
|
||||||
tags:
|
tags:
|
||||||
- categories
|
- service_categories
|
||||||
summary: Update a category
|
summary: Update a service-category
|
||||||
parameters:
|
parameters:
|
||||||
- name: categoryId
|
- name: serviceCategoryId
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
|
@ -898,7 +898,7 @@ paths:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/CategoryPayload'
|
$ref: '#/components/schemas/ServiceCategoryPayload'
|
||||||
required: true
|
required: true
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
|
@ -906,7 +906,7 @@ paths:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/CategoryRecord'
|
$ref: '#/components/schemas/ServiceCategoryRecord'
|
||||||
'401':
|
'401':
|
||||||
description: Unauthorized
|
description: Unauthorized
|
||||||
'404':
|
'404':
|
||||||
|
@ -923,10 +923,10 @@ paths:
|
||||||
- BasicAuth: [ ]
|
- BasicAuth: [ ]
|
||||||
delete:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- categories
|
- service_categories
|
||||||
summary: Delete a category
|
summary: Delete a service-category
|
||||||
parameters:
|
parameters:
|
||||||
- name: categoryId
|
- name: serviceCategoryId
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
|
@ -1986,7 +1986,7 @@ components:
|
||||||
description: This is a test service.
|
description: This is a test service.
|
||||||
availabilitiesType: flexible
|
availabilitiesType: flexible
|
||||||
attendantsNumber: 1
|
attendantsNumber: 1
|
||||||
categoryId: null
|
serviceCategoryId: null
|
||||||
ServicePayload:
|
ServicePayload:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
@ -2006,7 +2006,7 @@ components:
|
||||||
type: string
|
type: string
|
||||||
attendantsNumber:
|
attendantsNumber:
|
||||||
type: integer
|
type: integer
|
||||||
categoryId:
|
serviceCategoryId:
|
||||||
type: integer
|
type: integer
|
||||||
example:
|
example:
|
||||||
name: Test Service
|
name: Test Service
|
||||||
|
@ -2017,12 +2017,12 @@ components:
|
||||||
description: This is a test service.
|
description: This is a test service.
|
||||||
availabilitiesType: flexible
|
availabilitiesType: flexible
|
||||||
attendantsNumber: 1
|
attendantsNumber: 1
|
||||||
categoryId: null
|
serviceCategoryId: null
|
||||||
ServiceCollection:
|
ServiceCollection:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/ServiceRecord'
|
$ref: '#/components/schemas/ServiceRecord'
|
||||||
CategoryRecord:
|
ServiceCategoryRecord:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
|
@ -2035,7 +2035,7 @@ components:
|
||||||
id: 1
|
id: 1
|
||||||
name: Test Category
|
name: Test Category
|
||||||
description: This is a test category.
|
description: This is a test category.
|
||||||
CategoryPayload:
|
ServiceCategoryPayload:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
name:
|
name:
|
||||||
|
@ -2045,10 +2045,10 @@ components:
|
||||||
example:
|
example:
|
||||||
name: Test Category
|
name: Test Category
|
||||||
description: This is a test category.
|
description: This is a test category.
|
||||||
CategoryCollection:
|
ServiceCategoryCollection:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/CategoryRecord'
|
$ref: '#/components/schemas/ServiceCategoryRecord'
|
||||||
AdminRecord:
|
AdminRecord:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
Loading…
Reference in a new issue