mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-10-23 20:29:35 +00:00
Implemented custom table for kalender notiz, and added postgres triffer function for removing resources and stale notes
This commit is contained in:
@@ -20,6 +20,7 @@ class Tags extends Tag_Controller
|
||||
]);
|
||||
|
||||
$this->config->load('tempus');
|
||||
$this->load->model('ressource/KalenderNotiz_model', 'KalenderNotizModel');
|
||||
}
|
||||
|
||||
public function getTag($readonly_tags = null)
|
||||
@@ -30,14 +31,53 @@ class Tags extends Tag_Controller
|
||||
{
|
||||
parent::getTags($this->config->item('tempus_tags'));
|
||||
}
|
||||
public function getTagsByCalendar($eindeutige_kalender_gruppen_id = null)
|
||||
|
||||
public function getTagsByCalendar($eindeutige_kalender_gruppen_id)
|
||||
{
|
||||
parent::getTagsByAssignmentTypeValue('eindeutige_kalender_gruppen_id', $eindeutige_kalender_gruppen_id, $this->config->item('tempus_tags'));
|
||||
$language = $this->_getLanguageIndex();
|
||||
$index_bezeichnung_mehrsprachig = $language - 1;
|
||||
|
||||
$this->KalenderNotizModel->addSelect(
|
||||
'tbl_kalender_notiz.notiz_id as notiz_id,
|
||||
typ_kurzbz as tag_typ_kurzbz,
|
||||
array_to_json(bezeichnung_mehrsprachig::varchar[])->>'. $index_bezeichnung_mehrsprachig. ' as bezeichnung,
|
||||
style,
|
||||
beschreibung,
|
||||
tag,
|
||||
tbl_notiz.erledigt as done
|
||||
'
|
||||
);
|
||||
|
||||
$this->KalenderNotizModel->addJoin('public.tbl_notiz', 'tbl_kalender_notiz.notiz_id = public.tbl_notiz.notiz_id');
|
||||
$this->KalenderNotizModel->addJoin('public.tbl_notiz_typ', 'public.tbl_notiz.typ = public.tbl_notiz_typ.typ_kurzbz');
|
||||
|
||||
$this->KalenderNotizModel->addOrder('prioritaet');
|
||||
|
||||
$notiztypen = $this->KalenderNotizModel->loadWhere(array('aktiv' => true, 'eindeutige_kalender_gruppen_id' => $eindeutige_kalender_gruppen_id));
|
||||
$this->terminateWithSuccess(hasData($notiztypen) ? getData($notiztypen) : array());
|
||||
}
|
||||
|
||||
public function addTag($withZuordnung = true, $updatable_tags = null)
|
||||
{
|
||||
parent::addTag(true, $this->config->item('tempus_tags'));
|
||||
$postData = $this->getPostJson();
|
||||
|
||||
$return = array();
|
||||
foreach ($postData->values as $value)
|
||||
{
|
||||
$insertResult = parent::addTag(false, $this->config->item('tempus_tags'));
|
||||
|
||||
$insertZuordnung = $this->KalenderNotizModel->insert(array(
|
||||
'eindeutige_kalender_gruppen_id' => $value,
|
||||
'notiz_id' => $insertResult,
|
||||
));
|
||||
|
||||
if (isError($insertZuordnung))
|
||||
$this->terminateWithError('Error occurred', self::ERROR_TYPE_GENERAL);
|
||||
$return[] = ['eindeutige_kalender_gruppen_id' => $value, 'id' => $insertResult];
|
||||
}
|
||||
$this->terminateWithSuccess($return);
|
||||
}
|
||||
|
||||
public function updateTag($updatable_tags = null)
|
||||
{
|
||||
parent::updateTag($this->config->item('tempus_tags'));
|
||||
@@ -50,4 +90,13 @@ class Tags extends Tag_Controller
|
||||
{
|
||||
parent::doneTag($this->config->item('tempus_tags'));
|
||||
}
|
||||
|
||||
public function _getLanguageIndex()
|
||||
{
|
||||
$this->load->model('system/Sprache_model', 'SpracheModel');
|
||||
$this->SpracheModel->addSelect('index');
|
||||
$result = $this->SpracheModel->loadWhere(array('sprache' => getUserLanguage()));
|
||||
|
||||
return hasData($result) ? getData($result)[0]->index : 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class Tag_Controller extends FHCAPI_Controller
|
||||
$this->load->model('person/Notiz_model', 'NotizModel');
|
||||
$this->load->model('system/Notiztyp_model', 'NotiztypModel');
|
||||
$this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel');
|
||||
|
||||
|
||||
$this->loadPhrases([
|
||||
'ui'
|
||||
]);
|
||||
@@ -122,36 +122,7 @@ class Tag_Controller extends FHCAPI_Controller
|
||||
$notiztypen = $this->NotiztypModel->loadWhere(array('aktiv' => true));
|
||||
$this->terminateWithSuccess(hasData($notiztypen) ? getData($notiztypen) : array());
|
||||
}
|
||||
public function getTagsByAssignmentTypeValue($zuordnung_typ, $zuordnung_id, $tags = null)
|
||||
{
|
||||
$language = $this->_getLanguageIndex();
|
||||
$index_bezeichnung_mehrsprachig = $language - 1;
|
||||
|
||||
$this->NotizzuordnungModel->addSelect(
|
||||
'tbl_notizzuordnung.notiz_id as notiz_id,
|
||||
typ_kurzbz as tag_typ_kurzbz,
|
||||
array_to_json(bezeichnung_mehrsprachig::varchar[])->>'. $index_bezeichnung_mehrsprachig. ' as bezeichnung,
|
||||
style,
|
||||
beschreibung,
|
||||
tag,
|
||||
tbl_notiz.erledigt as done
|
||||
'
|
||||
);
|
||||
|
||||
if (is_array($tags) && !isEmptyArray($tags))
|
||||
{
|
||||
$tags = $this->_filterTag($tags, false);
|
||||
$this->NotizzuordnungModel->db->where_in('tbl_notiz_typ.typ_kurzbz', $tags);
|
||||
}
|
||||
|
||||
$this->NotizzuordnungModel->addJoin('public.tbl_notiz', 'public.tbl_notizzuordnung.notiz_id = public.tbl_notiz.notiz_id');
|
||||
$this->NotizzuordnungModel->addJoin('public.tbl_notiz_typ', 'public.tbl_notiz.typ = public.tbl_notiz_typ.typ_kurzbz');
|
||||
|
||||
$this->NotizzuordnungModel->addOrder('prioritaet');
|
||||
|
||||
$notiztypen = $this->NotizzuordnungModel->loadWhere(array('aktiv' => true, $zuordnung_typ => $zuordnung_id));
|
||||
$this->terminateWithSuccess(hasData($notiztypen) ? getData($notiztypen) : array());
|
||||
}
|
||||
public function addTag($withZuordnung = true, $updatable_tags = null)
|
||||
{
|
||||
$postData = $this->getPostJson();
|
||||
|
||||
@@ -192,7 +192,7 @@ class KalenderLib
|
||||
n.erledigt AS done,
|
||||
nt.prioritaet AS prioritaet,
|
||||
nz.eindeutige_kalender_gruppen_id
|
||||
FROM public.tbl_notizzuordnung AS nz
|
||||
FROM lehre.tbl_kalender_notiz AS nz
|
||||
JOIN public.tbl_notiz AS n ON nz.notiz_id = n.notiz_id
|
||||
JOIN public.tbl_notiz_typ AS nt ON n.typ = nt.typ_kurzbz " . $whereTags . "
|
||||
) AS tag
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
class KalenderNotiz_model extends DB_Model
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = 'lehre.tbl_kalender_notiz';
|
||||
$this->pk = array('eindeutige_kalender_gruppen_id', 'notiz_id');
|
||||
}
|
||||
}
|
||||
@@ -107,8 +107,8 @@ require_once('dbupdate_3.4/77080_tabulator_presets_table.php');
|
||||
require_once('dbupdate_3.4/78292_gehaltsanpassungtyp.php');
|
||||
require_once('dbupdate_3.4/77949_tempus_synchronisation.php');
|
||||
require_once('dbupdate_3.4/78287_tempus_raumzuordnung.php');
|
||||
|
||||
require_once('dbupdate_3.4/78285_tempus_stundenraster.php');
|
||||
require_once('dbupdate_3.4/83437_kalender_notiz_tbl.php');
|
||||
|
||||
// *** Pruefung und hinzufuegen der neuen Attribute und Tabellen
|
||||
echo '<H2>Pruefe Tabellen und Attribute!</H2>';
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
if (! defined('DB_NAME')) exit('No direct script access allowed');
|
||||
|
||||
if (!$result = @$db->db_query('SELECT 0 FROM lehre.tbl_kalender_notiz WHERE 0 = 1'))
|
||||
{
|
||||
//TODO zuordnung typ definieren
|
||||
$qry = 'CREATE TABLE lehre.tbl_kalender_notiz (
|
||||
eindeutige_kalender_gruppen_id UUID NOT NULL,
|
||||
notiz_id integer NOT NULL,
|
||||
|
||||
CONSTRAINT tbl_kalender_notiz_pk PRIMARY KEY (eindeutige_kalender_gruppen_id, notiz_id),
|
||||
CONSTRAINT tbl_kalender_notiz_notiz_fk FOREIGN KEY (notiz_id)
|
||||
REFERENCES public.tbl_notiz (notiz_id)
|
||||
ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);';
|
||||
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>lehre.tbl_kalender_notiz: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>lehre.tbl_kalender_notiz table created';
|
||||
|
||||
$qry = 'GRANT SELECT ON TABLE lehre.tbl_kalender_notiz TO web;';
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>lehre.tbl_kalender_notiz: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>Granted privileges to <strong>web</strong> on lehre.tbl_kalender_notiz';
|
||||
|
||||
$qry = 'GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE lehre.tbl_kalender_notiz TO vilesci;';
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>lehre.tbl_kalender_notiz: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>Granted privileges to <strong>vilesci</strong> on lehre.tbl_kalender_notiz';
|
||||
|
||||
// Delete the related note when its calendar-note assignment no longer exists.
|
||||
$qry = 'CREATE OR REPLACE FUNCTION lehre.cleanup_notiz_on_kalender_notiz_delete()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = pg_catalog
|
||||
AS $function$
|
||||
BEGIN
|
||||
DELETE FROM public.tbl_notiz
|
||||
WHERE notiz_id = OLD.notiz_id
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM lehre.tbl_kalender_notiz
|
||||
WHERE eindeutige_kalender_gruppen_id = OLD.eindeutige_kalender_gruppen_id
|
||||
AND notiz_id = OLD.notiz_id
|
||||
);
|
||||
|
||||
RETURN OLD;
|
||||
END;
|
||||
$function$;
|
||||
|
||||
CREATE TRIGGER cleanup_notiz_on_kalender_notiz_delete
|
||||
AFTER DELETE ON lehre.tbl_kalender_notiz
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE lehre.cleanup_notiz_on_kalender_notiz_delete();';
|
||||
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>lehre.tbl_notiz cleanup trigger: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>lehre.tbl_notiz cleanup trigger created';
|
||||
}
|
||||
|
||||
// Delete note assignments after a physical delete or when every row in the
|
||||
// calendar group has an inactive status.
|
||||
$qry = 'CREATE OR REPLACE FUNCTION lehre.cleanup_kalender_notiz()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = pg_catalog
|
||||
AS $function$
|
||||
DECLARE
|
||||
gruppen_id UUID;
|
||||
BEGIN
|
||||
IF TG_OP = \'DELETE\' THEN
|
||||
gruppen_id := OLD.eindeutige_kalender_gruppen_id;
|
||||
ELSIF TG_OP = \'UPDATE\' THEN
|
||||
IF (NEW.status_kurzbz IS DISTINCT FROM \'deleted\'
|
||||
AND NEW.status_kurzbz IS DISTINCT FROM \'archived\')
|
||||
OR OLD.status_kurzbz IS NOT DISTINCT FROM NEW.status_kurzbz
|
||||
THEN
|
||||
RETURN NEW;
|
||||
END IF;
|
||||
|
||||
gruppen_id := NEW.eindeutige_kalender_gruppen_id;
|
||||
ELSE
|
||||
RETURN NULL;
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM lehre.tbl_kalender
|
||||
WHERE eindeutige_kalender_gruppen_id = gruppen_id
|
||||
AND status_kurzbz IS DISTINCT FROM \'deleted\'
|
||||
AND status_kurzbz IS DISTINCT FROM \'archived\'
|
||||
)
|
||||
THEN
|
||||
DELETE FROM lehre.tbl_kalender_notiz
|
||||
WHERE eindeutige_kalender_gruppen_id = gruppen_id;
|
||||
END IF;
|
||||
|
||||
IF TG_OP = \'DELETE\' THEN
|
||||
RETURN OLD;
|
||||
END IF;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$function$;';
|
||||
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>lehre.tbl_kalender_notiz cleanup function: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>lehre.tbl_kalender_notiz cleanup function created';
|
||||
|
||||
$result = $db->db_query("SELECT 1
|
||||
FROM pg_catalog.pg_trigger AS t
|
||||
JOIN pg_catalog.pg_class AS c ON c.oid = t.tgrelid
|
||||
JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace
|
||||
WHERE n.nspname = 'lehre'
|
||||
AND c.relname = 'tbl_kalender'
|
||||
AND t.tgname = 'cleanup_kalender_notiz'
|
||||
AND NOT t.tgisinternal");
|
||||
|
||||
if ($db->db_num_rows($result) === 0)
|
||||
{
|
||||
$qry = 'CREATE TRIGGER cleanup_kalender_notiz
|
||||
AFTER DELETE OR UPDATE OF status_kurzbz ON lehre.tbl_kalender
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE lehre.cleanup_kalender_notiz();';
|
||||
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>lehre.tbl_kalender_notiz cleanup trigger: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>lehre.tbl_kalender_notiz cleanup trigger created';
|
||||
}
|
||||
|
||||
// Delete resource assignments after a physical delete or when every row in the
|
||||
// calendar group has an inactive status.
|
||||
$qry = 'CREATE OR REPLACE FUNCTION lehre.cleanup_betriebsmittel_kalender()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = pg_catalog
|
||||
AS $function$
|
||||
DECLARE
|
||||
gruppen_id UUID;
|
||||
BEGIN
|
||||
IF TG_OP = \'DELETE\' THEN
|
||||
gruppen_id := OLD.eindeutige_kalender_gruppen_id;
|
||||
ELSIF TG_OP = \'UPDATE\' THEN
|
||||
IF (NEW.status_kurzbz IS DISTINCT FROM \'deleted\'
|
||||
AND NEW.status_kurzbz IS DISTINCT FROM \'archived\')
|
||||
OR OLD.status_kurzbz IS NOT DISTINCT FROM NEW.status_kurzbz
|
||||
THEN
|
||||
RETURN NEW;
|
||||
END IF;
|
||||
|
||||
gruppen_id := NEW.eindeutige_kalender_gruppen_id;
|
||||
ELSE
|
||||
RETURN NULL;
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM lehre.tbl_kalender
|
||||
WHERE eindeutige_kalender_gruppen_id = gruppen_id
|
||||
AND status_kurzbz IS DISTINCT FROM \'deleted\'
|
||||
AND status_kurzbz IS DISTINCT FROM \'archived\'
|
||||
)
|
||||
THEN
|
||||
DELETE FROM lehre.tbl_betriebsmittel_kalender
|
||||
WHERE eindeutige_kalender_gruppen_id = gruppen_id;
|
||||
END IF;
|
||||
|
||||
IF TG_OP = \'DELETE\' THEN
|
||||
RETURN OLD;
|
||||
END IF;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$function$;';
|
||||
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>lehre.tbl_betriebsmittel_kalender cleanup function: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>lehre.tbl_betriebsmittel_kalender cleanup function created';
|
||||
|
||||
$result = $db->db_query("SELECT 1
|
||||
FROM pg_catalog.pg_trigger AS t
|
||||
JOIN pg_catalog.pg_class AS c ON c.oid = t.tgrelid
|
||||
JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace
|
||||
WHERE n.nspname = 'lehre'
|
||||
AND c.relname = 'tbl_kalender'
|
||||
AND t.tgname = 'cleanup_betriebsmittel_kalender'
|
||||
AND NOT t.tgisinternal");
|
||||
|
||||
if ($db->db_num_rows($result) === 0)
|
||||
{
|
||||
$qry = 'CREATE TRIGGER cleanup_betriebsmittel_kalender
|
||||
AFTER DELETE OR UPDATE OF status_kurzbz ON lehre.tbl_kalender
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE lehre.cleanup_betriebsmittel_kalender();';
|
||||
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>lehre.tbl_betriebsmittel_kalender cleanup trigger: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>lehre.tbl_betriebsmittel_kalender cleanup trigger created';
|
||||
}
|
||||
|
||||
$result = $db->db_query("SELECT 1
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'tbl_notizzuordnung'
|
||||
AND column_name = 'eindeutige_kalender_gruppen_id'");
|
||||
|
||||
if ($db->db_num_rows($result) === 1)
|
||||
{
|
||||
$qry = "ALTER TABLE public.tbl_notizzuordnung
|
||||
DROP COLUMN eindeutige_kalender_gruppen_id";
|
||||
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>public.tbl_notizzuordnung: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>public.tbl_notizzuordnung: eindeutige_kalender_gruppen_id column removed';
|
||||
}
|
||||
Reference in New Issue
Block a user