mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 16:32:20 +00:00
Ferienverwaltung: added new fields Organisationseinheit, Studienplan, added new table and field ferientyp, filtering by date instead of Studiengang
This commit is contained in:
@@ -26,6 +26,8 @@ if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
*/
|
||||
class Ferien extends FHCAPI_Controller
|
||||
{
|
||||
const DEFAULT_STUDIENGANG_KZ = 0;
|
||||
|
||||
/**
|
||||
* Calls the parent's constructor and prepares libraries and phrases
|
||||
*/
|
||||
@@ -33,6 +35,10 @@ class Ferien extends FHCAPI_Controller
|
||||
{
|
||||
parent::__construct([
|
||||
'getFerien' => 'basis/ferien:r',
|
||||
'getDefaultVonBis' => 'basis/ferien:r',
|
||||
'getOe' => 'basis/ferien:r',
|
||||
'getStudienplaene' => 'basis/ferien:r',
|
||||
'getFerientypen' => 'basis/ferien:r',
|
||||
'getStg' => 'basis/ferien:r',
|
||||
'insert' => 'basis/ferien:w',
|
||||
'update' => 'basis/ferien:w',
|
||||
@@ -41,6 +47,7 @@ class Ferien extends FHCAPI_Controller
|
||||
|
||||
// Load models
|
||||
$this->load->model('organisation/Ferien_model', 'FerienModel');
|
||||
$this->load->model('organisation/Studiengang_model', 'StudiengangModel');
|
||||
|
||||
// Load language phrases
|
||||
$this->loadPhrases([
|
||||
@@ -53,25 +60,31 @@ class Ferien extends FHCAPI_Controller
|
||||
|
||||
/**
|
||||
* Get Ferien
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getFerien()
|
||||
{
|
||||
$studiengang_kz = $this->input->get('studiengang_kz');
|
||||
// TODO check input
|
||||
|
||||
$this->addMeta('stgkz', $studiengang_kz);
|
||||
$filterVonDatum = $this->input->get('filterVonDatum');
|
||||
$filterBisDatum = $this->input->get('filterBisDatum');
|
||||
|
||||
if (!isset($studiengang_kz)) $this->terminateWithSuccess([]);
|
||||
$this->FerienModel->addSelect(
|
||||
'tbl_ferien.ferien_id, tbl_ferien.bezeichnung, tbl_ferien.vondatum, tbl_ferien.bisdatum,
|
||||
plan.studienplan_id, stg.studiengang_kz, oe.oe_kurzbz, fetyp.ferientyp_kurzbz,
|
||||
oe.bezeichnung AS oe_bezeichnung, UPPER(stg.typ::varchar(1) || stg.kurzbz) AS studiengang_kuerzel,
|
||||
plan.studienplan_id, plan.bezeichnung AS studienplan_bezeichnung, fetyp.mitarbeiter AS mitarbeiterrelevant, fetyp.studierende AS studierendenrelevant,
|
||||
fetyp.lehre'
|
||||
);
|
||||
$this->FerienModel->addJoin('public.tbl_studiengang stg', 'studiengang_kz', 'LEFT');
|
||||
$this->FerienModel->addJoin('lehre.tbl_studienplan plan', 'studienplan_id', 'LEFT');
|
||||
$this->FerienModel->addJoin('public.tbl_organisationseinheit oe', 'tbl_ferien.oe_kurzbz = oe.oe_kurzbz', 'LEFT');
|
||||
$this->FerienModel->addJoin('lehre.tbl_ferientyp fetyp', 'ferientyp_kurzbz', 'LEFT');
|
||||
|
||||
//~ if (isset($studiengang_kz) && !is_numeric($studiengang_kz))
|
||||
//~ $this->terminateWithError($this->p->t('ui', 'errorMissingOrInvalidParameters', ['parameter'=> 'Studiengang']), self::ERROR_TYPE_GENERAL);
|
||||
if (isset($filterVonDatum))
|
||||
$this->FerienModel->db->where('tbl_ferien.bisdatum >=', $filterVonDatum);
|
||||
|
||||
$this->FerienModel->addSelect('tbl_ferien.*, , UPPER(typ::varchar(1) || kurzbz) AS studiengang_kuerzel');
|
||||
$this->FerienModel->addJoin('public.tbl_studiengang', 'studiengang_kz');
|
||||
|
||||
if (isset($studiengang_kz) && is_numeric($studiengang_kz))
|
||||
$this->FerienModel->db->where('studiengang_kz', $studiengang_kz);
|
||||
if (isset($filterBisDatum))
|
||||
$this->FerienModel->db->where('tbl_ferien.vondatum <=', $filterBisDatum);
|
||||
|
||||
$this->FerienModel->addOrder('vondatum', 'DESC');
|
||||
$result = $this->FerienModel->load();
|
||||
@@ -82,17 +95,39 @@ class Ferien extends FHCAPI_Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of Studiengaenge
|
||||
*
|
||||
* @return void
|
||||
* Gets default dates (from - to) for filtering Ferien.
|
||||
*/
|
||||
public function getStg()
|
||||
public function getDefaultVonBis()
|
||||
{
|
||||
$this->load->model('organisation/Studiengang_model', 'StudiengangModel');
|
||||
$defaultVonBis = ['defaultVon' => null, 'defaultBis' => null];
|
||||
|
||||
$this->StudiengangModel->addSelect(' tbl_studiengang.*, UPPER(typ::varchar(1) || kurzbz) AS kuerzel');
|
||||
$this->StudiengangModel->addOrder('typ, kurzbz');
|
||||
$result = $this->StudiengangModel->load();
|
||||
// get current Studienjahr
|
||||
$this->load->model('organisation/Studienjahr_model', 'StudienjahrModel');
|
||||
|
||||
$result = $this->StudienjahrModel->getAktOrNextStudienjahr(62);
|
||||
|
||||
if (isError($result)) $this->terminateWithError(getError($result));
|
||||
|
||||
if (hasData($result))
|
||||
{
|
||||
$studienjahr = getData($result)[0];
|
||||
$defaultVonBis['defaultVon'] = $studienjahr->beginn;
|
||||
$defaultVonBis['defaultBis'] = $studienjahr->ende;
|
||||
}
|
||||
|
||||
$this->terminateWithSuccess($defaultVonBis);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of Organisationseinheiten
|
||||
*/
|
||||
public function getOe()
|
||||
{
|
||||
$this->load->model('organisation/Organisationseinheit_model', 'OrganisationseinheitModel');
|
||||
|
||||
//$this->StudiengangModel->addSelect(' tbl_studiengang.*, UPPER(typ::varchar(1) || kurzbz) AS kuerzel');
|
||||
$this->OrganisationseinheitModel->addOrder('organisationseinheittyp_kurzbz, oe_kurzbz');
|
||||
$result = $this->OrganisationseinheitModel->loadWhere(['aktiv' => true]);
|
||||
|
||||
$data = $this->getDataOrTerminateWithError($result);
|
||||
|
||||
@@ -100,9 +135,108 @@ class Ferien extends FHCAPI_Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Ferien
|
||||
*
|
||||
* @return void
|
||||
* Get list of Studienplaene.
|
||||
* Studienplaene are returned by Organisationseinheit, von and bis datum.
|
||||
*/
|
||||
public function getStudienplaene()
|
||||
{
|
||||
// check input
|
||||
//~ $this->load->library('form_validation');
|
||||
|
||||
//~ $this->form_validation->set_rules('oe_kurzbz', 'Organisationseinheit', 'max_length[32]');
|
||||
//~ $this->form_validation->set_rules('vondatum', 'Von Datum', 'is_valid_date');
|
||||
//~ $this->form_validation->set_rules('bisdatum', 'Bis Datum', 'is_valid_date');
|
||||
|
||||
//~ if (!$this->form_validation->run())
|
||||
//~ $this->terminateWithValidationErrors($this->form_validation->error_array());
|
||||
|
||||
$oe_kurzbz = $this->input->get('oe_kurzbz');
|
||||
$vondatum = $this->input->get('vondatum');
|
||||
$bisdatum = $this->input->get('bisdatum');
|
||||
|
||||
// get Studiengang from Oe
|
||||
$result = $this->StudiengangModel->loadWhere(['oe_kurzbz' => $oe_kurzbz]);
|
||||
|
||||
|
||||
if (isError($result)) $this->terminateWithError(getError($result));
|
||||
if (!hasData($result)) $this->terminateWithSuccess([]);
|
||||
$studiengangKzArr = array_column(getData($result), 'studiengang_kz');
|
||||
|
||||
// load models
|
||||
$this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel');
|
||||
$this->load->model('organisation/Studienplan_model', 'StudienplanModel');
|
||||
|
||||
// get all Studiensemester in requested date range
|
||||
$result = $this->StudiensemesterModel->getByDateRange($vondatum, $bisdatum);
|
||||
if (isError($result)) $this->terminateWithError(getError($result));
|
||||
if (!hasData($result)) $this->terminateWithSuccess([]);
|
||||
$studiensemesterArr = array_column(getData($result), 'studiensemester_kurzbz');
|
||||
|
||||
$studienplaene = [];
|
||||
foreach ($studiengangKzArr as $studiengang_kz)
|
||||
{
|
||||
foreach ($studiensemesterArr as $studiensemester_kurzbz)
|
||||
{
|
||||
// get studienplaene for each Studiengang and Studiensemester
|
||||
$this->StudienplanModel->addDistinct("studienplan_id");
|
||||
$this->StudienplanModel->addSelect("lehre.tbl_studienplan.*");
|
||||
$this->StudienplanModel->addJoin("lehre.tbl_studienordnung", "studienordnung_id");
|
||||
$this->StudienplanModel->addJoin("lehre.tbl_studienplan_semester", "studienplan_id");
|
||||
|
||||
$whereArray = array(
|
||||
"tbl_studienplan.aktiv" => "TRUE",
|
||||
"tbl_studienordnung.studiengang_kz" => $studiengang_kz,
|
||||
"tbl_studienplan_semester.studiensemester_kurzbz" => $studiensemester_kurzbz
|
||||
);
|
||||
|
||||
$result = $this->StudienplanModel->loadWhere($whereArray);
|
||||
|
||||
//$result = $this->StudienplanModel->getStudienplaeneBySemester($studiengang_kz, $studiensemester_kurzbz);
|
||||
if (isError($result)) $this->terminateWithError(getError($result));
|
||||
if (!hasData($result)) continue;
|
||||
|
||||
foreach (getData($result) as $studienplan)
|
||||
{
|
||||
$studienplaene[$studienplan->studienplan_id] = $studienplan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->terminateWithSuccess($studienplaene);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of Ferientypen
|
||||
*/
|
||||
public function getFerientypen()
|
||||
{
|
||||
$this->load->model('organisation/Ferientyp_model', 'FerientypModel');
|
||||
|
||||
$this->FerientypModel->addOrder('ferientyp_kurzbz');
|
||||
$result = $this->FerientypModel->load();
|
||||
|
||||
$data = $this->getDataOrTerminateWithError($result);
|
||||
|
||||
$this->terminateWithSuccess($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of Studiengaenge
|
||||
*/
|
||||
public function getStg()
|
||||
{
|
||||
$this->StudiengangModel->addSelect(' tbl_studiengang.*, UPPER(typ::varchar(1) || kurzbz) AS kuerzel');
|
||||
$this->StudiengangModel->addOrder('typ, kurzbz');
|
||||
$result = $this->StudiengangModel->loadWhere(['aktiv' => true]);
|
||||
|
||||
$data = $this->getDataOrTerminateWithError($result);
|
||||
|
||||
$this->terminateWithSuccess($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add Ferien
|
||||
*/
|
||||
public function insert()
|
||||
{
|
||||
@@ -110,11 +244,15 @@ class Ferien extends FHCAPI_Controller
|
||||
|
||||
$data = $this->_getData();
|
||||
|
||||
// TODO add insertaum and updateamum?
|
||||
//~ $data = [
|
||||
//~ 'insertamum' => date('c'),
|
||||
//~ 'insertvon' => getAuthUID()
|
||||
//~ ];
|
||||
// get studiengang_kz from oe, otherwise default kz
|
||||
$this->StudiengangModel->addSelect('studiengang_kz');
|
||||
$this->StudiengangModel->addLimit(1);
|
||||
$result = $this->StudiengangModel->loadWhere(['oe_kurzbz' => $data['oe_kurzbz']]);
|
||||
|
||||
$data['studiengang_kz'] = hasData($result) ? getData($result)[0]->studiengang_kz : self::DEFAULT_STUDIENGANG_KZ;
|
||||
|
||||
$data = array_merge($data, ['insertamum' => date('c'), 'insertvon' => getAuthUID()]);
|
||||
|
||||
$id = $this->getDataOrTerminateWithError($this->FerienModel->insert($data));
|
||||
|
||||
$this->terminateWithSuccess(hasData($id) ? getData($id) : null);
|
||||
@@ -122,8 +260,6 @@ class Ferien extends FHCAPI_Controller
|
||||
|
||||
/**
|
||||
* Update Ferien
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
@@ -137,13 +273,8 @@ class Ferien extends FHCAPI_Controller
|
||||
$data = $this->_getData();
|
||||
|
||||
if (isEmptyArray($data)) $this->terminateWithSuccess(null);
|
||||
// TODO add insertaum and updateamum?
|
||||
//~ $data = [
|
||||
//~ 'updateamum' => date('c'),
|
||||
//~ 'updatevon' => getAuthUID()
|
||||
//~ ];
|
||||
|
||||
$data['ferien_id'] = $id;
|
||||
$data = array_merge($data, ['ferien_id' => $id, 'updateamum' => date('c'), 'updatevon' => getAuthUID()]);
|
||||
|
||||
$result = $this->FerienModel->update($id, $data);
|
||||
|
||||
@@ -154,8 +285,6 @@ class Ferien extends FHCAPI_Controller
|
||||
|
||||
/**
|
||||
* Delete Ferien
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
@@ -170,7 +299,6 @@ class Ferien extends FHCAPI_Controller
|
||||
|
||||
$this->FerienModel->addSelect('ferien_id');
|
||||
$result = $this->FerienModel->load($ferien_id);
|
||||
$this->addMeta('res', $result);
|
||||
|
||||
if (!hasData($result))
|
||||
$this->terminateWithError($this->p->t('ferien', 'error_missing', [
|
||||
@@ -196,8 +324,6 @@ class Ferien extends FHCAPI_Controller
|
||||
|
||||
/**
|
||||
* Validate ferien post input.
|
||||
* @param
|
||||
* @return object success or error
|
||||
*/
|
||||
private function _validate()
|
||||
{
|
||||
@@ -206,7 +332,9 @@ class Ferien extends FHCAPI_Controller
|
||||
$this->form_validation->set_rules('vondatum', 'Von Datum', 'required|is_valid_date');
|
||||
$this->form_validation->set_rules('bisdatum', 'Bis Datum', 'required|is_valid_date');
|
||||
$this->form_validation->set_rules('bezeichnung', 'Bezeichnung', 'required|max_length[128]');
|
||||
$this->form_validation->set_rules('studiengang_kz', 'Studiengang', 'required|numeric');
|
||||
$this->form_validation->set_rules('oe_kurzbz', 'Organisationseinheit', 'required|max_length[32]');
|
||||
$this->form_validation->set_rules('studienplan_id', 'Studienplan', 'numeric');
|
||||
$this->form_validation->set_rules('ferientyp_kurzbz', 'Ferientyp', 'max_length[64]');
|
||||
|
||||
//Events::trigger('konto_insert_validation', $this->form_validation);
|
||||
|
||||
@@ -216,7 +344,6 @@ class Ferien extends FHCAPI_Controller
|
||||
|
||||
/**
|
||||
* Gets Ferien data from post input.
|
||||
* @return array
|
||||
*/
|
||||
private function _getData()
|
||||
{
|
||||
@@ -226,13 +353,14 @@ class Ferien extends FHCAPI_Controller
|
||||
'vondatum',
|
||||
'bisdatum',
|
||||
'bezeichnung',
|
||||
'studiengang_kz'
|
||||
'oe_kurzbz',
|
||||
'studienplan_id',
|
||||
'ferientyp_kurzbz'
|
||||
];
|
||||
|
||||
|
||||
foreach ($allowed as $field)
|
||||
{
|
||||
if ($this->input->post($field) !== null) $data[$field] = $this->input->post($field);
|
||||
$data[$field] = $this->input->post($field);
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
Reference in New Issue
Block a user