Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-27-2013, 01:22 PM   PM User | #1
dobers31
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
dobers31 is an unknown quantity at this point
Codeignitor Calendar template modification of content

I'm using the CI Calendar. The db that I've connected it with has columns for: date, hours, category, and notes. I started out with the same format as in this tutorial from net tuts+. I can get the calendar to display the notes on the appropriate day, but I'm not sure how to split up the content section into hours, category and notes. I know I have to modify the generate calender in the system file, but not sure how to do it.

Here's my code:

Controller:

Code:
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();

    }
Model:

Code:
<?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);

  }
}
Calendar Template:
Code:
<?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 code in my view:
Code:
$(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();
                        }
                    });

                }

        });

    });
});
I've done a ton of research and haven't really found what I'm looking for. So any help with this is greatly appreciated.
dobers31 is offline   Reply With Quote
Reply

Bookmarks

Tags
calendar, codeignitor, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:32 AM.


Advertisement
Log in to turn off these ads.