Location: PHPKode > projects > cataBlog > cataBlog-0.1-pre_alpha/0.1-pre_alpha/Module/cataBlog/Calendar.php
<?php
/**
 * @license PHP
 * @author  Jackson Miller <hide@address.com>
 * @version $Id: Calendar.php,v 1.1 2004/08/06 19:00:34 jaxn Exp $
 * @package cataBlog
 */

require_once('CEP/Module/cataBlog.php');
require_once('Structures/DataGrid.php');

/**
 * @todo add cataBlog.calendar.css
 * @todo replace "$data .=" with cepAddData calls
 */
class CEP_Module_cataBlog_Calendar extends CEP_Module_cataBlog {

    /**
     * @uses CEP_Library_cataBlog::getActiveDays()
     */
    function _renderDisplay() {
        // Build the data structure
        if (isset($this->cep_get_vars['month']) && isset($this->cep_get_vars['year'])) {
            $this->month = $this->cep_get_vars['month'];
            $this->year = $this->cep_get_vars['year'];
        }
        else {
            $this->month = date('n');
            $this->year = date('Y');
        }
        
        // get entries for month
        $month_entries = CEP_Library_cataBlog::getActiveDays($this->year,$this->month);
        
        $Month = new Calendar_Month_Weekdays($this->year, $this->month);
        $Month->build();
    
        // Data to be printed by DataGrid
        require_once('CEP/Library/SimpleCalendar.php');
        //$dg_data = CEP_Library_SimpleCalendar::getEvents();
    
        // Define New DataGrid with a limit of 10 records
        $dg = new Structures_DataGrid(6, $this->cep_get_vars['view']);


        // Define DataGrid Color Attributes
        $dg->renderer->settableAttribute('bgcolor','#CCCCFF');
        $dg->renderer->setTableHeaderAttributes(array('bgcolor'=>'#F0F0F0'));
        $dg->renderer->setTableOddRowAttributes(array('bgcolor'=>'#F0F0F0'));
        $dg->renderer->setTableEvenRowAttributes(array('bgcolor'=>'#FFFFFF'));
    
        // Define DataGrid Table Attributes
        $dg->renderer->setTableAttribute('width', '50%');
        $dg->renderer->setTableAttribute('align', 'center');
        $dg->renderer->setTableAttribute('cellspacing', '1');
        $dg->renderer->setTableAttribute('cellpadding', '4');
        $dg->renderer->setTableAttribute('bgcolor','#CCCCCC');
        $dg->renderer->setTableAttribute('class', 'datagrid');
    
        // Set empty row table attributes
        // Clean me!
        $dg->renderer->allowEmptyRows = true;
        $dg->renderer->emptyRowAttributes = array('bgcolor' => '#FFFFFF');


        // Define columns for the DataGrid
        $column = new Structures_DataGrid_Column('Sunday', 'sunday', null, array('width' => '15%'));
        $dg->addColumn($column);
        $column = new Structures_DataGrid_Column('Monday', 'monday', null, array('width' => '15%'));
        $dg->addColumn($column);
        $column = new Structures_DataGrid_Column('Tuesday', 'tuesday', null, array('width' => '15%'));
        $dg->addColumn($column);
        $column = new Structures_DataGrid_Column('Wednesday', 'wednesday', null, array('width' => '15%'));
        $dg->addColumn($column);
        $column = new Structures_DataGrid_Column('Thursday', 'thursday', null, array('width' => '15%'));
        $dg->addColumn($column);
        $column = new Structures_DataGrid_Column('Friday', 'friday', null, array('width' => '15%'));
        $dg->addColumn($column);
        $column = new Structures_DataGrid_Column('Saturday', 'saturday', null, array('width' => '15%'));
        $dg->addColumn($column);
        
        while ($Day = $Month->fetch()) {
            if ($Day->isFirst()) {
                if ($Day->isEmpty()) {
                    $week['sunday'] = '';
                }
                else{
                    $week['sunday'] = $Day->thisDay();
                }
                $x++;
                continue;
            }
            if (!$Day->isFirst() && !$Day->isLast()) {
                switch ($x) {
                    case 1:
                        $day = "monday";
                        break;
                    case 2:
                        $day = "tuesday";
                        break;
                    case 3:
                        $day = "wednesday";
                        break;
                    case 4:
                        $day = "thursday";
                        break;
                    case 5:
                        $day = "friday";
                        break;
                }
                if ($Day->isEmpty()) {
                    $week[$day] = '';
                } else {
                    $week[$day] = $Day->thisDay();
                }
                if ($Day->thisDay() == 3) {
                    echo $x." --- ".$Day->thisDay()." -- ".$day." --- ";
                }
                $x++;
                continue;
            }
            if ($x > 5) {
                if ($Day->isEmpty()) {
                    $week['saturday'] = '';
                }
                else {
                    $week['saturday'] = $Day->thisDay();
                }
                $week = new Structures_DataGrid_Record($week);
                $result = $dg->addRecord($week);
                if (PEAR::isError($result)) {
                    echo $result->getMessage();
                }
                $x = 0;
                unset($week);
                continue;
            }
        }
    
        $data = '';

        $last_month = $this->month - 1;
        if ($last_month == 0) {
            $last_month = 12;
            $last_year = $this->year - 1;
        }
        else {
            $last_year = $this->year;
        }
        $next_month = $this->month + 1;
        if ($next_month == 13) {
            $next_month = 1;
            $next_year = $this->year + 1;
        }
        else {
            $next_year = $this->year;
        }
        $last_month_url = $this->cepCreateUri(array('month'=>"{$last_month}", 'year'=>"{$last_year}"));
        $last_month_label = date("F , Y", strtotime("{$last_year}-{$last_month}-01 12:00:00"));
        $data .= "<div align='center'><a href='{$last_month_url}'>{$last_month_label}</a> | ";
        
        $this_month_label = date("F , Y", strtotime("{$this->year}-{$this->month}-01 12:00:00"));
        $data .= "<b> {$this_month_label} </b>";
        
        $next_month_url = $this->cepCreateUri(array('month'=>"{$next_month}", 'year'=>"{$next_year}"));
        $next_month_label = date("F , Y", strtotime("{$next_year}-{$next_month}-01 12:00:00"));
        $data .= " | <a href='{$next_month_url}'>{$next_month_label}</a></div>";
        // Print the DataGrid
        $data .= $dg->render();
        //$data .= $dg->renderer->getPaging();
        return $this->cepAddData($data);
    }
}
?>
Return current item: cataBlog