mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
Noten manuell ändern
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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: `
|
||||
<div class="stv-details-noten-zeugnis h-100 d-flex flex-column">
|
||||
<div v-if="!validStudent">Kein Student</div>
|
||||
@@ -67,6 +79,9 @@ export default {
|
||||
:side-menu="false"
|
||||
reload
|
||||
>
|
||||
<template #actions="{selected}">
|
||||
<zeugnis-actions :selected="selected" @set-grades="setGrades"></zeugnis-actions>
|
||||
</template>
|
||||
</core-filter-cmpt>
|
||||
</div>`
|
||||
};
|
||||
@@ -0,0 +1,54 @@
|
||||
import {CoreRESTClient} from '../../../../../../RESTClient.js';
|
||||
|
||||
export default {
|
||||
emits: [
|
||||
'setGrades'
|
||||
],
|
||||
props: {
|
||||
selected: Array
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
grades: []
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
current: {
|
||||
get() {
|
||||
if (!this.selected.length)
|
||||
return '';
|
||||
if (this.selected.length == 1)
|
||||
return this.selected[0].note;
|
||||
const grades = Object.keys(this.selected.reduce((a,c) => {
|
||||
a[c.note] = true;
|
||||
return a;
|
||||
}, {}));
|
||||
if (grades.length == 1)
|
||||
return grades[0];
|
||||
return '';
|
||||
},
|
||||
set(note) {
|
||||
this.$emit('setGrades', this.selected.map(zeugnis => {
|
||||
const { lehrveranstaltung_id, uid: student_uid, studiensemester_kurzbz } = zeugnis;
|
||||
return { lehrveranstaltung_id, student_uid, studiensemester_kurzbz, note };
|
||||
}));
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
CoreRESTClient
|
||||
.get('components/stv/Noten/get')
|
||||
.then(result => result.data)
|
||||
.then(result => {
|
||||
this.grades = result.retval;
|
||||
})
|
||||
.catch(this.$fhcAlert.handleSystemError);
|
||||
},
|
||||
template: `
|
||||
<div class="stv-details-noten-zeugnis-actions">
|
||||
<select class="form-select" v-model="current" :disabled="!selected.length">
|
||||
<option value="" disabled>Note setzen</option>
|
||||
<option v-for="grade in grades" :key="grade.note" :value="grade.note">{{ grade.bezeichnung }}</option>
|
||||
</select>
|
||||
</div>`
|
||||
};
|
||||
Reference in New Issue
Block a user