This commit is contained in:
SimonGschnell
2024-08-01 15:04:18 +02:00
parent 8c84a63757
commit d4e33eb1df
8 changed files with 44 additions and 113 deletions
@@ -27,20 +27,15 @@ class Ampeln extends FHCAPI_Controller
public function __construct() public function __construct()
{ {
parent::__construct([ parent::__construct([
'getNonConfirmedActiveAmpeln' => self::PERM_LOGGED, 'open' => self::PERM_LOGGED,
'getAllActiveAmpeln' => self::PERM_LOGGED, 'all' => self::PERM_LOGGED,
'getConfirmedActiveAmpeln' => self::PERM_LOGGED, 'confirm' => self::PERM_LOGGED,
'confirmAmpel' => self::PERM_LOGGED,
'alleAmpeln' => self::PERM_LOGGED, 'alleAmpeln' => self::PERM_LOGGED,
]); ]);
$this->load->model('content/Ampel_model', 'AmpelModel'); $this->load->model('content/Ampel_model', 'AmpelModel');
$this->load->model('system/Sprache_model','SpracheModel'); $this->load->model('system/Sprache_model','SpracheModel');
//? put the uid and pid inside the controller for reusability
$this->uid = getAuthUID(); $this->uid = getAuthUID();
$this->pid = getAuthPersonID(); $this->pid = getAuthPersonID();
@@ -50,22 +45,19 @@ class Ampeln extends FHCAPI_Controller
// Public methods // Public methods
/** /**
* confirms ampel and inserts ampelID in public.tbl_ampel_benutzer_bestaetigt * confirms ampel and inserts ampel_id in public.tbl_ampel_benutzer_bestaetigt
* @access public * @access public
* *
*/ */
public function confirmAmpel($ampel_id) public function confirm($ampel_id)
{ {
if(!isset($ampel_id)){ $this->load->library('form_validation');
$this->terminateWithError("missing parameter"); $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->AmpelModel->confirmAmpel($ampel_id,$this->uid);
if(isError($insert_into_result)){
$this->terminateWithError(getError($insert_into_result));
}
$insert_into_result = $this->getDataOrTerminateWithError($insert_into_result); $insert_into_result = $this->getDataOrTerminateWithError($insert_into_result);
$this->terminateWithSuccess($insert_into_result); $this->terminateWithSuccess($insert_into_result);
@@ -76,9 +68,8 @@ class Ampeln extends FHCAPI_Controller
* @access public * @access public
* *
*/ */
public function getNonConfirmedActiveAmpeln() public function open()
{ {
$userAmpeln = array(); $userAmpeln = array();
// fetch active ampeln // fetch active ampeln
@@ -98,33 +89,9 @@ class Ampeln extends FHCAPI_Controller
// check if the user was assigned to the ampel // check if the user was assigned to the ampel
$zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select); $zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select);
if(isError($zugeteilt)){ $zugeteilt = $this->getDataOrTerminateWithError($zugeteilt);
$this->addError(getError($zugeteilt));
$zugeteilt = false;
}else{
$zugeteilt = $this->getDataOrTerminateWithError($zugeteilt);
}
if($zugeteilt) $userAmpeln[] = $this->translateAmpel($ampel); if($zugeteilt) $userAmpeln[] = $this->translateAmpel($ampel);
// old way to check if an ampel was assigned to the user
/* $userUID_array = $this->AmpelModel->execBenutzerSelect($ampel->benutzer_select);
if(isError($userUID_array)){
$this->addError(getError($userUID_array));
}
$userUID_array = $this->getDataOrTerminateWithError($userUID_array);
// check if user is assigned to the ampel
foreach($userUID_array as $user_obj){
// property is called uid for students and mitarbeiter_uid for employees
$user_uid = property_exists($user_obj,"uid") ? $user_obj->uid : $user_obj->mitarbeiter_uid;
if($user_uid === $this->uid){
$userAmpeln[] = $this->translateAmpel($ampel);
}
} */
} }
} }
@@ -132,11 +99,11 @@ class Ampeln extends FHCAPI_Controller
} }
/** /**
* queries active ampeln by the user * queries all ampeln of the user
* @access public * @access public
* *
*/ */
public function getAllActiveAmpeln() public function all()
{ {
$userAmpeln = array(); $userAmpeln = array();
@@ -151,15 +118,9 @@ class Ampeln extends FHCAPI_Controller
// check if the ampel was assigned to the user // check if the ampel was assigned to the user
$zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select); $zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select);
if(isError($zugeteilt)){ $zugeteilt = $this->getDataOrTerminateWithError($zugeteilt);
$this->addError(getError($zugeteilt));
$zugeteilt = false;
}else{
$zugeteilt = $this->getDataOrTerminateWithError($zugeteilt);
}
if($zugeteilt) $userAmpeln[] = $this->translateAmpel($ampel); if($zugeteilt) $userAmpeln[] = $this->translateAmpel($ampel);
} }
$this->terminateWithSuccess($userAmpeln); $this->terminateWithSuccess($userAmpeln);
@@ -175,8 +136,6 @@ class Ampeln extends FHCAPI_Controller
//fetch all ampeln //fetch all ampeln
$alle_ampeln = $this->AmpelModel->alleAmpeln($this->uid); $alle_ampeln = $this->AmpelModel->alleAmpeln($this->uid);
if(isError($alle_ampeln)) $this->terminateWithError(getError($alle_ampeln));
$alle_ampeln = $this->getDataOrTerminateWithError($alle_ampeln); $alle_ampeln = $this->getDataOrTerminateWithError($alle_ampeln);
$alle_ampeln = array_map(function($ampel){ $alle_ampeln = array_map(function($ampel){
@@ -206,12 +165,14 @@ class Ampeln extends FHCAPI_Controller
$userLanguage = $this->SpracheModel->loadWhere(["sprache" => $userLanguage]); $userLanguage = $this->SpracheModel->loadWhere(["sprache" => $userLanguage]);
if(isError($userLanguage)) $this->terminateWithError(getError($userLanguage));
$userLanguage = $this->getDataOrTerminateWithError($userLanguage)[0]->index - 1; // why does the index start at 1? $userLanguage = $this->getDataOrTerminateWithError($userLanguage)[0]->index - 1; // why does the index start at 1?
// translate the ampel description and button text // translate the ampel description and button text
if(isset($ampel->beschreibung) && count($ampel->beschreibung)>=($userLanguage+1)) $ampel->beschreibung = $ampel->beschreibung[$userLanguage]; if(isset($ampel->beschreibung) && count($ampel->beschreibung)>=($userLanguage+1))
if(isset($ampel->buttontext) && count($ampel->buttontext)>=($userLanguage+1)) $ampel->buttontext = $ampel->buttontext[$userLanguage]; $ampel->beschreibung = $ampel->beschreibung[$userLanguage];
if(isset($ampel->buttontext) && count($ampel->buttontext)>=($userLanguage+1))
$ampel->buttontext = $ampel->buttontext[$userLanguage];
return $ampel; return $ampel;
@@ -25,6 +25,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
/** /**
* Used to create a return object, should not be used directly * Used to create a return object, should not be used directly
* @return stdClass
*/ */
function _createReturnObject($code, $error, $retval) function _createReturnObject($code, $error, $retval)
{ {
+8 -12
View File
@@ -16,7 +16,7 @@ class Ampel_model extends DB_Model
* 1. not after the deadline date * 1. not after the deadline date
* 2. not before the vorlaufszeit * 2. not before the vorlaufszeit
* @param bool $email If true, then only ampeln are retrieved that are marked to be sent by mail. * @param bool $email If true, then only ampeln are retrieved that are marked to be sent by mail.
* @return array Returns array of objects. * @return stdClass Returns array of objects.
*/ */
public function active($email = false) public function active($email = false)
{ {
@@ -52,7 +52,7 @@ class Ampel_model extends DB_Model
/** /**
* Returns all Ampel-receiver of a specific Ampel. * Returns all Ampel-receiver of a specific Ampel.
* @param string $benutzer_select SQL Statement which defines the Ampel-receiver. * @param string $benutzer_select SQL Statement which defines the Ampel-receiver.
* @return array Returns array of objects with property 'uid'. * @return stdClass Returns array of objects with property 'uid'.
*/ */
public function execBenutzerSelect($benutzer_select) public function execBenutzerSelect($benutzer_select)
{ {
@@ -102,19 +102,16 @@ class Ampel_model extends DB_Model
* confirms Ampel by the user. * confirms Ampel by the user.
* @param int $ampel_id Ampel-ID * @param int $ampel_id Ampel-ID
* @param string $uid UID * @param string $uid UID
* @return bool insert into result * @return stdClass insert into result
*/ */
public function confirmAmpel($ampel_id, $uid) public function confirmAmpel($ampel_id, $uid)
{ {
if(isset($ampel_id) && isset($uid)){ if(isset($ampel_id) && isset($uid))
return $this->execQuery(' return error("parameter were missing to execute the insert into");
INSERT INTO public.tbl_ampel_benutzer_bestaetigt (ampel_id, uid)
VALUES (?,?);', array($ampel_id, $uid));
}else{
return error("parameter were missing to execute the insert into");
}
return $this->execQuery('
INSERT INTO public.tbl_ampel_benutzer_bestaetigt (ampel_id, uid)
VALUES (?,?);', array($ampel_id, $uid));
} }
/** /**
@@ -139,7 +136,6 @@ class Ampel_model extends DB_Model
$zugeteilt = getData($zugeteilt); $zugeteilt = getData($zugeteilt);
return success(current($zugeteilt)->zugeteilt); return success(current($zugeteilt)->zugeteilt);
} }
+6 -21
View File
@@ -1,33 +1,18 @@
export default { export default {
getNonConfirmedActiveAmpeln: function () { open: function () {
return this.$fhcApi.get( return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root + `/api/frontend/v1/Ampeln/open`,{});
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/Ampeln/getNonConfirmedActiveAmpeln`,{});
}, },
getAllActiveAmpeln: function () { all: function () {
return this.$fhcApi.get( return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root + `/api/frontend/v1/Ampeln/all`,{});
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/Ampeln/getAllActiveAmpeln`,{});
}, },
confirm: function (ampel_id) {
confirmAmpel: function (ampel_id) {
return this.$fhcApi.get( return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root + `/api/frontend/v1/Ampeln/confirm/${ampel_id}`,{});
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/Ampeln/confirmAmpel/${ampel_id}`,{});
},
alleAmpeln: function () {
return this.$fhcApi.get(
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/api/frontend/v1/Ampeln/alleAmpeln`,{});
}, },
} }
+2 -3
View File
@@ -1,7 +1,6 @@
import {CoreNavigationCmpt} from '../../components/navigation/Navigation.js'; import {CoreNavigationCmpt} from '../../components/navigation/Navigation.js';
import DashboardAdmin from '../../components/Dashboard/Admin.js'; import DashboardAdmin from '../../components/Dashboard/Admin.js';
import Phrasen from "../../plugin/Phrasen.js" import Phrasen from "../../plugin/Phrasen.js";
import FhcAlert from "../../plugin/FhcAlert.js"
const app = Vue.createApp({ const app = Vue.createApp({
data: () => ({ data: () => ({
@@ -13,5 +12,5 @@ const app = Vue.createApp({
} }
}); });
app.config.unwrapInjectedRef = true; app.config.unwrapInjectedRef = true;
app.use(Phrasen).use(FhcAlert); app.use(Phrasen);
app.mount('#main'); app.mount('#main');
+1 -2
View File
@@ -1,6 +1,5 @@
import FhcDashboard from '../../components/Dashboard/Dashboard.js'; import FhcDashboard from '../../components/Dashboard/Dashboard.js';
import Phrasen from "../../plugin/Phrasen.js" import Phrasen from "../../plugin/Phrasen.js"
import FhcAlert from "../../plugin/FhcAlert.js"
const app = Vue.createApp({ const app = Vue.createApp({
data: () => ({ data: () => ({
@@ -11,5 +10,5 @@ const app = Vue.createApp({
} }
}); });
app.config.unwrapInjectedRef = true; app.config.unwrapInjectedRef = true;
app.use(Phrasen).use(FhcAlert); app.use(Phrasen);
app.mount('#content'); app.mount('#content');
+3 -13
View File
@@ -10,7 +10,6 @@ export default {
source: '', source: '',
allAmpeln:null, allAmpeln:null,
activeAmpeln:null, activeAmpeln:null,
isPhrasenLoaded: false,
}), }),
mixins: [ mixins: [
AbstractWidget AbstractWidget
@@ -52,12 +51,9 @@ export default {
default: return data; default: return data;
} }
}, },
toggleFilter(value){ toggleFilter(value){
this.filter === value ? this.filter = '' : this.filter = value; this.filter === value ? this.filter = '' : this.filter = value;
}, },
closeOffcanvasAmpeln() closeOffcanvasAmpeln()
{ {
for (let i = 0; i < this.ampelnComputed.length; i++) for (let i = 0; i < this.ampelnComputed.length; i++)
@@ -81,19 +77,17 @@ export default {
// maybe we also want to reset the source (open/alle) of the displayed ampeln // maybe we also want to reset the source (open/alle) of the displayed ampeln
}, },
async fetchNonConfirmedActiveAmpeln(){ async fetchNonConfirmedActiveAmpeln(){
await this.$fhcApi.factory.ampeln.open().then(res=>{
await this.$fhcApi.factory.ampeln.getNonConfirmedActiveAmpeln().then(res=>{
this.activeAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline)); this.activeAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline));
}); });
}, },
async fetchAllActiveAmpeln(){ async fetchAllActiveAmpeln(){
await this.$fhcApi.factory.ampeln.all().then(res=>{
await this.$fhcApi.factory.ampeln.getAllActiveAmpeln().then(res=>{
this.allAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline)); this.allAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline));
}); });
}, },
async confirm(ampelId){ async confirm(ampelId){
this.$fhcApi.factory.ampeln.confirmAmpel(ampelId) this.$fhcApi.factory.ampeln.confirm(ampelId)
.then(res => res.data) .then(res => res.data)
.then(result => { .then(result => {
this.$fhcAlert.alertSuccess(this.$p.t('ampeln','ampelBestaetigt')); this.$fhcAlert.alertSuccess(this.$p.t('ampeln','ampelBestaetigt'));
@@ -114,13 +108,9 @@ export default {
} }
}, },
created() { created() {
this.$p.loadCategory(['ampel','ui']).then(() => {
this.isPhrasenLoaded = true;
});
this.$emit('setConfig', false); this.$emit('setConfig', false);
}, },
async mounted() { async mounted() {
await this.fetchNonConfirmedActiveAmpeln(); await this.fetchNonConfirmedActiveAmpeln();
await this.fetchAllActiveAmpeln(); await this.fetchAllActiveAmpeln();
}, },
@@ -36,7 +36,7 @@ export default {
}, },
created() { created() {
this.$emit('setConfig', false); this.$emit('setConfig', false);
/* axios axios
.get(this.apiurl + '/components/Cis/Stundenplan/Stunden').then(res => { .get(this.apiurl + '/components/Cis/Stundenplan/Stunden').then(res => {
res.data.retval.forEach(std => { res.data.retval.forEach(std => {
this.stunden[std.stunde] = std; // TODO(chris): geht besser this.stunden[std.stunde] = std; // TODO(chris): geht besser
@@ -57,7 +57,7 @@ export default {
}) })
.catch(err => { console.log(err);console.error('ERROR: ', err.response.data) }); .catch(err => { console.log(err);console.error('ERROR: ', err.response.data) });
}) })
.catch(err => { console.error('ERROR: ', err.response.data) }); */ .catch(err => { console.error('ERROR: ', err.response.data) });
}, },
template: ` template: `
<div class="dashboard-widget-stundenplan d-flex flex-column h-100"> <div class="dashboard-widget-stundenplan d-flex flex-column h-100">