Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Front-end display of widget.
- *
- * @see WP_Widget::widget()
- *
- * @param array $args Widget arguments.
- * @param array $instance Saved values from database.
- */
- public function widget( $args, $instance ) {
- $title = apply_filters( 'widget_title', $instance['title'] );
- $user=wp_get_current_user();
- $course_ids=ld_get_mycourses($user);
- echo $args['before_widget'];
- foreach ($course_ids as $course_id) {
- $course_status = learndash_course_status($course_id,$user->ID);
- $course = get_post($course_id);
- echo "<h4>Events : ".get_the_title($course_id)."</h4>";
- $m=date('n');
- $y=date('Y');
- draw_calendar($m,$y,$course);
- /*-----------The Problem-------------*/
- //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.
- //Any Ideas??
- }
- echo $args['after_widget'];
- }
- /*The calendar function:*/
- //Calendar:
- function draw_calendar($month,$year,$course_id){
- // Draw table for Calendar
- $calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';
- $calendar.= '<caption class="calendar-cap">'.date('F').'</caption>';
- // Draw Calendar table headings
- $headings = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
- $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';
- //days and weeks variable for now ...
- $running_day = date('w',mktime(0,0,0,$month,1,$year));
- $days_in_month = date('t',mktime(0,0,0,$month,1,$year));
- $days_in_this_week = 1;
- $day_counter = 0;
- $dates_array = array();
- // row for week one
- $calendar.= '<tr class="calendar-row">';
- // Display "blank" days until the first of the current week
- for($x = 0; $x < $running_day; $x++):
- $calendar.= '<td class="calendar-day-np"> </td>';
- $days_in_this_week++;
- endfor;
- $lessons = learndash_get_course_lessons_list($course);
- $comp_time_m[$d]=date('m',get_option($user->ID.$lessons[$d]["post"]->ID.'comp_time'));
- $comp_time_d[$d]=date('d',get_option($user->ID.$lessons[$d]["post"]->ID.'comp_time'));
- for($list_day = 1; $list_day <= $days_in_month; $list_day++):
- if(empty($comp_time)) {
- //Current day styling
- if($list_day==$access_from_d && $month==$access_from_m)
- {
- $currentday='currentday';
- }else
- {
- $currentday='';
- }
- $calendar.= '<td class="calendar-day '.$currentday.'">';
- // Add in the day number
- if($list_day<date('d') && $month==date('n'))
- {
- $showtoday=$list_day;
- }else
- {
- $showtoday=$list_day;
- }
- $calendar.= '<div class="day-number">'.$showtoday.'</a></div>';
- // Draw table end
- $calendar.= '</td>';
- if($running_day == 6):
- $calendar.= '</tr>';
- if(($day_counter+1) != $days_in_month):
- $calendar.= '<tr class="calendar-row">';
- endif;
- $running_day = -1;
- $days_in_this_week = 0;
- endif;
- }else{
- //Current day styling
- if($list_day==$comp_time_d[$d] && $month==$comp_time_m[$d])
- {
- $currentday='currentday';
- }else
- {
- $currentday='';
- }
- $calendar.= '<td class="calendar-day '.$currentday.'">';
- // Add in the day number
- if($list_day<date('d') && $month==date('n'))
- {
- $showtoday=$list_day;
- }else
- {
- $showtoday=$list_day;
- }
- $calendar.= '<div class="day-number">'.$showtoday.'</a></div>';
- // Draw table end
- $calendar.= '</td>';
- if($running_day == 6):
- $calendar.= '</tr>';
- if(($day_counter+1) != $days_in_month):
- $calendar.= '<tr class="calendar-row">';
- endif;
- $running_day = -1;
- $days_in_this_week = 0;
- endif;
- }
- $days_in_this_week++; $running_day++; $day_counter++;
- endfor;
- // Finish the rest of the days in the week
- if($days_in_this_week < 8):
- for($x = 1; $x <= (8 - $days_in_this_week); $x++):
- $calendar.= '<td class="calendar-day-np"> </td>';
- endfor;
- endif;
- // Draw table final row
- $calendar.= '</tr>';
- // Draw table end the table
- $calendar.= '</table>';
- // Finally all done, return result
- echo $calendar;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement