1

CIカレンダーを使用しています。接続したデータベースには、日付、時間、カテゴリ、メモの列があります。私はnettuts+からこのチュートリアルと同じフォーマットで始めました。カレンダーに適切な日にメモを表示させることはできますが、コンテンツセクションを時間、カテゴリ、メモに分割する方法がわかりません。システムファイルの生成カレンダーを変更する必要があることはわかっていますが、その方法がわかりません。

これが私のコードです:

コントローラ:

function index($year = null, $month = null)
    {
        if (!$year) {
            $year = date('Y');
        }
        if (!$month) {
            $month = date('m');
        }

        $this->load->model('calendar_model');

        if ($day = $this->input->post('day')) {
            $this->calendar_model->add_calendar_data(
                "$year-$month-$day",
                $this->input->post('hours'),
                $this->input->post('category'),
                $this->input->post('notes')
            );
        }

        $data['calendar'] = $this->calendar_model->generate($year, $month);


        // Load a view in the content partial
        $this->template->content->view('includes/user_navigation');
        $this->template->content->view('dashboard', $data);

        // Display the template
        $this->template->publish();

    }

モデル:

<?php

class Calendar_model extends CI_Model {

   var $conf;

     function Calendar_model()
    {
      parent::__construct();


  }

  function get_calendar_data($year, $month) {

    $query = $this->db->select()->from('calendar')
      ->like('date', "$year-$month", 'after')->get();

    $cal_data = array();

    foreach ($query->result() as $row) {
      $cal_data[substr($row->date,8,2)] = $row->notes;


      /* Testing purposes */
      echo "<p>" . $row->date . "</p>";
      echo"<p>" . $row->hours . "</p>";
      echo "<p>" . $row->category . "</p>";
      echo "<p>" . $row->notes . "</p>";
    }

    return $cal_data;

  }

  function add_calendar_data($date, $hours, $category, $notes) {

    if ($this->db->select('date')->from('calendar')
        ->where('date', $date)->count_all_results()) {

      $this->db->where('date', $date)
        ->update('calendar', array(
        'date' => $date,
        'hours' => $hours,
        'category' => $category,
        'notes' => $notes
      ));

    } else {

      $this->db->insert('calendar', array(
        'date' => $date,
        'hours' => $hours,
        'category' => $category,
        'notes' => $notes
      ));
    }

  }

  function generate ($year, $month) {

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

    $cal_data = $this->get_calendar_data($year, $month);

    return $this->calendar->generate($year, $month, $cal_data);

  }
}

カレンダーテンプレート:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Calendar configuration
|--------------------------------------------------------------------------
| This file will contain the settings for the calendar template library.
|
*/

$config['day_type'] = 'long';
$config['show_next_prev'] = true;
$config['next_prev_url'] = base_url('index.php/calendar/display');

$config['template'] = '

      {table_open}
        <table class="calendar">
      {/table_open}

      {heading_row_start}<tr>{/heading_row_start}
      {heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}
      {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
      {heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}
      {heading_row_end}</tr>{/heading_row_end}

      {week_day_cell}
        <th class="day_header">{week_day}</th>
      {/week_day_cell}

      {cal_row_start}<tr class="days">{/cal_row_start}
      {cal_cell_start}<td class="day">{/cal_cell_start}

      {cal_cell_content}
        <div class="day_num">{day}</div>
        <div class="content">
          <div class="category">{category}
            <div class="hours">{hours}
              <div class="notes">{notes}
                {content}
              </div>
            </div>
          </div>
        </div>
      {/cal_cell_content}

      {cal_cell_content_today}
        <div class="today"><div class="day_num">{day}</div>
        <div class="content">{content}</div></div>
      {/cal_cell_content_today}

      {cal_cell_no_content}
        <div class="day_num">{day}</div>
      {/cal_cell_no_content}

      {cal_cell_no_content_today}
        <div class="today"><div class="day_num">{day}</div></div>
      {/cal_cell_no_content_today}
    ';

私の見解ではjsコード:

$(document).ready(function(){
var date;
   // === Prepare calendar === //
   $('.calendar .day').click(function() {
        day_num = $(this).find('.day_num').html();
        $("#activityModal").modal('toggle');

        $('#add-event-submit').click(function(){
                var hrs = document.getElementById('activityHrs').value;
                var note = document.getElementById('activityNotes').value;
                var cat = document.getElementById('activityCats');
                var selectedCat = cat.options[cat.selectedIndex].text;

            var message = "Date: " + date + "\n";
                message += "hrs: " + hrs + "\n";
                message += "category: " + selectedCat + "\n";
                message += "note: " + note;
                message += "day num: " + day_num;


                //alert(message);


                if (hrs != null && selectedCat !=null && note !=null) {

                    $.ajax({
                        url: window.location,
                        type: 'POST',
                        data: {
                            day: day_num,
                            hours: hrs,
                            category: selectedCat,
                            notes: note
                        },
                        success: function(msg) {
                            location.reload();
                        }
                    });
                }
        });
    });
});
4

0 に答える 0