Dashboard Test V1

This commit is contained in:
Cris
2022-09-06 15:29:42 +02:00
parent 7f64f5c29f
commit 522e341d3d
13 changed files with 788 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
*/
class Test extends Auth_Controller
{
private $_uid; // uid of the logged user
/**
* Constructor
*/
public function __construct()
{
// Set required permissions
parent::__construct(
array(
'index' => 'user:r',
)
);
$this->load->library('AuthLib');
$this->load->library('WidgetLib');
$this->_setAuthUID(); // sets property uid
$this->setControllerId(); // sets the controller id
}
// -----------------------------------------------------------------------------------------------------------------
// Public methods
public function index()
{
$this->load->view('test/Test.php', []);
}
// -----------------------------------------------------------------------------------------------------------------
// Private methods
/**
* Retrieve the UID of the logged user and checks if it is valid
*/
private function _setAuthUID()
{
$this->_uid = getAuthUID();
if (!$this->_uid) show_error('User authentification failed');
}
}
@@ -0,0 +1,54 @@
<?php
/**
* FH-Complete
*
* @package FHC-API
* @author FHC-Team
* @copyright Copyright (c) 2016, fhcomplete.org
* @license GPLv3
* @link http://fhcomplete.org
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Dashboard extends API_Controller
{
/**
* Appdaten API constructor.
*/
public function __construct()
{
parent::__construct([
'Widgets' => 'user:r'
]);
}
/**
* @return void
*/
public function getWidgets()
{
$this->load->model('dashboard/Dashboard_model', 'DashboardModel');
$result = $this->DashboardModel->loadWhere(['name'=>$this->get('dashboard')]);
if (isError($result))
return $this->response($result, REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
if (!hasData($result))
return $this->response('No Dashboard with the name "' . $this->get('dashboard') . '" found.', REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$dashboard_id = current(getData($result))->dashboard_id;
$this->load->model('dashboard/Dashboardwidget_model', 'DashboardwidgetModel');
$result = $this->DashboardwidgetModel->loadWidgets($dashboard_id);
if (isError($result))
return $this->response($result, REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
if (!hasData($result))
return $this->response('No Widgets for Dashboard "' . $this->get('dashboard') . '" found.', REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$this->response(getData($result), REST_Controller::HTTP_OK);
}
protected function _check_whitelist_auth() {}
}
@@ -0,0 +1,89 @@
<?php
/**
* FH-Complete
*
* @package FHC-API
* @author FHC-Team
* @copyright Copyright (c) 2016, fhcomplete.org
* @license GPLv3
* @link http://fhcomplete.org
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
if (!defined('BASEPATH')) exit('No direct script access allowed');
class User extends API_Controller
{
/**
* Appdaten API constructor.
*/
public function __construct()
{
parent::__construct([
'AuthObj' => 'user:r',
'Widget' => 'user:r',
'Widgets' => 'user:r'
]);
}
/**
* @return void
*/
public function getAuthObj()
{
$result = $this->authlib->getAuthObj();
$this->response($result, REST_Controller::HTTP_OK);
}
/**
* @return void
*/
public function getWidget()
{
$this->load->model('dashboard/Widget_model', 'WidgetModel');
$result = $this->WidgetModel->load($this->get('widget_id'));
if (isError($result))
return $this->response($result, REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
if (!hasData($result))
return $this->response('No Widget with the id "' . $this->get('widget_id') . '" found.', REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$result = current(getData($result));
$this->response($result, REST_Controller::HTTP_OK);
}
/**
* @return void
*/
public function getWidgets()
{
$this->load->model('dashboard/Dashboard_model', 'DashboardModel');
$result = $this->DashboardModel->loadWhere(['name'=>$this->get('dashboard')]);
if (isError($result))
return $this->response($result, REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
if (!hasData($result))
return $this->response('No Dashboard with the name "' . $this->get('dashboard') . '" found.', REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$dashboard_id = current(getData($result))->dashboard_id;
$authObj = $this->authlib->getAuthObj();
$this->load->model('dashboard/Dashboardpreset_model', 'DashboardpresetModel');
$result = $this->DashboardpresetModel->loadForUser($dashboard_id, $authObj->username);
if (isError($result))
return $this->response($result, REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
if (!hasData($result))
return $this->response('No Dashboard for user "' . $authObj->username . '" found.', REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$result = (current(getData($result))->config);
$result = json_decode($result);
if ($result === null)
return $this->response(json_last_error_msg(), REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$this->response($result, REST_Controller::HTTP_OK);
}
protected function _check_whitelist_auth() {}
}