public function _createContent(&$toReturn)
 {
     $agendaService = new AgendaService();
     $serviceDate = new DateService();
     //on détermine le jour d'affichage
     if ($this->getParam('day') == null) {
         $day = date('Ymd');
     } else {
         $day = $this->getParam('day');
     }
     //on récupère les évènements de la journée
     foreach ($this->getParam('arAgendasAffiches') as $idAgenda) {
         $arEventsSemaine[$idAgenda] = $agendaService->checkEventOfAgendaInBdd($idAgenda, $day, $day);
     }
     //on ordonne les évènements par ordre croissant d'heure de début d'évènement dans la journée
     $arEventByDay = $agendaService->getEventsByDay($arEventsSemaine, $day, $day);
     $arEventByDay = $agendaService->getEventsInOrderByDay($arEventByDay);
     //on simplifie le tableau pour le passer à la zone
     $arDayEvent = $arEventByDay[$day]->events;
     //on récupère la couleur d'affichage de chaque évènement
     //$arColorByEvent = $agendaService->getColorByIdEvent($arDayEvent);
     $arAgendas = $agendaService->getTilteAgendaByIdAgenda($this->getParam('arAgendasAffiches'));
     //on récupère la couleur d'affichage pour chaque agenda
     $boolCroise = array();
     $daoAgenda =& CopixDAOFactory::getInstanceOf('agenda|agenda');
     foreach ($this->getParam('arAgendasAffiches') as $id) {
         $agenda = $daoAgenda->get($id);
         $boolCroise[$agenda->type_agenda] = $boolCroise[$agenda->type_agenda] == false;
         $colors = $agendaService->getColorAgendaByIdAgenda($id);
         $arColorAgenda[$id] = $boolCroise[$agenda->type_agenda] ? $colors[0] : $colors[1];
     }
     $arEventToDisplay = array();
     foreach ($arDayEvent as $event) {
         $event->color = $arColorAgenda[$event->id_agenda];
         $arEventToDisplay[] = $event;
     }
     $jour = substr($day, 6, 2);
     $mois = $serviceDate->moisNumericToMoisLitteral(substr($day, 4, 2));
     $annee = substr($day, 0, 4);
     $tpl = new CopixTpl();
     $tpl->assign('jour', $jour);
     $tpl->assign('mois', $mois);
     $tpl->assign('annee', $annee);
     //$tpl->assign('arEvent'       , $arDayEvent);
     $tpl->assign('arEvent', $arEventToDisplay);
     $tpl->assign('arAgendas', $arAgendas);
     $tpl->assign('arColorByEvent', $arColorByEvent);
     $tpl->assign('arColorAgenda', $arColorAgenda);
     $toReturn = $tpl->fetch('aujourdhui.agenda.tpl');
     return true;
 }
 /**
  * Fonction appelée lorsque l'on clique sur le bouton 'import'
  * Appel la méthode privée _validFromFormImportParams
  * vérifie les infos saisies dans le formulaire
  * stock l'objet en session
  * @author Audrey Vassal <*****@*****.**>
  */
 public function doExport()
 {
     $serviceAuth = new AgendaAuth();
     $serviceExport = new ExportService();
     $agendaService = new AgendaService();
     $dateService = new DateService();
     //demande de mettre l'objet à jour en fonction des valeurs saisies dans le formulaire
     if (!($exportParams = $this->_getSessionExport())) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('agenda.error.cannotFindSession'), 'back' => CopixUrl::get('agenda|agenda|vueSemaine')));
     }
     //on vérifie les droits des utilisateurs sur la liste des agendas sélectionnés
     foreach ((array) $this->getRequest('agenda') as $id_agenda) {
         //on vérifie si l'utilisateur a les droits d'écriture sur un des agendas affiché
         if ($serviceAuth->getCapability($id_agenda) < $serviceAuth->getRead()) {
             return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('agenda.error.enableToWrite'), 'back' => CopixUrl::get('agenda|agenda|vueSemaine')));
         }
     }
     $this->_validFromFormExportParams($exportParams);
     $errors = $this->_checkExport($exportParams);
     if (count($errors) > 0) {
         $this->_setSessionExport($exportParams);
         return CopixActionGroup::process('agenda|ImportExport::getPrepareExport', array('e' => 1, 'errors' => $errors));
     } else {
         //var_dump($exportParams);
         //die();
         //on récupère tous les évènements des agendas cochés dans la période demandée
         foreach ((array) _request('agenda') as $idAgenda) {
             $arEventsPeriode[$idAgenda] = $agendaService->checkEventOfAgendaInBdd($idAgenda, CopixDateTime::dateToYYYYMMDD($exportParams->datedeb_export), CopixDateTime::dateToYYYYMMDD($exportParams->datefin_export));
         }
         //on classe ces évènements par jour
         $arEventByDay = $agendaService->getEventsByDay($arEventsPeriode, CopixDateTime::dateToYYYYMMDD($exportParams->datedeb_export), CopixDateTime::dateToYYYYMMDD($exportParams->datefin_export));
         //on ordonne les évènements par ordre croissant d'heure de début d'évènement dans la journée
         //var_dump($arEventByDay);
         $arEventByDay = $agendaService->getEventsInOrderByDay($arEventByDay);
         $content = $serviceExport->getFileICal($arEventByDay, CopixDateTime::dateToTimestamp($exportParams->datedeb_export), CopixDateTime::dateToTimestamp($exportParams->datefin_export));
     }
     //on vide la session
     $this->_setSessionExport(null);
     return _arContent($content, array('filename' => 'agenda.ics', 'content-disposition' => 'attachement', 'content-type' => CopixMIMETypes::getFromExtension('.ics')));
 }
 /**
  * Fonction qui prépare l'affichage de la vue semaine
  */
 public function getVueSemaine()
 {
     CopixHTMLHeader::addCSSLink(_resource("styles/module_agenda.css"));
     CopixHtmlHeader::addJSLink(CopixUrl::get() . 'js/iconito/module_agenda.js');
     $obj = new AgendaService();
     $listAgendas = $obj->getAvailableAgenda();
     $agendaService = new AgendaService();
     $dateService = new DateService();
     if (($params = $this->_getSessionSemaineParams()) == null) {
         $params = new SemaineParams();
         $params->numSemaine = $this->getRequest('numSemaine', $dateService->dateToWeeknum(mktime()), true);
         $params->annee = $this->getRequest('annee', date('Y'), true);
     } else {
         $params->numSemaine = $this->getRequest('numSemaine', $params->numSemaine, true);
         $params->annee = $this->getRequest('annee', $params->annee, true);
     }
     //pour savoir si on a cliqué sur un agenda à afficher
     if (_request('updateAgendaAffiches')) {
         $arIdAgendas = array();
         foreach ($listAgendas as $agenda) {
             if (_request('agendas_' . $agenda->id_agenda)) {
                 $arIdAgendas[$agenda->id_agenda] = $agenda->id_agenda;
             }
         }
         $agendaService->setAgendaAffiches($arIdAgendas);
     }
     //on récupère en session les agendas à afficher
     $params->agendas = $agendaService->getAgendaAffiches();
     //on met à jour la session
     $this->_setSessionSemaineParams($params);
     //on determine la date de début et de fin de la semaine en cours d'affichage
     $dateDebutSemaine = date('Ymd', $dateService->numweekToDate($params->numSemaine, $params->annee, 1));
     //date au format bdd
     $dateFinSemaine = date('Ymd', $dateService->numweekToDate($params->numSemaine, $params->annee, 0));
     //date au format bdd
     $arEventsSemaine = array();
     //on récupère tous les évènements de la semaine en cours de vue
     foreach ((array) $params->agendas as $idAgenda) {
         $arEventsSemaine[$idAgenda] = $agendaService->checkEventOfAgendaInBdd($idAgenda, $dateDebutSemaine, $dateFinSemaine);
     }
     //on classe ces évènements par jour
     $arEventByDay = $agendaService->getEventsByDay($arEventsSemaine, $dateDebutSemaine, $dateFinSemaine);
     //on ordonne les évènements par ordre croissant d'heure de début d'évènement dans la journée
     $arEventByDay = $agendaService->getEventsInOrderByDay($arEventByDay);
     //on détermine l'heure de début et l'heure de fin pour l'affichage du calendrier
     //on travail sur des heures sans séparateur pour pouvoir les comparer
     $heureDeb = CopixConfig::get('agenda|heuredebcal');
     $heureFin = CopixConfig::get('agenda|heurefincal');
     foreach ((array) $arEventByDay as $jours) {
         if (!isset($jours->events)) {
             continue;
         }
         //print_r($jours);
         foreach ((array) $jours->events as $event) {
             if ($event->alldaylong_event == 0) {
                 if ($dateService->heureWithSeparateurToheureWithoutSeparateur($event->heuredeb_event) < $dateService->heureWithSeparateurToheureWithoutSeparateur($heureDeb)) {
                     $heureDeb = $dateService->heureWithSeparateurToheureWithoutSeparateur($event->heuredeb_event);
                 }
                 if ($dateService->heureWithSeparateurToheureWithoutSeparateur($heureFin) < $dateService->heureWithSeparateurToheureWithoutSeparateur($event->heurefin_event)) {
                     $heureFin = $dateService->heureWithSeparateurToheureWithoutSeparateur($event->heurefin_event);
                 }
             }
         }
     }
     //on arrondit à l'heure inférieure pour l'heure de début et à l'heure supérieure pour l'heure de fin
     $heureDeb = substr($heureDeb, 0, 2);
     if (substr($heureFin, 2, 2) == 0) {
         //si les minutes sont à 0, on arrondit à l'heure
         $heureFin = substr($heureFin, 0, 2);
     } else {
         //si les minutes ne sont pas à 0, on arrondit à l'heure supérieure
         $heureFin = substr($heureFin, 0, 2) + 1;
     }
     //on récupère les leçons de la semaine à afficher
     $arLecons = $agendaService->getLeconsByDay((array) $params->agendas, $dateDebutSemaine, $dateFinSemaine);
     // On récupère les travaux de la semaine par agenda
     $travailDAO = _ioDAO('cahierdetextes|cahierdetextestravail');
     $agenda2cahier = array();
     $arTravauxEnClasse = array();
     $arTravauxAFaire = array();
     foreach ($params->agendas as $agendaId) {
         $agendaInfos = Kernel::getModParentInfo('MOD_AGENDA', $agendaId);
         $agendaType = AgendaType::getAgendaTypeForNode($agendaInfos['type'], $agendaInfos['id']);
         $mods = Kernel::getModEnabled($agendaInfos['type'], $agendaInfos['id']);
         $cahierDeTextes = Kernel::filterModuleList($mods, 'MOD_CAHIERDETEXTES');
         $agendaLevel = Kernel::getLevel($agendaInfos['type'], $agendaInfos['id']);
         if (isset($cahierDeTextes[0])) {
             $agenda2cahier[$agendaId] = $cahierDeTextes[0]->module_id;
             $travauxEnClasse = $travailDAO->findTravauxEnClasseByAgendaParJour($agendaId, $dateDebutSemaine, $dateFinSemaine, $agendaInfos['type'], $agendaInfos['id'], $agendaLevel);
             if (!is_null($travauxEnClasse)) {
                 foreach ($travauxEnClasse as $date => $travail) {
                     $arTravauxEnClasse[$date][$agendaId] = $travail;
                 }
             }
             $travauxAFaire = $travailDAO->findTravauxAFaireByAgendaParJour($agendaId, $dateDebutSemaine, $dateFinSemaine, $agendaInfos['type'], $agendaInfos['id'], $agendaLevel);
             if (!is_null($travauxAFaire)) {
                 foreach ($travauxAFaire as $date => $travail) {
                     $arTravauxAFaire[$date][$agendaId] = $travail;
                 }
             }
         }
     }
     //récupération de la liste des agendas affichés
     $listAgendasAffiches = $obj->getAgendaAffiches();
     //template pour agenda
     $tplAgenda = new CopixTpl();
     $tplAgenda->assign('MAIN_AGENDA', CopixZone::process('agenda|agendavuesemaine', array('elementsSemaineAffichee' => $params, 'arEventByDay' => $arEventByDay, 'heureDeb' => $heureDeb, 'heureFin' => $heureFin, 'arLecons' => $arLecons, 'arTravauxEnClasse' => $arTravauxEnClasse, 'arTravauxAFaire' => $arTravauxAFaire, 'agenda2cahier' => $agenda2cahier)));
     $title = $obj->getCurrentTitle();
     //template principal
     $tpl = new CopixTpl();
     $tpl->assign('TITLE_PAGE', $title['title']);
     $menu = $agendaService->getAgendaMenu('week');
     $tpl->assign('MENU', $menu);
     $tpl->assign('MAIN', $tplAgenda->fetch('agenda|main.agenda.tpl'));
     return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl);
 }