mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-10-12 15:04:04 +00:00
Exposed API route for fetching lvplan calendar events
This commit is contained in:
@@ -120,6 +120,7 @@ $route['api/frontend/v1/stv/[sS]tudents/([WS]S[0-9]{4})/prestudent/(:num)'] = 'a
|
||||
$route['api/frontend/v1/stv/[sS]tudents/([WS]S[0-9]{4})/person/(:num)'] = 'api/frontend/v1/stv/Students/getPerson/$1/$2';
|
||||
|
||||
|
||||
$route['api/frontend/v1/lvplan/calendar-events'] = 'api/frontend/v1/LvPlanCalendarEvents/getCalendarData';
|
||||
$route['lvplan/caldav'] = 'LvPlanCalDAV';
|
||||
$route['lvplan/caldav/.*'] = 'LvPlanCalDAV';
|
||||
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Provides the authenticated user's LVPlan events as JSON.
|
||||
*/
|
||||
class LvPlanCalendarEvents extends FHCAPI_Controller
|
||||
{
|
||||
/**
|
||||
* Object initialization.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct([
|
||||
'getCalendarData' => self::PERM_LOGGED
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authenticated user's mapped calendar events.
|
||||
*/
|
||||
public function getCalendarData()
|
||||
{
|
||||
$this->output->set_header('Cache-Control: no-store');
|
||||
|
||||
if ($this->input->method() !== 'get')
|
||||
{
|
||||
$this->output->set_header('Allow: GET');
|
||||
$this->terminateWithError(
|
||||
'Method not allowed',
|
||||
self::ERROR_TYPE_GENERAL,
|
||||
REST_Controller::HTTP_METHOD_NOT_ALLOWED
|
||||
);
|
||||
}
|
||||
|
||||
$startDate = $this->input->get('start_date', true);
|
||||
$endDate = $this->input->get('end_date', true);
|
||||
$validationErrors = array();
|
||||
|
||||
if (!is_null($startDate) && !$this->isValidDate($startDate))
|
||||
$validationErrors['start_date'] = 'The start_date field must use the YYYY-MM-DD format.';
|
||||
|
||||
if (!is_null($endDate) && !$this->isValidDate($endDate))
|
||||
$validationErrors['end_date'] = 'The end_date field must use the YYYY-MM-DD format.';
|
||||
|
||||
if (!empty($validationErrors))
|
||||
$this->terminateWithValidationErrors($validationErrors);
|
||||
|
||||
$today = new DateTimeImmutable('today', new DateTimeZone('Europe/Vienna'));
|
||||
|
||||
if (is_null($startDate))
|
||||
$startDate = $today->modify('-14 days')->format('Y-m-d');
|
||||
|
||||
if (is_null($endDate))
|
||||
$endDate = $today->modify('+6 months')->format('Y-m-d');
|
||||
|
||||
if ($startDate > $endDate)
|
||||
{
|
||||
$this->terminateWithValidationErrors(array(
|
||||
'end_date' => 'The end_date field must be on or after start_date.'
|
||||
));
|
||||
}
|
||||
|
||||
$userUID = getAuthUID();
|
||||
$this->load->model('ressource/Mitarbeiter_model', 'MitarbeiterModel');
|
||||
$this->load->library('KalenderLib', ['uid' => $userUID]);
|
||||
|
||||
$isUserEmployeeResult = $this->MitarbeiterModel->isMitarbeiter($userUID);
|
||||
$isUserEmployee = $this->getDataOrTerminateWithError($isUserEmployeeResult);
|
||||
|
||||
if ($isUserEmployee)
|
||||
{
|
||||
$events = $this->kalenderlib->getPlanForLecturerByLecturer(
|
||||
$startDate,
|
||||
$endDate,
|
||||
$userUID
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$events = $this->kalenderlib->getPlanForStudentByStudent(
|
||||
$startDate,
|
||||
$endDate,
|
||||
$userUID
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_array($events))
|
||||
$events = array();
|
||||
|
||||
$this->terminateWithSuccess($events);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a date uses the exact YYYY-MM-DD format.
|
||||
*
|
||||
* @param mixed $date
|
||||
* @return bool
|
||||
*/
|
||||
private function isValidDate($date)
|
||||
{
|
||||
if (!is_string($date) || $date === '')
|
||||
return false;
|
||||
|
||||
$parsedDate = DateTimeImmutable::createFromFormat('!Y-m-d', $date);
|
||||
$errors = DateTimeImmutable::getLastErrors();
|
||||
|
||||
return $parsedDate !== false
|
||||
&& ($errors === false
|
||||
|| ($errors['warning_count'] === 0 && $errors['error_count'] === 0))
|
||||
&& $parsedDate->format('Y-m-d') === $date;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
node_modules
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
!.env.example
|
||||
/cypress/videos
|
||||
/cypress/screenshots
|
||||
/results
|
||||
Reference in New Issue
Block a user