Funktionserweiterungen um idType

This commit is contained in:
ma0068
2024-01-16 14:34:13 +01:00
parent 09c02b0906
commit 28fe3ef839
5 changed files with 163 additions and 111 deletions
@@ -29,18 +29,30 @@ class Notiz extends FHC_Controller
$this->outputJsonError($result);
}
public function getNotizen($person_id)
public function getNotizen($id, $type)
{
$this->load->model('person/Notiz_model', 'NotizModel');
$type = 'person';
$this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel');
$result = $this->NotizModel->getNotizWithDocEntries($person_id);
//check if valid type
$isValidType = $this->NotizzuordnungModel->isValidType($type);
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
if($isValidType)
{
$result = $this->NotizModel->getNotizWithDocEntries($id, $type);
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$this->outputJson(getError($result));
} else {
$this->outputJson(getData($result) ?: []);
}
}
else
{
//Todo manu (correct return to ajax)
$result = "datatype not yet implemented for notes";
$this->outputJson(getError($result));
} else {
$this->outputJson(getData($result) ?: []);
}
}
@@ -60,8 +72,7 @@ class Notiz extends FHC_Controller
}
elseif (!hasData($result)) {
$this->outputJson($result); //success mit Wert null
// $this->outputJson(getData($result) ?: []);
$this->outputJson($result);
}
else
{
@@ -69,7 +80,7 @@ class Notiz extends FHC_Controller
}
}
public function addNewNotiz($id)
public function addNewNotiz($id, $paramTyp = null)
{
$this->load->model('person/Notiz_model', 'NotizModel');
@@ -87,6 +98,18 @@ class Notiz extends FHC_Controller
}
}
//Überprüfung ob type übergeben wurde (entweder Funktions- oder Postparameter)
if ($paramTyp)
$type = $paramTyp;
if(isset($_POST['typeId']))
$type = $this->input->post('typeId');
if(!$type)
{
//Todo(manu) return error
var_dump("ERROR no type");
}
//Form Validation
$this->form_validation->set_rules('titel', 'titel', 'required');
$this->form_validation->set_rules('text', 'Text', 'required');
@@ -101,11 +124,11 @@ class Notiz extends FHC_Controller
$erledigt = $this->input->post('erledigt');
$verfasser_uid = isset($_POST['verfasser_uid']) ? $_POST['verfasser_uid'] : $uid;
$bearbeiter_uid = isset($_POST['bearbeiter']) ? $_POST['bearbeiter'] : null;
$type = $this->input->post('typeId');
//$type = $this->input->post('typeId');
$start = $this->input->post('von');
$ende = $this->input->post('bis');
//Speichern der Notiz und Notizzuordnung
//Speichern der Notiz und Notizzuordnung inkl Prüfung ob valid type
$result = $this->NotizModel->addNotizForType($type, $id, $titel, $text, $uid, $start, $ende, $erledigt, $verfasser_uid, $bearbeiter_uid);
if (isError($result))
{
@@ -219,7 +242,10 @@ class Notiz extends FHC_Controller
return $this->outputJson(getError($result));
}
//Todo(manu) update von Notizzuordnung?? typeId?
//neue Files speichern
//Todo(manu) update files
foreach ($_FILES as $k => $file)
{
$dms = array(
@@ -291,7 +317,6 @@ class Notiz extends FHC_Controller
}
}
//Todo(manu) rollback?
//delete Notiz und Notizzuordnung
$this->load->model('person/Notiz_model', 'NotizModel');
+29 -19
View File
@@ -140,11 +140,31 @@ class Notiz_model extends DB_Model
* @param id for Dokumentzuordnung (person_id, prestudent_id, uid, projekt_id...)
* @param titel, text, start, ende, erledigt, verfasser_uid, bearbeiter_uid, insertvon Parameter for notiz
*/
public function addNotizForType($type, $id, $titel, $text, $insertvon, $start=null, $ende=null, $erledigt=false, $verfasser_uid=null, $bearbeiter_uid=null)
{
public function addNotizForType(
$type,
$id,
$titel,
$text,
$insertvon,
$start = null,
$ende = null,
$erledigt = false,
$verfasser_uid = null,
$bearbeiter_uid = null
) {
// Loads model Notizzuordnung_model
$this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel');
//check if valid type
$isValidType = $this->NotizzuordnungModel->isValidType($type);
if(!$isValidType)
{
//Todo manu (correct return to controller)
$msg = "datatype " . $type . " not implemented for notes";
return error($msg, EXIT_ERROR);
}
// Start DB transaction
$this->db->trans_start(false);
@@ -180,13 +200,10 @@ class Notiz_model extends DB_Model
return $result;
}
/**
* Add a Notiz for a given person with DMS_id
*/
//TODO(manu) add type for Notizzuordnung
public function addNotizForPersonWithDoc($person_id, $titel, $text, $erledigt, $verfasser_uid, $von, $bis, $dms_id=null)
public function addNotizForPersonWithDoc($person_id, $titel, $text, $erledigt, $verfasser_uid, $von, $bis, $dms_id = null)
{
// Loads model Notizzuordnung_model
$this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel');
@@ -243,16 +260,12 @@ class Notiz_model extends DB_Model
/**
* gets all Notizen with Documententries for a certain type and type_id
* @param $person_id
* @param String type of id eg. person_id, prestudent_id, mitarbeiter_uid, projekt_kurzbz, projektphase_id, projekttask_id,
* bestellung_id, lehreinheit_id, anrechnung_id, uid)
* @param $id the corresponding id, part of public.tbl_notizzuordnung
*/
//Todo(Manu) rewrite in CI-Style
//Todo(Manu) auf andere types erweitern
public function getNotizWithDocEntries($id)
public function getNotizWithDocEntries($id, $type)
{
$type = 'writeFunction';
//$type_id = 'z.person_id';
$qry = "
SELECT
n.*, count(dms_id) as countDoc, z.notizzuordnung_id
@@ -265,16 +278,15 @@ class Notiz_model extends DB_Model
LEFT JOIN
campus.tbl_dms_version USING (dms_id)
WHERE
z.person_id = ?
z.$type = ?
GROUP BY
notiz_id, z.notizzuordnung_id
";
return $this->execQuery($qry, array($id));
}
/**
* gets all Notizen for a person with a specific title
* @param $person_id
@@ -361,6 +373,4 @@ class Notiz_model extends DB_Model
return $this->loadWhere(array('anrechnung_id' => $anrechnung_id));
}
// ------------------------------------------------------------------------------------------------------
}
@@ -11,4 +11,35 @@ class Notizzuordnung_model extends DB_Model
$this->dbTable = 'public.tbl_notizzuordnung';
$this->pk = 'notizzuordnung_id';
}
public function isValidType($type)
{
//var_dump($type);
$validTypes = [];
$qry = "
SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'tbl_notizzuordnung'
";
$type_arr = $this->execQuery($qry);
$type_arr = $type_arr->retval;
foreach ($type_arr as $t) {
$validTypes[] = $t->column_name;
}
if (in_array($type, $validTypes))
{
// var_dump($type . " is IN ARRAY");
return true;
}
else
{
//var_dump($type . " is NOT IN ARRAY");
return false;
}
}
}