Codeigniter在5次预订后禁用日历日期

时间:2017-03-24 01:18:47

标签: php codeigniter codeigniter-3

我有日历,其日期已预订并保存在数据库中。我试图从数据库中提取预订,然后在相应的日期下显示。一切都工作正常,除了事情,我希望日期只是文本而不是链接,当有超过5个事件到那个日期。

我知道日历模板没有内容单元格和内容单元格。但我希望日期在附加超过5个事件时没有链接。

我的模特:

const weathermap = this.state.weather.wind.speed

1 个答案:

答案 0 :(得分:0)

您拥有的选项有限,因为Codeigniters日历库只有模板中的两个伪变量cal_cell_no_contentcal_cell_content可以根据您要显示的内容进行播放。

快速查看门后显示库使用isset()来确定要使用的两个伪变量中的哪一个。 它会在{content}之前调用str_replace {day},这会打开一个有点hacky的解决方案:

public function bookingcalender($year=null,$month=null)
    {
        if(!$year)
        {
            $y = date('Y');
        }
        else
        {
            $y = $year;
        }
        if(!$month)
        {
            $m = date('m');
        }
        else
        {
            $m = $month;
        }
        $this->config = array(
            'show_next_prev'  => TRUE,
            'next_prev_url'   => 'http://joshuaflinn.com/CI/booking/show',
            'template' => '{table_open}<table class="availability-calendar">{/table_open}          
            {heading_row_start}<tr class="toolbar">{/heading_row_start}        
            {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
            {heading_previous_cell}<th><a href="{previous_url}">&lt;</a></th>{/heading_previous_cell}
            {heading_next_cell}<th><a href="{next_url}">&gt;</a></th>{/heading_next_cell}
            {heading_row_end}</tr>{/heading_row_end}
            {week_row_start}<tr>{/week_row_start}
            {week_day_cell}<td>{week_day}</td>{/week_day_cell}
            {week_row_end}</tr>{/week_row_end}
            {cal_row_start}<tr>{/cal_row_start}
            {cal_cell_start}<td>{/cal_cell_start}
            {cal_cell_start_today}<td>{/cal_cell_start_today}
            {cal_cell_start_other}<td class="other-month">{/cal_cell_start_other}
            {cal_cell_content}{content}{/cal_cell_content}
            {cal_cell_content_today}<div class="highlight">{content}</div>{/cal_cell_content_today}
            {cal_cell_no_content}<a href="#" data-toggle="collapse" data-target="#bookingform" data="'.$y.'-'.$m.'-{day}">{day}</a>{/cal_cell_no_content}
            {cal_cell_no_content_today}<a href="#" data-toggle="collapse" data-target="#bookingform"><div class="highlight">{day}</div></a>{/cal_cell_no_content_today}
            {cal_cell_blank}&nbsp;{/cal_cell_blank}
            {cal_cell_other}{day}{/cal_cel_other}
            {cal_cell_end}</td>{/cal_cell_end}
            {cal_cell_end_today}</td>{/cal_cell_end_today}
            {cal_cell_end_other}</td>{/cal_cell_end_other}
            {cal_row_end}</tr>{/cal_row_end}
            {table_close}</table>{/table_close}'
            );

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

        $conf_data = $this->get_booked_dates($year,$month);
        return $this->calendar->generate($year,$month,$conf_data);

    }  


    public function get_booked_dates($year,$month)
    {
        $query = $this->db->select('client_name,booking_date')->from('bookings')->like('booking_date',"$year-$month")->get();

        $cal_data = array();

        foreach($query->result() as $row)
        {
            $dt = explode("-", $row->booking_date);
            $k = intval($dt[2]); // MAKE INTEGER OF DAY NUMBER 

            if( @$cal_data[$k] == '' )
            {
                $cal_data[$k] = $row->client_name;                
            }
            else
            {
                $cal_data[$k] .= ','.$row->client_name;                
            }

        }     

        // LOOP THROUGH EACH DAY TO FIND THOSE WITH MORE THAN 5 EVENTS
        foreach($cal_data as $key=>$val){
            // COUNT THE NUMBER OF COMMAS THAT OCCUR IN STRING
            $count = strlen($val) - strlen(str_replace(',','',$val));
            if($count > 4){ // IF MORE THAN 4 COMMAS (> 5 EVENTS) THEN NO LINK... 
                $cal_data[$key] = '{day}<span class="date-data">'.$val.'</span>';   
            } else { // LINKED DAY 
                $cal_data[$key] = '<a href="#" data-toggle="collapse" data-target="#bookingform" data="'.$year.'-'.$month.'-{day}">{day}</a><span class="date-data">'.$val.'</span>';               
            }
        }

        return $cal_data;
    }

注意:我在模板中更改了两行:{cal_cell_content}{content}{/cal_cell_content}{cal_cell_content_today}<div class="highlight">{content}</div>{/cal_cell_content_today}

您现在只需要设置{content},因为在包含查询返回的html的内容中指定了{day}

更新:我现在已经测试了解决方案,它似乎工作正常!

如果您需要更灵活的解决方案,并且不想在查询返回的内容中混合使用模板html,则必须操作或扩展日历库。