Skip to content

Commit

Permalink
Add support for custom fields on customers (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextselegidis committed Dec 11, 2023
1 parent aa10b57 commit e6b3ffd
Show file tree
Hide file tree
Showing 47 changed files with 771 additions and 436 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ developers to maintain and readjust their custom modifications on the main proje
- Create new layout structure for the markup, so that common HTML markup is being reused (#1152)
- Have an option to hide customer data fields during booking (#1081)
- Add a SECURITY.md file to the repository (#1122)
- Add support for custom fields on customers (#1133)

### Changed

Expand Down
152 changes: 65 additions & 87 deletions application/controllers/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Customers extends EA_Controller {
class Customers extends EA_Controller
{
/**
* Customers constructor.
*/
Expand Down Expand Up @@ -49,10 +50,8 @@ public function index()

$user_id = session('user_id');

if (cannot('view', PRIV_CUSTOMERS))
{
if ($user_id)
{
if (cannot('view', PRIV_CUSTOMERS)) {
if ($user_id) {
abort(403, 'Forbidden');
}

Expand All @@ -75,8 +74,7 @@ public function index()

$secretary_providers = [];

if ($role_slug === DB_SLUG_SECRETARY)
{
if ($role_slug === DB_SLUG_SECRETARY) {
$secretary = $this->secretaries_model->find($user_id);

$secretary_providers = $secretary['providers'];
Expand All @@ -88,7 +86,7 @@ public function index()
'date_format' => $date_format,
'time_format' => $time_format,
'timezones' => $this->timezones->to_array(),
'secretary_providers' => $secretary_providers,
'secretary_providers' => $secretary_providers
]);

html_vars([
Expand All @@ -105,21 +103,45 @@ public function index()
'require_address' => $require_address,
'require_city' => $require_city,
'require_zip_code' => $require_zip_code,
'available_languages' => config('available_languages'),
'available_languages' => config('available_languages')
]);

$this->load->view('pages/customers');
}

/**
* Find a customer.
*/
public function find()
{
try {
if (cannot('view', PRIV_CUSTOMERS)) {
abort(403, 'Forbidden');
}

$user_id = session('user_id');

$customer_id = request('customer_id');

if (!$this->permissions->has_customer_access($user_id, $customer_id)) {
abort(403, 'Forbidden');
}

$customer = $this->customers_model->find($customer_id);

json_response($customer);
} catch (Throwable $e) {
json_exception($e);
}
}

/**
* Filter customers by the provided keyword.
*/
public function search()
{
try
{
if (cannot('view', PRIV_CUSTOMERS))
{
try {
if (cannot('view', PRIV_CUSTOMERS)) {
abort(403, 'Forbidden');
}

Expand All @@ -135,32 +157,24 @@ public function search()

$user_id = session('user_id');

foreach ($customers as $index => &$customer)
{
if ( ! $this->permissions->has_customer_access($user_id, $customer['id']))
{
foreach ($customers as $index => &$customer) {
if (!$this->permissions->has_customer_access($user_id, $customer['id'])) {
unset($customers[$index]);

continue;
}

$appointments = $this->appointments_model->get(['id_users_customer' => $customer['id']]);

foreach ($appointments as &$appointment)
{
$this->appointments_model->load($appointment, [
'service',
'provider',
]);
foreach ($appointments as &$appointment) {
$this->appointments_model->load($appointment, ['service', 'provider']);
}

$customer['appointments'] = $appointments;
}

json_response(array_values($customers));
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
Expand All @@ -170,15 +184,12 @@ public function search()
*/
public function store()
{
try
{
if (cannot('add', PRIV_CUSTOMERS))
{
try {
if (cannot('add', PRIV_CUSTOMERS)) {
abort(403, 'Forbidden');
}

if (session('role_slug') !== DB_SLUG_ADMIN && setting('limit_customer_visibility'))
{
if (session('role_slug') !== DB_SLUG_ADMIN && setting('limit_customer_visibility')) {
abort(403);
}

Expand All @@ -196,6 +207,11 @@ public function store()
'notes',
'timezone',
'language',
'custom_field_1',
'custom_field_2',
'custom_field_3',
'custom_field_4',
'custom_field_5'
]);

$customer_id = $this->customers_model->save($customer);
Expand All @@ -205,12 +221,10 @@ public function store()
$this->webhooks_client->trigger(WEBHOOK_CUSTOMER_SAVE, $customer);

json_response([
'success' => TRUE,
'success' => true,
'id' => $customer_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
Expand All @@ -220,19 +234,16 @@ public function store()
*/
public function update()
{
try
{
if (cannot('edit', PRIV_CUSTOMERS))
{
try {
if (cannot('edit', PRIV_CUSTOMERS)) {
abort(403, 'Forbidden');
}

$user_id = session('user_id');

$customer = request('customer');

if ( ! $this->permissions->has_customer_access($user_id, $customer['id']))
{
if (!$this->permissions->has_customer_access($user_id, $customer['id'])) {
abort(403, 'Forbidden');
}

Expand All @@ -249,6 +260,11 @@ public function update()
'notes',
'timezone',
'language',
'custom_field_1',
'custom_field_2',
'custom_field_3',
'custom_field_4',
'custom_field_5'
]);

$customer_id = $this->customers_model->save($customer);
Expand All @@ -258,12 +274,10 @@ public function update()
$this->webhooks_client->trigger(WEBHOOK_CUSTOMER_SAVE, $customer);

json_response([
'success' => TRUE,
'success' => true,
'id' => $customer_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
Expand All @@ -273,19 +287,16 @@ public function update()
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_CUSTOMERS))
{
try {
if (cannot('delete', PRIV_CUSTOMERS)) {
abort(403, 'Forbidden');
}

$user_id = session('user_id');

$customer_id = request('customer_id');

if ( ! $this->permissions->has_customer_access($user_id, $customer_id))
{
if (!$this->permissions->has_customer_access($user_id, $customer_id)) {
abort(403, 'Forbidden');
}

Expand All @@ -296,42 +307,9 @@ public function destroy()
$this->webhooks_client->trigger(WEBHOOK_CUSTOMER_DELETE, $customer);

json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}

/**
* Find a customer.
*/
public function find()
{
try
{
if (cannot('view', PRIV_CUSTOMERS))
{
abort(403, 'Forbidden');
}

$user_id = session('user_id');

$customer_id = request('customer_id');

if ( ! $this->permissions->has_customer_access($user_id, $customer_id))
{
abort(403, 'Forbidden');
}

$customer = $this->customers_model->find($customer_id);

json_response($customer);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
Expand Down
4 changes: 3 additions & 1 deletion application/language/arabic/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,7 @@
$lang['blocked_period_save'] = 'Blocked Period Save';
$lang['blocked_period_delete'] = 'Blocked Period Delete';
$lang['blocked_periods_hint'] = 'Define periods of time where public bookings will be disabled for all providers (e.g. closed dates, holidays etc.).';
$lang['auxiliary_field'] = 'Auxiliary Field';
$lang['custom_field'] = 'Custom Field';
$lang['custom_fields'] = 'Custom Fields';
$lang['label'] = 'Label';
// End
4 changes: 3 additions & 1 deletion application/language/bulgarian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,7 @@
$lang['blocked_period_save'] = 'Blocked Period Save';
$lang['blocked_period_delete'] = 'Blocked Period Delete';
$lang['blocked_periods_hint'] = 'Define periods of time where public bookings will be disabled for all providers (e.g. closed dates, holidays etc.).';
$lang['auxiliary_field'] = 'Auxiliary Field';
$lang['custom_field'] = 'Custom Field';
$lang['custom_fields'] = 'Custom Fields';
$lang['label'] = 'Label';
// End
4 changes: 3 additions & 1 deletion application/language/catalan/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,7 @@
$lang['blocked_period_save'] = 'Blocked Period Save';
$lang['blocked_period_delete'] = 'Blocked Period Delete';
$lang['blocked_periods_hint'] = 'Define periods of time where public bookings will be disabled for all providers (e.g. closed dates, holidays etc.).';
$lang['auxiliary_field'] = 'Auxiliary Field';
$lang['custom_field'] = 'Custom Field';
$lang['custom_fields'] = 'Custom Fields';
$lang['label'] = 'Label';
// End
4 changes: 3 additions & 1 deletion application/language/chinese/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,7 @@
$lang['blocked_period_save'] = 'Blocked Period Save';
$lang['blocked_period_delete'] = 'Blocked Period Delete';
$lang['blocked_periods_hint'] = 'Define periods of time where public bookings will be disabled for all providers (e.g. closed dates, holidays etc.).';
$lang['auxiliary_field'] = 'Auxiliary Field';
$lang['custom_field'] = 'Custom Field';
$lang['custom_fields'] = 'Custom Fields';
$lang['label'] = 'Label';
// End
4 changes: 3 additions & 1 deletion application/language/croatian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,7 @@
$lang['blocked_period_save'] = 'Blocked Period Save';
$lang['blocked_period_delete'] = 'Blocked Period Delete';
$lang['blocked_periods_hint'] = 'Define periods of time where public bookings will be disabled for all providers (e.g. closed dates, holidays etc.).';
$lang['auxiliary_field'] = 'Auxiliary Field';
$lang['custom_field'] = 'Custom Field';
$lang['custom_fields'] = 'Custom Fields';
$lang['label'] = 'Label';
// End
4 changes: 3 additions & 1 deletion application/language/czech/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,7 @@
$lang['blocked_period_save'] = 'Blocked Period Save';
$lang['blocked_period_delete'] = 'Blocked Period Delete';
$lang['blocked_periods_hint'] = 'Define periods of time where public bookings will be disabled for all providers (e.g. closed dates, holidays etc.).';
$lang['auxiliary_field'] = 'Auxiliary Field';
$lang['custom_field'] = 'Custom Field';
$lang['custom_fields'] = 'Custom Fields';
$lang['label'] = 'Label';
// End
4 changes: 3 additions & 1 deletion application/language/danish/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,7 @@
$lang['blocked_period_save'] = 'Blocked Period Save';
$lang['blocked_period_delete'] = 'Blocked Period Delete';
$lang['blocked_periods_hint'] = 'Define periods of time where public bookings will be disabled for all providers (e.g. closed dates, holidays etc.).';
$lang['auxiliary_field'] = 'Auxiliary Field';
$lang['custom_field'] = 'Custom Field';
$lang['custom_fields'] = 'Custom Fields';
$lang['label'] = 'Label';
// End
4 changes: 3 additions & 1 deletion application/language/dutch/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,7 @@
$lang['blocked_period_save'] = 'Blocked Period Save';
$lang['blocked_period_delete'] = 'Blocked Period Delete';
$lang['blocked_periods_hint'] = 'Define periods of time where public bookings will be disabled for all providers (e.g. closed dates, holidays etc.).';
$lang['auxiliary_field'] = 'Auxiliary Field';
$lang['custom_field'] = 'Custom Field';
$lang['custom_fields'] = 'Custom Fields';
$lang['label'] = 'Label';
// End
4 changes: 3 additions & 1 deletion application/language/english/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,7 @@
$lang['blocked_period_save'] = 'Blocked Period Save';
$lang['blocked_period_delete'] = 'Blocked Period Delete';
$lang['blocked_periods_hint'] = 'Define periods of time where public bookings will be disabled for all providers (e.g. closed dates, holidays etc.).';
$lang['auxiliary_field'] = 'Auxiliary Field';
$lang['custom_field'] = 'Custom Field';
$lang['custom_fields'] = 'Custom Fields';
$lang['label'] = 'Label';
// End
4 changes: 3 additions & 1 deletion application/language/estonian/translations_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,7 @@
$lang['blocked_period_save'] = 'Blocked Period Save';
$lang['blocked_period_delete'] = 'Blocked Period Delete';
$lang['blocked_periods_hint'] = 'Define periods of time where public bookings will be disabled for all providers (e.g. closed dates, holidays etc.).';
$lang['auxiliary_field'] = 'Auxiliary Field';
$lang['custom_field'] = 'Custom Field';
$lang['custom_fields'] = 'Custom Fields';
$lang['label'] = 'Label';
// End
Loading

0 comments on commit e6b3ffd

Please sign in to comment.