• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting event using a date, not a day in every month?

#1
[eluser]stef569[/eluser]
Hi,

When I add a event to my calendar I want to set it to a specific date.

atm I use

Code:
<?php $events = array(
    1/11/2007  => 'AAAAAAAAAAAAAAA',
  7  => 'B',
  13 => 'C',
  26 => 'D'
  ); ?>

But it appears to only work with days, I tried to put a date in but AAA is not showing up.
Does the calender only support reoccuring events over months?

nvm reading uri.. can't delete this topic.

#2
[eluser]gtech[/eluser]
It took me a while to understand what you mean but I think you want something like the following?

Code:
<?php
class Some_class extends Controller {

  function Some_class() {
    parent::Controller();
    $base = base_url();
    $prefs = array (
      'start_day'    => 'monday',
      'month_type'   => 'long',
      'day_type'     => 'short',
      'show_next_prev' => TRUE,
      'next_prev_url'  => $base."/index.php/some_class/show/"
    );
    $this->load->library('calendar', $prefs);
  }
    
  function show() {
    $events = array();
    if ($this->uri->segment(3) == '2007') {
      if ($this->uri->segment(4) == '11') {
        $events = array(7  => 'B', 13 => 'C', 26 => 'D');
      }
    }
    echo $this->calendar->generate($this->uri->segment(3),        
                                   $this->uri->segment(4),
                                   $events);
  }
}
?>

#3
[eluser]stef569[/eluser]
Well, yes but I use a db so my code looks as following:
Code:
function show() {
        $month = $this->uri->segment(3);
        $year = $this->uri->segment(4);
        $query = $this->db->query('SELECT user_id, event_Bday, event_EDay FROM events WHERE event_month='.$month.' AND event_year='.$year);
        $data['events'] = this->createEvents($query);
        $data['heading'] = 'Week toeren Kalender';
        $this->load->view('calender_view', $data);
    }
    
    // Create array of days with content
    function createEvents($query) {
        foreach($query->result() as $row) {
            $curDay = $row['event_Bday'];
            while($curDay < $row['event_EDay']) {
                $curDay++;
                $events = array($curDay  => $row['user_id']);
            }
        }
        return $events;
    }

but I get
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: events

Filename: controllers/calender.php

Line Number: 82
Confused

#4
[eluser]gtech[/eluser]
Code:
// Create array of days with content

    function createEvents($query) {
        $events = array();
        foreach($query->result_array() as $row) {
            $curDay = $row['event_Bday'];
            while($curDay < $row['event_EDay']) {
                $curDay++;
                $events[$curDay] = $row['user_id'];
            }
        }
        return $events;
    }

I'll put my pennies worth in..



think as you are using arrays to access the query result you should be using $query->result_array();

you need to default the events array in case nothing is returned and also you were also overwriting the events array (not sure that was desired behavior?)

I have tried to do a fix see above but it is untested.

another tip, if your debugging use echo and print_r to display variables (you can take them out when it works)

e.g.

Code:
...
  ...
  while($curDay < $row['event_EDay']) {
    $curDay++;
    $events[$curDay] = $row['user_id'];
    echo "Current Day:".$curDay."<br>";
    echo "Events Array<br>";
    print_r($events);
  }
  ...
  ...

#5
[eluser]stef569[/eluser]
Hi, I saw my errors and correct them,

1. I was overwriting my array (no that wasen't part of the plan :d)
2. I thought I got an aray when it was an object.
3. Input validation
4. Testing i didn't know about the print_r will look into it.

This works:
Code:
// Create array of days as key with content(userId)
    //@param $query db record object.
    function createEvents($query) {
         if ($query->num_rows() > 0) {
          foreach ($query->result() as $row) {
                $curDay = $row->event_Bday;
                while($curDay <= $row->event_EDay) {
                    echo 'Day: '.$curDay.' UserId: '.$row->user_id.'<br/>';
                    $events[$curDay++] = $row->user_id;
                }
            }
        } else {
            echo 'No Events for this month.';
        }
         return $events;
    }

Thx for the help once again, I realy learnt alot from your code examples
Mayby once I can help you out Smile so we are even again Wink


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.