Exemple #1
0
 /** Fonction qui remplis un tableau de cours.
  *  Utilise icalendar.
  */
 public function getCours()
 {
     /* Parse l'ics*/
     $nb = 0;
     $tab = array();
     $ical = new SG_iCalReader($this->ICS);
     $query = new SG_iCal_Query();
     $evts = $ical->getEvents();
     $data = array();
     if (!is_array($evts)) {
         echo "ERREUR, d'initialisation des evenements.";
         echo '<br>$evts= ' . $evts;
     }
     foreach ($evts as $id => $ev) {
         $jsEvt = array("id" => $id + 1, "title" => $ev->getProperty('summary'), "start" => $ev->getStart(), "end" => $ev->getEnd(), "allDay" => $ev->isWholeDay(), "location" => $ev->getProperty('location'), "description" => $ev->getProperty('description'));
         if (isset($ev->recurrence)) {
             $count = 0;
             $start = $ev->getStart();
             $freq = $ev->getFrequency();
             if ($freq->firstOccurrence() == $start) {
                 $data[] = $jsEvt;
             }
             while (($next = $freq->nextOccurrence($start)) > 0) {
                 if (!$next or $count >= 1000) {
                     break;
                 }
                 $count++;
                 $start = $next;
                 $jsEvt["start"] = $start;
                 $jsEvt["end"] = $start + $ev->getDuration();
                 $data[] = $jsEvt;
             }
         } else {
             $data[] = $jsEvt;
         }
         $String2 = htmlentities($jsEvt["description"], ENT_QUOTES, "UTF-8");
         $String = nl2br($String2);
         $sum = htmlentities($jsEvt["title"], ENT_QUOTES, "UTF-8");
         $sum2 = nl2br($sum);
         $Matiere = between('Mati&egrave;re : ', '<br />', $String);
         $prof = between('Personnel : ', '<br />', $String);
         $promo = between('Groupe : ', 'Groupe ', $String);
         $tmp = between('Groupe :', 'Salle ', $String);
         $sous_groupe = rtrim(trim(stripslashes(after('-', $tmp))));
         if ($sous_groupe == "") {
             $sous_groupe = "0";
         }
         $tabGroupe = array();
         $promo = trim($promo);
         $tmp_groupe = between('Groupe :', 'Salle', $String2);
         //--> 'INFO 2 Groupe 2\, INFO 2 Groupe 3'
         // echo $tmp.'<br/>';
         $tmp_tab = explode(",", $tmp_groupe);
         foreach ($tmp_tab as $g) {
             if (strpos($g, 'TP') !== FALSE) {
                 $tmp = between("TP ", "-", $String2);
             } else {
                 $tmp = after($promo . ' Groupe ', $g);
                 $tmp = trim(stripslashes($tmp));
                 // Enlève antislash et les espaces
                 if ($tmp == "") {
                     $tmp = "0";
                 }
             }
             array_push($tabGroupe, $tmp);
         }
         $type = before(' -', $sum2);
         $salle = between('Salle : ', '<br />', $String);
         $date_debut = $jsEvt['start'];
         $date_fin = $jsEvt['end'];
         $date = new DateTime('@' . $date_debut);
         /* Instancie les BEANs*/
         $cours = new Cours();
         $cours->setDateDebut($date_debut);
         $cours->setMatiere($Matiere);
         $cours->setDateFin($date_fin);
         $cours->setType($type);
         $cours->setProf($prof);
         $cours->setSalle($salle);
         foreach ($tabGroupe as $g) {
             $Groupe = new Groupe();
             $Groupe->setSousGroupe($sous_groupe[0]);
             $Groupe->setNumero($g);
             $Groupe->setPromo($promo);
             $cours->setGroupe($Groupe);
         }
         $cours->setId();
         $tab[$nb++] = $cours;
         sort($tab);
         // Noé
         array_push($this->tab_cours, $cours);
     }
 }