Skip to content
Snippets Groups Projects
Commit 59cfb489 authored by llaffont's avatar llaffont
Browse files

Ajout viewhelper pour l'affichage du calendrier sous forme de tableau

parent 26349f6a
Branches
Tags
No related merge requests found
......@@ -2406,6 +2406,7 @@ library/ZendAfi/View/Helper/BoitesDivision.php -text
library/ZendAfi/View/Helper/Bouton.php -text
library/ZendAfi/View/Helper/BoutonIco.php -text
library/ZendAfi/View/Helper/BoutonRetour.php -text
library/ZendAfi/View/Helper/Calendar/Table.php -text
library/ZendAfi/View/Helper/CalendarContent.php -text
library/ZendAfi/View/Helper/CkEditor.php -text
library/ZendAfi/View/Helper/ComboCategories.php -text
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* AFI-OPAC 2.0 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_Calendar_Table extends Zend_View_Helper_HtmlElement {
use Trait_Translator, Trait_TimeSource;
protected
$param,
$id_module,
$WEEK_DAYS,
$MONTHS;
public function calendar_Table($articles, $month, $year, $param) {
$this->month = $month;
$this->year = $year;
$this->param = $param;
$this->id_module = $param['ID_MODULE'];
$this->today = date("dmY", $this->getTimeSource()->time());
$this->WEEK_DAYS = array($this->_("dim"),
$this->_("lun"),
$this->_("mar"),
$this->_("mer"),
$this->_("jeu"),
$this->_("ven"),
$this->_("sam"));
$this->MONTHS = array($this->_('janvier'),
$this->_('février'),
$this->_('mars'),
$this->_('avril'),
$this->_('mai'),
$this->_('juin'),
$this->_('juillet'),
$this->_('août'),
$this->_('septembre'),
$this->_('octobre'),
$this->_('novembre'),
$this->_('décembre'));
$html ="<div><table class=\"calendar_main\">";
$html.=" <tr class=\"calendar_title\">";
$html.=" <td class=\"calendar_title_left_arrow\"></td>";
$html.=" <td class=\"calendar_title_month\">
<a data-ajax='false' href=\"".$this->getURL("LAST_MONTH")."\" class=\"calendar_title_month_clickable\">&laquo;&nbsp;</a>
<a href=\"".$this->getURL("MONTH")."\" class=\"calendar_title_month_clickable\" target='_parent'>".$this->MONTHS[$this->month-1].strftime(" %Y", mktime(5,0,0, $this->month, 1, $this->year))."</a>
<a data-ajax='false' href=\"".$this->getURL("NEXT_MONTH")."\" class=\"calendar_title_month_clickable\">&nbsp;&raquo;</a></td>";
$html.=" <td class=\"calendar_title_right_arrow\"></td>";
$html.=" </tr>";
$html.=" <tr>";
$html.=" <td colspan=\"3\">";
$html.=" <table class=\"calendar_table\">";
$html.=" <tr>";
///////////////////////////////////////////////////////////////////////////
// HTML - Nom des jours
///////////////////////////////////////////////////////////////////////////
for ($counter = 0; $counter < 7; $counter++) {
$html.=" <th>".$this->WEEK_DAYS[(1 + $counter) % 7]."</th>";
}
$html.=" </tr>";
$first_month_day = gmmktime(0, 0, 0, $this->month, 1, $this->year);
$offset = (7 - (1 % 7 - gmdate("w", $first_month_day))) % 7;
$current_day = $first_month_day - 3600 * 24 * $offset;
$row_number = ceil((gmdate("t", $first_month_day) + $offset) / 7);
///////////////////////////////////////////////////////////////////////////
// HTML - No des jours
///////////////////////////////////////////////////////////////////////////
for ($row = 1; $row <= $row_number; $row++) {
// The first loop displays the rows
$html.=" <tr>";
for ($column = 1; $column <= 7; $column++) {
// Day currently displayed
$day = gmdate("j", $current_day);
// If it is saturday or sunday, we use the "weekend" style
if (gmdate("w", $current_day) == 6 || gmdate("w", $current_day) == 0) {
$table_cell = " <td class=\"calendar_weekend\">";
}
else {
$table_cell = " <td>";
}
// We display the current day
$day_classes = array();
if (gmdate("dmY", $current_day) == $this->today) {
$day_classes []= "calendar_today_clickable";
$today_click = '<b>'.$day.'</b>';
} else {
$today_click=$day;
if (gmdate("n", $current_day) != $this->month) {
$day_classes []= "calendar_other_month";
} else {
$day_classes []= "calendar_day_non_clickable";
}
}
///////////////////////////////////////////////////////////////////////////
// HTML - News
///////////////////////////////////////////////////////////////////////////
if ($this->dayHasEvents($current_day, $articles)) $day_classes []= "day_clickable";
if ($this->anEventStartThisDay($current_day, $articles)) $day_classes []= "calendar_day_event_start";
$cell_classes = implode(' ', array_unique($day_classes));
if (in_array('day_clickable', $day_classes)) {
$table_cell .= "<a href=\"".$this->getURL('EVENTS',$day)."\" class='".$cell_classes."' target='_parent'>".$today_click."</a>";
} else {
$table_cell .= "<span class=\"".$cell_classes."\">".$day."</span>";
}
// End of day cell
$html.=$table_cell."</td>";
// Next day
$current_day += 3600 * 24 + 1;
}
$html.=" </tr>";
}
$html.=" </table>";
$html.=" </td>";
$html.=" </tr>";
$html.="</table></div>";
return $html;
}
function getURL($type,$jour = "") {
switch($type) {
case "LAST_MONTH" :
$url = BASE_URL.'/cms/calendar?date='.$this->getLastMonth($this->month, $this->year);
break;
case "MONTH" :
if(strlen($this->month) == 1) $mois='0'.$this->month; else $mois = $this->month;
$url = BASE_URL."/cms/articleviewbydate?d=".$this->year.'-'.$mois;
break;
case "NEXT_MONTH" :
$url = BASE_URL.'/cms/calendar?date='.$this->getNextMonth($this->month, $this->year);
break;
case "EVENTS" :
if(strlen($this->month) == 1) $mois='0'.$this->month; else $mois = $this->month;
if(strlen($jour) == 1) $day='0'.$jour; else $day = $jour;
$url = BASE_URL."/cms/articleviewbydate?d=".$this->year.'-'.$mois.'-'.$day;
break;
}
return $url."&amp;".http_build_query(array(
'id_module' => $this->id_module,
'id_profil' => Class_Profil::getCurrentProfil()->getId(),
'select_id_categorie' => $this->param["SELECT_ID_CAT"]),
null,
'&amp;');
}
function getLastMonth($month, $year) {
if ($month == 1) {
$new_month = "12";
$new_year = $year - 1;
} else {
$new_month = (($month > 10)?"":"0").($month - 1);
$new_year = $year;
}
return $new_year.'-'.$new_month;
}
function getNextMonth($month, $year) {
if ($month == 12) {
$new_month = "01";
$new_year = $year + 1;
} else {
$new_month = (($month < 9)?"0":"").($month + 1);
$new_year = $year;
}
return $new_year.'-'.$new_month;
}
protected function dayHasEvents($date, $events) {
//TODO au prochain refactoring, si on construit un dictionnaire
// jour -> [articles *], ça simplifie pas mal de code.
// Pour construire le calendrier, il suffira de parcourir
// le dictionnaire et virer tout ce code bizarre.
$day = (int)gmdate("j", $date);
$month = (int)gmdate("m", $date);
foreach($events as $event) {
$event_debut = strtotime($event->getEventsDebut());
$event_fin = strtotime($event->getEventsFin());
$jour_debut = (int)date('y', $event_debut);
$mois_debut = (int)date('m', $event_debut);
$jour_fin = (int)date('j', $event_fin);
$mois_fin = (int)date('m', $event_fin);
// Jour clickable
if($mois_debut == $month && $mois_fin == $month) {
if($day >= $jour_debut && $day <= $jour_fin)
return true;
}
elseif($mois_debut == $month && $mois_fin != $month) {
if($day >= $jour_debut && $day <= 31)
return true;
}
elseif($mois_debut != $month && $mois_fin == $month) {
if($day >= 1 && $day <= $jour_fin)
return true;
}
elseif($mois_debut <= $month && $mois_fin >= $month) {
if($day >= 1 && $day <= 31)
return true;
}
}
return false;
}
protected function anEventStartThisDay($date, $events) {
$day = (int)gmdate("j", $date);
$month = (int)gmdate("m", $date);
foreach($events as $event) {
$event_debut = strtotime($event->getEventsDebut());
if (((int)date('m', $event_debut) == $month) && ((int)date('j', $event_debut) == $day))
return true;
}
return false;
}
}
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment