Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TCalendar.php

Documentation is available at TCalendar.php

  1. <?php
  2. namespace Adianti\Widget\Util;
  3.  
  4. use Adianti\Core\AdiantiCoreTranslator;
  5. use Adianti\Control\TAction;
  6. use Adianti\Widget\Container\TTable;
  7. use Adianti\Widget\Base\TElement;
  8.  
  9. /**
  10.  * Calendar Widget
  11.  *
  12.  * @version    7.4
  13.  * @package    widget
  14.  * @subpackage util
  15.  * @author     Pablo Dall'Oglio
  16.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  17.  * @license    http://www.adianti.com.br/framework-license
  18.  */
  19. class TCalendar extends TElement
  20. {
  21.     private $months;
  22.     private $year;
  23.     private $month;
  24.     private $width;
  25.     private $height;
  26.     private $action;
  27.     private $selectedDays;
  28.     private $weekendHighlight;
  29.     
  30.     /**
  31.      * Class Constructor
  32.      */
  33.     public function __construct()
  34.     {
  35.         parent::__construct('div');
  36.         $this->{'class''tcalendar';
  37.         $this->width 400;
  38.         $this->height 300;
  39.         $this->selectedDays array();
  40.         $this->weekendHighlight false;
  41.         $this->months [AdiantiCoreTranslator::translate('January')AdiantiCoreTranslator::translate('February')AdiantiCoreTranslator::translate('March')AdiantiCoreTranslator::translate('April')AdiantiCoreTranslator::translate('May')AdiantiCoreTranslator::translate('June'),
  42.                          AdiantiCoreTranslator::translate('July')AdiantiCoreTranslator::translate('August')AdiantiCoreTranslator::translate('September')AdiantiCoreTranslator::translate('October')AdiantiCoreTranslator::translate('November')AdiantiCoreTranslator::translate('December')];
  43.     }
  44.     
  45.     /**
  46.      * highglight weekend
  47.      */
  48.     public function highlightWeekend()
  49.     {
  50.         $this->weekendHighlight true;
  51.     }
  52.     
  53.     /**
  54.      * Define the calendar's size
  55.      * @param  $width  Window's width
  56.      * @param  $height Window's height
  57.      */
  58.     public function setSize($width$height)
  59.     {
  60.         $this->width  $width;
  61.         $this->height $height;
  62.     }
  63.     
  64.     /**
  65.      * Define the current month to display
  66.      * @param  $month Month to display
  67.      */
  68.     public function setMonth($month)
  69.     {
  70.         $this->month $month;
  71.     }
  72.     
  73.     /**
  74.      * Define the current year to display
  75.      * @param  $year Year to display
  76.      */
  77.     public function setYear($year)
  78.     {
  79.         $this->year $year;
  80.     }
  81.     
  82.     /**
  83.      * Return the current month
  84.      */
  85.     public function getMonth()
  86.     {
  87.         return $this->month;
  88.     }
  89.     
  90.     /**
  91.      * Return the current year
  92.      */
  93.     public function getYear()
  94.     {
  95.         return $this->year;
  96.     }
  97.     
  98.     /**
  99.      * Define the action when click at some day
  100.      * @param  $action TAction object
  101.      */
  102.     public function setAction(TAction $action)
  103.     {
  104.         $this->action $action;
  105.     }
  106.     
  107.     /**
  108.      * Select a collection of days
  109.      * @param  $days Collection of days
  110.      */
  111.     public function selectDays(array $days)
  112.     {
  113.         $this->selectedDays $days;
  114.     }
  115.     
  116.     /**
  117. /**
  118.      * Show the calendar
  119.      */
  120.     public function show()
  121.     {
  122.         $this->{'style'"width: {$this->width}px; height: {$this->height}px";
  123.         
  124.         $this->month $this->month $this->month date('m');
  125.         $this->year $this->year $this->year date('Y');
  126.         
  127.         $table new TTable;
  128.         $table-> width '100%';
  129.         parent::add($table);
  130.         
  131.         $row $table->addRow();
  132.         $cell $row->addCell($this->months[$this->month -1' ' $this->year);
  133.         $cell->{'colspan'7;
  134.         $cell->{'class''calendar-header';
  135.         
  136.         $row $table->addRow();
  137.         $row->addCell(substr(AdiantiCoreTranslator::translate('Sunday'),0,1))->{'class''calendar-header-day';
  138.         $row->addCell(substr(AdiantiCoreTranslator::translate('Monday'),0,1))->{'class''calendar-header-day';
  139.         $row->addCell(substr(AdiantiCoreTranslator::translate('Tuesday'),0,1))->{'class''calendar-header-day';
  140.         $row->addCell(substr(AdiantiCoreTranslator::translate('Wednesday'),0,1))->{'class''calendar-header-day';
  141.         $row->addCell(substr(AdiantiCoreTranslator::translate('Thursday'),0,1))->{'class''calendar-header-day';
  142.         $row->addCell(substr(AdiantiCoreTranslator::translate('Friday'),0,1))->{'class''calendar-header-day';
  143.         $row->addCell(substr(AdiantiCoreTranslator::translate('Saturday'),0,1))->{'class''calendar-header-day';
  144.         
  145.         
  146.         $prev_year  $this->year;
  147.         $next_year  $this->year;
  148.         $prev_month $this->month 1;
  149.         $next_month $this->month 1;
  150.          
  151.         if ($prev_month == )
  152.         {
  153.             $prev_month 12;
  154.             $prev_year $this->year 1;
  155.         }
  156.         
  157.         if ($next_month == 13 )
  158.         {
  159.             $next_month 1;
  160.             $next_year $this->year 1;
  161.         }
  162.         
  163.         $timestamp mktime000$this->month1$this->year );
  164.         $maxday date("t"$timestamp);
  165.         $thismonth getdate ($timestamp);
  166.         $startday $thismonth['wday'];
  167.         $dayofweek 0;
  168.         
  169.         for ($i=0$i<($maxday $startday)$i++)
  170.         {
  171.             if (($i 7== )
  172.             {
  173.                 $row $table->addRow();
  174.                 $row->{'class''calendar-rowdata';
  175.                 $dayofweek 0;
  176.             }
  177.             
  178.             if ($i $startday)
  179.             {
  180.                 $row->addCell('');
  181.                 $dayofweek ++;
  182.             }
  183.             else
  184.             {
  185.                 $current_day ($i $startday 1);
  186.                 $cell $row->addCell$current_day );
  187.                 $dayofweek ++;
  188.                 
  189.                 if (in_array($current_day$this->selectedDays))
  190.                 {
  191.                     $cell->{'class''calendar-data calendar-selected';
  192.                 }
  193.                 else
  194.                 {
  195.                     $cell->{'class''calendar-data';
  196.                 }
  197.                 
  198.                 if ($this->weekendHighlight)
  199.                 {
  200.                     if ($dayofweek == || $dayofweek == 7)
  201.                     {
  202.                         $cell->{'class'.= ' weekend';
  203.                     }
  204.                 }
  205.                 
  206.                 $cell->{'valign''middle';
  207.                 
  208.                 if ($this->action instanceof TAction)
  209.                 {
  210.                     $this->action->setParameter('year'$this->year)
  211.                     $this->action->setParameter('month'$this->month);
  212.                     $this->action->setParameter('day'$current_day);
  213.                     $string_action $this->action->serialize(FALSE);
  214.                     $cell->{'onclick'"__adianti_ajax_exec('{$string_action}')";
  215.                 }
  216.             }
  217.         }
  218.         parent::show();
  219.     }
  220. }