diff --git a/application/controllers/components/stv/Noten.php b/application/controllers/components/stv/Noten.php index 6ba5863c5..dfde2892b 100644 --- a/application/controllers/components/stv/Noten.php +++ b/application/controllers/components/stv/Noten.php @@ -7,13 +7,29 @@ class Noten extends Auth_Controller public function __construct() { parent::__construct([ - 'getZeugnis' => 'student/noten:r' + 'get' => 'student/noten:r', + 'getZeugnis' => 'student/noten:r', + 'update' => ['admin:w', 'assistenz:w'] ]); // Load Libraries $this->load->library('VariableLib', ['uid' => getAuthUID()]); } + public function get() + { + $this->load->model('codex/Note_model', 'NoteModel'); + + $result = $this->NoteModel->addOrder('note'); + + $result = $this->NoteModel->load(); + if (isError($result)) { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + } + + return $this->outputJson($result); + } + public function getZeugnis($prestudent_id) { $this->load->model('crm/Student_model', 'StudentModel'); @@ -40,4 +56,113 @@ class Noten extends Auth_Controller return $this->outputJson($result); } + + public function update() + { + $this->load->model('crm/Student_model', 'StudentModel'); + $this->load->model('organisation/Studienplan_model', 'StudienplanModel'); + $this->load->model('education/Lehrveranstaltung_model', 'LehrveranstaltungModel'); + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + + $this->load->library('form_validation'); + + $_POST = json_decode(utf8_encode($this->input->raw_input_stream), true); + + if (empty($_POST) || !is_array(current($_POST))) { + $result = $this->hasPermissionUpdate($this->input->post('lehrveranstaltung_id'), $this->input->post('student_uid')); + if (isError($result)) { + $this->output->set_status_header(REST_Controller::HTTP_FORBIDDEN); + return $this->outputJson($result); + } + + $this->form_validation->set_rules('lehrveranstaltung_id', 'Lehrverantaltung ID', 'required|numeric'); + $this->form_validation->set_rules('student_uid', 'Student UID', 'required'); + $this->form_validation->set_rules('studiensemester_kurzbz', 'Studiensemester Kurzbezeichnung', 'required'); + $this->form_validation->set_rules('note', 'Note', 'required|numeric'); + $post = [$_POST]; + } else { + foreach ($_POST as $i => $data) { + $lvid = isset($data['lehrveranstaltung_id']) ? $data['lehrveranstaltung_id'] : null; + $uid = isset($data['student_uid']) ? $data['student_uid'] : null; + $result = $this->hasPermissionUpdate($lvid, $uid); + if (isError($result)) { + $this->output->set_status_header(REST_Controller::HTTP_FORBIDDEN); + return $this->outputJson($result); + } + + $this->form_validation->set_rules($i . '[lehrveranstaltung_id]', '#' . $i . ' Lehrverantaltung ID', 'required|numeric'); + $this->form_validation->set_rules($i . '[student_uid]', '#' . $i . ' Student UID', 'required'); + $this->form_validation->set_rules($i . '[studiensemester_kurzbz]', '#' . $i . ' Studiensemester Kurzbezeichnung', 'required'); + $this->form_validation->set_rules($i . '[note]', '#' . $i . ' Note', 'required|numeric'); + } + $post = $_POST; + } + if ($this->form_validation->run() == false) { + $this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST); + return $this->outputJsonError($this->form_validation->error_array()); + } + + $final_result = success(); + $this->ZeugnisnoteModel->db->trans_start(); + + foreach ($post as $i => $data) { + $note = $data['note']; + unset($data['note']); + $result = $this->ZeugnisnoteModel->update($data, [ + 'note' => $note, + 'benotungsdatum' => date('c'), + 'updateamum' => date('c'), + 'updatevon' => getAuthUID() + ]); + if (isError($result)) { + $final_result = $result; + break; + } + } + + $this->ZeugnisnoteModel->db->trans_complete(); + + if (isError($final_result)) { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + } + + $this->outputJson($final_result); + } + + protected function hasPermissionUpdate($lehrveranstaltung_id, $student_uid) + { + // TODO(chris): error phrases! + if ($lehrveranstaltung_id === null || $student_uid === null) + return success(); + $result = $this->StudentModel->load([$student_uid]); + if (isError($result)) + return $result; + if (!hasData($result)) + return error('Fehler beim Ermitteln des Studenten'); + $student = current(getData($result)); + + if ($this->permissionlib->isBerechtigt('admin', 'suid', $student->studiengang_kz)) + return success(); + if ($this->permissionlib->isBerechtigt('assistenz', 'suid', $student->studiengang_kz)) + return success(); + + $result = $this->StudienplanModel->getAllOesForLv($lehrveranstaltung_id); + if (isError($result)) + return $result; + $oes = getData($result) ?: []; + $result = $this->LehrveranstaltungModel->getStg($lehrveranstaltung_id); + if (isError($result)) + return $result; + if (hasData($result)) + $oes[] = current(getData($result)); + + foreach ($oes as $oe) { + if ($this->permissionlib->isBerechtigt('admin', 'suid', $oe->oe_kurzbz)) + return success(); + if ($this->permissionlib->isBerechtigt('assistenz', 'suid', $oe->oe_kurzbz)) + return success(); + } + + return error('Forbidden'); + } } diff --git a/application/models/education/Lehrveranstaltung_model.php b/application/models/education/Lehrveranstaltung_model.php index 1f1b90131..cefd147b9 100644 --- a/application/models/education/Lehrveranstaltung_model.php +++ b/application/models/education/Lehrveranstaltung_model.php @@ -493,4 +493,11 @@ class Lehrveranstaltung_model extends DB_Model return $this->execQuery($qry, array($student_uid)); } + + public function getStg($lehrveranstaltung_id) + { + $this->addSelect('stg.*'); + $this->addJoin('public.tbl_studiengang stg', 'studiengang_kz'); + return $this->load($lehrveranstaltung_id); + } } diff --git a/application/models/organisation/Studienplan_model.php b/application/models/organisation/Studienplan_model.php index 66ec06ba8..b68f74bd8 100644 --- a/application/models/organisation/Studienplan_model.php +++ b/application/models/organisation/Studienplan_model.php @@ -90,4 +90,17 @@ class Studienplan_model extends DB_Model 'tbl_studienplan_lehrveranstaltung.semester' => $semester )); } + + public function getAllOesForLv($lehrveranstaltung_id) + { + $this->addDistinct('oe_kurzbz'); + + $this->addJoin('lehre.tbl_studienplan_lehrveranstaltung lv', 'studienplan_id'); + $this->addJoin('lehre.tbl_studienordnung', 'studienordnung_id'); + $this->addJoin('public.tbl_studiengang', 'studiengang_kz'); + + return $this->loadWhere([ + 'lv.lehrveranstaltung_id' => $lehrveranstaltung_id + ]); + } } diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Noten/Zeugnis.js b/public/js/components/Stv/Studentenverwaltung/Details/Noten/Zeugnis.js index 8dcc52d96..95875f868 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Noten/Zeugnis.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Noten/Zeugnis.js @@ -1,9 +1,11 @@ import {CoreFilterCmpt} from "../../../../filter/Filter.js"; import {CoreRESTClient} from '../../../../../RESTClient.js'; +import ZeugnisActions from './Zeugnis/Actions.js'; export default { components: { - CoreFilterCmpt + CoreFilterCmpt, + ZeugnisActions }, props: { student: Object @@ -51,10 +53,20 @@ export default { ], layout: 'fitDataStretch', height: '100%', + selectable: true, + selectableRangeMode: 'click', persistence: true }; } }, + methods: { + setGrades(selected) { + CoreRESTClient + .post('components/stv/Noten/update', selected) + .then(this.$refs.table.reloadTable) + .catch(this.$fhcAlert.handleFormValidation); + } + }, template: `