Add a new "is_private" flag to services and providers so that they do not appear in the booking page (#378).

This commit is contained in:
Alex Tselegidis 2022-01-24 20:50:14 +01:00
parent 86d3ce8dc9
commit 2f41c28786
38 changed files with 220 additions and 20 deletions

View file

@ -86,8 +86,8 @@ class Booking extends EA_Controller {
return;
}
$available_services = $this->services_model->get_available_services();
$available_providers = $this->providers_model->get_available_providers();
$available_services = $this->services_model->get_available_services(TRUE);
$available_providers = $this->providers_model->get_available_providers(TRUE);
foreach ($available_providers as &$available_provider)
{
@ -224,7 +224,7 @@ class Booking extends EA_Controller {
'available_providers' => $available_providers,
'company_name' => $company_name,
'company_logo' => $company_logo,
'company_color' => $company_color,
'company_color' => $company_color === '#ffffff' ? '' : $company_color,
'date_format' => $date_format,
'time_format' => $time_format,
'first_weekday' => $first_weekday,
@ -364,7 +364,7 @@ class Booking extends EA_Controller {
*/
protected function search_any_provider(int $service_id, string $date, string $hour = NULL): ?int
{
$available_providers = $this->providers_model->get_available_providers();
$available_providers = $this->providers_model->get_available_providers(TRUE);
$service = $this->services_model->find($service_id);
@ -652,7 +652,7 @@ class Booking extends EA_Controller {
*/
protected function search_providers_by_service(int $service_id): array
{
$available_providers = $this->providers_model->get_available_providers();
$available_providers = $this->providers_model->get_available_providers(TRUE);
$provider_list = [];
foreach ($available_providers as $provider)

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -356,4 +356,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -357,4 +357,6 @@ $lang['company'] = 'Company';
$lang['remove'] = 'Remove';
$lang['login_button'] = 'Login Button';
$lang['display_login_button_hint'] = 'Defines whether the login button is being displayed in the booking page.';
$lang['private'] = 'Private';
$lang['private_hint'] = 'Private records will not be displayed or processed in public pages such as the booking page.';
// End

View file

@ -0,0 +1,45 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
* @link http://easyappointments.org
* @since v1.4.0
* ---------------------------------------------------------------------------- */
class Migration_Add_is_private_column_to_services_table extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
if ( ! $this->db->field_exists('is_private', 'services'))
{
$fields = [
'is_private' => [
'type' => 'TINYINT',
'constraint' => '4',
'default' => '0',
'after' => 'attendants_number'
]
];
$this->dbforge->add_column('services', $fields);
}
}
/**
* Downgrade method.
*/
public function down()
{
if ( ! $this->db->field_exists('is_private', 'services'))
{
$this->dbforge->drop_column('services', 'is_private');
}
}
}

View file

@ -0,0 +1,45 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
* @link http://easyappointments.org
* @since v1.4.0
* ---------------------------------------------------------------------------- */
class Migration_Add_is_private_column_to_users_table extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
if ( ! $this->db->field_exists('is_private', 'users'))
{
$fields = [
'is_private' => [
'type' => 'TINYINT',
'constraint' => '4',
'default' => '0',
'after' => 'language'
]
];
$this->dbforge->add_column('users', $fields);
}
}
/**
* Downgrade method.
*/
public function down()
{
if ( ! $this->db->field_exists('is_private', 'users'))
{
$this->dbforge->drop_column('users', 'is_private');
}
}
}

View file

@ -24,6 +24,7 @@ class Providers_model extends EA_Model {
*/
protected $casts = [
'id' => 'integer',
'is_private' => 'boolean',
'id_roles' => 'integer',
];
@ -44,6 +45,7 @@ class Providers_model extends EA_Model {
'timezone' => 'timezone',
'language' => 'language',
'notes' => 'notes',
'isPrivate' => 'is_private',
'roleId' => 'id_roles',
];
@ -609,10 +611,17 @@ class Providers_model extends EA_Model {
/**
* Get all the provider records that are assigned to at least one service.
*
* @param bool $without_private Only include the public providers.
*
* @return array Returns an array of providers.
*/
public function get_available_providers(): array
public function get_available_providers(bool $without_private = FALSE): array
{
if ($without_private)
{
$this->db->where('users.is_private', FALSE);
}
$providers = $this
->db
->select('users.*')

View file

@ -26,6 +26,7 @@ class Services_model extends EA_Model {
'id' => 'integer',
'price' => 'float',
'attendants_number' => 'integer',
'is_private' => 'boolean',
'id_categories' => 'integer',
];
@ -43,6 +44,7 @@ class Services_model extends EA_Model {
'color' => 'color',
'availabilitiesType' => 'availabilities_type',
'attendantsNumber' => 'attendants_number',
'isPrivate' => 'is_private',
'categoryId' => 'id_categories',
];
@ -284,7 +286,7 @@ class Services_model extends EA_Model {
$services = $this->db->get('services', $limit, $offset)->result_array();
foreach ($services as $service)
foreach ($services as &$service)
{
$this->cast($service);
}
@ -295,10 +297,17 @@ class Services_model extends EA_Model {
/**
* Get all the service records that are assigned to at least one provider.
*
* @param bool $without_private Only include the public services.
*
* @return array Returns an array of services.
*/
public function get_available_services(): array
public function get_available_services(bool $without_private = FALSE): array
{
if ($without_private)
{
$this->db->where('services.is_private', FALSE);
}
$services = $this
->db
->distinct()
@ -310,7 +319,7 @@ class Services_model extends EA_Model {
->get()
->result_array();
foreach ($services as $service)
foreach ($services as &$service)
{
$this->cast($service);
}
@ -352,7 +361,7 @@ class Services_model extends EA_Model {
->get()
->result_array();
foreach ($services as $service)
foreach ($services as &$service)
{
$this->cast($service);
}

View file

@ -19,7 +19,9 @@
<link rel="stylesheet" type="text/css" href="<?= asset_url('assets/css/general.css') ?>">
<link rel="stylesheet" type="text/css" href="<?= asset_url('assets/css/layouts/booking_layout.css') ?>">
<?php component('company_color_style', ['company_color' => vars('company_color')]) ?>
<?php if (vars('company_color')): ?>
<?php component('company_color_style', ['company_color' => vars('company_color')]) ?>
<?php endif ?>
</head>
<body>

View file

@ -146,6 +146,21 @@
<input id="zip-code" class="form-control" maxlength="64" disabled>
</div>
<div class="mb-3">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="private">
<label class="form-check-label" for="private">
<?= lang('private') ?>
</label>
</div>
<div class="form-text text-muted">
<small>
<?= lang('private_hint') ?>
</small>
</div>
</div>
<div class="mb-3">
<label class="form-label" for="notes">
<?= lang('notes') ?>

View file

@ -128,6 +128,21 @@
<?php component('color_selection', ['attributes' => 'id="color"']) ?>
</div>
<div class="mb-3">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="private">
<label class="form-check-label" for="private">
<?= lang('private') ?>
</label>
</div>
<div class="form-text text-muted">
<small>
<?= lang('private_hint') ?>
</small>
</div>
</div>
<div class="mb-3">
<label class="form-label" for="description">
<?= lang('description') ?>

View file

@ -26,6 +26,7 @@ App.Pages.Providers = (function () {
const $city = $('#city');
const $state = $('#state');
const $zipCode = $('#zip-code');
const $private = $('#private');
const $notes = $('#notes');
const $timezone = $('#timezone');
const $username = $('#username');
@ -162,6 +163,7 @@ App.Pages.Providers = (function () {
city: $city.val(),
state: $state.val(),
zip_code: $zipCode.val(),
is_private: Number($private.prop('checked')),
notes: $notes.val(),
timezone: $timezone.val(),
settings: {
@ -381,6 +383,7 @@ App.Pages.Providers = (function () {
$city.val(provider.city);
$state.val(provider.state);
$zipCode.val(provider.zip_code);
$private.prop('checked', provider.is_private);
$notes.val(provider.notes);
$timezone.val(provider.timezone);

View file

@ -24,6 +24,7 @@ App.Pages.Services = (function () {
const $category = $('#category');
const $availabilitiesType = $('#availabilities-type');
const $attendantsNumber = $('#attendants-number');
const $private = $('#private');
const $location = $('#location');
const $description = $('#description');
const $filterServices = $('#filter-services');
@ -134,6 +135,7 @@ App.Pages.Services = (function () {
color: App.Components.ColorSelection.getColor($color),
availabilities_type: $availabilitiesType.val(),
attendants_number: $attendantsNumber.val(),
is_private: Number($private.prop('checked')),
id_categories: $category.val() || null
};
@ -288,6 +290,7 @@ App.Pages.Services = (function () {
$location.val(service.location);
$availabilitiesType.val(service.availabilities_type);
$attendantsNumber.val(service.attendants_number);
$private.prop('checked', service.is_private);
App.Components.ColorSelection.setColor($color, service.color);
const categoryId = service.id_categories !== null ? service.id_categories : '';