mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 12:19:28 +00:00
use fhcApi for grades tab
This commit is contained in:
+76
-44
@@ -1,36 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2024 fhcomplete.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Noten extends Auth_Controller
|
||||
/**
|
||||
* This controller operates between (interface) the JS (GUI) and the back-end
|
||||
* Provides data to the ajax get calls about grades
|
||||
* This controller works with JSON calls on the HTTP GET or POST and the output is always JSON
|
||||
*/
|
||||
class Grades extends FHCAPI_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct([
|
||||
'get' => 'student/noten:r',
|
||||
'getZeugnis' => 'student/noten:r',
|
||||
'update' => ['admin:w', 'assistenz:w']
|
||||
'list' => 'student/noten:r',
|
||||
'getCertificate' => 'student/noten:r',
|
||||
'updateCertificate' => ['admin:w', 'assistenz:w'],
|
||||
'getGradeFromPoints' => 'student/noten:r'
|
||||
]);
|
||||
|
||||
// Load Libraries
|
||||
$this->load->library('VariableLib', ['uid' => getAuthUID()]);
|
||||
}
|
||||
|
||||
public function get()
|
||||
public function list()
|
||||
{
|
||||
$this->load->model('codex/Note_model', 'NoteModel');
|
||||
|
||||
$result = $this->NoteModel->addOrder('note');
|
||||
$this->NoteModel->addOrder('note');
|
||||
|
||||
$result = $this->NoteModel->load();
|
||||
if (isError($result)) {
|
||||
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
$grades = $this->getDataOrTerminateWithError($result);
|
||||
|
||||
return $this->outputJson($result);
|
||||
$this->terminateWithSuccess($grades);
|
||||
}
|
||||
|
||||
public function getZeugnis($prestudent_id, $all = null)
|
||||
public function getCertificate($prestudent_id, $all = null)
|
||||
{
|
||||
$this->load->model('crm/Student_model', 'StudentModel');
|
||||
$this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel');
|
||||
@@ -38,26 +59,25 @@ class Noten extends Auth_Controller
|
||||
$result = $this->StudentModel->loadWhere([
|
||||
'prestudent_id' => $prestudent_id
|
||||
]);
|
||||
if (isError($result)) {
|
||||
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
|
||||
return $this->outputJson($result);
|
||||
}
|
||||
if (!hasData($result))
|
||||
return $this->outputJsonSuccess(null);
|
||||
|
||||
$student = $this->getDataOrTerminateWithError($result);
|
||||
if (!$student)
|
||||
$this->terminateWithSuccess([]);
|
||||
|
||||
$student_uid = current(getData($result))->student_uid;
|
||||
|
||||
$student_uid = current($student)->student_uid;
|
||||
|
||||
$studiensemester_kurzbz = ($all === null) ? $this->variablelib->getVar('semester_aktuell') : null;
|
||||
|
||||
$result = $this->ZeugnisnoteModel->getZeugnisnoten($student_uid, $studiensemester_kurzbz);
|
||||
if (isError($result)) {
|
||||
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
return $this->outputJson($result);
|
||||
$result = $this->ZeugnisnoteModel->getZeugnisnoten($student_uid, $studiensemester_kurzbz);
|
||||
|
||||
$grades = $this->getDataOrTerminateWithError($result);
|
||||
|
||||
$this->terminateWithSuccess($grades);
|
||||
}
|
||||
|
||||
public function update()
|
||||
public function updateCertificate()
|
||||
{
|
||||
$this->load->model('crm/Student_model', 'StudentModel');
|
||||
$this->load->model('organisation/Studienplan_model', 'StudienplanModel');
|
||||
@@ -66,13 +86,10 @@ class Noten extends Auth_Controller
|
||||
|
||||
$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->terminateWithError(getError($result), self::ERROR_TYPE_AUTH, REST_Controller::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
$this->form_validation->set_rules('lehrveranstaltung_id', 'Lehrverantaltung ID', 'required|numeric');
|
||||
@@ -86,8 +103,7 @@ class Noten extends Auth_Controller
|
||||
$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->terminateWithError(getError($result), self::ERROR_TYPE_AUTH, REST_Controller::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
$this->form_validation->set_rules($i . '[lehrveranstaltung_id]', '#' . $i . ' Lehrverantaltung ID', 'required|numeric');
|
||||
@@ -97,13 +113,11 @@ class Noten extends Auth_Controller
|
||||
}
|
||||
$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());
|
||||
}
|
||||
if (!$this->form_validation->run())
|
||||
$this->terminateWithValidationErrors($this->form_validation->error_array());
|
||||
|
||||
$final_result = success();
|
||||
$this->ZeugnisnoteModel->db->trans_start();
|
||||
$authUID = getAuthUID();
|
||||
|
||||
foreach ($post as $i => $data) {
|
||||
$note = $data['note'];
|
||||
@@ -112,21 +126,39 @@ class Noten extends Auth_Controller
|
||||
'note' => $note,
|
||||
'benotungsdatum' => date('c'),
|
||||
'updateamum' => date('c'),
|
||||
'updatevon' => getAuthUID()
|
||||
'updatevon' => $authUID
|
||||
]);
|
||||
if (isError($result)) {
|
||||
$final_result = $result;
|
||||
break;
|
||||
}
|
||||
$this->getDataOrTerminateWithError($result);
|
||||
}
|
||||
|
||||
$this->ZeugnisnoteModel->db->trans_complete();
|
||||
|
||||
if (isError($final_result)) {
|
||||
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
$this->terminateWithSuccess(true);
|
||||
}
|
||||
|
||||
$this->outputJson($final_result);
|
||||
public function getGradeFromPoints()
|
||||
{
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$this->form_validation->set_rules("lehrveranstaltung_id", "Lehrverantaltung ID", "required|integer"); // TODO(chris): phrase
|
||||
$this->form_validation->set_rules("points", "Punkte", "required|numeric"); // TODO(chris): phrase
|
||||
|
||||
if (!$this->form_validation->run())
|
||||
$this->terminateWithValidationErrors($this->form_validation->error_array());
|
||||
|
||||
$this->load->model('education/Notenschluesselaufteilung_model', 'NotenschluesselaufteilungModel');
|
||||
|
||||
$studiensemester_kurzbz = $this->variablelib->getVar('semester_aktuell');
|
||||
|
||||
$result = $this->NotenschluesselaufteilungModel->getNote(
|
||||
$this->input->post('points'),
|
||||
$this->input->post('lehrveranstaltung_id'),
|
||||
$studiensemester_kurzbz
|
||||
);
|
||||
|
||||
$note = $this->getDataOrTerminateWithError($result);
|
||||
|
||||
$this->terminateWithSuccess($note);
|
||||
}
|
||||
|
||||
protected function hasPermissionUpdate($lehrveranstaltung_id, $student_uid)
|
||||
@@ -2,12 +2,14 @@ import verband from './stv/verband.js';
|
||||
import students from './stv/students.js';
|
||||
import filter from './stv/filter.js';
|
||||
import konto from './stv/konto.js';
|
||||
import grades from './stv/grades.js';
|
||||
|
||||
export default {
|
||||
verband,
|
||||
students,
|
||||
filter,
|
||||
konto,
|
||||
grades,
|
||||
configStudent() {
|
||||
return this.$fhcApi.get('api/frontend/v1/stv/config/student');
|
||||
},
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
export default {
|
||||
list() {
|
||||
return this.$fhcApi.get('api/frontend/v1/stv/grades/list');
|
||||
},
|
||||
getCertificate(prestudent_id, all) {
|
||||
all = all ? '/all' : '';
|
||||
return this.$fhcApi.get('api/frontend/v1/stv/grades/getCertificate/' + prestudent_id + all);
|
||||
},
|
||||
updateCertificate(data) {
|
||||
return this.$fhcApi.post('api/frontend/v1/stv/grades/updateCertificate', data);
|
||||
},
|
||||
getGradeFromPoints(points) {
|
||||
return this.$fhcApi.post('api/frontend/v1/stv/grades/getGradeFromPoints', data);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import {CoreFilterCmpt} from "../../../../filter/Filter.js";
|
||||
import {CoreRESTClient} from '../../../../../RESTClient.js';
|
||||
import ZeugnisActions from './Zeugnis/Actions.js';
|
||||
|
||||
const LOCAL_STORAGE_ID = 'stv_details_noten_zeugnis_2024-01-11_stdsem_all';
|
||||
@@ -20,18 +19,24 @@ export default {
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
ajaxURL() {
|
||||
return CoreRESTClient._generateRouterURI('components/stv/Noten/getZeugnis/' + this.student.prestudent_id + this.stdsem);
|
||||
},
|
||||
tabulatorOptions() {
|
||||
return {
|
||||
ajaxURL: this.ajaxURL,
|
||||
ajaxURL: 'dummy',
|
||||
ajaxRequestFunc: (url, config, params) => {
|
||||
return this.$fhcApi.factory.stv.grades.getCertificate(params.prestudent_id, params.stdsem);
|
||||
},
|
||||
ajaxParams: () => {
|
||||
return {
|
||||
prestudent_id: this.student.prestudent_id,
|
||||
stdsem: this.stdsem
|
||||
};
|
||||
},
|
||||
ajaxResponse: (url, params, response) => {
|
||||
if (!response.retval)
|
||||
if (!response.data)
|
||||
this.validStudent = false;
|
||||
else
|
||||
this.validStudent = true;
|
||||
return response.retval || [];
|
||||
return response.data || [];
|
||||
},
|
||||
columns: [
|
||||
{ field: 'zeugnis', title: 'Zeugnis', formatter: 'tickCross' },
|
||||
@@ -63,15 +68,17 @@ export default {
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
ajaxURL(n) {
|
||||
if (this.$refs.table)
|
||||
this.$refs.table.tabulator.setData(n);
|
||||
student(n) {
|
||||
this.$refs.table.reloadTable();
|
||||
},
|
||||
stdsem(n) {
|
||||
this.$refs.table.reloadTable();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
setGrades(selected) {
|
||||
CoreRESTClient
|
||||
.post('components/stv/Noten/update', selected)
|
||||
this.$fhcApi.factory
|
||||
.stv.grades.updateCertificate(selected)
|
||||
.then(this.$refs.table.reloadTable)
|
||||
.catch(this.$fhcAlert.handleFormValidation);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import {CoreRESTClient} from '../../../../../../RESTClient.js';
|
||||
|
||||
export default {
|
||||
emits: [
|
||||
'setGrades'
|
||||
@@ -36,11 +34,10 @@ export default {
|
||||
}
|
||||
},
|
||||
created() {
|
||||
CoreRESTClient
|
||||
.get('components/stv/Noten/get')
|
||||
.then(result => result.data)
|
||||
this.$fhcApi.factory
|
||||
.stv.grades.list()
|
||||
.then(result => {
|
||||
this.grades = result.retval;
|
||||
this.grades = result.data;
|
||||
})
|
||||
.catch(this.$fhcAlert.handleSystemError);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user