. */ 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([ 'ContentID' => self::PERM_LOGGED, 'getOrtKurzbzContent' => self::PERM_LOGGED, 'getRooms' => self::PERM_LOGGED, 'getTypes' => self::PERM_LOGGED ]); $this->load->model('ressource/Ort_model', 'OrtModel'); } //------------------------------------------------------------------------------------------------------------------ // Public methods /** * Retrieves all Ort entries filtered by the provided parameters */ public function getRooms() { // TODO: form validation $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/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= ?"; } $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]); $result = $this->OrtModel->execReadOnlyQuery($qry, $params); $this->terminateWithSuccess($result); } public function getTypes() { $this->load->model('ressource/Raumtyp_model', 'RaumtypModel'); $result = $this->OrtModel->execReadOnlyQuery(" SELECT * FROM public.tbl_raumtyp WHERE aktiv = true ORDER BY raumtyp_kurzbz; "); $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); } }