2017-09-15 14:44:40 +03:00
|
|
|
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
2016-01-09 23:29:28 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2018-03-27 10:23:09 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2018, Alex Tselegidis
|
2016-01-09 23:29:28 +02:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Roles Model
|
|
|
|
*
|
|
|
|
* @package Models
|
|
|
|
*/
|
|
|
|
class Roles_Model extends CI_Model {
|
|
|
|
/**
|
|
|
|
* Get the record id of a particular role.
|
|
|
|
*
|
2017-09-08 15:03:45 +03:00
|
|
|
* @param string $role_slug The selected role slug. Slugs are defined in the "application/config/constants.php" file.
|
|
|
|
*
|
2016-01-09 23:29:28 +02:00
|
|
|
* @return int Returns the database id of the roles record.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function get_role_id($role_slug)
|
|
|
|
{
|
|
|
|
return $this->db->get_where('ea_roles', ['slug' => $role_slug])->row()->id;
|
2016-01-09 23:29:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all the privileges (bool values) of a role slug.
|
|
|
|
*
|
2017-09-08 15:03:45 +03:00
|
|
|
* The privilege numbers are converted into bool values of the four main actions (view, add, edit, delete). By
|
|
|
|
* checking each value you can know if the user is able to perform this action.
|
2016-01-09 23:29:28 +02:00
|
|
|
*
|
|
|
|
* @param string $slug The role slug.
|
2017-09-08 15:03:45 +03:00
|
|
|
*
|
2016-01-09 23:29:28 +02:00
|
|
|
* @return array Returns the privilege value.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function get_privileges($slug)
|
|
|
|
{
|
|
|
|
$privileges = $this->db->get_where('ea_roles', ['slug' => $slug])->row_array();
|
2016-01-09 23:29:28 +02:00
|
|
|
unset($privileges['id'], $privileges['name'], $privileges['slug'], $privileges['is_admin']);
|
|
|
|
|
2017-09-08 15:03:45 +03:00
|
|
|
// Convert the int values to bool so that is easier to check whether a
|
2016-01-09 23:29:28 +02:00
|
|
|
// user has the required privileges for a specific action.
|
2017-09-15 14:36:37 +03:00
|
|
|
foreach ($privileges as &$value)
|
|
|
|
{
|
2016-01-09 23:29:28 +02:00
|
|
|
$privileges_number = $value;
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
$value = [
|
2016-01-09 23:29:28 +02:00
|
|
|
'view' => FALSE,
|
|
|
|
'add' => FALSE,
|
|
|
|
'edit' => FALSE,
|
|
|
|
'delete' => FALSE
|
2017-09-15 14:36:37 +03:00
|
|
|
];
|
2016-01-09 23:29:28 +02:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ($privileges_number > 0)
|
|
|
|
{
|
|
|
|
if ((int)($privileges_number / PRIV_DELETE) == 1)
|
|
|
|
{
|
2016-01-09 23:29:28 +02:00
|
|
|
$value['delete'] = TRUE;
|
|
|
|
$privileges_number -= PRIV_DELETE;
|
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ((int)($privileges_number / PRIV_EDIT) == 1)
|
|
|
|
{
|
2016-01-09 23:29:28 +02:00
|
|
|
$value['edit'] = TRUE;
|
|
|
|
$privileges_number -= PRIV_EDIT;
|
|
|
|
}
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ((int)($privileges_number / PRIV_ADD) == 1)
|
|
|
|
{
|
2016-01-09 23:29:28 +02:00
|
|
|
$value['add'] = TRUE;
|
|
|
|
$privileges_number -= PRIV_ADD;
|
|
|
|
}
|
|
|
|
|
|
|
|
$value['view'] = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $privileges;
|
|
|
|
}
|
|
|
|
}
|