mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-22 07:52:29 +03:00
Improved condition checks in the API controller classes
This commit is contained in:
parent
9b24ce1e57
commit
3dca937728
8 changed files with 31 additions and 31 deletions
|
@ -49,7 +49,7 @@ class Admins extends API_V1_Controller {
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$condition = $id !== NULL ? 'id = ' . $id : NULL;
|
$condition = $id !== NULL ? ['id' => $id] : NULL;
|
||||||
$admins = $this->admins_model->get_batch($condition);
|
$admins = $this->admins_model->get_batch($condition);
|
||||||
|
|
||||||
if ($id !== NULL && count($admins) === 0)
|
if ($id !== NULL && count($admins) === 0)
|
||||||
|
@ -94,7 +94,7 @@ class Admins extends API_V1_Controller {
|
||||||
$id = $this->admins_model->add($admin);
|
$id = $this->admins_model->add($admin);
|
||||||
|
|
||||||
// Fetch the new object from the database and return it to the client.
|
// Fetch the new object from the database and return it to the client.
|
||||||
$batch = $this->admins_model->get_batch('id = ' . $id);
|
$batch = $this->admins_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$status = new NonEmptyText('201 Created');
|
$status = new NonEmptyText('201 Created');
|
||||||
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
||||||
|
@ -115,7 +115,7 @@ class Admins extends API_V1_Controller {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Update the admin record.
|
// Update the admin record.
|
||||||
$batch = $this->admins_model->get_batch('id = ' . $id);
|
$batch = $this->admins_model->get_batch(['id' => $id]);
|
||||||
|
|
||||||
if ($id !== NULL && count($batch) === 0)
|
if ($id !== NULL && count($batch) === 0)
|
||||||
{
|
{
|
||||||
|
@ -130,7 +130,7 @@ class Admins extends API_V1_Controller {
|
||||||
$id = $this->admins_model->add($updatedAdmin);
|
$id = $this->admins_model->add($updatedAdmin);
|
||||||
|
|
||||||
// Fetch the updated object from the database and return it to the client.
|
// Fetch the updated object from the database and return it to the client.
|
||||||
$batch = $this->admins_model->get_batch('id = ' . $id);
|
$batch = $this->admins_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$response->encode($this->parser)->singleEntry($id)->output();
|
$response->encode($this->parser)->singleEntry($id)->output();
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ class Appointments extends API_V1_Controller {
|
||||||
$this->notifications->notify_appointment_saved($appointment, $service, $provider, $customer, $settings, FALSE);
|
$this->notifications->notify_appointment_saved($appointment, $service, $provider, $customer, $settings, FALSE);
|
||||||
|
|
||||||
// Fetch the new object from the database and return it to the client.
|
// Fetch the new object from the database and return it to the client.
|
||||||
$batch = $this->appointments_model->get_batch('id = ' . $id);
|
$batch = $this->appointments_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$status = new NonEmptyText('201 Created');
|
$status = new NonEmptyText('201 Created');
|
||||||
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
||||||
|
@ -156,7 +156,7 @@ class Appointments extends API_V1_Controller {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Update the appointment record.
|
// Update the appointment record.
|
||||||
$batch = $this->appointments_model->get_batch('id = ' . $id);
|
$batch = $this->appointments_model->get_batch(['id' => $id]);
|
||||||
|
|
||||||
if ($id !== NULL && count($batch) === 0)
|
if ($id !== NULL && count($batch) === 0)
|
||||||
{
|
{
|
||||||
|
@ -186,7 +186,7 @@ class Appointments extends API_V1_Controller {
|
||||||
|
|
||||||
|
|
||||||
// Fetch the updated object from the database and return it to the client.
|
// Fetch the updated object from the database and return it to the client.
|
||||||
$batch = $this->appointments_model->get_batch('id = ' . $id);
|
$batch = $this->appointments_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$response->encode($this->parser)->singleEntry($id)->output();
|
$response->encode($this->parser)->singleEntry($id)->output();
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Categories extends API_V1_Controller {
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$condition = $id !== NULL ? 'id = ' . $id : NULL;
|
$condition = $id !== NULL ? ['id' => $id] : NULL;
|
||||||
$categories = $this->services_model->get_all_categories($condition);
|
$categories = $this->services_model->get_all_categories($condition);
|
||||||
|
|
||||||
if ($id !== NULL && count($categories) === 0)
|
if ($id !== NULL && count($categories) === 0)
|
||||||
|
@ -94,7 +94,7 @@ class Categories extends API_V1_Controller {
|
||||||
$id = $this->services_model->add_category($category);
|
$id = $this->services_model->add_category($category);
|
||||||
|
|
||||||
// Fetch the new object from the database and return it to the client.
|
// Fetch the new object from the database and return it to the client.
|
||||||
$batch = $this->services_model->get_all_categories('id = ' . $id);
|
$batch = $this->services_model->get_all_categories(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$status = new NonEmptyText('201 Created');
|
$status = new NonEmptyText('201 Created');
|
||||||
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
||||||
|
@ -115,7 +115,7 @@ class Categories extends API_V1_Controller {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Update the category record.
|
// Update the category record.
|
||||||
$batch = $this->services_model->get_all_categories('id = ' . $id);
|
$batch = $this->services_model->get_all_categories(['id' => $id]);
|
||||||
|
|
||||||
if ($id !== NULL && count($batch) === 0)
|
if ($id !== NULL && count($batch) === 0)
|
||||||
{
|
{
|
||||||
|
@ -130,7 +130,7 @@ class Categories extends API_V1_Controller {
|
||||||
$id = $this->services_model->add_category($updated_category);
|
$id = $this->services_model->add_category($updated_category);
|
||||||
|
|
||||||
// Fetch the updated object from the database and return it to the client.
|
// Fetch the updated object from the database and return it to the client.
|
||||||
$batch = $this->services_model->get_all_categories('id = ' . $id);
|
$batch = $this->services_model->get_all_categories(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$response->encode($this->parser)->singleEntry($id)->output();
|
$response->encode($this->parser)->singleEntry($id)->output();
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Customers extends API_V1_Controller {
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$condition = $id !== NULL ? 'id = ' . $id : NULL;
|
$condition = $id !== NULL ? ['id' => $id] : NULL;
|
||||||
$customers = $this->customers_model->get_batch($condition);
|
$customers = $this->customers_model->get_batch($condition);
|
||||||
|
|
||||||
if ($id !== NULL && count($customers) === 0)
|
if ($id !== NULL && count($customers) === 0)
|
||||||
|
@ -94,7 +94,7 @@ class Customers extends API_V1_Controller {
|
||||||
$id = $this->customers_model->add($customer);
|
$id = $this->customers_model->add($customer);
|
||||||
|
|
||||||
// Fetch the new object from the database and return it to the client.
|
// Fetch the new object from the database and return it to the client.
|
||||||
$batch = $this->customers_model->get_batch('id = ' . $id);
|
$batch = $this->customers_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$status = new NonEmptyText('201 Created');
|
$status = new NonEmptyText('201 Created');
|
||||||
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
||||||
|
@ -115,7 +115,7 @@ class Customers extends API_V1_Controller {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Update the customer record.
|
// Update the customer record.
|
||||||
$batch = $this->customers_model->get_batch('id = ' . $id);
|
$batch = $this->customers_model->get_batch(['id' => $id]);
|
||||||
|
|
||||||
if ($id !== NULL && count($batch) === 0)
|
if ($id !== NULL && count($batch) === 0)
|
||||||
{
|
{
|
||||||
|
@ -130,7 +130,7 @@ class Customers extends API_V1_Controller {
|
||||||
$id = $this->customers_model->add($updated_customer);
|
$id = $this->customers_model->add($updated_customer);
|
||||||
|
|
||||||
// Fetch the updated object from the database and return it to the client.
|
// Fetch the updated object from the database and return it to the client.
|
||||||
$batch = $this->customers_model->get_batch('id = ' . $id);
|
$batch = $this->customers_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$response->encode($this->parser)->singleEntry($id)->output();
|
$response->encode($this->parser)->singleEntry($id)->output();
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Providers extends API_V1_Controller {
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$condition = $id !== NULL ? 'id = ' . $id : NULL;
|
$condition = $id !== NULL ? ['id' => $id] : NULL;
|
||||||
$providers = $this->providers_model->get_batch($condition);
|
$providers = $this->providers_model->get_batch($condition);
|
||||||
|
|
||||||
if ($id !== NULL && count($providers) === 0)
|
if ($id !== NULL && count($providers) === 0)
|
||||||
|
@ -94,7 +94,7 @@ class Providers extends API_V1_Controller {
|
||||||
$id = $this->providers_model->add($provider);
|
$id = $this->providers_model->add($provider);
|
||||||
|
|
||||||
// Fetch the new object from the database and return it to the client.
|
// Fetch the new object from the database and return it to the client.
|
||||||
$batch = $this->providers_model->get_batch('id = ' . $id);
|
$batch = $this->providers_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$status = new NonEmptyText('201 Created');
|
$status = new NonEmptyText('201 Created');
|
||||||
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
||||||
|
@ -115,7 +115,7 @@ class Providers extends API_V1_Controller {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Update the provider record.
|
// Update the provider record.
|
||||||
$batch = $this->providers_model->get_batch('id = ' . $id);
|
$batch = $this->providers_model->get_batch(['id' => $id]);
|
||||||
|
|
||||||
if ($id !== NULL && count($batch) === 0)
|
if ($id !== NULL && count($batch) === 0)
|
||||||
{
|
{
|
||||||
|
@ -130,7 +130,7 @@ class Providers extends API_V1_Controller {
|
||||||
$id = $this->providers_model->add($updated_provider);
|
$id = $this->providers_model->add($updated_provider);
|
||||||
|
|
||||||
// Fetch the updated object from the database and return it to the client.
|
// Fetch the updated object from the database and return it to the client.
|
||||||
$batch = $this->providers_model->get_batch('id = ' . $id);
|
$batch = $this->providers_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$response->encode($this->parser)->singleEntry($id)->output();
|
$response->encode($this->parser)->singleEntry($id)->output();
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Secretaries extends API_V1_Controller {
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$condition = $id !== NULL ? 'id = ' . $id : NULL;
|
$condition = $id !== NULL ? ['id' => $id] : NULL;
|
||||||
$secretaries = $this->secretaries_model->get_batch($condition);
|
$secretaries = $this->secretaries_model->get_batch($condition);
|
||||||
|
|
||||||
if ($id !== NULL && count($secretaries) === 0)
|
if ($id !== NULL && count($secretaries) === 0)
|
||||||
|
@ -94,7 +94,7 @@ class Secretaries extends API_V1_Controller {
|
||||||
$id = $this->secretaries_model->add($secretary);
|
$id = $this->secretaries_model->add($secretary);
|
||||||
|
|
||||||
// Fetch the new object from the database and return it to the client.
|
// Fetch the new object from the database and return it to the client.
|
||||||
$batch = $this->secretaries_model->get_batch('id = ' . $id);
|
$batch = $this->secretaries_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$status = new NonEmptyText('201 Created');
|
$status = new NonEmptyText('201 Created');
|
||||||
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
||||||
|
@ -115,7 +115,7 @@ class Secretaries extends API_V1_Controller {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Update the secretary record.
|
// Update the secretary record.
|
||||||
$batch = $this->secretaries_model->get_batch('id = ' . $id);
|
$batch = $this->secretaries_model->get_batch(['id' => $id]);
|
||||||
|
|
||||||
if ($id !== NULL && count($batch) === 0)
|
if ($id !== NULL && count($batch) === 0)
|
||||||
{
|
{
|
||||||
|
@ -130,7 +130,7 @@ class Secretaries extends API_V1_Controller {
|
||||||
$id = $this->secretaries_model->add($updated_secretary);
|
$id = $this->secretaries_model->add($updated_secretary);
|
||||||
|
|
||||||
// Fetch the updated object from the database and return it to the client.
|
// Fetch the updated object from the database and return it to the client.
|
||||||
$batch = $this->secretaries_model->get_batch('id = ' . $id);
|
$batch = $this->secretaries_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$response->encode($this->parser)->singleEntry($id)->output();
|
$response->encode($this->parser)->singleEntry($id)->output();
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Services extends API_V1_Controller {
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$condition = $id !== NULL ? 'id = ' . $id : NULL;
|
$condition = $id !== NULL ? ['id' => $id] : NULL;
|
||||||
$services = $this->services_model->get_batch($condition);
|
$services = $this->services_model->get_batch($condition);
|
||||||
|
|
||||||
if ($id !== NULL && count($services) === 0)
|
if ($id !== NULL && count($services) === 0)
|
||||||
|
@ -94,7 +94,7 @@ class Services extends API_V1_Controller {
|
||||||
$id = $this->services_model->add($service);
|
$id = $this->services_model->add($service);
|
||||||
|
|
||||||
// Fetch the new object from the database and return it to the client.
|
// Fetch the new object from the database and return it to the client.
|
||||||
$batch = $this->services_model->get_batch('id = ' . $id);
|
$batch = $this->services_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$status = new NonEmptyText('201 Created');
|
$status = new NonEmptyText('201 Created');
|
||||||
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
||||||
|
@ -115,7 +115,7 @@ class Services extends API_V1_Controller {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Update the service record.
|
// Update the service record.
|
||||||
$batch = $this->services_model->get_batch('id = ' . $id);
|
$batch = $this->services_model->get_batch(['id' => $id]);
|
||||||
|
|
||||||
if ($id !== NULL && count($batch) === 0)
|
if ($id !== NULL && count($batch) === 0)
|
||||||
{
|
{
|
||||||
|
@ -130,7 +130,7 @@ class Services extends API_V1_Controller {
|
||||||
$id = $this->services_model->add($updated_service);
|
$id = $this->services_model->add($updated_service);
|
||||||
|
|
||||||
// Fetch the updated object from the database and return it to the client.
|
// Fetch the updated object from the database and return it to the client.
|
||||||
$batch = $this->services_model->get_batch('id = ' . $id);
|
$batch = $this->services_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$response->encode($this->parser)->singleEntry($id)->output();
|
$response->encode($this->parser)->singleEntry($id)->output();
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Unavailabilities extends API_V1_Controller {
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$condition = $id !== NULL ? 'id = ' . $id : 'is_unavailable = 1';
|
$condition = $id !== NULL ? ['id' => $id] : 'is_unavailable = 1';
|
||||||
$unavailabilities = $this->appointments_model->get_batch($condition);
|
$unavailabilities = $this->appointments_model->get_batch($condition);
|
||||||
|
|
||||||
if ($id !== NULL && count($unavailabilities) === 0)
|
if ($id !== NULL && count($unavailabilities) === 0)
|
||||||
|
@ -94,7 +94,7 @@ class Unavailabilities extends API_V1_Controller {
|
||||||
$id = $this->appointments_model->add_unavailable($unavailability);
|
$id = $this->appointments_model->add_unavailable($unavailability);
|
||||||
|
|
||||||
// Fetch the new object from the database and return it to the client.
|
// Fetch the new object from the database and return it to the client.
|
||||||
$batch = $this->appointments_model->get_batch('id = ' . $id);
|
$batch = $this->appointments_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$status = new NonEmptyText('201 Created');
|
$status = new NonEmptyText('201 Created');
|
||||||
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
|
||||||
|
@ -115,7 +115,7 @@ class Unavailabilities extends API_V1_Controller {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Update the appointment record.
|
// Update the appointment record.
|
||||||
$batch = $this->appointments_model->get_batch('id = ' . $id);
|
$batch = $this->appointments_model->get_batch(['id' => $id]);
|
||||||
|
|
||||||
if ($id !== NULL && count($batch) === 0)
|
if ($id !== NULL && count($batch) === 0)
|
||||||
{
|
{
|
||||||
|
@ -130,7 +130,7 @@ class Unavailabilities extends API_V1_Controller {
|
||||||
$id = $this->appointments_model->add_unavailable($updatedUnavailability);
|
$id = $this->appointments_model->add_unavailable($updatedUnavailability);
|
||||||
|
|
||||||
// Fetch the updated object from the database and return it to the client.
|
// Fetch the updated object from the database and return it to the client.
|
||||||
$batch = $this->appointments_model->get_batch('id = ' . $id);
|
$batch = $this->appointments_model->get_batch(['id' => $id]);
|
||||||
$response = new Response($batch);
|
$response = new Response($batch);
|
||||||
$response->encode($this->parser)->singleEntry($id)->output();
|
$response->encode($this->parser)->singleEntry($id)->output();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue