2020-04-22 22:48:56 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2018-06-24 18:27:16 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2020-03-11 12:10:59 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
2018-06-24 18:27:16 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.3.2
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Consents_model
|
|
|
|
*
|
|
|
|
* @package Models
|
|
|
|
*/
|
2020-11-16 11:29:36 +03:00
|
|
|
class Consents_model extends EA_Model {
|
2018-06-24 18:27:16 +03:00
|
|
|
/**
|
|
|
|
* Add a consent record to the database.
|
|
|
|
*
|
|
|
|
* This method adds a consent to the database.
|
|
|
|
*
|
|
|
|
* @param array $consent Associative array with the consent's data.
|
|
|
|
*
|
|
|
|
* @return int Returns the consent ID.
|
2020-09-23 13:36:24 +03:00
|
|
|
*
|
|
|
|
* @throws Exception
|
2018-06-24 18:27:16 +03:00
|
|
|
*/
|
|
|
|
public function add($consent)
|
|
|
|
{
|
|
|
|
$this->validate($consent);
|
|
|
|
|
|
|
|
if ( ! isset($consent['id']))
|
|
|
|
{
|
2020-04-23 21:48:20 +03:00
|
|
|
$consent['id'] = $this->insert($consent);
|
2018-06-24 18:27:16 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-23 21:48:20 +03:00
|
|
|
$this->update($consent);
|
2018-06-24 18:27:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $consent['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate consent data before the insert or update operation is executed.
|
|
|
|
*
|
|
|
|
* @param array $consent Contains the consent data.
|
|
|
|
*
|
|
|
|
* @throws Exception If customer validation fails.
|
|
|
|
*/
|
|
|
|
public function validate($consent)
|
|
|
|
{
|
|
|
|
if ( ! isset($consent['first_name'])
|
|
|
|
|| ! isset($consent['last_name'])
|
|
|
|
|| ! isset($consent['email'])
|
|
|
|
|| ! isset($consent['ip'])
|
|
|
|
|| ! isset($consent['type']))
|
|
|
|
{
|
|
|
|
throw new Exception('Not all required fields are provided: '
|
|
|
|
. print_r($consent, TRUE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert a new consent record to the database.
|
|
|
|
*
|
|
|
|
* @param array $consent Associative array with the consent's data.
|
|
|
|
*
|
|
|
|
* @return int Returns the ID of the new record.
|
|
|
|
*
|
|
|
|
* @throws Exception If consent record could not be inserted.
|
|
|
|
*/
|
2020-04-23 21:48:20 +03:00
|
|
|
protected function insert($consent)
|
2018-06-24 18:27:16 +03:00
|
|
|
{
|
2020-09-23 13:36:24 +03:00
|
|
|
$consent['created'] = date('Y-m-d H:i:s');
|
|
|
|
$consent['modified'] = date('Y-m-d H:i:s');
|
2020-03-09 23:51:50 +03:00
|
|
|
|
2020-04-23 21:48:20 +03:00
|
|
|
if ( ! $this->db->insert('consents', $consent))
|
2018-06-24 18:27:16 +03:00
|
|
|
{
|
|
|
|
throw new Exception('Could not insert consent to the database.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int)$this->db->insert_id();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update an existing consent record in the database.
|
|
|
|
*
|
|
|
|
* The consent data argument should already include the record ID in order to process the update operation.
|
|
|
|
*
|
|
|
|
* @param array $consent Associative array with the consent's data.
|
|
|
|
*
|
|
|
|
* @return int Returns the updated record ID.
|
|
|
|
*
|
|
|
|
* @throws Exception If consent record could not be updated.
|
|
|
|
*/
|
2020-04-23 21:48:20 +03:00
|
|
|
protected function update($consent)
|
2018-06-24 18:27:16 +03:00
|
|
|
{
|
2020-09-23 13:36:24 +03:00
|
|
|
$consent['modified'] = date('Y-m-d H:i:s');
|
2020-03-09 23:51:50 +03:00
|
|
|
|
2020-04-23 21:48:20 +03:00
|
|
|
if ( ! $this->db->update('consents', $consent, ['id' => $consent['id']]))
|
2018-06-24 18:27:16 +03:00
|
|
|
{
|
|
|
|
throw new Exception('Could not update consent to the database.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int)$consent['id'];
|
|
|
|
}
|
|
|
|
}
|