Advertisement
vsananthu

calendar widget problem

Jul 24th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1. /**
  2. * Front-end display of widget.
  3. *
  4. * @see WP_Widget::widget()
  5. *
  6. * @param array $args Widget arguments.
  7. * @param array $instance Saved values from database.
  8. */
  9. public function widget( $args, $instance ) {
  10. $title = apply_filters( 'widget_title', $instance['title'] );
  11. $user=wp_get_current_user();
  12. $course_ids=ld_get_mycourses($user);
  13.  
  14. echo $args['before_widget'];
  15.  
  16. foreach ($course_ids as $course_id) {
  17.  
  18. $course_status = learndash_course_status($course_id,$user->ID);
  19. $course = get_post($course_id);
  20.  
  21. echo "<h4>Events : ".get_the_title($course_id)."</h4>";
  22. $m=date('n');
  23. $y=date('Y');
  24.  
  25. draw_calendar($m,$y,$course);
  26.  
  27. /*-----------The Problem-------------*/
  28. //I need to loop through the $course array,get the $lessons array,loop through $lessons array and call a //method on the post object(i.e $lesson["post"]).I need to compare a value from the database with the id //of $lesson as key.The calendars need only be drawn according to no of courses and not no of lessons.
  29. //Any Ideas??
  30.  
  31. }
  32. echo $args['after_widget'];
  33. }
  34.  
  35. /*The calendar function:*/
  36. //Calendar:
  37. function draw_calendar($month,$year,$course_id){
  38.  
  39.  
  40.  
  41.  
  42. // Draw table for Calendar
  43.  
  44. $calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';
  45. $calendar.= '<caption class="calendar-cap">'.date('F').'</caption>';
  46. // Draw Calendar table headings
  47. $headings = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  48. $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';
  49.  
  50. //days and weeks variable for now ...
  51. $running_day = date('w',mktime(0,0,0,$month,1,$year));
  52. $days_in_month = date('t',mktime(0,0,0,$month,1,$year));
  53. $days_in_this_week = 1;
  54. $day_counter = 0;
  55. $dates_array = array();
  56.  
  57. // row for week one
  58. $calendar.= '<tr class="calendar-row">';
  59.  
  60. // Display "blank" days until the first of the current week
  61. for($x = 0; $x < $running_day; $x++):
  62. $calendar.= '<td class="calendar-day-np">&nbsp;</td>';
  63. $days_in_this_week++;
  64. endfor;
  65. $lessons = learndash_get_course_lessons_list($course);
  66.  
  67. $comp_time_m[$d]=date('m',get_option($user->ID.$lessons[$d]["post"]->ID.'comp_time'));
  68. $comp_time_d[$d]=date('d',get_option($user->ID.$lessons[$d]["post"]->ID.'comp_time'));
  69.  
  70.  
  71. for($list_day = 1; $list_day <= $days_in_month; $list_day++):
  72. if(empty($comp_time)) {
  73. //Current day styling
  74. if($list_day==$access_from_d && $month==$access_from_m)
  75. {
  76. $currentday='currentday';
  77. }else
  78. {
  79. $currentday='';
  80. }
  81. $calendar.= '<td class="calendar-day '.$currentday.'">';
  82.  
  83. // Add in the day number
  84. if($list_day<date('d') && $month==date('n'))
  85. {
  86. $showtoday=$list_day;
  87. }else
  88. {
  89. $showtoday=$list_day;
  90. }
  91. $calendar.= '<div class="day-number">'.$showtoday.'</a></div>';
  92.  
  93. // Draw table end
  94. $calendar.= '</td>';
  95. if($running_day == 6):
  96. $calendar.= '</tr>';
  97. if(($day_counter+1) != $days_in_month):
  98. $calendar.= '<tr class="calendar-row">';
  99. endif;
  100. $running_day = -1;
  101. $days_in_this_week = 0;
  102. endif;
  103.  
  104. }else{
  105.  
  106. //Current day styling
  107. if($list_day==$comp_time_d[$d] && $month==$comp_time_m[$d])
  108. {
  109. $currentday='currentday';
  110. }else
  111. {
  112. $currentday='';
  113. }
  114. $calendar.= '<td class="calendar-day '.$currentday.'">';
  115.  
  116. // Add in the day number
  117. if($list_day<date('d') && $month==date('n'))
  118. {
  119. $showtoday=$list_day;
  120. }else
  121. {
  122. $showtoday=$list_day;
  123. }
  124. $calendar.= '<div class="day-number">'.$showtoday.'</a></div>';
  125.  
  126. // Draw table end
  127. $calendar.= '</td>';
  128. if($running_day == 6):
  129. $calendar.= '</tr>';
  130. if(($day_counter+1) != $days_in_month):
  131. $calendar.= '<tr class="calendar-row">';
  132. endif;
  133. $running_day = -1;
  134. $days_in_this_week = 0;
  135. endif;
  136.  
  137. }
  138.  
  139. $days_in_this_week++; $running_day++; $day_counter++;
  140. endfor;
  141.  
  142.  
  143. // Finish the rest of the days in the week
  144. if($days_in_this_week < 8):
  145. for($x = 1; $x <= (8 - $days_in_this_week); $x++):
  146. $calendar.= '<td class="calendar-day-np">&nbsp;</td>';
  147. endfor;
  148. endif;
  149.  
  150. // Draw table final row
  151. $calendar.= '</tr>';
  152.  
  153. // Draw table end the table
  154. $calendar.= '</table>';
  155.  
  156. // Finally all done, return result
  157. echo $calendar;
  158.  
  159. }
  160.  
  161.  
  162.  
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement