Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

posting of values in event calendar

Status
Not open for further replies.

misslois74

Programmer
Sep 27, 2008
63
PH
im currently working in my event calendar and im having difficulty posting certain values in each cell that represents each day of the month, i have a table which stores the starting date and ending date of a particular task and it should display on my event calendar the posted task on all the days defined by the starting date and ending date as of now my calendar is just displaying on the starting date and ending date itself...
hope somebody could help me with this...
thanks in advance....
 
Lois

it's difficult to help specifically without the code. But in general you may find my calendar code helpful. You should see a method called addDay(). in that method you should grab the data that you want to display and then output it just before the </td> link. Even if you don't use the code, it should give you an idea of how to achieve your aim.

the code is here
 
i was looking at your codes and i can use some of the logic of methods that is defined there for instance the method for incrementing the day counter because i know that i have to increment the starting date that is stored on the database and compare it against the ending date, am I on the right track?
here is my code:

Code:
<?php
 add_stylesheet_to_page('project/calendar.css');
?>
 <div class="calendar" >
  <h2><?php echo clean(lang(sprintf('month %u', $month))); ?> <?php echo $year; ?></h2>
<?php
  //for milestone
  $calendar = array();
  if (is_array($milestones) && count($milestones)) {
    foreach ($milestones as $milestone) {
      $due = $milestone->getDueDate();
      if ($due->getYear() != $year or $due->getMonth() != $month) {
        continue;
      }
      $calendar[$due->getDay()][] = $milestone;
    }
  } // if
  
  //for meeting
  $calendar2 = array();
  if (is_array($meetings) && count($meetings)) {
    foreach ($meetings as $meeting) {
      $due = $meeting->getScheduledOn();
      if ($due->getYear() != $year or $due->getMonth() != $month) {
        continue;
      }
      $calendar2[$due->getDay()][] = $meeting;
    }
  } // if

  //for task
  $calendar3 = array();   //ending task
  $calendar4 = array();  //starting task
  if (is_array($tasks) && count($tasks)) {
    foreach ($tasks as $task) {
      $start = $task->getStartDate();
	  $due = $task->getEndDate();
      if ($due->getYear() != $year or $due->getMonth() != $month) { //or 
        continue;
      }
	 
	  if ($start->getYear() != $year or $start->getMonth() != $month) {
	    continue;
	  }
	  
	  $calendar3[$due->getDay()][] = $task;
	  $calendar4[$start->getDay()][] = $task;
    }
  } // if
  
  $thisMonth = gmmktime(0, 0, 0, $month, 1, $year);
  $prevMonth = strtotime('-1 month', $thisMonth);
  $nextMonth = strtotime('+1 month', $thisMonth);
  $daysInMonth = gmdate('d', strtotime('+1 month -1 day', $thisMonth));
  $firstDayOfWeek = 1; // configurable?
  $daysInWeek = 7;
  $lastDayOfWeek = $firstDayOfWeek + $daysInWeek;
  $firstDayOfMonth = (gmdate('w', $thisMonth))-1;
  
?>
 <table width="100%">
    <tr valign="top">
<?php
  for ($dow = $firstDayOfWeek; $dow < $lastDayOfWeek; $dow++) {
    if (in_array($dow > $daysInWeek ? $dow - $daysInWeek : $dow, array(1, 7))) {
      $dow_class = "weekend";
    } else {
      $dow_class = "weekday";
    }
?>
      <th class="<?php echo $dow_class; ?>"><?php echo clean(lang(sprintf('dow %u', $dow > $daysInWeek ? $dow - $daysInWeek : $dow))); ?></th>
<?php
  } // for
?>
    </tr>
    <tr valign="top">
<?php

  /*
   * Skip days from previous month.
   */

  for ($dow = $firstDayOfWeek; $dow <= $firstDayOfMonth; $dow++) {
    if (in_array($dow > $daysInWeek ? $dow - $daysInWeek : $dow, array(1, 7))) {
      $dow_class = "weekend";
    } else {
      $dow_class = "weekday";
    }
?>

	<td class="<?php echo $dow_class; ?>"></td>

<?php
  } // for

  /*
   * Render the month's calendar.
   */

  for ($dom = 1; $dom <= $daysInMonth; ) {
      for (; ($dow < $lastDayOfWeek) && ($dom <= $daysInMonth); $dow++,$dom++) {
	  
	  
      if (in_array($dow > $daysInWeek ? $dow - $daysInWeek : $dow, array(1, 7))) {
        $dow_class = "weekend";
      } else {
        $dow_class = "weekday";
      }
?>

<td class="<?php echo $dow_class; ?>" onMouseover="showdiv('date_value[<?php echo $dom ?>]')" onMouseout="hidediv('date_value[<?php echo $dom ?>]')" style="vertical-align:text-top;">
  <div class="date">
    <div id="date_value[<?php echo $dom ?>]" style="float:left; visibility:hidden">&nbsp;<a href="<?php echo active_project()->getMilestonesUrl() ?>"><img src="<?php echo icon_url('mi.gif') ?>" title="New Milestone"/></a>&nbsp;<a href="<?php echo active_project()->getTasksUrl() ?>"><img src="<?php echo icon_url('td.gif') ?>" title="New Task"/></a>&nbsp;<a href="<?php echo active_project()->getMeetingsUrl() ?>"><img src="<?php echo icon_url('me.gif') ?>" title="New Meeting" /></a></div>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  <?php if ($dom == date('d') && $month == date('m') && $year == date('Y')) {  ?>
	         <span class="date_today" style="font-size:14px; color:#0000FF; background-color:#FFFFCC;"><?php echo $dom; ?></span><br />
<?php } else { ?> <span style="font-size:12px; color: #000000"> <?php echo $dom;  ?> </span> <?php }  ?><br />
<br />
   <?php
      //display scheduled milestone per month
      if (isset($calendar[$dom]) && is_array($calendar[$dom])
        && count($calendar[$dom])) {
?>
  <?php foreach ($calendar[$dom] as $m) { ?> 
    <?php printf('<img src="'.icon_url('milestone.png').'"><a href="%s">%s</a>'."\n", 
                get_url("milestone", "view", $m->getId()),
                clean($m->getName())); ?>
    <br />
    <?php } //for
    } // if ?>
    
  <?php
	  //display scheduled ending date of task per month
      if (isset($calendar3[$dom]) && is_array($calendar3[$dom])
        && count($calendar3[$dom])) {
  ?>
  
   <?php 
       foreach ($calendar3[$dom] as $t) {
	         $task_start_date = $t->getStartDate()->getDay();
			 $task_end_date = $t->getEndDate()->getDay();
   		     
             if(($task_start_date <= $dom) || ($task_end_date == $dom)) {?>
             <?php printf('<img src="'.icon_url('task.png').'"><a href="%s">%s</a>'."\n", 
                   get_url("task", "task_list", $t->getId()),
                   clean($t->getText())); 
             } //if?>
    <br />
    <?php $task_start_date = $task_start_date + 1;
	      $task_end_date = $task_end_date + 1;     
     } //for
    } // if ?>


   <?php
	  //display scheduled starting date of task per month
      /*if (isset($calendar4[$dom]) && is_array($calendar4[$dom])
        && count($calendar4[$dom])) { 
  ?>
  <?php foreach ($calendar4[$dom] as $ta) { 
          // if ($due->getDay() == $dom) {
          //if(($t->getEndDate()->getDay() == $dom) || (($dom >= $t->getStartDate()->getDay()) && ($dom <= $t->getEndDate()->getDay()))) {?>
          <?php printf('<img src="'.icon_url('task.png').'"><a href="%s">%s</a>'."\n", 
                get_url("task", "task_list", $ta->getId()),
                clean($ta->getText())); 
           //} //if?>
    <br />
    <?php } //for
    } // if */?>

   
  <?php
      //display scheduled meeting per month
      if (isset($calendar2[$dom]) && is_array($calendar2[$dom])
        && count($calendar2[$dom])) {
?>
  <?php foreach ($calendar2[$dom] as $me) { ?>
  <?php printf('<img src="'.icon_url('meeting.png').'"><a href="%s">%s</a>'."\n", 
                get_url("meeting", "view", $me->getId()),
                clean($me->getDescription())); ?>
    <br />
    <?php } //for
    } // if ?>

<?php
    } // for
?>  </td>
<?php if ($dom <= $daysInMonth) { ?>
    </tr>
    <tr valign="top">
<?php
      $dow = $firstDayOfWeek;
    } // if
  } // for

  /*
   * Skip days from next month.
   */

  if ($dow < $lastDayOfWeek) {
    for (; $dow < $lastDayOfWeek; $dow++) {
      if (in_array($dow > $daysInWeek ? $dow - $daysInWeek : $dow, array(1, 7))) {
        $dow_class = "weekend";
      } else {
        $dow_class = "weekday";
      }
?>
      <td class="<?php echo $dow_class; ?>">&nbsp;</td>
<?php
    } // for
?>
    </tr>
<?php
  } // if
?>
</table>
  <div class="month-nav">
    <div class="prev-month"><a href="<?php echo get_url('calendar', 'index', gmdate('Ym', $prevMonth)); ?>"><?php echo clean(lang(sprintf('month %u', gmdate('m', $prevMonth)))); ?> <?php echo gmdate('Y', $prevMonth); ?></a></div>
    <div class="next-month"><a href="<?php echo get_url('calendar', 'index', gmdate('Ym', $nextMonth)); ?>"><?php echo clean(lang(sprintf('month %u', gmdate('m', $nextMonth)))); ?> <?php echo gmdate('Y', $nextMonth); ?></a></div>
  </div>
</div>
thanks in advance....
 
i have not thought about the entity mechanics of an event, to be honest. off the top of my head there might be two suitable methods

1. store a join table to keep a link between an event and a day.
2. duplicate an event for each day on which it is active, and then include a column that links each of those duplicates back to the original. you could use this method both for multi-day events and for repeating events (since they are essentially the same thing).

on balance i'd go for method 2

 
and for my code, i would add in a class for events and event and query the objects in the addDay method.
 
you were saying on your method 2 that I need to:

duplicate an event for each day on which it is active, and then include a column that links each of those duplicates back to the original. you could use this method both for multi-day events and for repeating events (since they are essentially the same thing).

does it mean that when i enter a task let say the starting date is Oct 20 and the ending date is Oct 25 it should store a duplicate event for Oct. 21-24 on the database, am I getting your idea?
 
yes. i think that is preferable to storing a start date and end date.
 
hi, Jpadie!

is there another way of doing it instead of duplicating my entry for the task for the days it will be active, im thinking of creating an array that would store the days from the starting date till the ending date and thats what i would call on the display on my calender

here is the code that stores in the array the date of the starting and ending date:

Code:
 $calendar3 = array();   //ending task
  $calendar4 = array();  //starting task
  if (is_array($tasks) && count($tasks)) {
    foreach ($tasks as $task) {
      $start = $task->getStartDate();
	  $due = $task->getEndDate();
      if ($due->getYear() != $year or $due->getMonth() != $month) { //or 
        continue;
      }
	 
	  if ($start->getYear() != $year or $start->getMonth() != $month) {
	    continue;
	  }
	  
	  $calendar3[$due->getDay()][] = $task;
	  $calendar4[$start->getDay()][] = $task;
    }
  } // if
 
it rather depends on how you integrate the events class and the date class. you might want to take a look at phpcalendar and look at how that app parses vCal files. that might well give you other ideas as to how to do the necessary.

if you are asking whether you can use php to read the whole events table and do some pre-processing to build a date based array, then sure: that would work. but it is less efficient that using mysql to do the heavy lifting for you.
 
hi Jpadie,

thanks for replying, anyways i was able to work it out my task is now being posted on the dates on which it is scheduled what i did was I used the function range put the field of starting date and ending date then i store it in an variable and thats what i used on my array...
thanks for sharing to me your codes for the event calendar....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top