Added migration for displayed/required booking fields

This commit is contained in:
Alex Tselegidis 2021-12-20 08:07:57 +01:00
parent 8ea4b17cf8
commit 29423647b6
2 changed files with 106 additions and 57 deletions

View File

@ -0,0 +1,106 @@
<?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) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
class Migration_Add_booking_field_settings extends EA_Migration {
/**
* @var array
*/
private $fields = [
'first_name' => [
'display' => '1',
'require' => '1',
],
'last_name' => [
'display' => '1',
'require' => '1',
],
'email' => [
'display' => '1',
'require' => '1',
],
'phone_number' => [
'display' => '1',
'require' => '1',
],
'address' => [
'display' => '1',
'require' => '0',
],
'city' => [
'display' => '1',
'require' => '0',
],
'zip_code' => [
'display' => '1',
'require' => '0',
],
'notes' => [
'display' => '1',
'require' => '0',
],
];
/**
* Upgrade method.
*/
public function up()
{
foreach ($this->fields as $field => $props)
{
foreach ($props as $prop => $value)
{
$setting_name = $prop . '_' . $field;
if ($this->db->get_where('settings', ['name' => $setting_name])->num_rows())
{
$setting = $this->db->get_where('settings', [
'name' => $setting_name,
])->row_array();
$value = $setting['value']; // Use existing value.
$this->db->delete('settings', ['name' => $setting_name]);
}
if ( ! $this->db->get_where('settings', ['name' => $setting_name])->num_rows())
{
$this->db->insert('settings', [
'name' => $setting_name,
'value' => $value
]);
}
}
}
}
/**
* Downgrade method.
*/
public function down()
{
foreach ($this->fields as $field => $props)
{
foreach ($props as $prop => $value)
{
$setting_name = $prop . '_' . $field;
if ($this->db->get_where('settings', ['name' => $setting_name])->num_rows())
{
$this->db->delete('settings', [
'name' => $setting_name,
]);
}
}
}
}
}

View File

@ -1,57 +0,0 @@
<?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) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
class Migration_Add_show_field_settings extends EA_Migration {
/**
* Upgrade method.
*/
public function up()
{
$this->db->insert('settings', [
'name' => 'show_phone_number',
'value' => '1'
]);
$this->db->insert('settings', [
'name' => 'show_address',
'value' => '1'
]);
$this->db->insert('settings', [
'name' => 'show_city',
'value' => '1'
]);
$this->db->insert('settings', [
'name' => 'show_zip_code',
'value' => '1'
]);
$this->db->insert('settings', [
'name' => 'show_notes',
'value' => '1'
]);
}
/**
* Downgrade method.
*/
public function down()
{
$this->db->delete('settings', ['name' => 'show_phone_number']);
$this->db->delete('settings', ['name' => 'show_address']);
$this->db->delete('settings', ['name' => 'show_city']);
$this->db->delete('settings', ['name' => 'show_zip_code']);
$this->db->delete('settings', ['name' => 'show_notes']);
}
}