From 230ebcaf9aa23352bb46b59abc6692e92cc61cfb Mon Sep 17 00:00:00 2001 From: KarpAlex Date: Mon, 20 Mar 2023 17:01:58 +0100 Subject: [PATCH 01/66] added table public.tbl_kennzeichen and kennzeichentyp for managing person Ids --- system/dbupdate_3.4.php | 1 + .../21620_neues_feld_zum_erfassen_des_ESI.php | 116 ++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 system/dbupdate_3.4/21620_neues_feld_zum_erfassen_des_ESI.php diff --git a/system/dbupdate_3.4.php b/system/dbupdate_3.4.php index bc8152a90..dcf882c43 100644 --- a/system/dbupdate_3.4.php +++ b/system/dbupdate_3.4.php @@ -32,6 +32,7 @@ require_once('dbupdate_3.4/26173_index_webservicelog.php'); require_once('dbupdate_3.4/24682_reihungstest_zugangscode_fuer_login.php'); require_once('dbupdate_3.4/17512_fehlercode_constraints.php'); require_once('dbupdate_3.4/19154_beurteilungsformulare_pruefungssenat.php'); +require_once('dbupdate_3.4/21620_neues_feld_zum_erfassen_des_ESI.php'); // *** Pruefung und hinzufuegen der neuen Attribute und Tabellen echo '

Pruefe Tabellen und Attribute!

'; diff --git a/system/dbupdate_3.4/21620_neues_feld_zum_erfassen_des_ESI.php b/system/dbupdate_3.4/21620_neues_feld_zum_erfassen_des_ESI.php new file mode 100644 index 000000000..a7d415b68 --- /dev/null +++ b/system/dbupdate_3.4/21620_neues_feld_zum_erfassen_des_ESI.php @@ -0,0 +1,116 @@ +db_query('SELECT 0 FROM public.tbl_kennzeichentyp WHERE 0 = 1')) +{ + $qry = 'CREATE TABLE public.tbl_kennzeichentyp ( + kennzeichentyp_kurzbz varchar(32) NOT NULL, + bezeichnung varchar(256) NOT NULL, + aktiv boolean NOT NULL DEFAULT TRUE + ); + + COMMENT ON TABLE public.tbl_kennzeichentyp IS \'Tabelle zur Verwaltung von Typen von externen Personenkennzeichen.\'; + COMMENT ON COLUMN public.tbl_kennzeichentyp.bezeichnung IS \'Voller Name des Kennzeichentyps.\'; + COMMENT ON COLUMN public.tbl_kennzeichentyp.aktiv IS \'Ob der Kennzeichentyp noch aktiv und verwendet wird.\'; + + ALTER TABLE public.tbl_kennzeichentyp ADD CONSTRAINT pk_tbl_kennzeichentyp PRIMARY KEY (kennzeichentyp_kurzbz)'; + + if (!$db->db_query($qry)) + echo 'public.tbl_kennzeichentyp: '.$db->db_last_error().'
'; + else + echo '
public.tbl_kennzeichentyp table created'; + + $qry = 'GRANT SELECT ON TABLE public.tbl_kennzeichentyp TO web;'; + if (!$db->db_query($qry)) + echo 'public.tbl_kennzeichentyp: '.$db->db_last_error().'
'; + else + echo '
Granted privileges to web on public.tbl_kennzeichentyp'; + + $qry = 'GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE public.tbl_kennzeichentyp TO vilesci;'; + if (!$db->db_query($qry)) + echo 'public.tbl_kennzeichentyp: '.$db->db_last_error().'
'; + else + echo '
Granted privileges to vilesci on public.tbl_kennzeichentyp'; +} + +// SEQUENCE tbl_kennzeichen_id_seq +if ($result = $db->db_query("SELECT 0 FROM pg_class WHERE relname = 'tbl_kennzeichen_id_seq'")) +{ + if ($db->db_num_rows($result) == 0) + { + $qry = 'CREATE SEQUENCE public.tbl_kennzeichen_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1;'; + + if(!$db->db_query($qry)) + echo 'public.tbl_kennzeichen_id_seq '.$db->db_last_error().'
'; + else + echo '
Created sequence: public.tbl_kennzeichen_id_seq'; + + // GRANT SELECT, UPDATE ON SEQUENCE public.tbl_kennzeichen_id_seq TO vilesci; + $qry = 'GRANT SELECT, UPDATE ON SEQUENCE public.tbl_kennzeichen_id_seq TO vilesci;'; + if (!$db->db_query($qry)) + echo 'public.tbl_kennzeichen_id_seq '.$db->db_last_error().'
'; + else + echo '
Granted privileges to vilesci on public.tbl_kennzeichen_id_seq'; + + // GRANT SELECT, UPDATE ON SEQUENCE public.tbl_kennzeichen_id_seq TO fhcomplete; + $qry = 'GRANT SELECT, UPDATE ON SEQUENCE public.tbl_kennzeichen_id_seq TO fhcomplete;'; + if (!$db->db_query($qry)) + echo 'public.tbl_kennzeichen_id_seq '.$db->db_last_error().'
'; + else + echo '
Granted privileges to fhcomplete on public.tbl_kennzeichen_id_seq'; + } +} + +// Creates table public.tbl_kennzeichen if it doesn't exist and grants privileges +if (!$result = @$db->db_query('SELECT 0 FROM public.tbl_kennzeichen WHERE 0 = 1')) +{ + $qry = 'CREATE TABLE public.tbl_kennzeichen ( + kennzeichen_id integer NOT NULL DEFAULT NEXTVAL(\'public.tbl_kennzeichen_id_seq\'), + person_id integer NOT NULL, + kennzeichentyp_kurzbz varchar(32) NOT NULL, + inhalt text NOT NULL, + aktiv boolean NOT NULL DEFAULT TRUE, + insertamum timestamp DEFAULT NOW(), + insertvon varchar(32), + updateamum timestamp, + updatevon varchar(32) + ); + + COMMENT ON TABLE public.tbl_kennzeichen IS \'Tabelle zum Speichern von externen Personenkennzeichen.\'; + COMMENT ON COLUMN public.tbl_kennzeichen.kennzeichentyp_kurzbz IS \'Typ des externen Personen Kennzeichens.\'; + COMMENT ON COLUMN public.tbl_kennzeichen.inhalt IS \'Das externe Kennzeichen.\'; + COMMENT ON COLUMN public.tbl_kennzeichen.aktiv IS \'Ob das Kennzeichen noch aktiv ist und verwendet wird.\'; + + ALTER TABLE public.tbl_kennzeichen ADD CONSTRAINT pk_tbl_kennzeichen PRIMARY KEY (kennzeichen_id); + + ALTER TABLE public.tbl_kennzeichen ADD CONSTRAINT fk_kennzeichen_person FOREIGN KEY (person_id) REFERENCES public.tbl_person(person_id) ON UPDATE CASCADE ON DELETE RESTRICT; + ALTER TABLE public.tbl_kennzeichen ADD CONSTRAINT fk_kennzeichen_kennzeichentyp_kurzbz FOREIGN KEY (kennzeichentyp_kurzbz) REFERENCES public.tbl_kennzeichentyp(kennzeichentyp_kurzbz) ON UPDATE CASCADE ON DELETE RESTRICT; + + -- create unique constraint, no person can have the same kennzeichen twice + ALTER TABLE public.tbl_kennzeichen ADD CONSTRAINT uk_kennzeichen_person_id_inhalt UNIQUE (person_id, kennzeichentyp_kurzbz, inhalt); + -- create unique index - person can only have one active kennzeichen of each type + CREATE UNIQUE INDEX kennzeichen_aktiv_constraint ON public.tbl_kennzeichen (person_id, kennzeichentyp_kurzbz) WHERE aktiv;'; + + if (!$db->db_query($qry)) + echo 'public.tbl_kennzeichen: '.$db->db_last_error().'
'; + else + echo '
public.tbl_kennzeichen table created'; + + $qry = 'GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE public.tbl_kennzeichen TO web;'; + if (!$db->db_query($qry)) + echo 'public.tbl_kennzeichen: '.$db->db_last_error().'
'; + else + echo '
Granted privileges to web on public.tbl_kennzeichen'; + + $qry = 'GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE public.tbl_kennzeichen TO vilesci;'; + if (!$db->db_query($qry)) + echo 'public.tbl_kennzeichen: '.$db->db_last_error().'
'; + else + echo '
Granted privileges to vilesci on public.tbl_kennzeichen'; +} From cd6443d9c05a67c65d5b31623d1c1e726adefeb4 Mon Sep 17 00:00:00 2001 From: KarpAlex Date: Wed, 22 Mar 2023 17:41:15 +0100 Subject: [PATCH 02/66] -added scheduler for generating and saving ESI -first version of generateESI job --- application/controllers/jobs/ESIJob.php | 169 ++++++++++++++++++ .../jobs/schedulers/ESIScheduler.php | 108 +++++++++++ .../models/person/Kennzeichen_model.php | 36 ++++ .../21620_neues_feld_zum_erfassen_des_ESI.php | 34 +++- 4 files changed, 345 insertions(+), 2 deletions(-) create mode 100644 application/controllers/jobs/ESIJob.php create mode 100644 application/controllers/jobs/schedulers/ESIScheduler.php create mode 100644 application/models/person/Kennzeichen_model.php diff --git a/application/controllers/jobs/ESIJob.php b/application/controllers/jobs/ESIJob.php new file mode 100644 index 000000000..74c5a925d --- /dev/null +++ b/application/controllers/jobs/ESIJob.php @@ -0,0 +1,169 @@ +load->model('Person_model', 'PersonModel'); + $this->load->model('Kennzeichen_model', 'KennzeichenModel'); + + // load libraries + //$this->load->library('extensions/FHC-Core-DVUH/DVUHIssueLib'); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Initialises generateESI job, handles job queue, logs infos/errors + */ + public function generateESI() + { + //$jobType = 'DVUHSendPruefungsaktivitaeten'; + $this->logInfo(ESIScheduler::JOB_TYPE_GENERATE_ESI.' job start'); + + // Gets the latest jobs + $lastJobs = $this->getLastJobs(ESIScheduler::JOB_TYPE_GENERATE_ESI); + if (isError($lastJobs)) + { + $this->logError(getCode($lastJobs).': '.getError($lastJobs), ESIScheduler::JOB_TYPE_GENERATE_ESI); + } + else + { + $this->updateJobs( + getData($lastJobs), // Jobs to be updated + array(JobsQueueLib::PROPERTY_START_TIME), // Job properties to be updated + array(date('Y-m-d H:i:s')) // Job properties new values + ); + + $person_arr = $this->_getInputObjArray(getData($lastJobs)); + + foreach ($person_arr as $persobj) + { + if (!isset($persobj->person_id)) + $this->logError("Error when generating ESI: invalid parameters"); + else + { + $person_id = $persobj->person_id; + + // check if there already is an active ESI + $this->KennzeichenModel->addSelect('1'); + $activeKennzeichenRes = $this->KennzeichenModel->loadWhere( + array('person_id' => $person_id, 'kennzeichentyp_kurzbz' => ESIScheduler::KENNZEICHENTYP_KURZBZ, 'aktiv' => true) + ); + + if (hasData($activeKennzeichenRes)) + { + $this->logError("Active ESI for person Id $prestudent_id already exists"); + continue; + } + + // get Matrikelnr for person for which ESI should be generated + $this->PersonModel->addSelect('matr_nr'); + $personRes = $this->PersonModel->load($person_id); + + if (!hasData($personRes)) + { + $this->logError("Person with Id $person_id not found"); + continue; + } + + $matr_nr = getData($personRes)[0]->matr_nr; + + if (isEmptyString($matr_nr)) + { + $this->logError("Matrikelnummer for person with Id $person_id is empty"); + continue; + } + + $esi = self::ESI_PREFIX.$matrikelnr; + + // check if ESI was already used + $this->KennzeichenModel->addSelect('1'); + $existingKennzeichenRes = $this->KennzeichenModel->loadWhere( + array('person_id' => $person_id, 'kennzeichentyp_kurzbz' => ESIScheduler::KENNZEICHENTYP_KURZBZ, 'inhalt' => $esi) + ); + + if (hasData($existingKennzeichenRes)) + { + $this->logError("ESI $esi for person Id $prestudent_id already exists"); + continue; + } + + // if everything ok, save the esi for the person + $saveEsiResult = $this->Kennzeichen_model->insert( + array( + 'person_id' => $person_id, + 'kennzeichentyp_kurzbz' => ESIScheduler::KENNZEICHENTYP_KURZBZ, + 'inhalt' => $esi, + 'aktiv' => true + ) + ); + + if (isError($saveEsiResult)) + { + $this->logError("Error when sending ESI, person Id $person_id ".getError($saveEsiResult)); + } + elseif (hasData($saveEsiResult)) + { + // TODO everything ok + } + } + } + + // Update jobs properties values + $this->updateJobs( + getData($lastJobs), // Jobs to be updated + array(JobsQueueLib::PROPERTY_STATUS, JobsQueueLib::PROPERTY_END_TIME), // Job properties to be updated + array(JobsQueueLib::STATUS_DONE, date('Y-m-d H:i:s')) // Job properties new values + ); + + if (hasData($lastJobs)) $this->updateJobsQueue($jobType, getData($lastJobs)); + } + + $this->logInfo(ESIScheduler::JOB_TYPE_GENERATE_ESI.' job stop'); + } + + // -------------------------------------------------------------------------------------------- + // Private methods + + /** + * Extracts input data from jobs. + * @param $jobs + * @return array with jobinput + */ + private function _getInputObjArray($jobs) + { + $mergedUsersArray = array(); + + if (count($jobs) == 0) return $mergedUsersArray; + + foreach ($jobs as $job) + { + $decodedInput = json_decode($job->input); + if ($decodedInput != null) + { + foreach ($decodedInput as $el) + { + $mergedUsersArray[] = $el; + } + } + } + return $mergedUsersArray; + } +} diff --git a/application/controllers/jobs/schedulers/ESIScheduler.php b/application/controllers/jobs/schedulers/ESIScheduler.php new file mode 100644 index 000000000..3ab858937 --- /dev/null +++ b/application/controllers/jobs/schedulers/ESIScheduler.php @@ -0,0 +1,108 @@ +load->model('organisation/Studiensemester_model', 'StudiensemesterModel'); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Creates jobs queue entries for generateESI job. + * @param string $studiensemester_kurzbz semester for which ESIs should be generated + */ + public function generateESI($studiensemester_kurzbz = null) + { + // if no semester given, get current studiensemester + if (!isset($studiensemester_kurzbz)) + { + $semRes = $this->StudiensemesterModel->getAkt(); + + if (hasData($semRes)) + { + $studiensemester_kurzbz = getData($semRes)[0]->studiensemester_kurzbz; + } + } + + if (isset($studiensemester_kurzbz)) + { + $this->logInfo('Start job queue scheduler '.self::JOB_TYPE_GENERATE_ESI); + + $qry = " + SELECT + DISTINCT person_id + FROM + public.tbl_person pers + JOIN public.tbl_prestudent ps USING (person_id) + JOIN public.tbl_prestudentstatus pss USING (prestudent_id) + WHERE + pss.studiensemester_kurzbz = ? + AND pers.matr_nr IS NOT NULL + AND pss.status_kurzbz IN ? + AND NOT EXISTS ( -- has no ESI yet + SELECT 1 + FROM + public.tbl_kennzeichen + WHERE + person_id = pers.person_id + AND kennzeichentyp_kurzbz = ? + AND aktiv + ) + AND NOT EXISTS ( -- making sure it's not an incoming + SELECT 1 + FROM + public.tbl_prestudentstatus + WHERE + prestudent_id = ps.prestudent_id + AND status_kurzbz = 'Incoming' + )"; + + $db = new DB_Model(); + $jobInputResult = $db->execReadOnlyQuery($qry, array($studiensemester_kurzbz, $this->_active_status_kurzbz, self::KENNZEICHENTYP_KURZBZ)); + + // If an error occured then log it + if (isError($jobInputResult)) + { + $this->logError(getError($jobInputResult)); + } + elseif (hasData($jobInputResult)) // if persons found + { + // Add the new job to the jobs queue + $addNewJobResult = $this->addNewJobsToQueue( + self::JOB_TYPE_GENERATE_ESI, // job type + $this->generateJobs( // gnerate the structure of the new job + JobsQueueLib::STATUS_NEW, + json_encode(getData($jobInputResult)) + ) + ); + + // If error occurred return it + if (isError($addNewJobResult)) $this->logError(getError($addNewJobResult)); + } + } + else + { + $this->logError('Error when getting Studiensemester'); + } + + $this->logInfo('End job queue scheduler '.self::JOB_TYPE_GENERATE_ESI); + } +} diff --git a/application/models/person/Kennzeichen_model.php b/application/models/person/Kennzeichen_model.php new file mode 100644 index 000000000..7d00a68b4 --- /dev/null +++ b/application/models/person/Kennzeichen_model.php @@ -0,0 +1,36 @@ +dbTable = 'public.tbl_kennzeichen'; + $this->pk = 'kennzeichen_id'; + } + + /** + * + * @param + * @return object success or error + */ + public function _() + { + + } + + /** + * Get Zustelladress of given person. + * @param string $person_id + * @param string $select + * @return array + */ + //~ public function getZustellAdresse($person_id, $select = '*') + //~ { + //~ $this->addSelect($select); + //~ return $this->loadWhere(array('person_id' => $person_id, 'zustelladresse'=> true)); + //~ } +} diff --git a/system/dbupdate_3.4/21620_neues_feld_zum_erfassen_des_ESI.php b/system/dbupdate_3.4/21620_neues_feld_zum_erfassen_des_ESI.php index a7d415b68..5b6b22918 100644 --- a/system/dbupdate_3.4/21620_neues_feld_zum_erfassen_des_ESI.php +++ b/system/dbupdate_3.4/21620_neues_feld_zum_erfassen_des_ESI.php @@ -89,8 +89,10 @@ if (!$result = @$db->db_query('SELECT 0 FROM public.tbl_kennzeichen WHERE 0 = 1' ALTER TABLE public.tbl_kennzeichen ADD CONSTRAINT pk_tbl_kennzeichen PRIMARY KEY (kennzeichen_id); - ALTER TABLE public.tbl_kennzeichen ADD CONSTRAINT fk_kennzeichen_person FOREIGN KEY (person_id) REFERENCES public.tbl_person(person_id) ON UPDATE CASCADE ON DELETE RESTRICT; - ALTER TABLE public.tbl_kennzeichen ADD CONSTRAINT fk_kennzeichen_kennzeichentyp_kurzbz FOREIGN KEY (kennzeichentyp_kurzbz) REFERENCES public.tbl_kennzeichentyp(kennzeichentyp_kurzbz) ON UPDATE CASCADE ON DELETE RESTRICT; + ALTER TABLE public.tbl_kennzeichen ADD CONSTRAINT fk_kennzeichen_person FOREIGN KEY (person_id) + REFERENCES public.tbl_person(person_id) ON UPDATE CASCADE ON DELETE RESTRICT; + ALTER TABLE public.tbl_kennzeichen ADD CONSTRAINT fk_kennzeichen_kennzeichentyp_kurzbz FOREIGN KEY (kennzeichentyp_kurzbz) + REFERENCES public.tbl_kennzeichentyp(kennzeichentyp_kurzbz) ON UPDATE CASCADE ON DELETE RESTRICT; -- create unique constraint, no person can have the same kennzeichen twice ALTER TABLE public.tbl_kennzeichen ADD CONSTRAINT uk_kennzeichen_person_id_inhalt UNIQUE (person_id, kennzeichentyp_kurzbz, inhalt); @@ -114,3 +116,31 @@ if (!$result = @$db->db_query('SELECT 0 FROM public.tbl_kennzeichen WHERE 0 = 1' else echo '
Granted privileges to vilesci on public.tbl_kennzeichen'; } + +// public.tbl_kennzeichentyp: add type esi +if ($result = $db->db_query("SELECT 1 FROM public.tbl_kennzeichentyp WHERE kennzeichentyp_kurzbz='esi'")) +{ + if($db->db_num_rows($result)==0) + { + $qry = "INSERT INTO public.tbl_kennzeichentyp(kennzeichentyp_kurzbz, bezeichnung) VALUES('esi', 'European Student Identifier');"; + + if(!$db->db_query($qry)) + echo 'Kennzeichentyp: '.$db->db_last_error().'
'; + else + echo '
Neuer Kennzeichentyp esi in public.tbl_kennzeichentyp hinzugefügt'; + } +} + +// system.tbl_jobtypes: add type esi +if ($result = $db->db_query("SELECT 1 FROM system.tbl_jobtypes WHERE type='generateESI'")) +{ + if($db->db_num_rows($result)==0) + { + $qry = "INSERT INTO system.tbl_jobtypes(type, description) VALUES('generateESI', 'Generate and save European Student Identifier');"; + + if(!$db->db_query($qry)) + echo 'Jobtyp: '.$db->db_last_error().'
'; + else + echo '
Neuer Jobtyp generateESI in system.tbl_jobtypes hinzugefügt'; + } +} From 903f3d2f378537d0f94be9dcd05d4beb8bb57e66 Mon Sep 17 00:00:00 2001 From: KarpAlex Date: Thu, 23 Mar 2023 17:50:32 +0100 Subject: [PATCH 03/66] generateESI Job bugfixes (correct models, Ids in error logs), added insertvon --- application/controllers/jobs/ESIJob.php | 26 +++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/application/controllers/jobs/ESIJob.php b/application/controllers/jobs/ESIJob.php index 74c5a925d..c9a558a46 100644 --- a/application/controllers/jobs/ESIJob.php +++ b/application/controllers/jobs/ESIJob.php @@ -10,6 +10,7 @@ require_once('schedulers/ESIScheduler.php'); class ESIJob extends JQW_Controller { const ESI_PREFIX = 'urn:schac:personalUniqueCode:int:esi:at:'; + const INSERT_VON = 'generateEsiJob'; /** * Controller initialization @@ -19,11 +20,8 @@ class ESIJob extends JQW_Controller parent::__construct(); // load models - $this->load->model('Person_model', 'PersonModel'); - $this->load->model('Kennzeichen_model', 'KennzeichenModel'); - - // load libraries - //$this->load->library('extensions/FHC-Core-DVUH/DVUHIssueLib'); + $this->load->model('person/Person_model', 'PersonModel'); + $this->load->model('person/Kennzeichen_model', 'KennzeichenModel'); } //------------------------------------------------------------------------------------------------------------------ @@ -39,6 +37,7 @@ class ESIJob extends JQW_Controller // Gets the latest jobs $lastJobs = $this->getLastJobs(ESIScheduler::JOB_TYPE_GENERATE_ESI); + if (isError($lastJobs)) { $this->logError(getCode($lastJobs).': '.getError($lastJobs), ESIScheduler::JOB_TYPE_GENERATE_ESI); @@ -69,7 +68,7 @@ class ESIJob extends JQW_Controller if (hasData($activeKennzeichenRes)) { - $this->logError("Active ESI for person Id $prestudent_id already exists"); + $this->logError("Active ESI for person Id $person_id already exists"); continue; } @@ -91,7 +90,7 @@ class ESIJob extends JQW_Controller continue; } - $esi = self::ESI_PREFIX.$matrikelnr; + $esi = self::ESI_PREFIX.$matr_nr; // check if ESI was already used $this->KennzeichenModel->addSelect('1'); @@ -101,17 +100,18 @@ class ESIJob extends JQW_Controller if (hasData($existingKennzeichenRes)) { - $this->logError("ESI $esi for person Id $prestudent_id already exists"); + $this->logError("ESI $esi for person Id $person_id already exists"); continue; } // if everything ok, save the esi for the person - $saveEsiResult = $this->Kennzeichen_model->insert( + $saveEsiResult = $this->KennzeichenModel->insert( array( 'person_id' => $person_id, 'kennzeichentyp_kurzbz' => ESIScheduler::KENNZEICHENTYP_KURZBZ, 'inhalt' => $esi, - 'aktiv' => true + 'aktiv' => true, + 'insertvon' => self::INSERT_VON ) ); @@ -119,10 +119,6 @@ class ESIJob extends JQW_Controller { $this->logError("Error when sending ESI, person Id $person_id ".getError($saveEsiResult)); } - elseif (hasData($saveEsiResult)) - { - // TODO everything ok - } } } @@ -133,7 +129,7 @@ class ESIJob extends JQW_Controller array(JobsQueueLib::STATUS_DONE, date('Y-m-d H:i:s')) // Job properties new values ); - if (hasData($lastJobs)) $this->updateJobsQueue($jobType, getData($lastJobs)); + if (hasData($lastJobs)) $this->updateJobsQueue(ESIScheduler::JOB_TYPE_GENERATE_ESI, getData($lastJobs)); } $this->logInfo(ESIScheduler::JOB_TYPE_GENERATE_ESI.' job stop'); From d9eb0f5704732ce05549ffeb4e24a149ca3c5a99 Mon Sep 17 00:00:00 2001 From: ma0048 Date: Fri, 16 Jun 2023 11:30:03 +0200 Subject: [PATCH 04/66] - kennzeichen beim zusammenlegen uebernehmen --- .../models/person/Kennzeichen_model.php | 21 ----- vilesci/stammdaten/personen_wartung.php | 84 +++++++++++++++++++ 2 files changed, 84 insertions(+), 21 deletions(-) diff --git a/application/models/person/Kennzeichen_model.php b/application/models/person/Kennzeichen_model.php index 7d00a68b4..fe8a9ac62 100644 --- a/application/models/person/Kennzeichen_model.php +++ b/application/models/person/Kennzeichen_model.php @@ -12,25 +12,4 @@ class Kennzeichen_model extends DB_Model $this->pk = 'kennzeichen_id'; } - /** - * - * @param - * @return object success or error - */ - public function _() - { - - } - - /** - * Get Zustelladress of given person. - * @param string $person_id - * @param string $select - * @return array - */ - //~ public function getZustellAdresse($person_id, $select = '*') - //~ { - //~ $this->addSelect($select); - //~ return $this->loadWhere(array('person_id' => $person_id, 'zustelladresse'=> true)); - //~ } } diff --git a/vilesci/stammdaten/personen_wartung.php b/vilesci/stammdaten/personen_wartung.php index ee95854ed..c77b81b2b 100644 --- a/vilesci/stammdaten/personen_wartung.php +++ b/vilesci/stammdaten/personen_wartung.php @@ -319,6 +319,90 @@ if (isset($personToDelete) && isset($personToKeep) && $personToDelete >= 0 && $p } } } + + if($result = @$db->db_query("SELECT 1 FROM public.tbl_kennzeichen LIMIT 1")) + { + $kennzeichen_has_personToKeep = array(); + $kennzeichen_has_personToDelete = array(); + + $kennzeichen_query = " + SELECT * + FROM public.tbl_kennzeichen + WHERE ( + person_id = " . $db->db_add_param($personToKeep, FHC_INTEGER) . " OR + person_id = " . $db->db_add_param($personToDelete, FHC_INTEGER) . " + ) + ORDER BY kennzeichentyp_kurzbz, aktiv DESC"; + + if ($result = $db->db_query($kennzeichen_query)) + { + while ($row = $db->db_fetch_object($result)) + { + if ($row->person_id === $personToKeep) + { + $kennzeichen_has_personToKeep[] = $row; + } + else if ($row->person_id === $personToDelete) + { + $kennzeichen_has_personToDelete[] = $row; + } + } + } + + if (!empty($kennzeichen_has_personToDelete)) + { + foreach ($kennzeichen_has_personToDelete as $kennzeichen_toDelete) + { + $kennzeichen_toKeep_Kurzbz = array_column($kennzeichen_has_personToKeep, 'kennzeichentyp_kurzbz'); + + if (in_array($kennzeichen_toDelete->kennzeichentyp_kurzbz, $kennzeichen_toKeep_Kurzbz)) + { + $kennzeichen_toKeep_Keys = array_keys($kennzeichen_toKeep_Kurzbz, $kennzeichen_toDelete->kennzeichentyp_kurzbz); + + foreach ($kennzeichen_toKeep_Keys as $key) + { + if (($kennzeichen_has_personToKeep[$key]->aktiv === 't' && $kennzeichen_toDelete->aktiv === 'f') || + ($kennzeichen_has_personToKeep[$key]->aktiv === 'f' && $kennzeichen_toDelete->aktiv === 't') || + ($kennzeichen_has_personToKeep[$key]->aktiv === 'f' && $kennzeichen_toDelete->aktiv === 'f')) + { + if ($kennzeichen_has_personToKeep[$key]->inhalt !== $kennzeichen_toDelete->inhalt) + { + $sql_query_upd1 .= "UPDATE public.tbl_kennzeichen SET person_id=" . $db->db_add_param($personToKeep, FHC_INTEGER) . " WHERE kennzeichen_id=" . $db->db_add_param($kennzeichen_toDelete->kennzeichen_id, FHC_INTEGER) . ";"; + $kennzeichen_has_personToKeep[] = $kennzeichen_toDelete; + continue 2; + } + else + { + if ($kennzeichen_toDelete->aktiv === 'f') + { + $sql_query_upd1 .= "DELETE FROM public.tbl_kennzeichen WHERE kennzeichen_id=" . $db->db_add_param($kennzeichen_toDelete->kennzeichen_id, FHC_INTEGER) . ";"; + $msg_warning[] = "Das nicht aktive Kennzeichen mit der ID '" . $kennzeichen_toDelete->kennzeichen_id . "' wurde gelöscht,
+ da es der gleiche Inhalt wie beim Kennzeichen mit der ID '". $kennzeichen_has_personToKeep[$key]->kennzeichen_id ."' ist."; + continue 2; + } + $msg_error[] = 'Beide Personen haben ein Kennzeichen mit dem gleichen Typ ('. $kennzeichen_toDelete->kennzeichentyp_kurzbz.') und den gleichen Inhalt. Können nicht zusammengelegt werden.
+ Sie müssen die Datensätze manuell bereinigen, bevor Sie die Personen zusammenlegen können.'; + $error = true; + break 2; + } + } + else if ($kennzeichen_has_personToKeep[$key]->aktiv === 't' && $kennzeichen_toDelete->aktiv === 't') + { + $msg_error[] = 'Beide Personen haben ein aktives Kennzeichen mit dem gleichen Typ ('. $kennzeichen_toDelete->kennzeichentyp_kurzbz.'). Können nicht zusammengelegt werden.
+ Sie müssen die Datensätze manuell bereinigen, bevor Sie die Personen zusammenlegen können.'; + $error = true; + break 2; + } + } + } + else + { + $sql_query_upd1 .= "UPDATE public.tbl_kennzeichen SET person_id=" . $db->db_add_param($personToKeep, FHC_INTEGER) . " WHERE kennzeichen_id=" . $db->db_add_param($kennzeichen_toDelete->kennzeichen_id, FHC_INTEGER) . ";"; + } + } + } + } + if ($error == false) { // Wenn bei einer der Personen das Foto gesperrt ist, dann die Sperre uebernehmen From e60157dd9beb45f7d7441f445470459cd9734934 Mon Sep 17 00:00:00 2001 From: KarpAlex Date: Mon, 18 Dec 2023 17:16:20 +0100 Subject: [PATCH 05/66] Personen zusammenlegen: uhstat1daten are checked --- vilesci/stammdaten/personen_wartung.php | 58 +++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/vilesci/stammdaten/personen_wartung.php b/vilesci/stammdaten/personen_wartung.php index c77b81b2b..99f83c454 100644 --- a/vilesci/stammdaten/personen_wartung.php +++ b/vilesci/stammdaten/personen_wartung.php @@ -229,7 +229,7 @@ if (isset($personToDelete) && isset($personToKeep) && $personToDelete >= 0 && $p die('Es sind bereits beide Personen in SAP vorhanden. Bitte zuerst direkt in der tbl_sap_students lösen.'); } } - + $personToDelete_obj = new person(); if ($personToDelete_obj->load($personToDelete)) { @@ -333,7 +333,7 @@ if (isset($personToDelete) && isset($personToKeep) && $personToDelete >= 0 && $p person_id = " . $db->db_add_param($personToDelete, FHC_INTEGER) . " ) ORDER BY kennzeichentyp_kurzbz, aktiv DESC"; - + if ($result = $db->db_query($kennzeichen_query)) { while ($row = $db->db_fetch_object($result)) @@ -403,6 +403,58 @@ if (isset($personToDelete) && isset($personToKeep) && $personToDelete >= 0 && $p } } + if($result = @$db->db_query("SELECT 1 FROM bis.tbl_uhstat1daten LIMIT 1")) + { + $uhstat_has_personToKeep = array(); + $uhstat_has_personToDelete = array(); + + $uhstat_query = " + SELECT uhstat1daten_id, person_id + FROM bis.tbl_uhstat1daten + WHERE ( + person_id = " . $db->db_add_param($personToKeep, FHC_INTEGER) . " OR + person_id = " . $db->db_add_param($personToDelete, FHC_INTEGER) . " + ) + ORDER BY updateamum DESC NULLS LAST, insertamum DESC NULLS LAST"; + + // Herausfinden, ob UHSTAT Daten der löschenden oder zu belassenden Person zugeordnet sind + if ($result = $db->db_query($uhstat_query)) + { + while ($row = $db->db_fetch_object($result)) + { + if ($row->person_id === $personToKeep) + { + $uhstat_has_personToKeep[] = $row; + } + else if ($row->person_id === $personToDelete) + { + $uhstat_has_personToDelete[] = $row; + } + } + } + + // wenn UHSTAT Daten an Person, die gelöscht werden soll, hängen + if (!empty($uhstat_has_personToDelete)) + { + // Wenn es auch UHSTAT Daten für die Person, die bleibt, gibt + if (!empty($uhstat_has_personToKeep)) + { + // Unklar: welche Version der Daten soll behalten werden? + $msg_error[] = 'Beide Personen haben UHSTAT1 Daten. Können nicht zusammengelegt werden.
+ Sie müssen die Datensätze manuell bereinigen, bevor Sie die Personen zusammenlegen können.'; + $error = true; + } + else + { + // Es gibt nur UHSTAT Daten für die zu löschende Person: Update + foreach ($uhstat_has_personToDelete as $uhstat_toDelete) + { + $sql_query_upd1 .= "UPDATE bis.tbl_uhstat1daten SET person_id=" . $db->db_add_param($personToKeep, FHC_INTEGER) . " WHERE uhstat1daten_id=" . $db->db_add_param($uhstat_toDelete->uhstat1daten_id, FHC_INTEGER) . ";"; + } + } + } + } + if ($error == false) { // Wenn bei einer der Personen das Foto gesperrt ist, dann die Sperre uebernehmen @@ -521,7 +573,7 @@ if (isset($personToDelete) && isset($personToKeep) && $personToDelete >= 0 && $p Alte Anmerkungen: ".$personToDelete_obj->anmerkungen; $anmerkung .= " - + Zusammengelegt mit Person-ID ".$personToDelete_obj->person_id." am ".date('d.m.Y H:i:s')." von ".$uid; // Letztbenutzten Zugangscode abfragen und übernehmen From 8b9c023781d1e5c46c32f633249de102dd037e89 Mon Sep 17 00:00:00 2001 From: KarpAlex Date: Mon, 18 Dec 2023 17:51:05 +0100 Subject: [PATCH 06/66] Personen zusammenlegen: Rueckstellungen are checked --- vilesci/stammdaten/personen_wartung.php | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/vilesci/stammdaten/personen_wartung.php b/vilesci/stammdaten/personen_wartung.php index 99f83c454..b2aef6055 100644 --- a/vilesci/stammdaten/personen_wartung.php +++ b/vilesci/stammdaten/personen_wartung.php @@ -455,6 +455,58 @@ if (isset($personToDelete) && isset($personToKeep) && $personToDelete >= 0 && $p } } + if($result = @$db->db_query("SELECT 1 FROM public.tbl_rueckstellung LIMIT 1")) + { + $rueckstellung_has_personToKeep = array(); + $rueckstellung_has_personToDelete = array(); + + $rueckstellung_query = " + SELECT rueckstellung_id, person_id + FROM public.tbl_rueckstellung + WHERE ( + person_id = " . $db->db_add_param($personToKeep, FHC_INTEGER) . " OR + person_id = " . $db->db_add_param($personToDelete, FHC_INTEGER) . " + ) + ORDER BY insertamum DESC NULLS LAST"; + + // Herausfinden, ob Rueckstellung Daten der löschenden oder zu belassenden Person zugeordnet sind + if ($result = $db->db_query($rueckstellung_query)) + { + while ($row = $db->db_fetch_object($result)) + { + if ($row->person_id === $personToKeep) + { + $rueckstellung_has_personToKeep[] = $row; + } + else if ($row->person_id === $personToDelete) + { + $rueckstellung_has_personToDelete[] = $row; + } + } + } + + // wenn Rueckstellung Daten an Person, die gelöscht werden soll, hängen + if (!empty($rueckstellung_has_personToDelete)) + { + // Wenn es auch Rueckstellung Daten für die Person, die bleibt, gibt + if (!empty($rueckstellung_has_personToKeep)) + { + // Unklar: welche Version der Daten soll behalten werden? + $msg_error[] = 'Beide Personen haben Rückstellung Daten. Können nicht zusammengelegt werden.
+ Sie müssen die Datensätze manuell bereinigen, bevor Sie die Personen zusammenlegen können.'; + $error = true; + } + else + { + // Es gibt nur Rueckstellung Daten für die zu löschende Person: Update + foreach ($rueckstellung_has_personToDelete as $rueckstellung_toDelete) + { + $sql_query_upd1 .= "UPDATE public.tbl_rueckstellung SET person_id=" . $db->db_add_param($personToKeep, FHC_INTEGER) . " WHERE rueckstellung_id=" . $db->db_add_param($rueckstellung_toDelete->rueckstellung_id, FHC_INTEGER) . ";"; + } + } + } + } + if ($error == false) { // Wenn bei einer der Personen das Foto gesperrt ist, dann die Sperre uebernehmen From a2905c3e93acd0309a6ad505ae361c42f15aa05e Mon Sep 17 00:00:00 2001 From: ma0048 Date: Mon, 15 Jan 2024 12:25:34 +0100 Subject: [PATCH 07/66] - scheduler angepasst - config erweitert um mahnsperre und zahlungsbedingungen - fas config hinzugefuegt --- config/vilesci.config-default.inc.php | 11 ++++++++++- content/student/studentDBDML.php | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/config/vilesci.config-default.inc.php b/config/vilesci.config-default.inc.php index ddcf8d563..a372bc9da 100644 --- a/config/vilesci.config-default.inc.php +++ b/config/vilesci.config-default.inc.php @@ -283,7 +283,7 @@ define('FAS_DOPPELTE_BUCHUNGSTYPEN_CHECK', serialize( 'StudiengebuehrRestzahlung' => array('StudiengebuehrErhoeht', 'Studiengebuehr', 'StudiengebuehrRestzahlung'), 'OEH' => array('OEH') )) -)); +); // Spezialnoten die am Zeunigs und Diplomasupplement ignoriert werden define('ZEUGNISNOTE_NICHT_ANZEIGEN',serialize(array('iar', 'nz'))); @@ -295,4 +295,13 @@ define ('DEFAULT_LEHRMODUS','regulaer'); //Echter Dienstvertrag define ('DEFAULT_ECHTER_DIENSTVERTRAG',[103,110]); +//Buchungstypen die fix auf eine bestimmte Kostenstelle gebucht werden sollen +//Buchungstyp => Studiengang_kz +define('FAS_BUCHUNGSTYP_FIXE_KOSTENSTELLE', serialize( + array( + 'Test_1' => 0, + 'Test_2' => 2 + ) +)); + ?> diff --git a/content/student/studentDBDML.php b/content/student/studentDBDML.php index 4e5f5452c..88c11676a 100644 --- a/content/student/studentDBDML.php +++ b/content/student/studentDBDML.php @@ -2584,13 +2584,16 @@ if(!$error) } else { + if(defined('FAS_BUCHUNGSTYP_FIXE_KOSTENSTELLE') && isset(unserialize(FAS_BUCHUNGSTYP_FIXE_KOSTENSTELLE)[$_POST['buchungstyp_kurzbz']])) + $kostenstelle = unserialize(FAS_BUCHUNGSTYP_FIXE_KOSTENSTELLE)[$_POST['buchungstyp_kurzbz']]; + foreach ($person_ids as $person_id) { if($person_id!='') { $buchung = new konto(); $buchung->person_id = $person_id; - $buchung->studiengang_kz = $_POST['studiengang_kz']; + $buchung->studiengang_kz = isset($kostenstelle) ? $kostenstelle : $_POST['studiengang_kz']; $buchung->studiensemester_kurzbz = $_POST['studiensemester_kurzbz']; $buchung->buchungsnr_verweis=''; $buchung->betrag = $_POST['betrag']; From d66a6567b0650c8b656fd18cfbf4714ceffe7ece Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Tue, 23 Jan 2024 09:29:47 +0100 Subject: [PATCH 08/66] Form Components --- public/js/components/Form/Form.js | 137 +++++++++++ public/js/components/Form/Input.js | 278 ++++++++++++++++++++++ public/js/components/Form/Upload/Dms.js | 87 +++++++ public/js/components/Form/Upload/Image.js | 62 +++++ 4 files changed, 564 insertions(+) create mode 100644 public/js/components/Form/Form.js create mode 100644 public/js/components/Form/Input.js create mode 100644 public/js/components/Form/Upload/Dms.js create mode 100644 public/js/components/Form/Upload/Image.js diff --git a/public/js/components/Form/Form.js b/public/js/components/Form/Form.js new file mode 100644 index 000000000..2257eb289 --- /dev/null +++ b/public/js/components/Form/Form.js @@ -0,0 +1,137 @@ +import FhcFragment from "../Fragment.js"; + +export default { + components: { + FhcFragment + }, + provide() { + return { + $registerToForm: component => { + if (this.inputs.indexOf(component) < 0) + this.inputs.push(component); + } + }; + }, + props: { + tag: { + type: String, + default: 'form' + } + }, + data() { + return { + inputs: [] + } + }, + computed: { + sortedInputs() { + return this.inputs.reduce((a,c) => { + let name = c.name || '_default'; + if (!a[name]) + a[name] = []; + a[name].push(c); + + if (c.lcType == 'checkbox' && name.substr(-1) == ']' && name.indexOf('[')) { + name = name.substr(0, name.lastIndexOf('[')); + if (!a[name]) + a[name] = []; + a[name].push(c); + } + + return a; + }, {}); + } + }, + methods: { + _sendFeedbackToInput(inputs, feedback, valid) { + if (inputs.length) { + inputs.forEach(input => input.setFeedback(valid, feedback)); + return false; + } + if (this.$fhcAlert) { + this.$fhcAlert[valid ? 'alertSuccess' : 'alertError'](feedback); + return false; + } + return true; + }, + setFeedback(valid, feedback) { + if (Array.isArray(feedback)) { + let remaining = feedback.filter(fb => + this._sendFeedbackToInput( + this.sortedInputs['_default'] || [], + fb, + valid + ) + ); + return remaining.length ? remaining : null; + } + if (typeof feedback === 'object') { + let remaining = Object.entries(feedback).filter(([name, fb]) => + this._sendFeedbackToInput( + this.sortedInputs[name.split('.')[0] + name.split('.').slice(1).map(p => `[${p}]`).join("")] || this.sortedInputs['_default'] || [], + fb, + valid + ) + ); + return remaining.length ? Object.fromEntries(remaining) : null; + } + + let remaining = this._sendFeedbackToInput( + this.sortedInputs['_default'] || [], + feedback, + valid + ); + return remaining ? feedback : null; + }, + clearValidation() { + this.inputs.forEach(input => input.clearValidation()); + }, + send(promise) { + return new Promise((resolve, reject) => { + promise.then(result => { + if (result?.status == 200 && result.data) { + if (typeof result.data !== 'object' || !result.data.hasOwnProperty('retval')) + // TODO(chris): IMPLEMENT! Error in API + return reject(result); + if (result.data.error) + // TODO(chris): IMPLEMENT! Error in API + return reject(result); + const data = result.data.retval; + // TODO(chris): check for something better/add new standardized return value + if (result.data.code == 1) + this.setFeedback(true, data); + return resolve(data); + } + // TODO(chris): IMPLEMENT! Wrong result object + reject(result); + }).catch(result => { + if (result?.response?.status == 400 && result.response.data) { + if (typeof result.response.data !== 'object' || !result.response.data.hasOwnProperty('retval')) + // TODO(chris): IMPLEMENT! Error in API + return reject(result); + this.clearValidation(); + const remaining = this.setFeedback( + false, + result.response.data.retval + ); + if (remaining) { + result.response.data.retval = remaining; + return reject(result); + } + } else if (result?.response?.status == 500) { + if (this.$fhcAlert) + this.$fhcAlert.handleSystemError(result); + else + return reject(result); + } else { + return reject(result); + } + }); + }); + } + }, + template: ` + + + ` +} \ No newline at end of file diff --git a/public/js/components/Form/Input.js b/public/js/components/Form/Input.js new file mode 100644 index 000000000..1fc318523 --- /dev/null +++ b/public/js/components/Form/Input.js @@ -0,0 +1,278 @@ +import FhcFragment from "../Fragment.js"; + +let _uuid = {}; + +export default { + inheritAttrs: false, + components: { + FhcFragment + }, + inject: [ + '$registerToForm' + ], + props: { + bsFeedback: Boolean, + noAutoClass: Boolean, + noFeedback: Boolean, + inputGroup: Boolean, + type: String, + name: String, + containerClass: [String, Array, Object] + }, + data() { + return { + valid: undefined, + feedback: [] + } + }, + computed: { + hasContainer() { + if (!this.bsFeedback) + return true; + if (this.containerClass) + return true; + if (this.autoContainerClass) + return true; + return false; + }, + acc() { + if (!this.containerClass) + return {}; + if (typeof this.containerClass === 'string' || this.containerClass instanceof String) + return this.containerClass.split(' ').reduce((a,c) => {a[c] = true; return a}, {}); + if (Array.isArray(this.containerClass)) + return this.containerClass.reduce((a,c) => {a[c] = true; return a}, {}); + return this.containerClass; + }, + autoContainerClass() { + if (this.noAutoClass) + return this.acc; + + const acc = {...this.acc}; + + if (this.inputGroup) + acc['input-group-item'] = true; + + if (this.lcType == 'radio' || this.lcType == 'checkbox') + acc['form-check'] = true; + + if (this.inputGroup && acc['form-check']) { + acc['input-group-item'] = false; + acc['form-check'] = false; + acc['input-group-text'] = true; + } + return acc; + }, + lcType() { + if (!this.type) + return 'text'; + return this.type.toLowerCase(); + }, + tag() { + switch (this.lcType) { + case 'textarea': + case 'select': + return this.lcType; + case 'datepicker': + return 'VueDatePicker'; + case 'autocomplete': + return 'PvAutocomplete'; + case 'uploadimage': + return 'UploadImage'; + case 'uploadfile': + case 'uploaddms': + return 'UploadDms'; + default: + return 'input'; + } + }, + validationClass() { + const classes = []; + if (this.valid) + classes.push('is-valid'); + else if (this.valid === false) + classes.push('is-invalid'); + + if (!this.noAutoClass) { + let c = this.$attrs.class ? this.$attrs.class.split(' ') : []; + switch (this.lcType) { + // TODO(chris): complete list! + case 'select': + if (!c.includes('form-select')) + classes.push('form-select'); + break; + case 'range': + if (!c.includes('form-range')) + classes.push('form-range'); + break; + case 'radio': + case 'checkbox': + // TODO(chris): maybe different handling? + if (!c.includes('form-check-input') && !c.includes('btn-check')) + classes.push('form-check-input'); + break; + case 'autocomplete': + case 'datepicker': + classes.push('p-0'); + classes.push('border-0'); + case 'color': + if (!c.includes('form-control-color')) + classes.push('form-control-color'); + case 'text': + case 'number': + case 'password': + case 'textarea': + if (!c.includes('form-control')) + classes.push('form-control'); + break; + } + } + + return classes; + }, + feedbackClass() { + if (!this.feedback || this.feedback === true) + return ''; + if (!this.bsFeedback) + return { + 'valid-tooltip': this.valid === true, + 'invalid-tooltip': this.valid === false + }; + return { + 'valid-feedback': this.valid === true, + 'invalid-feedback': this.valid === false + }; + }, + modelValueCmp: { + get() { + return this.$attrs.modelValue; + }, + set(v) { + this.$emit('update:modelValue', v); + } + }, + idCmp() { + let uuid = this.$attrs.id; + if (this.lcType == 'datepicker') + uuid = this.$attrs.uid; + if (!uuid && this.$attrs.label) + uuid = 'fhc-form-input'; + if (!uuid) + return undefined; + if (this.lcType == 'datepicker') + uuid = 'dp-input-' + uuid; + if (_uuid[uuid] === undefined) + _uuid[uuid] = 0; + return uuid + '-' + (_uuid[uuid]++); + } + }, + methods: { + clearValidation() { + this.valid = undefined; + this.feedback = []; + }, + setFeedback(valid, feedback) { + if (!feedback) + feedback = []; + if (!Array.isArray(feedback)) + feedback = [feedback]; + this.valid = valid; + this.feedback = feedback; + }, + _loadComponents() { + if (this.tag == 'VueDatePicker' && !this._.components.VueDatePicker) { + this._.components.VueDatePicker = Vue.defineAsyncComponent(() => import("../vueDatepicker.js.php")); + } else if (this.tag == 'PvAutocomplete' && !this._.components.PvAutocomplete) { + this._.components.PvAutocomplete = Vue.defineAsyncComponent(() => import(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/public/js/components/primevue/autocomplete/autocomplete.esm.min.js")); + } else if (this.tag == 'UploadImage' && !this._.components.UploadImage) { + this._.components.UploadImage = Vue.defineAsyncComponent(() => import("./Upload/Image.js")); + } else if (this.tag == 'UploadDms' && !this._.components.UploadDms) { + this._.components.UploadDms = Vue.defineAsyncComponent(() => import("./Upload/Dms.js")); + } + } + }, + beforeMount() { + this._loadComponents(); + }, + beforeUpdate() { + this._loadComponents(); + }, + mounted() { + if (this.$registerToForm) + this.$registerToForm(this); + }, + template: ` + + + + + + {if(v) a.push(k);return a}, []), ...($attrs['input-class-name'] ? $attrs['input-class-name'].split(' ') : [])].join(' ')" + @update:model-value="clearValidation" + > + + + + + + + + + + + + +
+ +
+
+ ` +} \ No newline at end of file diff --git a/public/js/components/Form/Upload/Dms.js b/public/js/components/Form/Upload/Dms.js new file mode 100644 index 000000000..da37a2105 --- /dev/null +++ b/public/js/components/Form/Upload/Dms.js @@ -0,0 +1,87 @@ +export default { + emits: [ + 'update:modelValue' + ], + props: { + modelValue: { + type: [ FileList, Array ], + required: true + }, + multiple: Boolean, + id: String, + name: String, + inputClass: [String, Array, Object], + noList: Boolean + }, + methods: { + stringifyFile(file) { + return JSON.stringify({ + lastModified: file.lastModified, + lastModifiedDate: file.lastModifiedDate, + name: file.name, + size: file.size, + type: file.type + }); + }, + addFiles(event) { + if (!this.multiple) + return this.$emit('update:modelValue', event.target.files); + + const dt = new DataTransfer(); + const doubles = []; + for (var file of this.modelValue) { + dt.items.add(file); + doubles.push(this.stringifyFile(file)); + } + for (var file of event.target.files) { + // NOTE(chris): deep check (with FileReader) would require an async function so we only check the basic attributes + if (doubles.indexOf(this.stringifyFile(file)) < 0) + dt.items.add(file); + } + this.$emit('update:modelValue', dt.files); + }, + removeFile(id) { + const fileToRemove = Array.from(this.modelValue)[id]; + + const dt = new DataTransfer(); + for (var file of this.modelValue) { + if (file !== fileToRemove) + dt.items.add(file); + } + this.$emit('update:modelValue', dt.files); + } + }, + watch: { + modelValue(n) { + if (n instanceof FileList) + return this.$refs.upload.files = n; + + const dt = new DataTransfer(); + const dms = []; + for (var file of n) { + if (file instanceof File) { + dt.items.add(file); + } else { + const dmsFile = new File([JSON.stringify(file)], file.name, { + type: 'application/x.fhc-dms+json' + }); + dt.items.add(dmsFile); + } + } + this.$emit('update:modelValue', dt.files); + } + }, + template: ` +
+ +
    +
  • + + {{ file.name }} + +
  • +
+
` +} \ No newline at end of file diff --git a/public/js/components/Form/Upload/Image.js b/public/js/components/Form/Upload/Image.js new file mode 100644 index 000000000..b0b8d5b78 --- /dev/null +++ b/public/js/components/Form/Upload/Image.js @@ -0,0 +1,62 @@ +export default { + emits: [ + 'update:modelValue' + ], + props: { + modelValue: String + }, + computed: { + valueAsBase64DataString() { + if (!this.modelValue || this.modelValue.substring(0, 10) == 'data:image') + return this.modelValue; + return 'data:image/jpeg;charset=utf-8;base64,' + this.modelValue; + } + }, + methods: { + openUploadDialog() { + this.$refs.fileInput.click(); + }, + pickFile() { + let file = this.$refs.fileInput.files; + if (file && file[0]) { + let reader = new FileReader(); + reader.onload = e => { + this.$emit('update:modelValue', e.target.result); + } + reader.readAsDataURL(file[0]); + } + }, + deleteImage() { + this.$emit('update:modelValue', ''); + } + }, + template: ` +
+ + + +
` +} \ No newline at end of file From be82d9b6cbe090227fb548f8d88020914a17575d Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Tue, 23 Jan 2024 09:32:26 +0100 Subject: [PATCH 09/66] Tabs Component update --- public/js/components/Tabs.js | 90 ++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 24 deletions(-) diff --git a/public/js/components/Tabs.js b/public/js/components/Tabs.js index 84104b812..fed6957a0 100644 --- a/public/js/components/Tabs.js +++ b/public/js/components/Tabs.js @@ -6,12 +6,19 @@ export default { accessibility }, emits: [ - 'update:modelValue' + 'update:modelValue', + 'change', + 'changed' ], props: { - configUrl: String, + // TODO(chris): rename to config? + config: { + type: [String, Object], + required: true + }, default: String, - modelValue: [String, Number, Boolean, Array, Object, Date, Function, Symbol] + modelValue: [String, Number, Boolean, Array, Object, Date, Function, Symbol], + vertical: Boolean }, data() { return { @@ -35,50 +42,85 @@ export default { } } }, - created() { - CoreRESTClient - .get(this.configUrl) - .then(result => CoreRESTClient.getData(result.data)) - .then(result => { - const tabs = {}; - // TODO(chris): check if result is array - Object.entries(result).forEach(([key, config]) => { - if (!config.component) + watch: { + config(n) { + this.initConfig(n); + } + }, + methods: { + change(key) { + this.$emit("change", key) + this.current = key; + this.$nextTick(() => this.$emit("changed", key)); + }, + initConfig(config) { + if (!config) + return; + if (typeof config === 'string' || config instanceof String) + return CoreRESTClient.get(config) + .then(result => CoreRESTClient.getData(result.data)) + .then(this.initConfig) + .catch(this.$fhcAlert.handleSystemError); + + console.log(config); + const tabs = {}; + + if (Array.isArray(config)) { + config.forEach((item, key) => { + if (!item.component) return console.error('Component missing for ' + key); tabs[key] = { - component: Vue.markRaw(Vue.defineAsyncComponent(() => import(config.component))), - title: config.title || key, - config: config.config, + component: Vue.markRaw(Vue.defineAsyncComponent(() => import(item.component))), + title: item.title || key, + config: item.config, key } }); + } else { + Object.entries(config).forEach(([key, item]) => { + if (!item.component) + return console.error('Component missing for ' + key); + + tabs[key] = { + component: Vue.markRaw(Vue.defineAsyncComponent(() => import(item.component))), + title: item.title || key, + config: item.config, + key + } + }); + } + + if (this.current === null || !tabs[this.current]) { if (tabs[this.default]) this.current = this.default; else this.current = Object.keys(tabs)[0]; - this.tabs = tabs; - }) - .catch(this.$fhcAlert.handleSystemError); + } + this.tabs = tabs; + } + }, + created() { + this.initConfig(this.config); }, template: ` -
-