<?php
namespace App\Controller\FrontendBundle;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use App\BackendBundle\Helper\BoPartnerHelper;
use App\BackendBundle\Helper\CompanyHelper;
use App\BackendBundle\Helper\SecurityHelper;
use App\BackendBundle\Helper\SchoolHelper;
use App\BackendBundle\Helper\SchoolClassHelper;
use App\BackendBundle\Helper\SiteTitleHelper;
use App\BackendBundle\Helper\ScoreHelper;
use App\Entity\SchoolClass;
class FrontpageController extends AbstractController {
private $em;
private $boHelper;
private $companyHelper;
private $siteTitleHelper;
private $securityHelper;
private $scoreHelper;
private $schoolHelper;
private $schoolClassHelper;
public function __construct(SiteTitleHelper $sitehelper, SecurityHelper $securityhelper, SchoolHelper $schoolhelper,
SchoolClassHelper $schoolclasshelper, ScoreHelper $scorehelper, EntityManagerInterface $em, CompanyHelper $companyHelper,
BoPartnerHelper $boPartnerHelper) {
$this->boHelper = $boPartnerHelper;
$this->companyHelper = $companyHelper;
$this->em = $em;
$this->siteTitleHelper = $sitehelper;
$this->securityHelper = $securityhelper;
$this->schoolClassHelper = $schoolclasshelper;
$this->schoolHelper = $schoolhelper;
$this->scoreHelper = $scorehelper;
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/", name="frontpage_public", defaults={"title": "Die Welt der Berufe entdecken", "description": "berufsreise.at ist die größte Online-Plattform zum Thema Berufsorientierung in Tirol. Entdecke spannende Berufe, lerne Tiroler Unternehmen, BO-Institutionen und weiterführende Schulen kennen oder begleite Tiroler Lehrlinge und Schüler*innen in deren Ausbildungen!"})
*/
public function publicAction(Request $request) {
$this->siteTitleHelper->setTitleDescription($request);
return $this->render('@frontend/public/frontpage.html.twig');
}
private function getSliderItems() {
$query = "SELECT si FROM \App\Entity\SliderItem si "
. "WHERE (si.showAfter is NULL OR CURRENT_TIMESTAMP() >= si.showAfter) AND "
. "(si.showUntil is NULL or si.showUntil >= CURRENT_TIMESTAMP()) "
. "ORDER BY si.position ASC";
/* @var $dql_query Query */
$dql_query = $this->em->createQuery($query);
$sliderItems = $dql_query->getResult();
return $sliderItems;
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/meine-berufsreise", name="frontpage_private")
*/
public function privateAction(Request $request) {
return $this->redirectToRoute('security_login_redirect');
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/bopartner", name="bopartner_default_private")
*/
public function boPartnerAction() {
$user = $this->getUser();
/* @var $profile BoPartnerProfile */
$profile = $this->boHelper->getSelectedBoPartnerProfileByUser($user);
if ($profile == null) {
throw new NotFoundHttpException();
}
$this->securityHelper->authenticateByRoles($user, array('ROLE_BOPARTNER'));
return $this->render('@frontend/private/bopartner/frontpage.html.twig', array(
'profile' => $profile
));
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/unternehmen", name="company_default_private")
*/
public function companyAction() {
$user = $this->getUser();
/* @var $companyProfile CompanyProfile */
$companyProfile = $this->companyHelper->getSelectedCompanyProfileByUser($user);
if ($companyProfile == null) {
throw new NotFoundHttpException();
}
$this->securityHelper->authenticateByRoles($user, array('ROLE_COMPANY'));
return $this->render('@frontend/private/company/frontpage.html.twig', array(
'profile' => $companyProfile
));
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/schule", name="school_default_private")
*/
public function schoolAction() {
$user = $this->getUser();
/* @var $schoolProfile SchoolProfile */
$schoolProfile = $this->schoolHelper->getSelectedSchoolProfileByUser($user);
if ($schoolProfile == null) {
throw new NotFoundHttpException();
}
$this->securityHelper->authenticateByRoles($user, array('ROLE_SECONDARY_SCHOOL'));
return $this->render('@frontend/private/school/frontpage.html.twig', array(
'profile' => $schoolProfile
));
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/schulklasse", name="school_class_default_private")
*/
public function schoolClassAction() {
$user = $this->getUser();
$this->securityHelper->authenticateByRoles($user, array('ROLE_SCHOOL_CLASS'));
$schoolClass = $this->schoolClassHelper->getSchoolClassBySchoolClassUser($user);
/* @var $schoolClass SchoolClass */
$schoolClassUser = $schoolClass->getSchoolClassUser();
$isDemoClass = false;
if ($schoolClassUser->getEmail() == "demoSchoolClass@test.test") {
$isDemoClass = true;
}
$pointsBooking = $this->scoreHelper->getSchoolClassTotalScoreByTypeID($schoolClass, 2);
$pointsPreparationAndFeedback = $this->scoreHelper->getSchoolClassTotalScoreByTypeID($schoolClass, 4);
$pointsKlickThePic = $this->scoreHelper->getSchoolClassTotalScoreByTypeID($schoolClass, 3);
$pointsKannstDuPunkten = $this->scoreHelper->getSchoolClassTotalScoreByTypeID($schoolClass, 5);
$pointsLebenslaufGame = $this->scoreHelper->getSchoolClassTotalScoreByTypeID($schoolClass, 7);
$pointsAnschreibenGame = $this->scoreHelper->getSchoolClassTotalScoreByTypeID($schoolClass, 8);
$pointsStellenanzeigeGame = $this->scoreHelper->getSchoolClassTotalScoreByTypeID($schoolClass, 9);
$pointsBewerbungsknigge = $this->scoreHelper->getSchoolClassTotalScoreByTypeID($schoolClass, 10);
$pointsAwards = $this->scoreHelper->getSchoolClassTotalScoreByTypeID($schoolClass, 11);
$startDate = new \DateTime('2021-03-08 08:00');
$endDate = new \DateTime('2021-03-28 23:59');
$pointsFilteredAllArray = $this->scoreHelper->getScoresBySchoolClassAndDateRange($schoolClass, $startDate, $endDate);
$pointsFilteredAll = 0;
foreach ($pointsFilteredAllArray as $entry) {
$pointsFilteredAll += $entry->getPoints();
}
if ($pointsBooking == null) {
$pointsBooking = 0;
}
if ($pointsPreparationAndFeedback == null) {
$pointsPreparationAndFeedback = 0;
}
if ($pointsKlickThePic == null) {
$pointsKlickThePic = 0;
}
if ($pointsKannstDuPunkten == null) {
$pointsKannstDuPunkten = 0;
}
if ($pointsLebenslaufGame == null) {
$pointsLebenslaufGame = 0;
}
if ($pointsAnschreibenGame == null) {
$pointsAnschreibenGame = 0;
}
if ($pointsStellenanzeigeGame == null) {
$pointsStellenanzeigeGame = 0;
}
if ($pointsBewerbungsknigge == null) {
$pointsBewerbungsknigge = 0;
}
if ($pointsAwards == null) {
$pointsAwards = 0;
}
return $this->render('@frontend/private/school_class/frontpage.html.twig', array(
"schoolClass" => $schoolClass,
'pointsBooking' => $pointsBooking,
'pointsPreparationAndFeedback' => $pointsPreparationAndFeedback,
'pointsKlickThePic' => $pointsKlickThePic,
'pointsKannstDuPunkten' => $pointsKannstDuPunkten,
'pointsLebenslaufGame' => $pointsLebenslaufGame,
'pointsAnschreibenGame' => $pointsAnschreibenGame,
'pointsStellenanzeigeGame' => $pointsStellenanzeigeGame,
'pointsBewerbungsknigge' => $pointsBewerbungsknigge,
'pointsAwards' => $pointsAwards,
'pointsFilteredAll' => $pointsFilteredAll,
'pointsFilteredAllStartDate' => $startDate,
'pointsFilteredAllEndDate' => $endDate,
'dateNow' => new \DateTime(),
'isDemoClass' => $isDemoClass,
));
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/niederoesterreich", name="lower_austria_default_private")
*/
public function lowerAustriaAction() {
$user = $this->getUser();
$this->securityHelper->authenticateByRoles($user, array('ROLE_LOWER_AUSTRIA_SCHOOL_CLASS'));
$schoolClass = $this->schoolClassHelper->getSchoolClassBySchoolClassUser($user);
return $this->render('@frontend/private/lower_austria/frontpage.html.twig', array(
"schoolClass" => $schoolClass,
'dateNow' => new \DateTime(),
));
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/schulklasse/bewerbungswelt", name="school_class_application_categories")
*/
public function schoolClassApplicationCategoriesAction() {
return $this->render('@frontend/private/school_class/application_categories.html.twig');
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/lehrer", name="teacher_default_private")
*/
public function teacherAction(Session $session) {
if ($session->has('redirect_appointment')) {
$appointmentID = intval($session->get('redirect_appointment'));
return $this->redirectToRoute('event_booking_view', array('appointmentId' => $appointmentID));
}
$user = $this->getUser();
$this->securityHelper->authenticateByRoles($user, array('ROLE_TEACHER'));
$school = $this->schoolHelper->getSchoolByTeacher($user);
// the mapping of the current active Teacher
$role = "";
if ($school != null) {
$schoolTeacherMapping = $this->schoolHelper->getSchoolTeacherMapping($user, $school);
if ($this->schoolHelper->hasSchoolRole('ROLE_TEACHER_BO', $schoolTeacherMapping)) {
$role = 'ROLE_TEACHER_BO';
} else {
$role = 'ROLE_TEACHER_KV';
}
}
return $this->render('@frontend/private/teacher/frontpage.html.twig', array(
'role' => $role
));
}
/**
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/direktoren", name="director_default_private")
*/
public function directorAction() {
$user = $this->getUser();
$this->securityHelper->authenticateByRoles($user, array('ROLE_DIRECTOR'));
return $this->render('@frontend/private/director/frontpage.html.twig', array());
}
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function restrictedAction() {
return $this->render('@frontend/full/frontpage.html.twig', array(
'name' => 'private frontpage'
));
}
}