mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
381 lines
11 KiB
PHP
381 lines
11 KiB
PHP
<?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');
|
|
|
|
/**
|
|
* This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end)
|
|
* Provides data to the ajax get calls about the searchbar component
|
|
* This controller works with JSON calls on the HTTP GET and the output is always JSON
|
|
*/
|
|
class Ort extends FHCAPI_Controller
|
|
{
|
|
|
|
/**
|
|
* Object initialization
|
|
*/
|
|
public function __construct()
|
|
{
|
|
// NOTE(chris): additional permission checks will be done in SearchBarLib
|
|
parent::__construct([
|
|
'getAllRooms' => self::PERM_LOGGED,
|
|
'getRooms' => self::PERM_LOGGED,
|
|
'getTypes' => self::PERM_LOGGED,
|
|
'ContentID' => self::PERM_LOGGED,
|
|
'getOrtKurzbzContent' => self::PERM_LOGGED,
|
|
'getRoom' => self::PERM_LOGGED,
|
|
'createRoom' => self::PERM_LOGGED,
|
|
'updateRoom' => self::PERM_LOGGED,
|
|
'deleteRoom' => self::PERM_LOGGED,
|
|
]);
|
|
|
|
$this->load->library('form_validation');
|
|
|
|
$this->load->model('ressource/Ort_model', 'OrtModel');
|
|
$this->config->load('raumsuche');
|
|
|
|
$this->loadPhrases([
|
|
'global',
|
|
'ui',
|
|
]);
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
// Public methods
|
|
|
|
public function getAllRooms()
|
|
{
|
|
$filter = $this->input->get('filter', TRUE);
|
|
|
|
$filterData = [];
|
|
|
|
if (isset($filter['locationId']) && $filter['locationId'] !== '') {
|
|
$filterData['standort_id'] = $filter['locationId'];
|
|
}
|
|
if (isset($filter['organizationalUnitShortCode']) && $filter['organizationalUnitShortCode'] !== '') {
|
|
$filterData['oe_kurzbz'] = $filter['organizationalUnitShortCode'];
|
|
}
|
|
if (isset($filter['buildingComponent']) && $filter['buildingComponent'] !== '') {
|
|
$filterData['gebteil'] = $filter['buildingComponent'];
|
|
}
|
|
if (isset($filter['isForTrainingProgram']) && $filter['isForTrainingProgram'] === 'true') {
|
|
$filterData['lehre'] = $filter['isForTrainingProgram'] === 'true' ? true : false;
|
|
}
|
|
if (isset($filter['isReservationNeeded']) && $filter['isReservationNeeded'] === 'true') {
|
|
$filterData['reservieren'] = $filter['isReservationNeeded'] === 'true' ? true : false;
|
|
}
|
|
if (isset($filter['isActive']) && $filter['isActive'] === 'true') {
|
|
$filterData['aktiv'] = $filter['isActive'] === 'true' ? true : false;
|
|
}
|
|
|
|
$this->OrtModel->addOrder("ort_kurzbz", "ASC");
|
|
|
|
$result = $this->OrtModel->loadWhere($filterData);
|
|
|
|
$this->terminateWithSuccess($this->getDataOrTerminateWithError($result));
|
|
}
|
|
|
|
/**
|
|
* Retrieves all Ort entries filtered by the provided parameters
|
|
*/
|
|
public function getRooms()
|
|
{
|
|
$this->load->library('form_validation');
|
|
$this->form_validation->set_data($_GET);
|
|
$this->form_validation->set_rules('datum','Datum','required');
|
|
$this->form_validation->set_rules('von','Uhrzeit Von','required|regexresponse_match[/^[0-9]{2}:[0-9]{2}$/]');
|
|
$this->form_validation->set_rules('bis','Uhrzeit Bis','required|regex_match[/^[0-9]{2}:[0-9]{2}$/]');
|
|
if($this->form_validation->run() == FALSE) {
|
|
$this->terminateWithValidationErrors($this->form_validation->error_array());
|
|
}
|
|
|
|
$datum = $this->input->get('datum', TRUE);
|
|
$von = $this->input->get('von', TRUE);
|
|
$bis = $this->input->get('bis', TRUE);
|
|
$typ = $this->input->get('typ', TRUE);
|
|
$personenanzahl = $this->input->get('personenanzahl', TRUE);
|
|
|
|
|
|
$this->load->model('ressource/Mitarbeiter_model', 'MitarbeiterModel');
|
|
$isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter(getAuthUID())->retval;
|
|
|
|
$this->load->model('ressource/Stunde_model', 'StundeModel');
|
|
$vonStunde = getData($this->StundeModel->getStundeForTime($von))[0]->stunde;
|
|
$bisStunde = getData($this->StundeModel->getStundeForTime($bis))[0]->stunde;
|
|
|
|
$params = array();
|
|
$qry = "SELECT DISTINCT tbl_ort.*
|
|
FROM public.tbl_ort JOIN public.tbl_ortraumtyp USING(ort_kurzbz)
|
|
WHERE aktiv AND lehre AND ort_kurzbz NOT LIKE '\\\\_%'";
|
|
if($typ) {
|
|
$params[] = $typ;
|
|
$qry.= "AND raumtyp_kurzbz = ?";
|
|
}
|
|
|
|
if(!$isMitarbeiter) { // students are only allowed to get a subset defined by config
|
|
$qry.= ' AND raumtyp_kurzbz IN ?';
|
|
$params[] = $this->config->item('roomtypes_student');
|
|
$this->addMeta('config', $this->config->item('roomtypes_student'));
|
|
}
|
|
|
|
$qry.= "AND (max_person>= ? OR max_person is null)";
|
|
$params[] = $personenanzahl;
|
|
|
|
$qry.=" AND ort_kurzbz NOT IN
|
|
(
|
|
SELECT ort_kurzbz FROM lehre.tbl_stundenplandev WHERE datum = ? AND stunde >= ? AND stunde <= ?
|
|
UNION
|
|
SELECT ort_kurzbz FROM campus.tbl_reservierung WHERE datum= ? AND stunde >= ? AND stunde <= ?
|
|
)
|
|
";
|
|
$params = array_merge($params, [$datum, $vonStunde, $bisStunde, $datum, $vonStunde, $bisStunde]);
|
|
// $this->addMeta('qry', $qry);
|
|
// $this->addMeta('params', $params);
|
|
$result = $this->OrtModel->execReadOnlyQuery($qry, $params);
|
|
|
|
$this->terminateWithSuccess($result);
|
|
}
|
|
|
|
public function getTypes()
|
|
{
|
|
$this->load->model('ressource/Raumtyp_model', 'RaumtypModel');
|
|
$qry = "SELECT * FROM public.tbl_raumtyp WHERE aktiv = true";
|
|
$params = array();
|
|
$this->load->model('ressource/Mitarbeiter_model', 'MitarbeiterModel');
|
|
|
|
$isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter(getAuthUID())->retval;
|
|
if(!$isMitarbeiter) { // students are only allowed to get a subset defined by config
|
|
$qry.= ' AND raumtyp_kurzbz IN ?';
|
|
$params[] = $this->config->item('roomtypes_student');
|
|
}
|
|
|
|
$qry .= " ORDER BY raumtyp_kurzbz;";
|
|
|
|
$result = $this->OrtModel->execReadOnlyQuery($qry, $params);
|
|
|
|
$this->terminateWithSuccess(getData($result));
|
|
}
|
|
|
|
/**
|
|
* Gets a JSON body via HTTP POST and provides the parameters
|
|
*/
|
|
public function ContentID()
|
|
{
|
|
// if error
|
|
//$this->terminateWithError(SearchBarLib::ERROR_WRONG_JSON, self::ERROR_TYPE_GENERAL);
|
|
|
|
$ort_kurzbz = $this->input->get('ort_kurzbz',TRUE);
|
|
|
|
if(!$ort_kurzbz){
|
|
$this->terminateWithError("missing ort_kurzbz parameter", self::ERROR_TYPE_GENERAL);
|
|
}
|
|
|
|
$result = $this->OrtModel->getContentID($ort_kurzbz);
|
|
|
|
if(isError($result)){
|
|
$this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
|
|
}
|
|
|
|
$result = hasData($result) ? current(getData($result)) : null;
|
|
|
|
$this->terminateWithSuccess($result->content_id ?? NULL);
|
|
}
|
|
|
|
/**
|
|
* @param int $version
|
|
* @param string $sprache
|
|
* @param boolean $sichtbar
|
|
*
|
|
* @return $content
|
|
*/
|
|
public function getOrtKurzbzContent($version = null, $sprache = null, $sichtbar = true)
|
|
{
|
|
$content_id = $this->input->get("content_id",TRUE);
|
|
|
|
$this->load->library('CmsLib');
|
|
|
|
$content = $this->cmslib->getContent($content_id, $version, $sprache, $sichtbar);
|
|
|
|
if (isError($content))
|
|
$this->terminateWithError(getError($content), self::ERROR_TYPE_GENERAL);
|
|
|
|
$content = hasData($content) ? getData($content) : null;
|
|
|
|
$this->terminateWithSuccess($content);
|
|
}
|
|
|
|
public function getRoom($ort_kurzbz)
|
|
{
|
|
$result = $this->OrtModel->load($ort_kurzbz);
|
|
|
|
if (isError($result)) {
|
|
$this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
|
|
}
|
|
|
|
$result = hasData($result) ? current(getData($result)) : null;
|
|
|
|
return $this->terminateWithSuccess($result);
|
|
}
|
|
|
|
public function createRoom()
|
|
{
|
|
$this->form_validation->set_rules('ort_kurzbz', 'ort_kurzbz', 'required', [
|
|
'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('ui', 'shortCode')])
|
|
]);
|
|
|
|
if($this->form_validation->run() == FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array());
|
|
|
|
$this->db->trans_start();
|
|
|
|
$result = $this->OrtModel->db->query("INSERT INTO public.tbl_ort
|
|
(
|
|
oe_kurzbz,
|
|
content_id,
|
|
standort_id,
|
|
ort_kurzbz,
|
|
bezeichnung,
|
|
planbezeichnung,
|
|
aktiv,
|
|
lehre,
|
|
reservieren,
|
|
max_person,
|
|
stockwerk,
|
|
lageplan,
|
|
dislozierung,
|
|
kosten,
|
|
ausstattung,
|
|
telefonklappe,
|
|
m2,
|
|
gebteil,
|
|
arbeitsplaetze,
|
|
insertamum,
|
|
insertvon,
|
|
updateamum,
|
|
updatevon
|
|
)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [
|
|
$this->input->post('oe_kurzbz'),
|
|
$this->input->post('contentId'),
|
|
$this->input->post('standort_id'),
|
|
$this->input->post('ort_kurzbz'),
|
|
$this->input->post('bezeichnung'),
|
|
$this->input->post('planbezeichnung'),
|
|
$this->input->post('aktiv') ? true : false,
|
|
$this->input->post('lehre') ? true : false,
|
|
$this->input->post('reservieren') ? true : false,
|
|
$this->input->post('max_person'),
|
|
$this->input->post('stockwerk'),
|
|
$this->input->post('lageplan'),
|
|
$this->input->post('dislozierung'),
|
|
$this->input->post('kosten'),
|
|
$this->input->post('ausstattung'),
|
|
$this->input->post('telefonklappe'),
|
|
$this->input->post('m2'),
|
|
$this->input->post('gebteil'),
|
|
$this->input->post('arbeitsplatze'),
|
|
date('c'),
|
|
getAuthUid(),
|
|
date('c'),
|
|
getAuthUid()
|
|
]);
|
|
|
|
$this->db->trans_complete();
|
|
|
|
|
|
return $this->terminateWithSuccess($result);
|
|
}
|
|
|
|
public function updateRoom($ort_kurzbz)
|
|
{
|
|
if (!$ort_kurzbz) {
|
|
$this->terminateWithError("missing ort_kurzbz parameter", self::ERROR_TYPE_GENERAL);
|
|
}
|
|
|
|
$this->db->trans_start();
|
|
|
|
$result = $this->OrtModel->db->query("UPDATE public.tbl_ort SET
|
|
oe_kurzbz = ?,
|
|
content_id = ?,
|
|
standort_id = ?,
|
|
bezeichnung = ?,
|
|
planbezeichnung = ?,
|
|
aktiv = ?,
|
|
lehre = ?,
|
|
reservieren = ?,
|
|
max_person = ?,
|
|
stockwerk = ?,
|
|
lageplan = ?,
|
|
dislozierung = ?,
|
|
kosten = ?,
|
|
ausstattung = ?,
|
|
telefonklappe = ?,
|
|
m2 = ?,
|
|
gebteil = ?,
|
|
arbeitsplaetze = ?,
|
|
updateamum = ?,
|
|
updatevon = ?
|
|
WHERE ort_kurzbz = ?", [
|
|
$this->input->post('oe_kurzbz'),
|
|
$this->input->post('contentId'),
|
|
$this->input->post('standort_id'),
|
|
$this->input->post('bezeichnung'),
|
|
$this->input->post('planbezeichnung'),
|
|
$this->input->post('aktiv') ? true : false,
|
|
$this->input->post('lehre') ? true : false,
|
|
$this->input->post('reservieren') ? true : false,
|
|
$this->input->post('max_person'),
|
|
$this->input->post('stockwerk'),
|
|
$this->input->post('lageplan'),
|
|
$this->input->post('dislozierung'),
|
|
$this->input->post('kosten'),
|
|
$this->input->post('ausstattung'),
|
|
$this->input->post('telefonklappe'),
|
|
$this->input->post('m2'),
|
|
$this->input->post('gebteil'),
|
|
$this->input->post('arbeitsplatze'),
|
|
date('c'),
|
|
getAuthUid(),
|
|
$ort_kurzbz
|
|
]);
|
|
|
|
$this->db->trans_complete();
|
|
|
|
|
|
return $this->terminateWithSuccess($result);
|
|
}
|
|
|
|
public function deleteRoom($ort_kurzbz)
|
|
{
|
|
|
|
$this->db->trans_start();
|
|
|
|
$result = $this->OrtModel->delete([
|
|
"ort_kurzbz" => $ort_kurzbz
|
|
]);
|
|
|
|
if (isError($result)) {
|
|
$this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL);
|
|
}
|
|
|
|
$this->db->trans_complete();
|
|
|
|
return $this->terminateWithSuccess(true);
|
|
}
|
|
}
|
|
|