From e4151e09057a3f35cb602b852336c7f393202684 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 17 Mar 2017 11:54:02 +0100 Subject: [PATCH] First version of the VileSci interface that allows easily to add more prestudent to a group or change their stufe --- application/controllers/system/Users.php | 164 ++++++++++++++++ application/models/crm/Prestudent_model.php | 16 ++ .../models/crm/Prestudentstatus_model.php | 17 ++ application/views/system/users.php | 120 ++++++++++++ application/views/widgets/usersfilters.php | 103 ++++++++++ application/widgets/Usersfilters_widget.php | 183 ++++++++++++++++++ 6 files changed, 603 insertions(+) create mode 100644 application/controllers/system/Users.php create mode 100644 application/views/system/users.php create mode 100644 application/views/widgets/usersfilters.php create mode 100644 application/widgets/Usersfilters_widget.php diff --git a/application/controllers/system/Users.php b/application/controllers/system/Users.php new file mode 100644 index 000000000..e170671c2 --- /dev/null +++ b/application/controllers/system/Users.php @@ -0,0 +1,164 @@ +load->helper('message'); + + // Load the library to use the widgets + $this->load->library('TemplateLib'); + } + + public function index() + { + $studiengang = $this->input->post('studiengang'); + $studiensemester = $this->input->post('studiensemester'); + $gruppe = $this->input->post('gruppe'); + $reihungstest = $this->input->post('reihungstest'); + $stufe = $this->input->post('stufe'); + + $returnUsers = null; + if ($studiengang != null || $studiensemester != null || $gruppe!= null + || $reihungstest != null || $stufe != null) + { + $returnUsers = $this->_getUsers($studiengang, $studiensemester, $gruppe, $reihungstest, $stufe); + } + + $users = null; + if (hasData($returnUsers)) + { + $users = $returnUsers->retval; + } + + $viewData = array( + 'studiengang' => $studiengang, + 'studiensemester' => $studiensemester, + 'gruppe' => $gruppe, + 'reihungstest' => $reihungstest, + 'stufe' => $stufe, + 'users' => $users + ); + + $this->load->view('system/users', $viewData); + } + + public function linkToStufe() + { + $prestudentIdArray = $this->input->post('prestudent_id'); + $stufe = $this->input->post('stufe'); + + // Load model PrestudentstatusModel + $this->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); + + $result = $this->PrestudentstatusModel->updateStufe($prestudentIdArray, $stufe); + + if (isSuccess($result)) + { + echo "Tutto ok!"; + } + else + { + echo "Kaputt!"; + } + } + + public function linkToAufnahmegruppe() + { + $prestudentIdArray = $this->input->post('prestudent_id'); + $aufnahmegruppe = $this->input->post('aufnahmegruppe'); + + // Load model PrestudentstatusModel + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + + $result = $this->PrestudentModel->updateAufnahmegruppe($prestudentIdArray, $aufnahmegruppe); + + if (isSuccess($result)) + { + echo "Tutto ok!"; + } + else + { + echo "Kaputt!"; + } + } + + private function _getUsers($studiengang, $studiensemester, $gruppe, $reihungstest, $stufe) + { + // Load model prestudentm_model + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + + $this->PrestudentModel->addSelect( + 'DISTINCT ON(p.person_id, prestudent_id) p.person_id, + prestudent_id, + p.nachname, + p.vorname, + p.geschlecht, + p.gebdatum, + k.kontakt AS email, + sg.kurzbzlang, + sg.bezeichnung, + sg.orgform_kurzbz, + sgt.bezeichnung AS typ, + ps.rt_stufe, + rtp.punkte' + ); + + $this->PrestudentModel->addJoin('public.tbl_rt_person rtp', 'person_id'); + $this->PrestudentModel->addJoin('public.tbl_person p', 'person_id', 'LEFT'); + $this->PrestudentModel->addJoin( + '( + SELECT person_id, + kontakt + FROM public.tbl_kontakt + WHERE zustellung = TRUE + AND kontakttyp = \'email\' + ORDER BY kontakt_id DESC + ) k', + 'person_id', + 'LEFT' + ); + $this->PrestudentModel->addJoin('public.tbl_prestudentstatus ps', 'prestudent_id'); + $this->PrestudentModel->addJoin('lehre.tbl_studienplan s', 's.studienplan_id = ps.studienplan_id'); + $this->PrestudentModel->addJoin('lehre.tbl_studienordnung so', 'studienordnung_id'); + $this->PrestudentModel->addJoin('public.tbl_studiengang sg', 'sg.studiengang_kz = so.studiengang_kz'); + $this->PrestudentModel->addJoin('public.tbl_studiengangstyp sgt', 'typ'); + + $this->PrestudentModel->addOrder('p.person_id', 'ASC'); + $this->PrestudentModel->addOrder('prestudent_id', 'ASC'); + + $parametersArray = array('p.aktiv' => true, 'ps.status_kurzbz' => 'Interessent'); + + if ($studiengang != null && $studiengang != '-1') + { + $parametersArray['sg.studiengang_kz'] = $studiengang; + } + + if ($studiensemester != null && $studiensemester != '-1') + { + $parametersArray['ps.studiensemester_kurzbz'] = $studiensemester; + } + + if ($gruppe != null && $gruppe != '-1') + { + $parametersArray['aufnahmegruppe_kurzbz'] = $gruppe; + } + + if ($reihungstest != null && $reihungstest != '-1') + { + $parametersArray['rtp.rt_id'] = $reihungstest; + } + + if ($stufe != null && $stufe != '-1') + { + $parametersArray['ps.rt_stufe'] = $stufe; + } + + return $this->PrestudentModel->loadWhere($parametersArray); + } +} \ No newline at end of file diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index 07fccde28..a638f04fa 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -58,4 +58,20 @@ class Prestudent_model extends DB_Model return $this->execQuery($query, $parametersArray); } + + /** + * + */ + public function updateAufnahmegruppe($prestudentIdArray, $aufnahmegruppe) + { + return $this->execQuery( + 'UPDATE public.tbl_prestudent + SET aufnahmegruppe_kurzbz = ? + WHERE prestudent_id IN ?', + array( + $aufnahmegruppe, + $prestudentIdArray + ) + ); + } } \ No newline at end of file diff --git a/application/models/crm/Prestudentstatus_model.php b/application/models/crm/Prestudentstatus_model.php index 1f84ca034..48619645b 100644 --- a/application/models/crm/Prestudentstatus_model.php +++ b/application/models/crm/Prestudentstatus_model.php @@ -51,4 +51,21 @@ class Prestudentstatus_model extends DB_Model return $this->execQuery($query, $parametersArray); } + + /** + * + */ + public function updateStufe($prestudentIdArray, $stufe) + { + return $this->execQuery( + 'UPDATE public.tbl_prestudentstatus + SET rt_stufe = ? + WHERE status_kurzbz = \'Interessent\' + AND prestudent_id IN ?', + array( + $stufe, + $prestudentIdArray + ) + ); + } } \ No newline at end of file diff --git a/application/views/system/users.php b/application/views/system/users.php new file mode 100644 index 000000000..bbe65b9ac --- /dev/null +++ b/application/views/system/users.php @@ -0,0 +1,120 @@ +load->view("templates/header", array("title" => "MessageReply", "jquery" => true, "tinymce" => true)); ?> + + + +
+
+ templatelib->widget( + 'Usersfilters_widget', + array( + 'studiengang' => $studiengang, + 'studiensemester' => $studiensemester, + 'gruppe' => $gruppe, + 'reihungstest' => $reihungstest, + 'stufe' => $stufe + ) + ); + ?> +
+
+ +
+
+ Stufe: +
+
+ Gruppe: +
+ +
+
+ +
+ prestudent_id . '"> - '; + echo $user->prestudent_id . ' - '; + echo $user->vorname . ' - '; + echo $user->nachname; + echo '
'; + } + } + else + { + echo 'No data found!!!'; + } + ?> +
+
+ + + + + + + + \ No newline at end of file diff --git a/application/views/widgets/usersfilters.php b/application/views/widgets/usersfilters.php new file mode 100644 index 000000000..0a7553f8b --- /dev/null +++ b/application/views/widgets/usersfilters.php @@ -0,0 +1,103 @@ + 0) + { +?> +
+ + retval; ?>
+ +
+ +
+
+ + AND + + -> + +
+
+ AND +
+
+ + AND + +
+
\ No newline at end of file diff --git a/application/widgets/Usersfilters_widget.php b/application/widgets/Usersfilters_widget.php new file mode 100644 index 000000000..86c443ccc --- /dev/null +++ b/application/widgets/Usersfilters_widget.php @@ -0,0 +1,183 @@ +load->helper('message'); + + // Initialising properties + $this->_setProperties($args); + } + + public function display($widgetData) + { + $errors = array(); // Array containing possible errors + + // Studiengaenge + $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); + $this->StudiengangModel->addOrder('kurzbzlang'); + $studiengaenge = $this->StudiengangModel->loadWhere(array('aktiv' => true)); + if (hasData($studiengaenge)) + { + // Adding an empty element at the beginning + $emptyElement = new stdClass(); + $emptyElement->studiengang_kz = '-1'; + $emptyElement->kurzbzlang = 'Select a studiengang...'; + $emptyElement->bezeichnung = ''; + array_unshift($studiengaenge->retval, $emptyElement); + } + else + { + $errors[] = $studiengaenge; // Adding the error to the array of errors + } + + // Studiensemester + $this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel'); + $this->StudiengangModel->addSelect('studiensemester_kurzbz, studiensemester_kurzbz AS beschreibung'); + $this->StudiengangModel->addOrder('studiensemester_kurzbz', 'DESC'); + $studiensemester = $this->StudiensemesterModel->load(); + if (hasData($studiensemester)) + { + // Adding an empty element at the beginning + $emptyElement = new stdClass(); + $emptyElement->studiensemester_kurzbz = '-1'; + $emptyElement->beschreibung = 'Select a studiensemester...'; + array_unshift($studiensemester->retval, $emptyElement); + } + else + { + $errors[] = $studiensemester; // Adding the error to the array of errors + } + + // Gruppen + $this->load->model('organisation/Gruppe_model', 'GruppeModel'); + $this->GruppeModel->addOrder('beschreibung'); + $gruppen = $this->GruppeModel->loadWhere(array('aktiv' => true, 'aufnahmegruppe' => true)); + if (hasData($gruppen)) + { + // Adding an empty element at the beginning + $emptyElement = new stdClass(); + $emptyElement->gruppe_kurzbz = '-1'; + $emptyElement->beschreibung = 'Select a group...'; + array_unshift($gruppen->retval, $emptyElement); + } + else + { + $errors[] = $gruppen; // Adding the error to the array of errors + } + + // Stufe + $this->load->model('crm/Reihungstest_model', 'ReihungstestModel'); + $this->ReihungstestModel->addSelect('DISTINCT ON(stufe) stufe, stufe AS beschreibung'); + $this->ReihungstestModel->addOrder('stufe'); + $stufen = $this->ReihungstestModel->loadWhere('stufe IS NOT NULL'); + if (hasData($stufen)) + { + // Adding an empty element at the beginning + $emptyElement = new stdClass(); + $emptyElement->stufe = '-1'; + $emptyElement->beschreibung = 'Select a stufe...'; + array_unshift($stufen->retval, $emptyElement); + } + else + { + $errors[] = $stufen; // Adding the error to the array of errors + } + + // Reihungstest + $reihungstest = success(array()); // default value empty array + // If the parameters studiengang or studiensemester are given and are not empty + if (($this->studiengang != null && !empty($this->studiengang)) + || ($this->studiensemester != null && !empty($this->studiensemester))) + { + $this->ReihungstestModel->resetQuery(); // cleans any previous setting + $this->ReihungstestModel->addSelect('reihungstest_id, concat(datum, \' \', uhrzeit, \' \', anmerkung) AS beschreibung'); + $this->ReihungstestModel->addOrder('datum', 'DESC'); + + $parametersArray = array(); + if ($this->studiengang != null) + { + $parametersArray['studiengang_kz'] = $this->studiengang; + } + if ($this->studiensemester != null) + { + $parametersArray['studiensemester_kurzbz'] = $this->studiensemester; + } + + $reihungstest = $this->ReihungstestModel->loadWhere($parametersArray); + if (isError($reihungstest)) + { + $errors[] = $reihungstest; // Adding the error to the array of errors + } + } + + if (!isError($reihungstest)) + { + // Adding an empty element at the beginning + $emptyElement = new stdClass(); + $emptyElement->reihungstest_id = '-1'; + $emptyElement->beschreibung = 'Select a reihungstest...'; + array_unshift($reihungstest->retval, $emptyElement); + } + + // Data to be used in the widget view + $viewData = array( + 'studiengaenge' => $studiengaenge->retval, + 'studiensemester' => $studiensemester->retval, + 'gruppen' => $gruppen->retval, + 'stufen' => $stufen->retval, + 'reihungstest' => $reihungstest->retval, + 'errors' => $errors, + 'selectedStudiengang' => $this->studiengang, + 'selectedStudiensemester' => $this->studiensemester, + 'selectedGruppe' => $this->gruppe, + 'selectedReihungstest' => $this->reihungstest, + 'selectedStufe' => $this->stufe + ); + + // Loads widget view + $this->view('widgets/usersfilters', $viewData); + } + + /** + * Initialising properties + */ + private function _setProperties($args) + { + if (isset($args) && is_array($args)) + { + if (isset($args['studiengang']) && $args['studiengang'] != '-1') + { + $this->studiengang = $args['studiengang']; + } + if (isset($args['studiensemester']) && $args['studiensemester'] != '-1') + { + $this->studiensemester = $args['studiensemester']; + } + if (isset($args['gruppe']) && $args['gruppe'] != '-1') + { + $this->gruppe = $args['gruppe']; + } + if (isset($args['reihungstest']) && $args['reihungstest'] != '-1') + { + $this->reihungstest = $args['reihungstest']; + } + if (isset($args['stufe']) && $args['stufe'] != '-1') + { + $this->stufe = $args['stufe']; + } + } + } +} \ No newline at end of file