. */ if (! defined('BASEPATH')) exit('No direct script access allowed'); class Ampeln extends FHCAPI_Controller { /** * Object initialization */ public function __construct() { parent::__construct([ 'open' => self::PERM_LOGGED, 'all' => self::PERM_LOGGED, 'confirm' => self::PERM_LOGGED, 'alleAmpeln' => self::PERM_LOGGED, ]); $this->load->model('content/Ampel_model', 'AmpelModel'); $this->load->model('system/Sprache_model','SpracheModel'); $this->uid = getAuthUID(); $this->pid = getAuthPersonID(); } //------------------------------------------------------------------------------------------------------------------ // Public methods /** * confirms ampel and inserts ampel_id in public.tbl_ampel_benutzer_bestaetigt * @access public * */ public function confirm($ampel_id) { $this->load->library('form_validation'); $this->form_validation->set_data(['ampel_id'=> $ampel_id]); $this->form_validation->set_rules('ampel_id', 'Ampel ID', 'required|integer'); if($this->form_validation->run() == FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array()); $insert_into_result = $this->AmpelModel->confirmAmpel($ampel_id,$this->uid); $insert_into_result = $this->getDataOrTerminateWithError($insert_into_result); $this->terminateWithSuccess($insert_into_result); } /** * queries active and not confirmed ampeln by the user * @access public * */ public function open() { $userAmpeln = array(); // fetch active ampeln $activeAmpeln = $this->AmpelModel->active(); $activeAmpeln = $this->getDataOrTerminateWithError($activeAmpeln); foreach($activeAmpeln as $ampel){ // check if ampel is confirmed by user $confirmedByUser = $this->AmpelModel->isConfirmed($ampel->ampel_id,$this->uid); $ampel->bestaetigt = $confirmedByUser; // only include non confirmed active ampeln in the result if(!$confirmedByUser){ // check if the user was assigned to the ampel $zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select); $zugeteilt = $this->getDataOrTerminateWithError($zugeteilt); if($zugeteilt) $userAmpeln[] = $ampel; } } $this->terminateWithSuccess($userAmpeln); } /** * queries all ampeln of the user * @access public * */ public function all() { $userAmpeln = array(); $ampel_result = $this->AmpelModel->active(); $ampel_result = $this->getDataOrTerminateWithError($ampel_result); foreach($ampel_result as $ampel){ $confirmedByUser = $this->AmpelModel->isConfirmed($ampel->ampel_id,$this->uid); $ampel->bestaetigt = $confirmedByUser; // check if the ampel was assigned to the user $zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select); $zugeteilt = $this->getDataOrTerminateWithError($zugeteilt); if($zugeteilt) $userAmpeln[] = $ampel; } $this->terminateWithSuccess($userAmpeln); } /** * queries all ampeln that were assigned to the user until start of first work day * @access public * */ public function alleAmpeln(){ //fetch all ampeln $alle_ampeln = $this->AmpelModel->alleAmpeln($this->uid); $alle_ampeln = $this->getDataOrTerminateWithError($alle_ampeln); $alle_ampeln = array_map(function($ampel){ // check if ampel is confirmed by user $confirmedByUser = $this->AmpelModel->isConfirmed($ampel->ampel_id,$this->uid); $ampel->bestaetigt = $confirmedByUser; return $ampel; }, $alle_ampeln); $this->terminateWithSuccess($alle_ampeln); } }