如何扩展或修改Codeigniter日历以处理每天的多日事件和多个事件

时间:2011-12-07 17:08:14

标签: php codeigniter calendar

如果它出现在某个地方,我不想重新发明这个,但有没有人扩展或修改了这个共同点日历,以便每天处理多天事件和多个事件,或者某个地方是否有可用的模块? / p>

2 个答案:

答案 0 :(得分:3)

一天的多个事件实际上非常容易。它只需更改日历模板,这是我的一些代码的示例。

public function print_calendar($year = 0, $month = 0)
{
    $prefs = array (
        'show_next_prev'  => FALSE,
        'next_prev_url'   => site_url('events/print_calendar'),
        'day_type'        => 'long',
        'template'        => '
            {heading_row_start}{/heading_row_start}
            {heading_previous_cell}{/heading_previous_cell}
            {heading_title_cell}<h1>{heading}</h1>{/heading_title_cell}
            {heading_next_cell}{/heading_next_cell}
            {heading_row_end}{/heading_row_end}

            {table_open}<table border="0" cellpadding="0" cellspacing="0">{/table_open}

            {week_row_start}<tr>{/week_row_start}
            {week_day_cell}<th bgcolor="#999999">{week_day}</th>{/week_day_cell}
            {week_row_end}</tr>{/week_row_end}

            {cal_row_start}<tr>{/cal_row_start}
            {cal_cell_start}<td background="'.s3_path('images/print_cal_cell.jpg').'">{/cal_cell_start}

            {cal_cell_content}<span class="cal_day">{day}</span>{content}{/cal_cell_content}
            {cal_cell_content_today}<span class="cal_day">{day}</span>{/cal_cell_content_today}

            {cal_cell_no_content}<span class="cal_day">{day}</span>{/cal_cell_no_content}
            {cal_cell_no_content_today}<span class="cal_day">{day}</span>{/cal_cell_no_content_today}

            {cal_cell_blank}&nbsp;{/cal_cell_blank}

            {cal_cell_end}</td>{/cal_cell_end}
            {cal_row_end}</tr>{/cal_row_end}

            {table_close}</table>{/table_close}
        '
    );

    $this->load->library('calendar', $prefs);

    $year = ($year == 0) ? date('Y') : $year;
    $month = ($month == 0) ? date('n') : $month;
    $start = strtotime('1-'.$month.'-'.$year);

    $events = $this->events_model->get_by_date($start, strtotime('+1 month', $start));
    $this->template->set_layout('');

    if ($events)
    {
        foreach ($events as $key => $event)
        {
            $day = date('j', $event['showing_start_time']);
            $vars[$day] = $this->template->build('events/calendar/cal_item', $event, TRUE);
        }
    }

    $vars['content'] = $this->calendar->generate($year, $month, $vars);
    $this->load->view('calendar/cal_layout', $vars);
}

希望代码清晰,可以为您提供一个良好的起点。如果他们跨越多天,我通常会做的就是每天都包含该项目。

答案 1 :(得分:1)

可以在文件system/libraries/Calendar.php中轻松修改,并添加以下代码。我知道编辑任何系统文件都被认为是禁忌,但这对我的应用程序帮了大忙。请注意注释部分中的foreach()循环,其中显示//If more than one event on the same day.这是需要添加到Calendar.php库文件的代码。此资源可在以下链接中进一步详述。

http://codeigniter.com/forums/viewthread/196998/

Calendar.php修改代码:

if (isset($data[$day]))
                    {
                        // Cells with content
                        $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];

                        // If more than one event on the same day
                        if (is_array($data[$day]))
                        {
                          $several_events = '';
                          foreach ($data[$day] as $key => $value)
                          {
                            $several_events .= '<li id="'.$key.'">'.$value.'</li>';
                          }
                          $out .= str_replace('{day}', $day, str_replace('{content}', $several_events, $temp));
                        }

                        // One event per day
                        else
                        {
                          $out .= str_replace('{day}', $day, str_replace('{content}', $data[$day], $temp));
                        }
                    }
                    else
                    {
                        // Cells with no content
                        $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content'];
                        $out .= str_replace('{day}', $day, $temp);
                    }
                }
                else
                {
                    // Blank cells
                    $out .= $this->temp['cal_cell_blank'];
                }

请注意,我展示的不仅仅是上面编辑的代码,以帮助您在Calendar.php内找到它。我希望这有帮助!