The get_value method check the existence of a property with array_key_exists

This commit is contained in:
Alex Tselegidis 2020-12-05 11:43:38 +02:00
parent 9c3d253456
commit 843a476d0b
6 changed files with 30 additions and 25 deletions

View File

@ -404,21 +404,23 @@ class Admins_model extends EA_Model {
// Check whether the admin record exists.
$result = $this->db->get_where('users', ['id' => $admin_id]);
if ($result->num_rows() == 0)
if ($result->num_rows() === 0)
{
throw new Exception('The record with the given id does not exist in the '
. 'database: ' . $admin_id);
}
// Check if the required field name exist in database.
$provider = $result->row_array();
if ( ! isset($provider[$field_name]))
$row_data = $result->row_array();
if ( ! array_key_exists($field_name, $row_data))
{
throw new Exception('The given $field_name argument does not exist in the '
. 'database: ' . $field_name);
}
return $provider[$field_name];
return $row_data[$field_name];
}
/**

View File

@ -352,13 +352,13 @@ class Appointments_model extends EA_Model {
if ($this->db->get_where('appointments', ['id' => $appointment_id])->num_rows() == 0)
{
throw new Exception('The record with the provided id '
. 'does not exist in the database: ' . $appointment_id);
throw new Exception('The record with the provided ID does not exist in the database: '
. $appointment_id);
}
$row_data = $this->db->get_where('appointments', ['id' => $appointment_id])->row_array();
if ( ! isset($row_data[$field_name]))
if ( ! array_key_exists($field_name, $row_data))
{
throw new Exception('The given field name does not exist in the database: ' . $field_name);
}

View File

@ -331,10 +331,10 @@ class Customers_model extends EA_Model {
$row_data = $this->db->get_where('users', ['id' => $customer_id])->row_array();
if ( ! isset($row_data[$field_name]))
if ( ! array_key_exists($field_name, $row_data))
{
throw new Exception('The given $field_name argument does not'
. 'exist in the database: ' . $field_name);
throw new Exception('The given $field_name argument does not exist in the database: '
. $field_name);
}
$customer = $this->db->get_where('users', ['id' => $customer_id])->row_array();

View File

@ -493,18 +493,18 @@ class Providers_model extends EA_Model {
if ($result->num_rows() == 0)
{
throw new Exception('The record with the $provider_id argument does not exist in '
. 'the database: ' . $provider_id);
throw new Exception('The record with the $provider_id argument does not exist in the database: '
. $provider_id);
}
$provider = $result->row_array();
$row_data = $result->row_array();
if ( ! isset($provider[$field_name]))
if ( ! isset($row_data[$field_name]))
{
throw new Exception('The given $field_name argument does not exist in the database: ' . $field_name);
}
return $provider[$field_name];
return $row_data[$field_name];
}
/**

View File

@ -480,21 +480,23 @@ class Secretaries_model extends EA_Model {
// Check whether the secretary record exists.
$result = $this->db->get_where('users', ['id' => $secretary_id]);
if ($result->num_rows() == 0)
if ($result->num_rows() === 0)
{
throw new Exception('The record with the given id does not exist in the '
. 'database: ' . $secretary_id);
}
// Check if the required field name exist in database.
$provider = $result->row_array();
if ( ! isset($provider[$field_name]))
$row_data = $result->row_array();
if ( ! array_key_exists($field_name, $row_data))
{
throw new Exception('The given $field_name argument does not exist in the '
. 'database: ' . $field_name);
throw new Exception('The given $field_name argument does not exist in the database: '
. $field_name);
}
return $provider[$field_name];
return $row_data[$field_name];
}
/**

View File

@ -303,13 +303,14 @@ class Services_model extends EA_Model {
}
$row_data = $this->db->get_where('services', ['id' => $service_id])->row_array();
if ( ! isset($row_data[$field_name]))
if ( ! array_key_exists($field_name, $row_data))
{
throw new Exception('The given $field_name argument does not exist in the database: ' . $field_name);
throw new Exception('The given $field_name argument does not exist in the database: '
. $field_name);
}
$setting = $this->db->get_where('services', ['id' => $service_id])->row_array();
return $setting[$field_name];
return $row_data[$field_name];
}
/**