c
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\AdminController;
|
||||
|
||||
use Hura8\System\Permission;
|
||||
use Hura8\Traits\ClassCacheTrait;
|
||||
|
||||
class ClientPermissionController
|
||||
{
|
||||
|
||||
use ClassCacheTrait;
|
||||
|
||||
public function getClientEntityPermission(){
|
||||
return static::getCache("getClientEntityPermission", function (){
|
||||
return $this->getClientEntityPermission_raw();
|
||||
});
|
||||
}
|
||||
|
||||
protected function getClientEntityPermission_raw() {
|
||||
|
||||
$system_file = ROOT_DIR. "/config/system/admin.entity.permission.php";
|
||||
$entity_group = include $system_file;
|
||||
|
||||
$client_allowed_entities = Permission::getClientEntities();
|
||||
|
||||
$final_config = [];
|
||||
foreach ($entity_group as $_group) {
|
||||
|
||||
$settings = include ROOT_DIR. "/config/system/entity_permission/".$_group.".php";
|
||||
|
||||
$children_match = [];
|
||||
foreach ($settings['children'] as $_entity => $_p) {
|
||||
if(in_array($_entity, $client_allowed_entities)) {
|
||||
$children_match[$_entity] = $_p;
|
||||
}
|
||||
}
|
||||
|
||||
if(sizeof($children_match)) {
|
||||
$final_config[$_group] = [
|
||||
'title' => $settings['title'],
|
||||
'children' => $children_match,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $final_config;
|
||||
}
|
||||
|
||||
|
||||
public function getClientMenu() {
|
||||
return static::getCache("getClientMenu", function (){
|
||||
$menu_config_file = ROOT_DIR. "/config/client/admin/admin.menu.php";
|
||||
|
||||
$header_admin_config = [];
|
||||
$menu_group = include $menu_config_file;
|
||||
foreach ($menu_group as $_group) {
|
||||
$content = include ROOT_DIR. "/config/client/admin/admin_menu/".$_group.".php";
|
||||
$enabled_menu_item = array_filter($content['menu'], function ($item){ return $item['enable'];});
|
||||
|
||||
if(sizeof($enabled_menu_item) > 0) {
|
||||
$header_admin_config[$_group] = [
|
||||
'enable' => $content['enable'],
|
||||
'name' => $content['name'],
|
||||
'url' => $content['url'],
|
||||
'menu' => $enabled_menu_item,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $header_admin_config;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\AdminController;
|
||||
|
||||
use Hura8\Components\Staff\Model\StaffAuthModel;
|
||||
use Hura8\Components\Staff\Model\StaffModel;
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\IDGenerator;
|
||||
|
||||
|
||||
class StaffAdminController
|
||||
{
|
||||
|
||||
protected $objStaffAuthModel;
|
||||
protected $objStaffModel;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$this->objStaffAuthModel = new StaffAuthModel();
|
||||
$this->objStaffModel = new StaffModel();
|
||||
}
|
||||
|
||||
public function getLoginListByIds(array $staff_ids) : array
|
||||
{
|
||||
return $this->objStaffAuthModel->getLoginListByIds($staff_ids);
|
||||
}
|
||||
|
||||
public function getList(array $conditions) : array
|
||||
{
|
||||
return $this->objStaffModel->getList($conditions);
|
||||
}
|
||||
|
||||
public function getInfo($id) : ?array
|
||||
{
|
||||
return $this->objStaffModel->getInfo($id);
|
||||
}
|
||||
|
||||
public function getEmptyInfo(array $additional_fields = []) : array
|
||||
{
|
||||
return $this->objStaffModel->getEmptyInfo($additional_fields);
|
||||
}
|
||||
|
||||
public function update($id, array $input_info) : AppResponse
|
||||
{
|
||||
// change password
|
||||
if(isset($input_info['password']) && strlen($input_info['password']) > 5) {
|
||||
$this->objStaffAuthModel->createOrUpdatePassword($id, $input_info['password']);
|
||||
}
|
||||
|
||||
return $this->objStaffModel->update($id, $input_info);
|
||||
}
|
||||
|
||||
public function create(array $input_info, $password = "") : AppResponse
|
||||
{
|
||||
$db_res = $this->objStaffModel->create($input_info);
|
||||
|
||||
if($db_res->getStatus() == 'ok') {
|
||||
|
||||
$new_id = $db_res->getData();
|
||||
|
||||
if(!$password) $password = IDGenerator::createStringId(6);
|
||||
|
||||
$this->objStaffAuthModel->createOrUpdatePassword($new_id, $password);
|
||||
|
||||
return new AppResponse('ok', '', ["id" => $new_id, "password" => $password]);
|
||||
}
|
||||
|
||||
return new AppResponse('error', 'Cannot create');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\AdminController;
|
||||
|
||||
use Hura8\Components\Staff\Model\StaffDepartmentModel;
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\Traits\ClassCacheTrait;
|
||||
|
||||
|
||||
class StaffAdminDepartmentController
|
||||
{
|
||||
use ClassCacheTrait;
|
||||
|
||||
protected $objStaffDepartmentModel;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$this->objStaffDepartmentModel = new StaffDepartmentModel();
|
||||
}
|
||||
|
||||
public function getList(array $conditions) {
|
||||
return $this->objStaffDepartmentModel->getList($conditions);
|
||||
}
|
||||
|
||||
public function getInfo($id) {
|
||||
return self::getCache("getInfo-".$id, function () use ($id){
|
||||
return $this->objStaffDepartmentModel->getInfo($id);
|
||||
});
|
||||
}
|
||||
|
||||
public function getEmptyInfo(array $additional_fields = [])
|
||||
{
|
||||
return $this->objStaffDepartmentModel->getEmptyInfo($additional_fields);
|
||||
}
|
||||
|
||||
public function update($id, array $input_info) {
|
||||
return $this->objStaffDepartmentModel->update($id, $input_info);
|
||||
}
|
||||
|
||||
public function create(array $input_info) {
|
||||
return $this->objStaffDepartmentModel->create($input_info);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\AdminController;
|
||||
|
||||
use Hura8\Components\Staff\Model\StaffDepartmentPermissionModel;
|
||||
|
||||
|
||||
class StaffDepartmentPermissionController extends ClientPermissionController
|
||||
{
|
||||
|
||||
protected $objStaffDepartmentPermissionModel;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$this->objStaffDepartmentPermissionModel = new StaffDepartmentPermissionModel();
|
||||
}
|
||||
|
||||
|
||||
public function getDepartmentMenuPermissionSetting($department_id) {
|
||||
|
||||
$current_permission = $this->getDepartmentMenuPermission($department_id);
|
||||
|
||||
$user_menu_settings = [];
|
||||
foreach ($this->getClientMenu() as $group_id => $group_info) {
|
||||
|
||||
$rebuild_menu = [];
|
||||
foreach ($group_info['menu'] as $index => $menu) {
|
||||
$rebuild_menu[$index] = $menu;
|
||||
|
||||
$rebuild_menu[$index]['is_user_permitted'] = (in_array($menu['id'], $current_permission)) ? 1 : 0;
|
||||
}
|
||||
|
||||
$user_menu_settings[$group_id] = $group_info;
|
||||
$user_menu_settings[$group_id]['menu'] = $rebuild_menu;
|
||||
}
|
||||
|
||||
return $user_menu_settings;
|
||||
}
|
||||
|
||||
|
||||
public function saveDepartmentMenuPermission($department_id, array $new_permission) {
|
||||
$this->objStaffDepartmentPermissionModel->saveDepartmentMenuPermission($department_id, $new_permission);
|
||||
}
|
||||
|
||||
|
||||
public function getDepartmentMenuPermission($department_id) {
|
||||
return $this->objStaffDepartmentPermissionModel->getDepartmentMenuPermission($department_id);
|
||||
}
|
||||
|
||||
|
||||
public function getDepartmentEntityPermissionSetting($department_id) {
|
||||
|
||||
$current_permission = $this->getDepartmentEntityPermission($department_id);
|
||||
|
||||
$_settings = [];
|
||||
foreach ($this->getClientEntityPermission() as $group_id => $group_info) {
|
||||
|
||||
$rebuild_children = [];
|
||||
foreach ($group_info['children'] as $entity => $info) {
|
||||
|
||||
$actions = [];
|
||||
foreach ($info['action'] as $action_key => $action_title) {
|
||||
$actions[] = [
|
||||
'action' => $action_key,
|
||||
'title' => $action_title,
|
||||
'is_user_permitted' => (isset($current_permission[$group_id]) && isset($current_permission[$group_id][$entity]) && isset($current_permission[$group_id][$entity][$action_key])) ? $current_permission[$group_id][$entity][$action_key] : false ,
|
||||
];
|
||||
}
|
||||
|
||||
$rebuild_children[$entity] = [
|
||||
'title' => $info['title'],
|
||||
'action_list' => $actions,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$_settings[$group_id] = $group_info;
|
||||
$_settings[$group_id]['children'] = $rebuild_children;
|
||||
}
|
||||
|
||||
return $_settings;
|
||||
}
|
||||
|
||||
|
||||
public function saveDepartmentEntityPermission($department_id, array $new_permission) {
|
||||
$this->objStaffDepartmentPermissionModel->saveDepartmentEntityPermission(
|
||||
$department_id, $new_permission
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function getDepartmentEntityPermission($department_id) {
|
||||
return static::getCache("getDepartmentEntityPermission-".$department_id, function () use ($department_id){
|
||||
return $this->objStaffDepartmentPermissionModel->getDepartmentEntityPermission($department_id);
|
||||
}) ;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\AdminController;
|
||||
|
||||
use Hura8\Components\Staff\Model\StaffLogModel;
|
||||
|
||||
class StaffLogController
|
||||
{
|
||||
protected $objStaffLogModel;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$this->objStaffLogModel = new StaffLogModel();
|
||||
}
|
||||
|
||||
public function getList(array $conditions) {
|
||||
return $this->objStaffLogModel->getList($conditions);
|
||||
}
|
||||
|
||||
public function getTotal(array $conditions) {
|
||||
return $this->objStaffLogModel->getTotal($conditions);
|
||||
}
|
||||
|
||||
public function create(array $input_info) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\AdminController;
|
||||
|
||||
use Hura8\Components\Staff\Model\StaffPermissionModel;
|
||||
use Hura8\Components\Staff\PublicController\StaffLoginController;
|
||||
|
||||
|
||||
class StaffPermissionController extends ClientPermissionController
|
||||
{
|
||||
|
||||
protected $objStaffPermissionModel;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$this->objStaffPermissionModel = new StaffPermissionModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $entity_group
|
||||
* @param $entity
|
||||
* @param string $action valid values in PermissionType::
|
||||
* @return bool
|
||||
*/
|
||||
public function checkEntityActionPermission($is_super_user, $entity_group, $entity, $action ) : bool {
|
||||
|
||||
// super is allowed by default
|
||||
if($is_super_user) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$current_permission = $this->getCurrentUserEntityPermission();
|
||||
|
||||
if (
|
||||
isset($current_permission[$entity_group]) &&
|
||||
isset($current_permission[$entity_group][$entity]) &&
|
||||
isset($current_permission[$entity_group][$entity][$action])
|
||||
) {
|
||||
return $current_permission[$entity_group][$entity][$action] ;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getUserProductMenuList() {
|
||||
|
||||
return self::getCache("getUserProductMenuList", function (){
|
||||
$menu_list = include CONFIG_DIR. '/client/admin/product_menu.php';
|
||||
|
||||
$final_list = [];
|
||||
foreach (array_filter($menu_list, function ($item){ return $item['enabled'];}) as $key => $value) {
|
||||
|
||||
// check if the current staff can see
|
||||
// todo
|
||||
// ...
|
||||
|
||||
$final_list[$key] = $value;
|
||||
}
|
||||
|
||||
return $final_list;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function saveUserMenuPermission($admin_id, array $new_permission) {
|
||||
$this->objStaffPermissionModel->saveUserMenuPermission($admin_id, $new_permission);
|
||||
}
|
||||
|
||||
|
||||
public function saveUserEntityPermission($admin_id, array $new_permission) {
|
||||
$this->objStaffPermissionModel->saveUserEntityPermission($admin_id, $new_permission);
|
||||
}
|
||||
|
||||
/*
|
||||
* get menu for currently logged-in user
|
||||
*/
|
||||
public function getUserMenu($is_super_user) {
|
||||
|
||||
// super can see all
|
||||
if($is_super_user) {
|
||||
return $this->getClientMenu();
|
||||
}
|
||||
|
||||
$current_permission = $this->getCurrentUserMenuPermission();
|
||||
|
||||
$user_menu_settings = [];
|
||||
foreach ($this->getClientMenu() as $group_id => $group_info) {
|
||||
|
||||
$rebuild_menu = [];
|
||||
foreach ($group_info['menu'] as $index => $menu) {
|
||||
if(!in_array($menu['id'], $current_permission)) continue;
|
||||
|
||||
$rebuild_menu[$index] = $menu;
|
||||
}
|
||||
|
||||
if(sizeof($rebuild_menu)) {
|
||||
$user_menu_settings[$group_id] = $group_info;
|
||||
$user_menu_settings[$group_id]['menu'] = $rebuild_menu;
|
||||
}
|
||||
}
|
||||
|
||||
return $user_menu_settings;
|
||||
}
|
||||
|
||||
|
||||
public function getCurrentUserMenuPermission() {
|
||||
$current_staff_id = StaffLoginController::getLoggedInStaffId();
|
||||
return $this->objStaffPermissionModel->getUserMenuPermission($current_staff_id);
|
||||
}
|
||||
|
||||
|
||||
public function getCurrentUserEntityPermission() {
|
||||
$current_staff_id = StaffLoginController::getLoggedInStaffId();
|
||||
return $this->objStaffPermissionModel->getUserEntityPermission($current_staff_id);
|
||||
}
|
||||
|
||||
|
||||
public function getUserMenuPermissionSetting($admin_id) {
|
||||
|
||||
$current_permission = $this->objStaffPermissionModel->getUserMenuPermission($admin_id);
|
||||
|
||||
$user_menu_settings = [];
|
||||
foreach ($this->getClientMenu() as $group_id => $group_info) {
|
||||
|
||||
$rebuild_menu = [];
|
||||
foreach ($group_info['menu'] as $index => $menu) {
|
||||
$rebuild_menu[$index] = $menu;
|
||||
|
||||
$rebuild_menu[$index]['is_user_permitted'] = (in_array($menu['id'], $current_permission)) ? 1 : 0;
|
||||
}
|
||||
|
||||
$user_menu_settings[$group_id] = $group_info;
|
||||
$user_menu_settings[$group_id]['menu'] = $rebuild_menu;
|
||||
}
|
||||
|
||||
return $user_menu_settings;
|
||||
}
|
||||
|
||||
|
||||
public function getUserEntityPermissionSetting($admin_id) {
|
||||
|
||||
$current_permission = $this->objStaffPermissionModel->getUserEntityPermission($admin_id);
|
||||
|
||||
$_settings = [];
|
||||
|
||||
foreach ($this->getClientEntityPermission() as $group_id => $group_info) {
|
||||
|
||||
$rebuild_children = [];
|
||||
foreach ($group_info['children'] as $entity => $info) {
|
||||
|
||||
$actions = [];
|
||||
foreach ($info['action'] as $action_key => $action_title) {
|
||||
$actions[] = [
|
||||
'action' => $action_key,
|
||||
'title' => $action_title,
|
||||
'is_user_permitted' => (
|
||||
isset($current_permission[$group_id]) &&
|
||||
isset($current_permission[$group_id][$entity]) &&
|
||||
isset($current_permission[$group_id][$entity][$action_key])
|
||||
) ? $current_permission[$group_id][$entity][$action_key] : false ,
|
||||
];
|
||||
}
|
||||
|
||||
$rebuild_children[$entity] = [
|
||||
'title' => $info['title'],
|
||||
'action_list' => $actions,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$_settings[$group_id] = $group_info;
|
||||
$_settings[$group_id]['children'] = $rebuild_children;
|
||||
}
|
||||
|
||||
return $_settings;
|
||||
}
|
||||
|
||||
}
|
||||
64
inc/Hura8/Components/Staff/Model/StaffAuthModel.php
Normal file
64
inc/Hura8/Components/Staff/Model/StaffAuthModel.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
use Hura8\System\Model\AuthModel;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class StaffAuthModel extends AuthModel
|
||||
{
|
||||
|
||||
private $tb_staff_login = "tb_staff_login";
|
||||
private $tb_staff_access_code = "tb_staff_access_code";
|
||||
|
||||
private $tb_staff_login_log = "tb_staff_login_log";
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct($this->tb_staff_login, $this->tb_staff_access_code);
|
||||
}
|
||||
|
||||
|
||||
public function getLoginListByIds(array $staff_ids) {
|
||||
if(!sizeof($staff_ids)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
list($parameterized_ids, $bind_types) = create_bind_sql_parameter_from_value_list($staff_ids, 'int');
|
||||
|
||||
$bind_values = $staff_ids;
|
||||
|
||||
$query = $this->db->runQuery(
|
||||
"SELECT `user_id`, `last_login_time`, `last_login_ip`, `last_login_device`, `last_login_browser`
|
||||
FROM ".$this->tb_staff_login."
|
||||
WHERE `user_id` IN (".$parameterized_ids.") ",
|
||||
$bind_types,
|
||||
$bind_values
|
||||
);
|
||||
|
||||
$item_list = [];
|
||||
foreach ($this->db->fetchAll($query) as $item) {
|
||||
$item_list[$item['user_id']] = $item;
|
||||
}
|
||||
|
||||
return $item_list;
|
||||
}
|
||||
|
||||
|
||||
public function getLoginLog(array $conditions = []) {
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
$query = $this->db->runQuery(
|
||||
"SELECT * FROM ".$this->tb_staff_login_log." WHERE 1 ORDER BY `id` DESC LIMIT 100 ",
|
||||
$bind_types,
|
||||
$bind_values
|
||||
);
|
||||
|
||||
return $this->db->fetchAll($query) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
40
inc/Hura8/Components/Staff/Model/StaffDepartmentModel.php
Normal file
40
inc/Hura8/Components/Staff/Model/StaffDepartmentModel.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
|
||||
|
||||
class StaffDepartmentModel extends aEntityBaseModel
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('department');
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||
{
|
||||
$where_clause = "";
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
return [
|
||||
$where_clause,
|
||||
$bind_types,
|
||||
$bind_values
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
class StaffDepartmentPermissionModel
|
||||
{
|
||||
protected $objStaffDepartmentModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objStaffDepartmentModel = new StaffDepartmentModel();
|
||||
}
|
||||
|
||||
|
||||
public function getDepartmentMenuPermission($department_id) {
|
||||
$_info = $this->objStaffDepartmentModel->getInfo($department_id);
|
||||
|
||||
return ($_info['menu_permission']) ? \json_decode($_info['menu_permission'], true) : [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getDepartmentEntityPermission($department_id) {
|
||||
$_info = $this->objStaffDepartmentModel->getInfo($department_id);
|
||||
|
||||
return ($_info['entity_permission']) ? \json_decode($_info['entity_permission'], true) : [];
|
||||
}
|
||||
|
||||
}
|
||||
38
inc/Hura8/Components/Staff/Model/StaffLogModel.php
Normal file
38
inc/Hura8/Components/Staff/Model/StaffLogModel.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
|
||||
class StaffLogModel extends aEntityBaseModel
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('staff_log');
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $condition) : ?array
|
||||
{
|
||||
$where_clause = "";
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
return [
|
||||
$where_clause,
|
||||
$bind_types,
|
||||
$bind_values
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
58
inc/Hura8/Components/Staff/Model/StaffModel.php
Normal file
58
inc/Hura8/Components/Staff/Model/StaffModel.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
use Hura8\System\Security\DataValidator;
|
||||
|
||||
class StaffModel extends aEntityBaseModel
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('staff');
|
||||
$this->tb_staff = $this->tb_entity;
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getInfoByEmail($email) : ?array
|
||||
{
|
||||
$query = $this->db->runQuery("SELECT * FROM `".$this->tb_entity."` WHERE `email` = ? LIMIT 1 ", ['s'], [$email]) ;
|
||||
if( $item_info = $this->db->fetchAssoc($query)){
|
||||
return $this->formatItemInfo($item_info);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $condition) : ?array
|
||||
{
|
||||
/*$condition = array(
|
||||
"letter" => "",
|
||||
);*/
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
|
||||
if(isset($filter_condition["letter"]) && strlen($filter_condition["letter"]) == 1){
|
||||
$catCondition[] = " AND `letter` = ? ";
|
||||
$bind_types[] = 's';
|
||||
$bind_values[] = $filter_condition["letter"];
|
||||
}
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
}
|
||||
67
inc/Hura8/Components/Staff/Model/StaffPermissionModel.php
Normal file
67
inc/Hura8/Components/Staff/Model/StaffPermissionModel.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
|
||||
class StaffPermissionModel
|
||||
{
|
||||
|
||||
protected $objStaffModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objStaffModel = new StaffModel();
|
||||
}
|
||||
|
||||
|
||||
public function getUserEntityPermission($admin_id) {
|
||||
|
||||
/*return [
|
||||
// entity group => entity
|
||||
'product' => [
|
||||
'item' => [
|
||||
'view' => true,
|
||||
'create' => false,
|
||||
'delete' => true,
|
||||
'update' => false,
|
||||
],
|
||||
],
|
||||
|
||||
'article' => [
|
||||
'item' => [
|
||||
'view' => true,
|
||||
'create' => false,
|
||||
'delete' => false,
|
||||
'update' => true,
|
||||
],
|
||||
]
|
||||
];*/
|
||||
|
||||
$admin_info = $this->objStaffModel->getInfo($admin_id);
|
||||
|
||||
if($admin_info['entity_permission']) {
|
||||
$entity_permission = \json_decode($admin_info['entity_permission'], true);
|
||||
|
||||
if(sizeof($entity_permission) > 0) {
|
||||
return $entity_permission;
|
||||
}
|
||||
}
|
||||
|
||||
// else use department
|
||||
if($admin_info['department']) {
|
||||
$objStaffDepartmentPermissionModel = new StaffDepartmentPermissionModel();
|
||||
$department_entity_permission = $objStaffDepartmentPermissionModel->getDepartmentEntityPermission($admin_info['department']);
|
||||
|
||||
return $department_entity_permission;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
public function getUserMenuPermission($admin_id) {
|
||||
$admin_info = $this->objStaffModel->getInfo($admin_id);
|
||||
return ($admin_info['menu_permission']) ? \json_decode($admin_info['menu_permission'], true) : [];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user