2012-02-10 12 views
3

Codeigniterのカレンダーライブラリで2週間のビューを作成しようとしていますが、基本的に完全な月ビューは必要ありません。今週からの週表示。今週からCodeigniterのカレンダーライブラリで2週間のビューを生成

enter image description here

上記の画像は、私が達成したいものを類似性を示します。 Codeigniterのテンプレート側で生成すると、この種の機能は提供されません。私はjQuery UIのカレンダーを使用したくないのですが、これを実行するためにJSに頼るのではなく静的なカレンダーが必要です(特にユーザーがJSを無効にしている場合)。

このタイプのカレンダー表示を実行できるCodeigniterまたは特定のテンプレート文字列とマージできる特定の拡張ライブラリはありますか?

+0

fyi、 'js disabled'に関する懸念:http://developer.yahoo.com/blogs/ydn/posts/2010/10/how-many-users-have-javascript-disabled/ – Jakub

答えて

1

このためにカレンダーライブラリを拡張する必要があります。 application/libraries

MY_Calendar.phpを作成:

class MY_Calendar extends CI_Calendar { 
    public function generate2weeks($year = '', $month = '', $data = array()) 
    { 
     // code goes here 
    } 
} 

CI_Calendar::generate()機能を見てください。あなたは基本的にgenerate()と同じことをするが、日数が少ない新しい関数generate2weeks()を書く必要があります。私はgenerate()のコピーを作ってここから作業します。おそらく、試してみる価値のあるget_total_daysを上書きするだけで十分でしょう。

+0

あなたが言ったようにそれは完璧に働いた。ありがとう! – fjckls

0

Calendarクラスを拡張してgenerate()メソッドをオーバーライドする必要があります。私はgenerate()機能を微調整するために少し時間を費やしました。これが私の得たものです。

function generate($year = '', $month = '', $data = array()) 
{ 
    // Set and validate the supplied month/year 
    if ($year == '') 
     $year = date("Y", $this->local_time); 

    if ($month == '') 
     $month = date("m", $this->local_time); 

    if (strlen($year) == 1) 
     $year = '200'.$year; 

    if (strlen($year) == 2) 
     $year = '20'.$year; 

    if (strlen($month) == 1) 
     $month = '0'.$month; 

    $adjusted_date = $this->adjust_date($month, $year); 

    $month = $adjusted_date['month']; 
    $year = $adjusted_date['year']; 

    // Determine the total days in the month 
    $total_days = $this->get_total_days($month, $year); 

    // Set the starting day of the week 
    $start_days = array('sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6); 
    $start_day = (! isset($start_days[$this->start_day])) ? 0 : $start_days[$this->start_day]; 

    // Set the starting day number 
    $local_date = mktime(12, 0, 0, $month, date('j'), $year); 
    $date = getdate($local_date); 
    $day = $date["mday"]; 

    // Set the current month/year/day 
    // We use this to determine the "today" date 
    $cur_year = date("Y", $this->local_time); 
    $cur_month = date("m", $this->local_time); 
    $cur_day = date("j", $this->local_time); 

    $is_current_month = ($cur_year == $year AND $cur_month == $month) ? TRUE : FALSE; 

    // Generate the template data array 
    $this->parse_template(); 

    // Begin building the calendar output 
    $out = $this->temp['table_open']; 
    $out .= "\n"; 

    $out .= "\n"; 
    $out .= $this->temp['heading_row_start']; 
    $out .= "\n"; 

    // "previous" month link 
    if ($this->show_next_prev == TRUE) 
    { 
     // Add a trailing slash to the URL if needed 
     $this->next_prev_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->next_prev_url); 

     $adjusted_date = $this->adjust_date($month - 1, $year); 
     $out .= str_replace('{previous_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_previous_cell']); 
     $out .= "\n"; 
    } 

    // Heading containing the month/year 
    $colspan = ($this->show_next_prev == TRUE) ? 5 : 7; 

    $this->temp['heading_title_cell'] = str_replace('{colspan}', $colspan, $this->temp['heading_title_cell']); 
    $this->temp['heading_title_cell'] = str_replace('{heading}', $this->get_month_name($month)." ".$year, $this->temp['heading_title_cell']); 

    $out .= $this->temp['heading_title_cell']; 
    $out .= "\n"; 

    // "next" month link 
    if ($this->show_next_prev == TRUE) 
    { 
     $adjusted_date = $this->adjust_date($month + 1, $year); 
     $out .= str_replace('{next_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_next_cell']); 
    } 

    $out .= "\n"; 
    $out .= $this->temp['heading_row_end']; 
    $out .= "\n"; 

    // Write the cells containing the days of the week 
    $out .= "\n"; 
    $out .= $this->temp['week_row_start']; 
    $out .= "\n"; 

    $day_names = $this->get_day_names(); 

    for ($i = 0; $i < 7; $i ++) 
    { 
     $out .= str_replace('{week_day}', $day_names[($start_day + $i) %7], $this->temp['week_day_cell']); 
    } 

    $out .= "\n"; 
    $out .= $this->temp['week_row_end']; 
    $out .= "\n"; 

    // Build the main body of the calendar 
    $limit = $day + 13; 
    if ($limit > $total_days) 
    { 
     $total_days_left = $limit - $total_days; 
    } 
    while ($day <= $limit) 
    { 
     $out .= "\n"; 
     $out .= $this->temp['cal_row_start']; 
     $out .= "\n"; 

     for ($i = 0; $i < 7; $i++) 
     { 
      if ($day > $total_days) 
      { 
       $day = 1; 
       $limit = $total_days_left; 
      } 
      $out .= ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start']; 

      if ($day > 0 AND $day <= $limit) 
      { 
       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']; 
        $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']; 
      } 

      $out .= ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end'];     
      $day++; 
     } 
     $out .= "\n"; 
     $out .= $this->temp['cal_row_end']; 
     $out .= "\n"; 
    } 
    $out .= "\n"; 
    $out .= $this->temp['table_close']; 

    return $out; 
} 

あなたはこの1、ここで元の間の違いを見ることができます: http://www.diffnow.com/?report=51mkw

この意志は、現在の日付から2週間を示しています。カレンダーライブラリを呼び出すときしかし、あなたのようなdate('l')strtolower()を使用して、現在の日にstart_dayを指定する必要があります。

$prefs = array (
    'start_day' => strtolower(date('l')), 
); 
$this->load->library('calendar', $prefs); 

そうでなければ、日が間違って表示されるでしょう。

+0

Codeigniterのカレンダー 'next_prev_url'設定で月に2週間見ながらナビゲートする方法はありますか? – MacMac

+0

ああ、問題もあります。 'heading_title_cell'の日付は数字の日付に対応していません。例えば、13日の日曜日、14日の月曜日、15日の火曜日などと言われます。 – MacMac

+0

@lolwut残念ですが、わかりません'next_prev_url'問題について。不一致は '$ prefs'配列の' date( 'l') 'にstrtolower()を使うだけです。 –

関連する問題