Welcome Guest, Not a member yet? Register   Sign In
multiple calendars
#1

[eluser]timj[/eluser]
I am building an application that, on one page, projects 12 months of future mini calendars starting with the current month, but I am not finding samples of how to build that loop. Does someone have a code snippet to illustrate how this is constructed?
#2

[eluser]darky84[/eluser]
you need to create database and table called (calendar Smile
columns: date type date, data type text

this is the controller
Code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mycal extends CI_Controller
{
var $year ;
function __construct()
{
  parent::__construct();
}

function display($year = null, $month = null)
{
  $cur_year    = date("Y");
               $cur_month    = date("m");
        $cur_day    = date("d");
        $cur_week = date("W");
        echo $cur_week;
  
  if(!$year or $year == null)
  {
   $Date = date('Y-m-d');
   $year = substr($Date,0,4);
   $month = substr($Date,5,2);
  }
  
  if(!$month or $month ==  null)
  {
   $Date = date('Y-m-d');
  
   $month = substr($Date,5,2);
  }
  
  
  $this->load->model('mycal_model');
  $data = array();
  $data['calendar'] = $this->mycal_model->generate($year,$month);

  $this->load->view('mycal' , $data);

  
  
}

function yearly($year = null)
{

  //$year = date("Y");
  if(!$year or $year == null)
  {
   $Date = date('Y-m-d');
   $year = substr($Date,0,4);
   //$month = substr($Date,5,2);
  }
  $this->load->model('mycal_model');
  $data = array();
  
  $data['calendar1'] = $this->mycal_model->generateYear($year,1);
  $data['calendar2'] = $this->mycal_model->generateYear($year,2);
  $data['calendar3'] = $this->mycal_model->generateYear($year,3);
  $data['calendar4'] = $this->mycal_model->generateYear($year,4);
  $data['calendar5'] = $this->mycal_model->generateYear($year,5);
  $data['calendar6'] = $this->mycal_model->generateYear($year,6);
  $data['calendar7'] = $this->mycal_model->generateYear($year,7);
  $data['calendar8'] = $this->mycal_model->generateYear($year,8);
  $data['calendar9'] = $this->mycal_model->generateYear($year,9);
  $data['calendar10'] = $this->mycal_model->generateYear($year,10);
  $data['calendar11'] = $this->mycal_model->generateYear($year,11);
  $data['calendar12'] = $this->mycal_model->generateYear($year,12);

  $data['currentyear'] = $year;

  $this->load->view('year' , $data);
}

this is the model

Code:
<?php


class Mycal_model extends CI_Model
{
var $confMonth;
var $confYear;

function Mycal_model()
{
  parent::__construct();
  
  $this->confMonth = array(
      'start_day' => 'saturday',
      'show_next_prev' => true,
      'next_prev_url' => base_url() . 'mycal/display',
      'month_type'   => 'short',
                                  'day_type'     => 'long'
  );
  
  $this->confYear = array(
      'start_day' => 'saturday',
      'month_type'   => 'short',
                                  'day_type'     => 'long'
  );
  
}
function generate($year,$month)
{
  echo $year ." : " .$month;
  $this->load->library('calendar',$this->confMonth);
  $cal_data = $this->get_calendar_data($year,$month);
  return $this->calendar->generate($year,$month,$cal_data);
}

function generateYear($year,$month)
{
  $this->load->library('calendar',$this->confYear);
  $cal_data = $this->get_calendar_data_year($year,$month);
  return $this->calendar->generate($year,$month,$cal_data);
}

function get_calendar_data($year,$month)
{
  $cal_data = array();
  
  $query = $this->db->select('date,data')->from('calendar')->like('date',"$year-$month")->get();
  $query = $query->result();
  foreach ($query as $row)
  {
   $day = (int)substr($row->date,8,2);
   $cal_data[(int)$day] = $row->data;
  }
  
  return $cal_data;
}

function get_calendar_data_year($year,$month)
{
  $cal_data = array();
  $month = "0".$month;
  $query = $this->db->select('date,data')->from('calendar')->like('date',"$year-$month")->get();
  $query = $query->result();
  foreach ($query as $row)
  {
   $day = (int)substr($row->date,8,2);
  
   $cal_data[(int)$day] = $row->data;
  
  }
  return $cal_data;
}




Theme © iAndrew 2016 - Forum software by © MyBB