mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-23 18:02:18 +00:00
fixes the fetched ampeln in the ampelWidget
This commit is contained in:
@@ -78,14 +78,14 @@ class Ampeln extends FHCAPI_Controller
|
||||
*/
|
||||
public function getNonConfirmedActiveAmpeln()
|
||||
{
|
||||
|
||||
|
||||
$userAmpeln = array();
|
||||
|
||||
// fetch active ampeln
|
||||
$activeAmpeln = $this->AmpelModel->active();
|
||||
|
||||
$activeAmpeln = $this->getDataOrTerminateWithError($activeAmpeln);
|
||||
|
||||
|
||||
foreach($activeAmpeln as $ampel){
|
||||
|
||||
// check if ampel is confirmed by user
|
||||
@@ -94,22 +94,40 @@ class Ampeln extends FHCAPI_Controller
|
||||
|
||||
// only include non confirmed active ampeln in the result
|
||||
if(!$confirmedByUser){
|
||||
$userUID_array = $this->AmpelModel->execBenutzerSelect($ampel->benutzer_select);
|
||||
$userUID_array = $this->getDataOrTerminateWithError($userUID_array);
|
||||
|
||||
// check if the user was assigned to the ampel
|
||||
$zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select);
|
||||
|
||||
if(isError($zugeteilt)){
|
||||
$this->addError(getError($zugeteilt));
|
||||
$zugeteilt = false;
|
||||
}else{
|
||||
$zugeteilt = $this->getDataOrTerminateWithError($zugeteilt);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} */
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->terminateWithSuccess($userAmpeln);
|
||||
}
|
||||
|
||||
@@ -121,23 +139,27 @@ class Ampeln extends FHCAPI_Controller
|
||||
public function getAllActiveAmpeln()
|
||||
{
|
||||
$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;
|
||||
$userUID_array = $this->AmpelModel->execBenutzerSelect($ampel->benutzer_select);
|
||||
$userUID_array = $this->getDataOrTerminateWithError($userUID_array);
|
||||
foreach($userUID_array as $user_obj){
|
||||
|
||||
$user_uid = property_exists($user_obj,"uid") ? $user_obj->uid : $user_obj->mitarbeiter_uid;
|
||||
if($user_uid === $this->uid){
|
||||
$userAmpeln[] = $this->translateAmpel($ampel);
|
||||
}
|
||||
|
||||
// check if the ampel was assigned to the user
|
||||
$zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select);
|
||||
|
||||
if(isError($zugeteilt)){
|
||||
$this->addError(getError($zugeteilt));
|
||||
$zugeteilt = false;
|
||||
}else{
|
||||
$zugeteilt = $this->getDataOrTerminateWithError($zugeteilt);
|
||||
}
|
||||
|
||||
if($zugeteilt) $userAmpeln[] = $this->translateAmpel($ampel);
|
||||
|
||||
}
|
||||
|
||||
$this->terminateWithSuccess($userAmpeln);
|
||||
@@ -157,8 +179,13 @@ class Ampeln extends FHCAPI_Controller
|
||||
|
||||
$alle_ampeln = $this->getDataOrTerminateWithError($alle_ampeln);
|
||||
|
||||
// translate ampeln
|
||||
array_map(function($ampel){ return $this->translateAmpel($ampel);}, $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;
|
||||
// translate ampeln
|
||||
return $this->translateAmpel($ampel);
|
||||
}, $alle_ampeln);
|
||||
|
||||
$this->terminateWithSuccess($alle_ampeln);
|
||||
|
||||
@@ -183,8 +210,8 @@ class Ampeln extends FHCAPI_Controller
|
||||
$userLanguage = $this->getDataOrTerminateWithError($userLanguage)[0]->index - 1; // why does the index start at 1?
|
||||
|
||||
// translate the ampel description and button text
|
||||
$ampel->beschreibung = $ampel->beschreibung[$userLanguage];
|
||||
$ampel->buttontext = $ampel->buttontext[$userLanguage];
|
||||
if(isset($ampel->beschreibung) && count($ampel->beschreibung)>=($userLanguage+1)) $ampel->beschreibung = $ampel->beschreibung[$userLanguage];
|
||||
if(isset($ampel->buttontext) && count($ampel->buttontext)>=($userLanguage+1)) $ampel->buttontext = $ampel->buttontext[$userLanguage];
|
||||
|
||||
return $ampel;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
*/
|
||||
function _createReturnObject($code, $error, $retval)
|
||||
{
|
||||
|
||||
$returnObject = new stdClass();
|
||||
$returnObject->code = $code;
|
||||
$returnObject->error = $error;
|
||||
@@ -39,7 +40,7 @@ function _createReturnObject($code, $error, $retval)
|
||||
/**
|
||||
* Success
|
||||
*
|
||||
* @return array
|
||||
* @return stdClass
|
||||
*/
|
||||
function success($retval = null, $code = null)
|
||||
{
|
||||
@@ -49,7 +50,7 @@ function success($retval = null, $code = null)
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* @return array
|
||||
* @return stdClass
|
||||
*/
|
||||
function error($retval = null, $code = null)
|
||||
{
|
||||
|
||||
@@ -33,10 +33,16 @@ class Ampel_model extends DB_Model
|
||||
}
|
||||
|
||||
$query .= '(
|
||||
(NOW()<(deadline+(COALESCE(verfallszeit,0) || \' days\')::interval)::date)
|
||||
OR (verfallszeit IS NULL)
|
||||
AND (NOW()>(deadline-(COALESCE(vorlaufzeit,0) || \' days\')::interval)::date)
|
||||
OR (vorlaufzeit IS NULL AND NOW() < deadline))';
|
||||
(
|
||||
(NOW()<(deadline+(COALESCE(verfallszeit,0) || \' days\')::interval)::date)
|
||||
OR (verfallszeit IS NULL)
|
||||
)
|
||||
AND
|
||||
(
|
||||
(NOW()>(deadline-(COALESCE(vorlaufzeit,0) || \' days\')::interval)::date)
|
||||
OR (vorlaufzeit IS NULL AND NOW() < deadline)
|
||||
)
|
||||
)';
|
||||
|
||||
$query .= ' ORDER BY deadline DESC';
|
||||
|
||||
@@ -92,6 +98,12 @@ class Ampel_model extends DB_Model
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* confirms Ampel by the user.
|
||||
* @param int $ampel_id Ampel-ID
|
||||
* @param string $uid UID
|
||||
* @return bool insert into result
|
||||
*/
|
||||
public function confirmAmpel($ampel_id, $uid)
|
||||
{
|
||||
if(isset($ampel_id) && isset($uid)){
|
||||
@@ -105,6 +117,33 @@ class Ampel_model extends DB_Model
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if a user is assigned to an ampel
|
||||
* @param string $uid userID
|
||||
* @param string $benutzer_select the select query which gets all the user that are assigned to an ampel
|
||||
* @return stdClass
|
||||
*/
|
||||
public function isZugeteilt($uid, $benutzer_select){
|
||||
$zugeteilt = $this->execReadOnlyQuery("
|
||||
SELECT
|
||||
CASE WHEN ? IN (".$benutzer_select.")
|
||||
THEN true
|
||||
ELSE false
|
||||
END as zugeteilt
|
||||
", [$uid]);
|
||||
|
||||
if(isError($zugeteilt)){
|
||||
return $zugeteilt;
|
||||
}
|
||||
|
||||
$zugeteilt = getData($zugeteilt);
|
||||
|
||||
return success(current($zugeteilt)->zugeteilt);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function alleAmpeln($uid){
|
||||
|
||||
@@ -125,30 +164,43 @@ class Ampel_model extends DB_Model
|
||||
if(isError($allAmpeln)) return error(getError($allAmpeln));
|
||||
|
||||
$allAmpeln = getData($allAmpeln);
|
||||
|
||||
foreach($allAmpeln as $ampel){
|
||||
|
||||
// check if the ampel is assigned to the user
|
||||
$zugeteilt = $this->execReadOnlyQuery("
|
||||
SELECT
|
||||
CASE WHEN ? IN (?)
|
||||
CASE WHEN ? IN (".$ampel->benutzer_select.")
|
||||
THEN true
|
||||
ELSE false
|
||||
END as zugeteilt
|
||||
", [$uid, $ampel->benutzer_select]);
|
||||
|
||||
if(isError($zugeteilt)) return error(getError($zugeteilt));
|
||||
", [$uid]);
|
||||
|
||||
if($zugeteilt
|
||||
// datum der Ampel liegt nicht vor der Vorlaufzeit
|
||||
&& (isset($ampel->vorlaufzeit) && !($now < strtotime('-' . $ampel->vorlaufzeit . ' day', $datum->mktime_fromdate($ampel->deadline)) ))
|
||||
// verfallszeit nicht vor dem start Datum des Benutzers abgelaufen
|
||||
&& isset($ampel->verfallszeit) && $benutzerStartDate < strtotime('+' . $ampel->verfallszeit . ' day', $datum->mktime_fromdate($ampel->deadline))
|
||||
if(isError($zugeteilt)) return error(getError($zugeteilt));
|
||||
|
||||
// verfallszeit ist abgelaufen
|
||||
//&& $now > strtotime('+' . $ampel->verfallszeit . ' day', $ampel->deadline)
|
||||
|
||||
$zugeteilt = current(getData($zugeteilt))->zugeteilt;
|
||||
|
||||
|
||||
// abgelaufen check
|
||||
// $now > strtotime('+' . $ampel->verfallszeit . ' day', $ampel->deadline)
|
||||
|
||||
if(
|
||||
// aktuelles datum liegt vor der Vorlaufzeit der Ampel
|
||||
(isset($ampel->vorlaufzeit) && $now < strtotime('-' . $ampel->vorlaufzeit . ' day', $datum->mktime_fromdate($ampel->deadline)))
|
||||
||
|
||||
// ampel ist vor Arbeitsstart abgelaufen
|
||||
(isset($ampel->verfallszeit) && $benutzerStartDate > strtotime('+' . $ampel->verfallszeit . ' day', $datum->mktime_fromdate($ampel->deadline)))
|
||||
||
|
||||
// ampel ist vor Arbeitsstart abgelaufen (verfallszeit nicht vorhanden)
|
||||
($benutzerStartDate > strtotime('+' . $ampel->verfallszeit . ' day', $datum->mktime_fromdate($ampel->deadline)))
|
||||
){
|
||||
$zugeteile_ampeln[] = $ampel;
|
||||
// continue iteration if ampel is expired before work start or shouldn't be visible yet
|
||||
continue;
|
||||
}
|
||||
|
||||
$ampel->zugeteilt = $zugeteilt;
|
||||
|
||||
if($zugeteilt) $zugeteile_ampeln[] = $ampel;
|
||||
|
||||
}
|
||||
|
||||
return success($zugeteile_ampeln);
|
||||
|
||||
Reference in New Issue
Block a user