Refactoring PrimeVue Autocomplete Dropdown Functions

Refactoring PrimeVue Autocomplete Dropdown OrganisationUnits
Change Search from Backend to Frontend Filtering
minor changes Table Functions
This commit is contained in:
ma0068
2025-05-23 13:27:18 +02:00
parent 66e5384de6
commit fa0b534471
6 changed files with 162 additions and 216 deletions
@@ -11,14 +11,10 @@ class Funktionen extends FHCAPI_Controller
//TODO(Manu) check permissions
parent::__construct(array(
'getAllFunctions' => ['admin:r', 'assistenz:r'],
'getContractFunctions' => ['admin:r', 'assistenz:r'],
'getCurrentFunctions' => ['admin:r', 'assistenz:r'],
'getAllUserFunctions' => ['admin:r', 'assistenz:r'],
'getOrgHeads' => ['admin:r', 'assistenz:r'],
'getOrgetsForCompany' => ['admin:r', 'assistenz:r'],
'loadAllOes' => ['admin:r', 'assistenz:r'],
'searchOes' => ['admin:r', 'assistenz:r'],
'searchFunctions' => ['admin:r', 'assistenz:r'],
'getAllOrgUnits' => ['admin:r', 'assistenz:r'],
'loadFunction' => ['admin:r', 'assistenz:r'],
'insertFunction' => ['admin:rw', 'assistenz:rw'],
'updateFunction' => ['admin:rw', 'assistenz:rw'],
@@ -43,6 +39,20 @@ class Funktionen extends FHCAPI_Controller
$this->load->model('organisation/Organisationseinheit_model', 'OrganisationseinheitModel');
}
public function getAllFunctions()
{
$this->FunktionModel->addSelect("funktion_kurzbz");
$this->FunktionModel->addSelect("beschreibung");
$this->FunktionModel->addSelect("aktiv");
$this->FunktionModel->addSelect("beschreibung AS label");
$this->FunktionModel->addOrder("beschreibung");
$result = $this->FunktionModel->load();
$data = $this->getDataOrTerminateWithError($result);
$this->terminateWithSuccess($data);
}
public function getOrgHeads()
{
$result = $this->OrganisationseinheitModel->getHeads();
@@ -97,7 +107,7 @@ class Funktionen extends FHCAPI_Controller
WHERE
bf.uid = ?
ORDER BY
f.beschreibung, bf.datum_von ASC";
bf.datum_von, bf.datum_von ASC";
$benutzerfunktionen = $this->BenutzerfunktionModel->execReadOnlyQuery($sql, array($uid));
$data = $this->getDataOrTerminateWithError($benutzerfunktionen);
@@ -106,14 +116,35 @@ class Funktionen extends FHCAPI_Controller
}
/*
* return list of child orgets for a given company orget_kurzbz
* returns list of all organisation units
* as key value list to be used in select or autocomplete
*/
public function getOrgetsForCompany($companyOrgetkurzbz=null)
public function getAllOrgUnits()
{
$sql = "
SELECT
oe.oe_kurzbz,
oe.oe_kurzbz, oe.aktiv,
'[' || COALESCE(oet.bezeichnung, oet.organisationseinheittyp_kurzbz) ||
'] ' || COALESCE(oe.bezeichnung, oe.oe_kurzbz) AS label
FROM public.tbl_organisationseinheit oe
JOIN public.tbl_organisationseinheittyp oet ON oe.organisationseinheittyp_kurzbz = oet.organisationseinheittyp_kurzbz
ORDER BY oet.bezeichnung ASC, oe.bezeichnung ASC";
$result = $this->OrganisationseinheitModel->execReadOnlyQuery($sql);
$data = $this->getDataOrTerminateWithError($result);
$this->terminateWithSuccess($data);
}
/*
* return list of child orgets for a given company orget_kurzbz
* as key value list to be used in select or autocomplete
*/
public function getOrgetsForCompany($companyOrgetkurzbz = null)
{
$sql = "
SELECT
oe.oe_kurzbz, oe.aktiv,
'[' || COALESCE(oet.bezeichnung, oet.organisationseinheittyp_kurzbz) ||
'] ' || COALESCE(oe.bezeichnung, oe.oe_kurzbz) AS label
FROM (
@@ -139,25 +170,6 @@ class Funktionen extends FHCAPI_Controller
$this->terminateWithSuccess($data);
}
public function searchOes($companyOrgetKurzbz, $searchString = null)
{
$result = $this->OrganisationseinheitModel->getAutocompleteSuggestionsWithCompany($companyOrgetKurzbz, $searchString);
if (isError($result)) {
$this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
}
$this->terminateWithSuccess($result ?: []);
}
public function searchFunctions($searchString = null)
{
$result = $this->FunktionModel->getAutocompleteSuggestions($searchString);
if (isError($result)) {
$this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
}
$this->terminateWithSuccess($result ?: []);
}
public function loadFunction($benutzerfunktion_id)
{
$this->BenutzerfunktionModel->addSelect("*");
@@ -191,7 +191,7 @@ class Organisationseinheit_model extends DB_Model
/**
* @param string $oe_kurzbz
*
*
* @return stdClass
*/
public function getWithType($oe_kurzbz)
@@ -202,78 +202,6 @@ class Organisationseinheit_model extends DB_Model
return $this->load($oe_kurzbz);
}
/**
* Get OEs by eventQuery string. Use with autocomplete event queries.
* @param $eventQuery String
* @return array
*/
public function getAutocompleteSuggestions($eventQuery)
{
$this->addSelect('oe_kurzbz');
$this->addSelect('organisationseinheittyp_kurzbz, oe_kurzbz, bezeichnung, aktiv, lehre');
$this->addOrder('organisationseinheittyp_kurzbz, bezeichnung');
return $this->loadWhere("
oe_kurzbz ILIKE '%". $this->escapeLike($eventQuery). "%'
");
}
/**
* Get OEs by eventQuery string and companyOrgetKurzbz
* Use with autocomplete event queries in Function Component
* @param $searchString String
* @param $companyOrgetKurzbz String oe_kurzbz of the company (gst vs gmbh)
* @return array
*/
public function getAutocompleteSuggestionsWithCompany($companyOrgetKurzbz, $searchString)
{
$sql = "
WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) AS (
SELECT oe_kurzbz, oe_parent_kurzbz
FROM public.tbl_organisationseinheit
WHERE oe_kurzbz = ?
UNION ALL
SELECT o.oe_kurzbz, o.oe_parent_kurzbz
FROM public.tbl_organisationseinheit o
INNER JOIN oes ON o.oe_parent_kurzbz = oes.oe_kurzbz
)
SELECT
oe.oe_kurzbz, oe.aktiv,
'[' || COALESCE(oet.bezeichnung, oet.organisationseinheittyp_kurzbz) ||
'] ' || COALESCE(oe.bezeichnung, oe.oe_kurzbz) AS label
FROM (
SELECT oe_kurzbz FROM oes GROUP BY oe_kurzbz
) c
JOIN public.tbl_organisationseinheit oe ON oe.oe_kurzbz = c.oe_kurzbz
JOIN public.tbl_organisationseinheittyp oet ON oe.organisationseinheittyp_kurzbz = oet.organisationseinheittyp_kurzbz
";
$params = [$companyOrgetKurzbz];
if (!empty($searchString)) {
$escaped = $this->escapeLike($searchString);
$ilike = '%' . $escaped . '%';
$sql .= "
WHERE
oe.oe_kurzbz ILIKE ? OR
oe.bezeichnung ILIKE ? OR
oe.organisationseinheittyp_kurzbz ILIKE ?
";
$params[] = $ilike;
$params[] = $ilike;
$params[] = $ilike;
}
$sql .= " ORDER BY oet.bezeichnung ASC, oe.bezeichnung ASC";
$result = $this->execQuery($sql, $params);
return $result;
}
/**
* get highest organisation units
*/
@@ -11,26 +11,4 @@ class Funktion_model extends DB_Model
$this->dbTable = 'public.tbl_funktion';
$this->pk = 'funktion_kurzbz';
}
/**
* Get Functions by eventQuery string. Use with autocomplete event queries in Function Component
* @param $eventQuery String
* @return array
*/
public function getAutocompleteSuggestions($eventQuery)
{
$this->addSelect('funktion_kurzbz, beschreibung, aktiv');
$this->addSelect("beschreibung AS label");
$this->addOrder('beschreibung', 'ASC');
if($eventQuery === null)
{
return $this->load();
}
return $this->loadWhere("
funktion_kurzbz ILIKE '%". $this->escapeLike($eventQuery). "%'
OR beschreibung ILIKE '%". $this->escapeLike($eventQuery). "%'
");
}
}