Disclaimer: I’m new to Web Development
So Far: I’ve been passing primary key data from a MySQL database table into the id=”” field of the calendar class library list item that is displayed on the calendar when generated, and I’ve also been passing another value associated with the row of its respective primary key to the list item as well.
Scenario: I’m needing to pass another value from the same respective row of the primary key into the class=”” of the list item, and I’ve hit a wall. I may need to create a new function in my modal, or do something within the controller where said calendar is generated, or I may be totally overlooking something completely simple. Regardless, I could use some very appreciated help. Thank you so much!
P.S. Please let me know if you need anymore information to help me out. Thanks again! You’re all wonderful!
Model:
class Events_model extends crud_model {
public function __construct()
{
parent::__construct();
$this->pk = 'id';
$this->table_name = 'events';
}
public function get_events_for_calendar($user_id, $year = FALSE, $month = FALSE)
{
if ( ! $year )
{
$year = date("Y");
}
if ( ! $month )
{
$month = date("m");
}
$this->db->where("user_id", $user_id);
$events = parent::get_all();
$cal_events = array();
foreach ($events as $e)
{
if ( date("Y", $e->date) == $year && date("m", $e->date) == $month)
{
$day = intval( date("d", $e->date));
//Swap out to change between displaying type or title of events listed -lrussell810
//$cal_events[$day][$e->id] = $e->type;
$cal_events[$day][$e->id] = $e->title;
}
}
return $cal_events;
}
Controller:
$this->load->library('calendar', $config);
$title['title'] = 'Planner';
$data = $this->events->get_events_for_calendar($this->end_user->id, $this->uri->segment(4), $this->uri->segment(5));
$calendar['calendar'] = $this->calendar->generate($this->uri->segment(4), $this->uri->segment(5), $data);
$this->load->view('public/head_view', $title);
$this->load->view('user/header_view');
$this->load->view('user/planner_view', $calendar);
$this->load->view('user/footer_view');
Calendar Library:
// If more than one event on the same day
if (is_array($data[$day]))
{
$several_events = '';
foreach ($data[$day] as $key => $value)
{
$several_events .= '<li class="" id="'.$key.'">'.$value.'</li>';
}
$out .= str_replace('{day}', $day, str_replace('{content}', $several_events, $temp));
}
Other Calendar Library Information:
// --------------------------------------------------------------------
/**
* Initialize the user preferences
*
* Accepts an associative array as input, containing display preferences
*
* @access public
* @param array config preferences
* @return void
*/
function initialize($config = array())
{
foreach ($config as $key => $val)
{
if (isset($this->$key))
{
$this->$key = $val;
}
}
}
If I understood correctly you want to add ‘more’ to your event when it is output visually as html, so you are adding referencing pk’s as ID’s (hence my comment above).
You can create an associative array for each event like so:
You would then later reference that array in your calendar library like so:
Hopefully that’s what you are looking for.