* @version 1.0 (07/05/2005)
* @link http://resources.neolao.com/php/classes/components/calendarweek
*/
class CalendarWeek {
// ----------------------------- CONSTANTES --------------------------------
// ----------------------------- VARIABLES ---------------------------------
/**
* Le style CSS du composant (class)
* @var string
*/
private $_cssClass;
/**
* Le titre du composant
* @var string
*/
private $_title;
/**
* Les jours de la semaine (la semaine commence lundi)
* @var array
*/
private $_dayNames;
/**
* Les événement de la semaine
* @var array
*/
private $_events;
/**
* Le calendrier en html
* @var string
*/
private $_html;
/*===================== CONSTRUCTEUR & DESCTRUCTEUR ======================*/
/*========================================================================*/
/**
* Initialisation de la class
* @param string $cssClass Le style CSS du composant (class)
*/
function __construct($cssClass=null){
if(!is_null($cssClass)){
$this->_cssClass = $cssClass;
}
// valeurs par d�aut
$this->_title = "";
$this->_dayNames = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
}
/**
* Destruction de la class
*/
function __destruct(){
}
/*=============== FIN = CONSTRUCTEUR & DESCTRUCTEUR = FIN ================*/
/*========================================================================*/
/*=========================== METHODES PRIVEES ===========================*/
/*========================================================================*/
private function setHtml(){
$ok = false;
// V�ification de la validité des variables qui vont être utilisées
$ok = true;
if($ok){
// G��ation des variables utiles
// DL
$content = "
_cssClass)){
$content .= " class=\"".$this->_cssClass."\"";
}
$content .= ">";
// DT
$content .= "- ";
$content .= $this->_title;
$content .= "
";
// DD
$content .= "- ";
$content .= "
";
$content .= "";
$content .= "";
for($i=0; $i<7; $i++){
$content .= "| ".$this->_dayNames[$i]." | ";
}
$content .= "
";
$content .= "";
$content .= "";
$content .= "".str_repeat("| | ", 7)."
";
$content .= "";
$content .= "";
$content .= "";
for($i=0; $i<7; $i++){
$content .= "| ";
$totalEvents = count($this->_events[$i]);
if($totalEvents > 0){
$content .= "";
}else{
$content .= " ";
}
$content .= " | ";
}
$content .= "
";
$content .= "";
$content .= "
";
$content .= " ";
// DL fin
$content .= "
";
}else{
$content = "[CALENDAR WEEK - ERROR]";
}
$this->_html = $content;
}
/*===================== FIN = METHODES PRIVEES = FIN =====================*/
/*========================================================================*/
/*============================ GETTER SETTER ============================*/
/*========================================================================*/
public function __get($var){
switch($var){
case "html":
$this->setHtml();
return $this->_html;
case "title":
return $this->_title;
case "dayNames":
return $this->_dayNames;
default:
return null;
}
}
public function __set($var, $value){
switch($var){
case "title":
$this->_title = (string) $value;
break;
case "dayNames":
$this->_dayNames = (array) $value;
break;
default:
}
}
/*====================== FIN = GETTER SETTER = FIN ======================*/
/*========================================================================*/
/*========================== METHODES PUBLIQUES ==========================*/
/*========================================================================*/
/**
* Ajoute un événement
* @param int $day Le jour de l'événement
* @param string $title Le titre de l'événement
* @param string $dateStart L'heure de début
* @param string $url Le lien de l'événement
* @param string $description La description de l'événement
* @param int $titleLength La taille maximale du titre
* @param string $style Le style css de l'événement
*/
public function addEvent($day, $title, $dateStart, $url, $description, $titleLength=10, $style="event"){
if(!isset($this->_events)){
$this->_events = array();
}
if(!isset($this->_events[$day])){
$this->_events[$day] = array();
}
$currentTitleLength = strlen($title);
if($currentTitleLength > $titleLength){
$titleSort = preg_replace("/(&[^;]*)$/", "", substr($title, 0, $titleLength - 1))."…";
}else{
$titleSort = $title;
}
$this->_events[$day][] = array("titleSort"=>$titleSort,
"title"=>$title,
"dateStart"=>$dateStart,
"link"=>$url,
"description"=>$description,
"style"=>$style);
}
/*==================== FIN = METHODES PUBLIQUES = FIN ====================*/
/*========================================================================*/
}
?>