mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-26 09:04:28 +00:00
issues: added issue controller for displaying issues, added issuechecker controller and component
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
defined('BASEPATH') || exit('No direct script access allowed');
|
||||
|
||||
class IssueChecker extends FHCAPI_Controller
|
||||
{
|
||||
const DEFAULT_PERMISSION = 'system/issues_verwalten:r';
|
||||
|
||||
protected $person_id;
|
||||
protected $_extensionName = null;
|
||||
protected $_codeLibMappings = [];
|
||||
protected $_codeProducerLibMappings = [];
|
||||
protected $_app = null;
|
||||
|
||||
protected $errors = [];
|
||||
protected $infos = [];
|
||||
|
||||
public function __construct($permissions)
|
||||
{
|
||||
$default_permissions = [
|
||||
'checkPerson' => self::DEFAULT_PERMISSION,
|
||||
'countPersonOpenIssues' => self::DEFAULT_PERMISSION
|
||||
];
|
||||
|
||||
if(!is_array($permissions))
|
||||
{
|
||||
$this->terminateWithError("Issue Checker: permissions must be an array");
|
||||
}
|
||||
|
||||
$merged_permissions = array_merge($default_permissions, $permissions);
|
||||
|
||||
parent::__construct($merged_permissions);
|
||||
|
||||
$this->load->model('system/Issue_model', 'IssueModel');
|
||||
$this->load->model('person/Person_model', 'PersonModel');
|
||||
}
|
||||
|
||||
public function checkPerson()
|
||||
{
|
||||
$person_id = $this->input->post('person_id', true);
|
||||
|
||||
if (!is_numeric($person_id)) $this->terminateWithError($this->p->t('ui', 'error_invalidId', ['id'=> 'Person ID']), self::ERROR_TYPE_GENERAL);
|
||||
|
||||
$this->person_id = intval($person_id);
|
||||
|
||||
$persRes = $this->PersonModel->load($this->person_id);
|
||||
if (!hasData($persRes)) $this->terminateWithError('Person with id ' . $this->person_id . ' not found.', self::ERROR_TYPE_GENERAL);
|
||||
|
||||
$allCodeLibMappings = array_merge($this->_codeLibMappings, $this->_codeProducerLibMappings);
|
||||
|
||||
$this->load->library(
|
||||
'issues/PlausicheckProducerLib',
|
||||
array(
|
||||
'extensionName' => $this->_extensionName,
|
||||
'codeLibMappings' => $allCodeLibMappings
|
||||
),
|
||||
'PlausicheckProducerLib'
|
||||
);
|
||||
|
||||
$this->load->library(
|
||||
'issues/PlausicheckResolverLib',
|
||||
array(
|
||||
'extensionName' => $this->_extensionName,
|
||||
'codeLibMappings' => $this->_codeLibMappings,
|
||||
'codeProducerLibMappings' => $this->_codeProducerLibMappings
|
||||
),
|
||||
'PlausicheckResolverLib'
|
||||
);
|
||||
|
||||
$this->produceIssues();
|
||||
$this->resolveIssues();
|
||||
$this->produceIssues();
|
||||
|
||||
$openIssueCountRes = $this->countOpenIssues(array_keys($allCodeLibMappings));
|
||||
if (isError($openIssueCountRes)) $this->terminateWithError(getError($openIssueCountRes), self::ERROR_TYPE_GENERAL);
|
||||
|
||||
$data = array(
|
||||
'person_id' => $this->person_id,
|
||||
'openissues' => hasData($openIssueCountRes) ? getData($openIssueCountRes) : 0
|
||||
);
|
||||
|
||||
$this->addMeta('errors', $this->errors);
|
||||
$this->addMeta('infos', $this->infos);
|
||||
|
||||
$this->terminateWithSuccess($data);
|
||||
}
|
||||
|
||||
public function countPersonOpenIssues()
|
||||
{
|
||||
$person_id = $this->input->get('person_id', true);
|
||||
|
||||
if (!is_numeric($person_id)) $this->terminateWithError($this->p->t('ui', 'error_invalidId', ['id'=> 'Person ID']), self::ERROR_TYPE_GENERAL);
|
||||
|
||||
$this->person_id = intval($person_id);
|
||||
|
||||
$persRes = $this->PersonModel->load($this->person_id);
|
||||
|
||||
if (!hasData($persRes)) $this->terminateWithError('Person with id ' . $this->person_id . ' not found.', self::ERROR_TYPE_GENERAL);
|
||||
|
||||
$openIssueCountRes = $this->countOpenIssues(array_keys(array_merge($this->_codeLibMappings, $this->_codeProducerLibMappings)));
|
||||
if (isError($openIssueCountRes)) $this->terminateWithError(getError($openIssueCountRes), self::ERROR_TYPE_GENERAL);
|
||||
|
||||
$data = array(
|
||||
'person_id' => $this->person_id,
|
||||
'openissues' => hasData($openIssueCountRes) ? getData($openIssueCountRes) : 0
|
||||
);
|
||||
|
||||
$this->addMeta('errors', $this->errors);
|
||||
$this->addMeta('infos', $this->infos);
|
||||
|
||||
$this->terminateWithSuccess($data);
|
||||
}
|
||||
|
||||
protected function countOpenIssues($fehlercodes)
|
||||
{
|
||||
if (isEmptyArray($fehlercodes)) return success([]);
|
||||
|
||||
// load open issues with given errorcodes
|
||||
$openIssuesRes = $this->IssueModel->getOpenIssues(
|
||||
$fehlercodes,
|
||||
$this->person_id
|
||||
);
|
||||
|
||||
// log error if occured
|
||||
if (isError($openIssuesRes)) return $openIssuesRes;
|
||||
|
||||
$issues = hasData($openIssuesRes) ? getData($openIssuesRes) : [];
|
||||
$issuescount = is_array($issues) || $issues instanceof Countable ? count($issues) : 0;
|
||||
|
||||
return success($issuescount);
|
||||
}
|
||||
|
||||
protected function produceIssues()
|
||||
{
|
||||
if (isEmptyArray($this->_codeLibMappings) && isEmptyArray($this->_codeProducerLibMappings)) return success([]);
|
||||
|
||||
$allCodeLibMappings = array_merge($this->_codeLibMappings, $this->_codeProducerLibMappings);
|
||||
|
||||
$result = $this->PlausicheckProducerLib->producePlausicheckIssues(
|
||||
array('person_id' => $this->person_id)
|
||||
);
|
||||
|
||||
// log if error, or log info if inserted new issue
|
||||
if (isset($result->errors))
|
||||
$this->errors = array_merge($this->errors, $result->errors);
|
||||
if (isset($result->infos))
|
||||
$this->infos = array_merge($this->infos, $result->infos);
|
||||
}
|
||||
|
||||
protected function resolveIssues()
|
||||
{
|
||||
// load open issues with given errorcodes
|
||||
$openIssuesRes = $this->IssueModel->getOpenIssues(
|
||||
array_keys(array_merge($this->_codeLibMappings, $this->_codeProducerLibMappings)),
|
||||
$this->person_id
|
||||
);
|
||||
|
||||
if (hasData($openIssuesRes))
|
||||
{
|
||||
$openIssues = getData($openIssuesRes);
|
||||
|
||||
$result = $this->PlausicheckResolverLib->resolvePlausicheckIssues($openIssues);
|
||||
|
||||
// log if error, or log info if inserted new issue
|
||||
if (isset($result->errors))
|
||||
$this->errors = array_merge($this->errors, $result->errors);
|
||||
if (isset($result->infos))
|
||||
$this->infos = array_merge($this->infos, $result->infos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') || exit('No direct script access allowed');
|
||||
|
||||
|
||||
class Issues extends FHCAPI_Controller
|
||||
{
|
||||
const DEFAULT_PERMISSION = 'system/issues_verwalten:r';
|
||||
// code igniter
|
||||
protected $CI;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'getOpenIssuesByProperties' => Self::DEFAULT_PERMISSION
|
||||
)
|
||||
);
|
||||
|
||||
// Loads authentication library and starts authenticationfetc
|
||||
$this->load->library('AuthLib');
|
||||
|
||||
$this->load->model('extensions/FHC-Core-Personalverwaltung/Api_model','ApiModel');
|
||||
$this->load->model('person/Person_model','PersonModel');
|
||||
$this->load->model('system/Fehler_model','FehlerModel');
|
||||
$this->load->model('system/Issue_model', 'IssueModel');
|
||||
$this->load->model('person/Benutzer_model', 'BenutzerModel');
|
||||
|
||||
// get CI for transaction management
|
||||
$this->CI = &get_instance();
|
||||
}
|
||||
|
||||
public function getOpenIssuesByProperties()
|
||||
{
|
||||
$person_id = $this->input->get('person_id', true);
|
||||
$oe_kurzbz = $this->input->get('oe_kurzbz', true);
|
||||
$fehlertyp_kurzbz = $this->input->get('fehlertyp_kurzbz', true);
|
||||
$apps = $this->input->get('apps', true);
|
||||
$behebung_parameter = $this->input->get('behebung_parameter', true);
|
||||
|
||||
if (isset($person_id) && !is_numeric($person_id))
|
||||
$this->terminateWithError('person id is not numeric!');
|
||||
|
||||
if (isset($behebung_parameter) && !is_array($behebung_parameter))
|
||||
$this->terminateWithError('Behebung parameter invalid');
|
||||
|
||||
$issueRes = $this->IssueModel->getOpenIssuesByProperties($person_id, $oe_kurzbz, $fehlertyp_kurzbz, $apps, $behebung_parameter);
|
||||
|
||||
if (isError($issueRes))
|
||||
{
|
||||
$this->terminateWithError(getError($issueRes));
|
||||
}
|
||||
|
||||
$this->terminateWithSuccess(hasData($issueRes) ? getData($issueRes) : []);
|
||||
}
|
||||
|
||||
public function PersonenMitOffenenIssues()
|
||||
{
|
||||
|
||||
$sql = <<<EOSQL
|
||||
SELECT
|
||||
|
||||
person_id, uid, vorname, nachname, count(*) AS openissues ,
|
||||
(select count(*) anz_aktiv
|
||||
from hr.tbl_dienstverhaeltnis dv
|
||||
where dv.mitarbeiter_uid=uid and dv.von<=now() and
|
||||
(dv.bis is null OR dv.bis>=now())
|
||||
) aktiv
|
||||
FROM
|
||||
system.tbl_issue
|
||||
JOIN
|
||||
system.tbl_fehler USING (fehlercode)
|
||||
JOIN
|
||||
public.tbl_person USING (person_id)
|
||||
JOIN
|
||||
public.tbl_benutzer USING (person_id)
|
||||
JOIN
|
||||
public.tbl_mitarbeiter ON uid = mitarbeiter_uid
|
||||
WHERE
|
||||
app = 'personalverwaltung' AND verarbeitetamum IS NULL
|
||||
GROUP BY
|
||||
person_id, uid, vorname, nachname
|
||||
HAVING
|
||||
count(*) > 0
|
||||
ORDER BY
|
||||
count(*) DESC;
|
||||
|
||||
EOSQL;
|
||||
|
||||
$personenmitissues = $this->IssueModel->execReadOnlyQuery($sql);
|
||||
if( hasData($personenmitissues) )
|
||||
{
|
||||
$this->terminateWithSuccess(getData($personenmitissues));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->terminateWithSuccess(array());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user