Commit f0d08a2f authored by Francois Beaulieu's avatar Francois Beaulieu
Browse files

Initial Commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>calmsp</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.dltk.core.scriptbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
<?php
namespace MSP\Calmsp\Controller;
/***************************************************************
*
* Copyright notice
*
* (c) 2015 Maxime Demers <maxime.demers@msp.gouv.qc.ca>, Ministère de la sécurité Publique - Gouvernement du Québec
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* EventController
*/
class CalendrierController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* eventRepository
*
* @var \MSP\Calmsp\Domain\Repository\EventRepository
* @inject
*/
protected $eventRepository = NULL;
/**
* action show
*
* @param
* @return void
*/
public function showAction() {
$this->eventRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance ( "MSP\Calmsp\Domain\Repository\EventRepository" );
$events = $this->eventRepository->findAll();
$postedValue = $this->request->getArguments();
if(isset($postedValue["currentMonth"]) && isset($postedValue["currentYear"]) && isset($postedValue["todo"])){
if($postedValue["todo"] == "next"){
if($postedValue["currentMonth"] == 12){
$month = 1;
$year = $postedValue["currentYear"]+1;
}else{
$month = $postedValue["currentMonth"]+1;
$year = $postedValue["currentYear"];
}
}else{
if($postedValue["currentMonth"] == 1){
$month = 12;
$year = $postedValue["currentYear"]-1;
}else{
$month = $postedValue["currentMonth"]-1;
$year = $postedValue["currentYear"];
}
}
}else{
$month = date('n');
$year = date('Y');
}
$now = new \DateTime(date('Y-m-d'));
$now = $now->format('Ynd');
$eventsToShow = array();
foreach($events as $event){
if(($event->getDateLimite() != '' && $event->getDateLimite()->format('Ynd') > $now) || $event->getDateLimite() == ''){
if($event->getStart()->format("Ynd") == $event->getEnd()->format("Ynd") && $event->getStart()->format("n") == $month && $event->getStart()->format("Y") == $year && $event->getRepeatEvent() == "0"){
//$eventsToShow[$event->getStart()->format("d")][] = $event;
$eventTemp = array('timestamp' => $event->getStart()->getTimestamp(), 'detail' => $event);
$eventsToShow[$event->getStart()->format("d")][] = $eventTemp;
}else{
if($event->getRepeatEvent() == "0"){
//Vérifié un événement pour ce mois-ci seulement
$period = new \DatePeriod(
$event->getStart(),
new \DateInterval('P1D'),
$event->getEnd()->modify("+1 days")
);
foreach($period as $date){
if($date->format("n") == $month && $date->format("Y") == $year && (($event->getStart()->format("Y") == $year && $event->getStart()->format("n") == $month) || ($event->getEnd()->format("Y") == $year && $event->getEnd()->format("n") == $month))){
//$eventsToShow[$date->format("d")][] = $event;
$eventTemp = array('timestamp' => $date->getTimestamp(), 'detail' => $event);
$eventsToShow[$date->format("d")][] = $eventTemp;
}
}
}else{
//Vérifie si on répéte l'événement à l'infinie
if($event->getNumberOfRepeat() == 0){
//Ca ne sert à rien d'alle plus loins que le mois présent
$period = new \DatePeriod(
$event->getStart(),
new \DateInterval($event->getRepeatEvent()),
(new \DateTime($year."-".$month."-"."01"))->modify('first day of next month')//La périod est calculer entre les deux date exclusivement donc on va chercher le 1 du prochain mois
);
}else{
if($event->getDateLimite() == ''){
$period = new \DatePeriod(
$event->getStart(),
new \DateInterval($event->getRepeatEvent()),
$event->getNumberOfRepeat()-1
);
}else{
if($event->getDateLimite()->format('Ynd') > (new \DateTime($year."-".$month."-"."01"))->modify('last day of this month')->format('Ynd')){
if($event->getStart()->format('Ynd') < (new \DateTime($year."-".$month."-"."01"))->modify('first day of this month')->format('Ynd')){
$period = new \DatePeriod(
(new \DateTime($year."-".$month."-"."01"))->modify('first day of this month')->format('Ynd'),
new \DateInterval($event->getRepeatEvent()),
(new \DateTime($year."-".$month."-"."01"))->modify('first day of next month')->format('Ynd')
);
}else{
$period = new \DatePeriod(
$event->getStart(),
new \DateInterval($event->getRepeatEvent()),
(new \DateTime($year."-".$month."-"."01"))->modify('first day of next month')->format('Ynd')
);
}
}else{
if($event->getStart()->format('Ynd') < (new \DateTime($year."-".$month."-"."01"))->modify('first day of this month')->format('Ynd')){
$period = new \DatePeriod(
(new \DateTime($year."-".$month."-"."01"))->modify('first day of this month')->format('Ynd'),
new \DateInterval($event->getRepeatEvent()),
$event->getDateLimite()
);
}else{
$period = new \DatePeriod(
$event->getStart(),
new \DateInterval($event->getRepeatEvent()),
$event->getDateLimite()
);
}
}
}
}
//Pour chaque date qui est dans le mois, on rajoute à l'array à afficher
foreach($period as $date){
//La date de départ doit être dans le bon mois
if($date->format("n") == $month && $date->format("Y") == $year){
//Si l'événement de dure qu'un jour
if($event->getStart()->format("Ynd") == $event->getEnd()->format("Ynd")){
//$eventsToShow[$date->format("d")][] = $event;
$eventTemp = array('timestamp' => $date->getTimestamp(), 'detail' => $event);
$eventsToShow[$date->format("d")][] = $eventTemp;
}else{
//On calcul la durée de l'événement
//$dateDiff = abs($event->getStart() - $event->getEnd());
$end = new \DateTime($event->getEnd()->format("Y-m-d"));
$end->modify("+1 days");
$dateDiff = $event->getStart()->diff($end);
$periodTempEnd = new \DateTime($date->format("Y-m-d"));
$periodTempEnd->modify($dateDiff->format('%R%a days'));
//Obtient toutes les date qui sont pour l'événement
$periodTemp = new \DatePeriod(
$date,
new \DateInterval("P1D"),
$periodTempEnd);
foreach($periodTemp as $dateTemp){
//Si la date est dans le bon mois et année
if($dateTemp->format("n") == $month && $dateTemp->format("Y") == $year){
//$eventsToShow[$dateTemp->format("d")][] = $event;
$eventTemp = array('timestamp' => $dateTemp->getTimestamp(), 'detail' => $event);
$eventsToShow[$dateTemp->format("d")][] = $eventTemp;
}
}
}
}
}
}
}
}
}
//Générer le calendrier
$calendar = $this->draw_calendar($month,$year);
$this->view->assignMultiple(array(
'calendrier' => $calendar,
'monthNumber' => $month,
'yearNumber' => $year,
'events' => $eventsToShow
));
}
/* draws a calendar */
function draw_calendar($month,$year){
$monthArray = array("1" => "Janvier","2" => "Février","3" => "Mars","4" => "Avril","5" => "Mai","6" => "Juin","7" => "Juillet","8" => "Août","9" => "Septembre","10" => "Octobre","11" => "Novembre","12" => "Décembre");
$calendar = array();
$calendar["header"] = $this->settings["header"];
$calendar["month"] = $monthArray[$month];
$calendar["days"] = array();
/* days and weeks vars now ... */
$running_day = date('w',mktime(0,0,0,$month,1,$year));
$days_in_month = date('t',mktime(0,0,0,$month,1,$year));
$days_in_this_week = 1;
$day_counter = 0;
/* print "blank" days until the first of the current week */
for($x = 0; $x < $running_day; $x++):
$calendar["days"][]["type"] = '0';
$days_in_this_week++;
endfor;
/* keep going with days.... */
for($list_day = 1; $list_day <= $days_in_month; $list_day++):
if($running_day == 6 || $running_day == 0){
$calendar["days"][] = array("type" => "wkd", "number" => $list_day);
}else{
$calendar["days"][] = array("type" => "day", "number" => $list_day);
}
if($running_day == 6):
$running_day = -1;
$days_in_this_week = 0;
endif;
$days_in_this_week++; $running_day++; $day_counter++;
endfor;
/* finish the rest of the days in the week */
if($days_in_this_week < 8):
for($x = 1; $x <= (8 - $days_in_this_week); $x++):
$calendar["days"][]["type"] = '0';
endfor;
endif;
return $calendar;
}
}
?>
<?php
namespace MSP\Calmsp\Controller;
/***************************************************************
*
* Copyright notice
*
* (c) 2015 Maxime Demers <maxime.demers@msp.gouv.qc.ca>, Ministère de la sécurité Publique - Gouvernement du Québec
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* EventController
*/
class CalendrierController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* eventRepository
*
* @var \MSP\Calmsp\Domain\Repository\EventRepository
* @inject
*/
protected $eventRepository = NULL;
/**
* action show
*
* @param
* @return void
*/
public function showAction() {
$this->eventRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance ( "MSP\Calmsp\Domain\Repository\EventRepository" );
$events = $this->eventRepository->findAll();
$postedValue = $this->request->getArguments();
if(isset($postedValue["currentMonth"]) && isset($postedValue["currentYear"]) && isset($postedValue["todo"])){
if($postedValue["todo"] == "next"){
if($postedValue["currentMonth"] == 12){
$month = 1;
$year = $postedValue["currentYear"]+1;
}else{
$month = $postedValue["currentMonth"]+1;
$year = $postedValue["currentYear"];
}
}else{
if($postedValue["currentMonth"] == 1){
$month = 12;
$year = $postedValue["currentYear"]-1;
}else{
$month = $postedValue["currentMonth"]-1;
$year = $postedValue["currentYear"];
}
}
}else{
$month = date('n');
$year = date('Y');
}
$now = new \DateTime(date('Y-m-d'));
$now = $now->format('Ynd');
$eventsToShow = array();
foreach($events as $event){
if(($event->getDateLimite() != '' && $event->getDateLimite()->format('Ynd') > $now) || $event->getDateLimite() == ''){
if($event->getStart()->format("Ynd") == $event->getEnd()->format("Ynd") && $event->getStart()->format("n") == $month && $event->getStart()->format("Y") == $year && $event->getRepeatEvent() == "0"){
//$eventsToShow[$event->getStart()->format("d")][] = $event;
$eventTemp = array('timestamp' => $event->getStart()->getTimestamp(), 'detail' => $event);
$eventsToShow[$event->getStart()->format("d")][] = $eventTemp;
}else{
if($event->getRepeatEvent() == "0"){
//Vérifié un événement pour ce mois-ci seulement
$period = new \DatePeriod(
$event->getStart(),
new \DateInterval('P1D'),
$event->getEnd()->modify("+1 days")
);
foreach($period as $date){
if($date->format("n") == $month && $date->format("Y") == $year && (($event->getStart()->format("Y") == $year && $event->getStart()->format("n") == $month) || ($event->getEnd()->format("Y") == $year && $event->getEnd()->format("n") == $month))){
//$eventsToShow[$date->format("d")][] = $event;
$eventTemp = array('timestamp' => $date->getTimestamp(), 'detail' => $event);
$eventsToShow[$date->format("d")][] = $eventTemp;
}
}
}else{
//Vérifie si on répéte l'événement à l'infinie
if($event->getNumberOfRepeat() == 0){
//Ca ne sert à rien d'alle plus loins que le mois présent
$period = new \DatePeriod(
$event->getStart(),
new \DateInterval($event->getRepeatEvent()),
(new \DateTime($year."-".$month."-"."01"))->modify('first day of next month')//La périod est calculer entre les deux date exclusivement donc on va chercher le 1 du prochain mois
);
}else{
if($event->getDateLimite() == ''){
$period = new \DatePeriod(
$event->getStart(),
new \DateInterval($event->getRepeatEvent()),
$event->getNumberOfRepeat()-1
);
}else{
if($event->getDateLimite()->format('Ynd') > (new \DateTime($year."-".$month."-"."01"))->modify('last day of this month')->format('Ynd')){
if($event->getStart()->format('Ynd') < (new \DateTime($year."-".$month."-"."01"))->modify('first day of this month')->format('Ynd')){
$period = new \DatePeriod(
(new \DateTime($year."-".$month."-"."01"))->modify('first day of this month')->format('Ynd'),
new \DateInterval($event->getRepeatEvent()),
(new \DateTime($year."-".$month."-"."01"))->modify('first day of next month')->format('Ynd')
);
}else{
$period = new \DatePeriod(
$event->getStart(),
new \DateInterval($event->getRepeatEvent()),
(new \DateTime($year."-".$month."-"."01"))->modify('first day of next month')->format('Ynd')
);
}
}else{
if($event->getStart()->format('Ynd') < (new \DateTime($year."-".$month."-"."01"))->modify('first day of this month')->format('Ynd')){
$period = new \DatePeriod(
(new \DateTime($year."-".$month."-"."01"))->modify('first day of this month')->format('Ynd'),
new \DateInterval($event->getRepeatEvent()),
$event->getDateLimite()
);
}else{
$period = new \DatePeriod(
$event->getStart(),
new \DateInterval($event->getRepeatEvent()),
$event->getDateLimite()
);
}
}
}
}
//Pour chaque date qui est dans le mois, on rajoute à l'array à afficher
foreach($period as $date){
//echo "<pre>";
//var_dump($date);
//echo "</pre>";
//La date de départ doit être dans le bon mois
if($date->format("n") == $month && $date->format("Y") == $year){
//Si l'événement de dure qu'un jour
if($event->getStart()->format("Ynd") == $event->getEnd()->format("Ynd")){
//$eventsToShow[$date->format("d")][] = $event;
$eventTemp = array('timestamp' => $date->getTimestamp(), 'detail' => $event);
$eventsToShow[$date->format("d")][] = $eventTemp;
}else{
//On calcul la durée de l'événement
//$dateDiff = abs($event->getStart() - $event->getEnd());
$end = new \DateTime($event->getEnd()->format("Y-m-d"));
$end->modify("+1 days");
$dateDiff = $event->getStart()->diff($end);
$periodTempEnd = new \DateTime($date->format("Y-m-d"));
$periodTempEnd->modify($dateDiff->format('%R%a days'));
//Obtient toutes les date qui sont pour l'événement
$periodTemp = new \DatePeriod(
$date,
new \DateInterval("P1D"),
$periodTempEnd);
foreach($periodTemp as $dateTemp){
echo "<pre>";
var_dump($dateDiff);
echo "</pre>";
//Si la date est dans le bon mois et année
if($dateTemp->format("n") == $month && $dateTemp->format("Y") == $year){
//$eventsToShow[$dateTemp->format("d")][] = $event;
$eventTemp = array('timestamp' => $dateTemp->getTimestamp(), 'detail' => $event);
$eventsToShow[$dateTemp->format("d")][] = $eventTemp;
}
}
}
}
}
}
}
}
}
//Générer le calendrier
$calendar = $this->draw_calendar($month,$year);
$this->view->assignMultiple(array(
'calendrier' => $calendar,
'monthNumber' => $month,
'yearNumber' => $year,
'events' => $eventsToShow
));
}
/* draws a calendar */
function draw_calendar($month,$year){
$monthArray = array("1" => "Janvier","2" => "Février","3" => "Mars","4" => "Avril","5" => "Mai","6" => "Juin","7" => "Juillet","8" => "Août","9" => "Septembre","10" => "Octobre","11" => "Novembre","12" => "Décembre");
$calendar = array();
$calendar["header"] = $this->settings["header"];
$calendar["month"] = $monthArray[$month];
$calendar["days"] = array();
/* days and weeks vars now ... */
$running_day = date('w',mktime(0,0,0,$month,1,$year));
$days_in_month = date('t',mktime(0,0,0,$month,1,$year));
$days_in_this_week = 1;
$day_counter = 0;
/* print "blank" days until the first of the current week */
for($x = 0; $x < $running_day; $x++):
$calendar["days"][]["type"] = '0';
$days_in_this_week++;
endfor;
/* keep going with days.... */
for($list_day = 1; $list_day <= $days_in_month; $list_day++):
if($running_day == 6 || $running_day == 0){
$calendar["days"][] = array("type" => "wkd", "number" => $list_day);
}else{
$calendar["days"][] = array("type" => "day", "number" => $list_day);
}
if($running_day == 6):
$running_day = -1;
$days_in_this_week = 0;
endif;
$days_in_this_week++; $running_day++; $day_counter++;
endfor;
/* finish the rest of the days in the week */
if($days_in_this_week < 8):
for($x = 1; $x <= (8 - $days_in_this_week); $x++):
$calendar["days"][]["type"] = '0';
endfor;
endif;
return $calendar;
}
}
?>
<?php
namespace MSP\Calmsp\Controller;