/** * Test all the core functions that use the calendar type system. * * @param string $type the calendar type we want to test */ private function core_functions_test($type) { $this->set_calendar_type($type); // Get the calendar. $calendar = \core_calendar\type_factory::get_calendar_instance(); // Test the userdate function. $this->assertEquals($calendar->timestamp_to_date_string($this->user->timecreated, '', 99, true, true), userdate($this->user->timecreated)); // Test the calendar/lib.php functions. $this->assertEquals($calendar->get_weekdays(), calendar_get_days()); $this->assertEquals($calendar->get_starting_weekday(), calendar_get_starting_weekday()); $this->assertEquals($calendar->get_num_days_in_month('1986', '9'), calendar_days_in_month('9', '1986')); $this->assertEquals($calendar->get_next_month('1986', '9'), calendar_add_month('9', '1986')); $this->assertEquals($calendar->get_prev_month('1986', '9'), calendar_sub_month('9', '1986')); // Test the lib/moodle.php functions. $this->assertEquals($calendar->get_num_days_in_month('1986', '9'), days_in_month('9', '1986')); $this->assertEquals($calendar->get_weekday('1986', '9', '16'), dayofweek('16', '9', '1986')); }
/** * Get control options for Calendar * * @param string $type of calendar * @param array $data calendar information * @return string $content return available control for the calender in html */ function calendar_top_controls($type, $data) { global $PAGE; // Get the calendar type we are using. $calendartype = \core_calendar\type_factory::get_calendar_instance(); $content = ''; // Ensure course id passed if relevant. $courseid = ''; if (!empty($data['id'])) { $courseid = '&course=' . $data['id']; } // If we are passing a month and year then we need to convert this to a timestamp to // support multiple calendars. No where in core should these be passed, this logic // here is for third party plugins that may use this function. if (!empty($data['m']) && !empty($date['y'])) { if (!isset($data['d'])) { $data['d'] = 1; } if (!checkdate($data['m'], $data['d'], $data['y'])) { $time = time(); } else { $time = make_timestamp($data['y'], $data['m'], $data['d']); } } else { if (!empty($data['time'])) { $time = $data['time']; } else { $time = time(); } } // Get the date for the calendar type. $date = $calendartype->timestamp_to_date_array($time); $urlbase = $PAGE->url; // We need to get the previous and next months in certain cases. if ($type == 'frontpage' || $type == 'course' || $type == 'month') { $prevmonth = calendar_sub_month($date['mon'], $date['year']); $prevmonthtime = $calendartype->convert_to_gregorian($prevmonth[1], $prevmonth[0], 1); $prevmonthtime = make_timestamp($prevmonthtime['year'], $prevmonthtime['month'], $prevmonthtime['day'], $prevmonthtime['hour'], $prevmonthtime['minute']); $nextmonth = calendar_add_month($date['mon'], $date['year']); $nextmonthtime = $calendartype->convert_to_gregorian($nextmonth[1], $nextmonth[0], 1); $nextmonthtime = make_timestamp($nextmonthtime['year'], $nextmonthtime['month'], $nextmonthtime['day'], $nextmonthtime['hour'], $nextmonthtime['minute']); } switch ($type) { case 'frontpage': $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), $urlbase, false, false, false, true, $prevmonthtime); $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), $urlbase, false, false, false, true, $nextmonthtime); $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), false, false, false, $time); if (!empty($data['id'])) { $calendarlink->param('course', $data['id']); } if (right_to_left()) { $left = $nextlink; $right = $prevlink; } else { $left = $prevlink; $right = $nextlink; } $content .= html_writer::start_tag('div', array('class' => 'calendar-controls')); $content .= $left . '<span class="hide"> | </span>'; $content .= html_writer::tag('span', html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')), array('title' => get_string('monththis', 'calendar'))), array('class' => 'current')); $content .= '<span class="hide"> | </span>' . $right; $content .= "<span class=\"clearer\"><!-- --></span>\n"; $content .= html_writer::end_tag('div'); break; case 'course': $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), $urlbase, false, false, false, true, $prevmonthtime); $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), $urlbase, false, false, false, true, $nextmonthtime); $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), false, false, false, $time); if (!empty($data['id'])) { $calendarlink->param('course', $data['id']); } if (right_to_left()) { $left = $nextlink; $right = $prevlink; } else { $left = $prevlink; $right = $nextlink; } $content .= html_writer::start_tag('div', array('class' => 'calendar-controls')); $content .= $left . '<span class="hide"> | </span>'; $content .= html_writer::tag('span', html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')), array('title' => get_string('monththis', 'calendar'))), array('class' => 'current')); $content .= '<span class="hide"> | </span>' . $right; $content .= "<span class=\"clearer\"><!-- --></span>"; $content .= html_writer::end_tag('div'); break; case 'upcoming': $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'upcoming')), false, false, false, $time); if (!empty($data['id'])) { $calendarlink->param('course', $data['id']); } $calendarlink = html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear'))); $content .= html_writer::tag('div', $calendarlink, array('class' => 'centered')); break; case 'display': $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), false, false, false, $time); if (!empty($data['id'])) { $calendarlink->param('course', $data['id']); } $calendarlink = html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear'))); $content .= html_writer::tag('h3', $calendarlink); break; case 'month': $prevlink = calendar_get_link_previous(userdate($prevmonthtime, get_string('strftimemonthyear')), 'view.php?view=month' . $courseid . '&', false, false, false, false, $prevmonthtime); $nextlink = calendar_get_link_next(userdate($nextmonthtime, get_string('strftimemonthyear')), 'view.php?view=month' . $courseid . '&', false, false, false, false, $nextmonthtime); if (right_to_left()) { $left = $nextlink; $right = $prevlink; } else { $left = $prevlink; $right = $nextlink; } $content .= html_writer::start_tag('div', array('class' => 'calendar-controls')); $content .= $left . '<span class="hide"> | </span><h1 class="current">' . userdate($time, get_string('strftimemonthyear')) . "</h1>"; $content .= '<span class="hide"> | </span>' . $right; $content .= '<span class="clearer"><!-- --></span>'; $content .= html_writer::end_tag('div') . "\n"; break; case 'day': $days = calendar_get_days(); $prevtimestamp = $time - DAYSECS; $nexttimestamp = $time + DAYSECS; $prevdate = $calendartype->timestamp_to_date_array($prevtimestamp); $nextdate = $calendartype->timestamp_to_date_array($nexttimestamp); $prevname = $days[$prevdate['wday']]['fullname']; $nextname = $days[$nextdate['wday']]['fullname']; $prevlink = calendar_get_link_previous($prevname, 'view.php?view=day' . $courseid . '&', false, false, false, false, $prevtimestamp); $nextlink = calendar_get_link_next($nextname, 'view.php?view=day' . $courseid . '&', false, false, false, false, $nexttimestamp); if (right_to_left()) { $left = $nextlink; $right = $prevlink; } else { $left = $prevlink; $right = $nextlink; } $content .= html_writer::start_tag('div', array('class' => 'calendar-controls')); $content .= $left; $content .= '<span class="hide"> | </span><span class="current">' . userdate($time, get_string('strftimedaydate')) . '</span>'; $content .= '<span class="hide"> | </span>' . $right; $content .= "<span class=\"clearer\"><!-- --></span>"; $content .= html_writer::end_tag('div') . "\n"; break; } return $content; }
/** * Displays a month in detail * * @param calendar_information $calendar * @param moodle_url $returnurl the url to return to * @return string */ public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null) { global $CFG; if (empty($returnurl)) { $returnurl = $this->page->url; } // Get the calendar type we are using. $calendartype = \core_calendar\type_factory::get_calendar_instance(); // Store the display settings. $display = new stdClass(); $display->thismonth = false; // Get the specified date in the calendar type being used. $date = $calendartype->timestamp_to_date_array($calendar->time); $thisdate = $calendartype->timestamp_to_date_array(time()); if ($date['mon'] == $thisdate['mon'] && $date['year'] == $thisdate['year']) { $display->thismonth = true; $date = $thisdate; $calendar->time = time(); } // Get Gregorian date for the start of the month. $gregoriandate = $calendartype->convert_to_gregorian($date['year'], $date['mon'], 1); // Store the gregorian date values to be used later. list($gy, $gm, $gd, $gh, $gmin) = array($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute']); // Get the starting week day for this month. $startwday = dayofweek(1, $date['mon'], $date['year']); // Get the days in a week. $daynames = calendar_get_days(); // Store the number of days in a week. $numberofdaysinweek = $calendartype->get_num_weekdays(); $display->minwday = calendar_get_starting_weekday(); $display->maxwday = $display->minwday + ($numberofdaysinweek - 1); $display->maxdays = calendar_days_in_month($date['mon'], $date['year']); // These are used for DB queries, so we want unixtime, so we need to use Gregorian dates. $display->tstart = make_timestamp($gy, $gm, $gd, $gh, $gmin, 0); $display->tend = $display->tstart + $display->maxdays * DAYSECS - 1; // Align the starting weekday to fall in our display range // This is simple, not foolproof. if ($startwday < $display->minwday) { $startwday += $numberofdaysinweek; } // Get events from database $events = calendar_get_events($display->tstart, $display->tend, $calendar->users, $calendar->groups, $calendar->courses); if (!empty($events)) { foreach ($events as $eventid => $event) { $event = new calendar_event($event); if (!empty($event->modulename)) { $cm = get_coursemodule_from_instance($event->modulename, $event->instance); if (!\core_availability\info_module::is_user_visible($cm, 0, false)) { unset($events[$eventid]); } } } } // Extract information: events vs. time calendar_events_by_day($events, $date['mon'], $date['year'], $eventsbyday, $durationbyday, $typesbyday, $calendar->courses); $output = html_writer::start_tag('div', array('class' => 'header')); $output .= $this->course_filter_selector($returnurl, get_string('detailedmonthviewfor', 'calendar')); if (calendar_user_can_add_event($calendar->course)) { $output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time); } $output .= html_writer::end_tag('div', array('class' => 'header')); // Controls $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid, 'time' => $calendar->time)), array('class' => 'controls')); $table = new html_table(); $table->attributes = array('class' => 'calendarmonth calendartable'); $table->summary = get_string('calendarheading', 'calendar', userdate($calendar->time, get_string('strftimemonthyear'))); $table->data = array(); // Get the day names as the header. $header = array(); for ($i = $display->minwday; $i <= $display->maxwday; ++$i) { $header[] = $daynames[$i % $numberofdaysinweek]['shortname']; } $table->head = $header; // For the table display. $week is the row; $dayweek is the column. $week = 1; $dayweek = $startwday; $row = new html_table_row(array()); // Paddding (the first week may have blank days in the beginning) for ($i = $display->minwday; $i < $startwday; ++$i) { $cell = new html_table_cell(' '); $cell->attributes = array('class' => 'nottoday dayblank'); $row->cells[] = $cell; } // Now display all the calendar $weekend = CALENDAR_DEFAULT_WEEKEND; if (isset($CFG->calendar_weekend)) { $weekend = intval($CFG->calendar_weekend); } $daytime = $display->tstart - DAYSECS; for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) { $daytime = $daytime + DAYSECS; if ($dayweek > $display->maxwday) { // We need to change week (table row) $table->data[] = $row; $row = new html_table_row(array()); $dayweek = $display->minwday; ++$week; } // Reset vars $cell = new html_table_cell(); $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'day', 'course' => $calendar->courseid)), 0, 0, 0, $daytime); $cellclasses = array(); if ($weekend & 1 << $dayweek % $numberofdaysinweek) { // Weekend. This is true no matter what the exact range is. $cellclasses[] = 'weekend'; } // Special visual fx if an event is defined if (isset($eventsbyday[$day])) { if (count($eventsbyday[$day]) == 1) { $title = get_string('oneevent', 'calendar'); } else { $title = get_string('manyevents', 'calendar', count($eventsbyday[$day])); } $cell->text = html_writer::tag('div', html_writer::link($dayhref, $day, array('title' => $title)), array('class' => 'day')); } else { $cell->text = html_writer::tag('div', $day, array('class' => 'day')); } // Special visual fx if an event spans many days $durationclass = false; if (isset($typesbyday[$day]['durationglobal'])) { $durationclass = 'duration_global'; } else { if (isset($typesbyday[$day]['durationcourse'])) { $durationclass = 'duration_course'; } else { if (isset($typesbyday[$day]['durationgroup'])) { $durationclass = 'duration_group'; } else { if (isset($typesbyday[$day]['durationuser'])) { $durationclass = 'duration_user'; } } } } if ($durationclass) { $cellclasses[] = 'duration'; $cellclasses[] = $durationclass; } // Special visual fx for today if ($display->thismonth && $day == $date['mday']) { $cellclasses[] = 'day today'; } else { $cellclasses[] = 'day nottoday'; } $cell->attributes = array('class' => join(' ', $cellclasses)); if (isset($eventsbyday[$day])) { $cell->text .= html_writer::start_tag('ul', array('class' => 'events-new')); foreach ($eventsbyday[$day] as $eventindex) { // If event has a class set then add it to the event <li> tag $attributes = array(); if (!empty($events[$eventindex]->class)) { $attributes['class'] = $events[$eventindex]->class; } $dayhref->set_anchor('event_' . $events[$eventindex]->id); $link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true)); $cell->text .= html_writer::tag('li', $link, $attributes); } $cell->text .= html_writer::end_tag('ul'); } if (isset($durationbyday[$day])) { $cell->text .= html_writer::start_tag('ul', array('class' => 'events-underway')); foreach ($durationbyday[$day] as $eventindex) { $cell->text .= html_writer::tag('li', '[' . format_string($events[$eventindex]->name, true) . ']', array('class' => 'events-underway')); } $cell->text .= html_writer::end_tag('ul'); } $row->cells[] = $cell; } // Paddding (the last week may have blank days at the end) for ($i = $dayweek; $i <= $display->maxwday; ++$i) { $cell = new html_table_cell(' '); $cell->attributes = array('class' => 'nottoday dayblank'); $row->cells[] = $cell; } $table->data[] = $row; $output .= html_writer::table($table); return $output; }
/** * Get control options for Calendar * * @param string $type of calendar * @param array $data calendar information * @return string $content return available control for the calender in html */ function calendar_top_controls($type, $data) { global $CFG; $content = ''; if (!isset($data['d'])) { $data['d'] = 1; } // Ensure course id passed if relevant // Required due to changes in view/lib.php mainly (calendar_session_vars()) $courseid = ''; if (!empty($data['id'])) { $courseid = '&course=' . $data['id']; } if (!checkdate($data['m'], $data['d'], $data['y'])) { $time = time(); } else { $time = make_timestamp($data['y'], $data['m'], $data['d']); } $date = usergetdate($time); $data['m'] = $date['mon']; $data['y'] = $date['year']; //Accessibility: calendar block controls, replaced <table> with <div>. //$nexttext = link_arrow_right(get_string('monthnext', 'access'), $url='', $accesshide=true); //$prevtext = link_arrow_left(get_string('monthprev', 'access'), $url='', $accesshide=true); switch ($type) { case 'frontpage': list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']); list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']); $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), 'index.php?', 0, $nextmonth, $nextyear, $accesshide = true); $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), 'index.php?', 0, $prevmonth, $prevyear, true); $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), 1, $data['m'], $data['y']); if (!empty($data['id'])) { $calendarlink->param('course', $data['id']); } if (right_to_left()) { $left = $nextlink; $right = $prevlink; } else { $left = $prevlink; $right = $nextlink; } $content .= html_writer::start_tag('div', array('class' => 'calendar-controls')); $content .= $left . '<span class="hide"> | </span>'; $content .= html_writer::tag('span', html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')), array('title' => get_string('monththis', 'calendar'))), array('class' => 'current')); $content .= '<span class="hide"> | </span>' . $right; $content .= "<span class=\"clearer\"><!-- --></span>\n"; $content .= html_writer::end_tag('div'); break; case 'course': list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']); list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']); $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), 'view.php?id=' . $data['id'] . '&', 0, $nextmonth, $nextyear, $accesshide = true); $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), 'view.php?id=' . $data['id'] . '&', 0, $prevmonth, $prevyear, true); $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), 1, $data['m'], $data['y']); if (!empty($data['id'])) { $calendarlink->param('course', $data['id']); } if (right_to_left()) { $left = $nextlink; $right = $prevlink; } else { $left = $prevlink; $right = $nextlink; } $content .= html_writer::start_tag('div', array('class' => 'calendar-controls')); $content .= $left . '<span class="hide"> | </span>'; $content .= html_writer::tag('span', html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')), array('title' => get_string('monththis', 'calendar'))), array('class' => 'current')); $content .= '<span class="hide"> | </span>' . $right; $content .= "<span class=\"clearer\"><!-- --></span>"; $content .= html_writer::end_tag('div'); break; case 'upcoming': $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'upcoming')), 1, $data['m'], $data['y']); if (!empty($data['id'])) { $calendarlink->param('course', $data['id']); } $calendarlink = html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear'))); $content .= html_writer::tag('div', $calendarlink, array('class' => 'centered')); break; case 'display': $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), 1, $data['m'], $data['y']); if (!empty($data['id'])) { $calendarlink->param('course', $data['id']); } $calendarlink = html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear'))); $content .= html_writer::tag('h3', $calendarlink); break; case 'month': list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']); list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']); $prevdate = make_timestamp($prevyear, $prevmonth, 1); $nextdate = make_timestamp($nextyear, $nextmonth, 1); $prevlink = calendar_get_link_previous(userdate($prevdate, get_string('strftimemonthyear')), 'view.php?view=month' . $courseid . '&', 1, $prevmonth, $prevyear); $nextlink = calendar_get_link_next(userdate($nextdate, get_string('strftimemonthyear')), 'view.php?view=month' . $courseid . '&', 1, $nextmonth, $nextyear); if (right_to_left()) { $left = $nextlink; $right = $prevlink; } else { $left = $prevlink; $right = $nextlink; } $content .= html_writer::start_tag('div', array('class' => 'calendar-controls')); $content .= $left . '<span class="hide"> | </span><h1 class="current">' . userdate($time, get_string('strftimemonthyear')) . "</h1>"; $content .= '<span class="hide"> | </span>' . $right; $content .= '<span class="clearer"><!-- --></span>'; $content .= html_writer::end_tag('div') . "\n"; break; case 'day': $days = calendar_get_days(); $data['d'] = $date['mday']; // Just for convenience $prevdate = usergetdate(make_timestamp($data['y'], $data['m'], $data['d'] - 1)); $nextdate = usergetdate(make_timestamp($data['y'], $data['m'], $data['d'] + 1)); $prevname = calendar_wday_name($days[$prevdate['wday']]); $nextname = calendar_wday_name($days[$nextdate['wday']]); $prevlink = calendar_get_link_previous($prevname, 'view.php?view=day' . $courseid . '&', $prevdate['mday'], $prevdate['mon'], $prevdate['year']); $nextlink = calendar_get_link_next($nextname, 'view.php?view=day' . $courseid . '&', $nextdate['mday'], $nextdate['mon'], $nextdate['year']); if (right_to_left()) { $left = $nextlink; $right = $prevlink; } else { $left = $prevlink; $right = $nextlink; } $content .= html_writer::start_tag('div', array('class' => 'calendar-controls')); $content .= $left; $content .= '<span class="hide"> | </span><span class="current">' . userdate($time, get_string('strftimedaydate')) . '</span>'; $content .= '<span class="hide"> | </span>' . $right; $content .= "<span class=\"clearer\"><!-- --></span>"; $content .= html_writer::end_tag('div') . "\n"; break; } return $content; }
/** * Displays a month in detail * * @param calendar_information $calendar * @return string */ public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null) { global $CFG; if (empty($returnurl)) { $returnurl = $this->page->url; } $date = usergetdate(time()); $display = new stdClass(); $display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday()); $display->maxwday = $display->minwday + 6; $display->thismonth = $date['mon'] == $calendar->month; $display->maxdays = calendar_days_in_month($calendar->month, $calendar->year); $startwday = 0; if (get_user_timezone_offset() < 99) { // We 'll keep these values as GMT here, and offset them when the time comes to query the db $display->tstart = gmmktime(0, 0, 0, $calendar->month, 1, $calendar->year); // This is GMT $display->tend = gmmktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); // GMT $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ } else { // no timezone info specified $display->tstart = mktime(0, 0, 0, $calendar->month, 1, $calendar->year); $display->tend = mktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date() } // Align the starting weekday to fall in our display range if ($startwday < $display->minwday) { $startwday += 7; } // Get events from database $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $calendar->users, $calendar->groups, $calendar->courses); if (!empty($events)) { foreach ($events as $eventid => $event) { $event = new calendar_event($event); if (!empty($event->modulename)) { $cm = get_coursemodule_from_instance($event->modulename, $event->instance); if (!groups_course_module_visible($cm)) { unset($events[$eventid]); } } } } // Extract information: events vs. time calendar_events_by_day($events, $calendar->month, $calendar->year, $eventsbyday, $durationbyday, $typesbyday, $calendar->courses); $output = html_writer::start_tag('div', array('class' => 'header')); if (calendar_user_can_add_event($calendar->course)) { $output .= $this->add_event_button($calendar->course->id, null, $calendar->month, $calendar->year); } $output .= get_string('detailedmonthview', 'calendar') . ': ' . $this->course_filter_selector($returnurl); $output .= html_writer::end_tag('div', array('class' => 'header')); // Controls $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year)), array('class' => 'controls')); $days = calendar_get_days(); $table = new html_table(); $table->attributes = array('class' => 'calendarmonth calendartable'); $table->data = array(); $header = new html_table_row(); $header->attributes = array('class' => 'weekdays'); $header->cells = array(); for ($i = $display->minwday; $i <= $display->maxwday; ++$i) { // This uses the % operator to get the correct weekday no matter what shift we have // applied to the $display->minwday : $display->maxwday range from the default 0 : 6 $cell = new html_table_cell(get_string($days[$i % 7], 'calendar')); $cell->header = true; $header->cells[] = $cell; } // For the table display. $week is the row; $dayweek is the column. $week = 1; $dayweek = $startwday; // Create an array of all the week days. $wdays = array(0 => '<strong>' . get_string('sunday', 'calendar') . '</strong>', 1 => '<strong>' . get_string('monday', 'calendar') . '</strong>', 2 => '<strong>' . get_string('tuesday', 'calendar') . '</strong>', 3 => '<strong>' . get_string('wednesday', 'calendar') . '</strong>', 4 => '<strong>' . get_string('thursday', 'calendar') . '</strong>', 5 => '<strong>' . get_string('friday', 'calendar') . '</strong>', 6 => '<strong>' . get_string('saturday', 'calendar') . '</strong>'); // Loop only if the day offset is greater than 0. // This loop involves shifting the days around until the desired start day // is at the start of the array. $daycount = 0; while ($display->minwday > $daycount++) { $wdays_end = array_shift($wdays); array_push($wdays, $wdays_end); } // Now we set the (modified) array to the table header to be displayed. $table->head = $wdays; $row = new html_table_row(array()); // Paddding (the first week may have blank days in the beginning) for ($i = $display->minwday; $i < $startwday; ++$i) { $cell = new html_table_cell(' '); $cell->attributes = array('class' => 'nottoday'); $row->cells[] = $cell; } // Now display all the calendar $weekend = CALENDAR_DEFAULT_WEEKEND; if (isset($CFG->calendar_weekend)) { $weekend = intval($CFG->calendar_weekend); } for ($calendar->day = 1; $calendar->day <= $display->maxdays; ++$calendar->day, ++$dayweek) { if ($dayweek > $display->maxwday) { // We need to change week (table row) $table->data[] = $row; $row = new html_table_row(array()); $dayweek = $display->minwday; ++$week; } // Reset vars $cell = new html_table_cell(); $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'day', 'course' => $calendar->courseid)), $calendar->day, $calendar->month, $calendar->year); $cellclasses = array(); if ($weekend & 1 << $dayweek % 7) { // Weekend. This is true no matter what the exact range is. $cellclasses[] = 'weekend'; } // Special visual fx if an event is defined if (isset($eventsbyday[$calendar->day])) { if (count($eventsbyday[$calendar->day]) == 1) { $title = get_string('oneevent', 'calendar'); } else { $title = get_string('manyevents', 'calendar', count($eventsbyday[$calendar->day])); } $cell->text = html_writer::tag('div', html_writer::link($dayhref, $calendar->day, array('title' => $title)), array('class' => 'day')); } else { $cell->text = html_writer::tag('div', $calendar->day, array('class' => 'day')); } // Special visual fx if an event spans many days $durationclass = false; if (isset($typesbyday[$calendar->day]['durationglobal'])) { $durationclass = 'duration_global'; } else { if (isset($typesbyday[$calendar->day]['durationcourse'])) { $durationclass = 'duration_course'; } else { if (isset($typesbyday[$calendar->day]['durationgroup'])) { $durationclass = 'duration_group'; } else { if (isset($typesbyday[$calendar->day]['durationuser'])) { $durationclass = 'duration_user'; } } } } if ($durationclass) { $cellclasses[] = 'duration'; $cellclasses[] = $durationclass; } // Special visual fx for today if ($display->thismonth && $calendar->day == $calendar->day) { $cellclasses[] = 'today'; } else { $cellclasses[] = 'nottoday'; } $cell->attributes = array('class' => join(' ', $cellclasses)); if (isset($eventsbyday[$calendar->day])) { $cell->text .= html_writer::start_tag('ul', array('class' => 'events-new')); foreach ($eventsbyday[$calendar->day] as $eventindex) { // If event has a class set then add it to the event <li> tag $attributes = array(); if (!empty($events[$eventindex]->class)) { $attributes['class'] = $events[$eventindex]->class; } $dayhref->set_anchor('event_' . $events[$eventindex]->id); $link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true)); $cell->text .= html_writer::tag('li', $link, $attributes); } $cell->text .= html_writer::end_tag('ul'); } if (isset($durationbyday[$calendar->day])) { $cell->text .= html_writer::start_tag('ul', array('class' => 'events-underway')); foreach ($durationbyday[$calendar->day] as $eventindex) { $cell->text .= html_writer::tag('li', '[' . format_string($events[$eventindex]->name, true) . ']', array('class' => 'events-underway')); } $cell->text .= html_writer::end_tag('ul'); } $row->cells[] = $cell; } // Paddding (the last week may have blank days at the end) for ($i = $dayweek; $i <= $display->maxwday; ++$i) { $cell = new html_table_cell(' '); $cell->attributes = array('class' => 'nottoday'); $row->cells[] = $cell; } $table->data[] = $row; $output .= html_writer::table($table); // OK, now for the filtering display $output .= $this->filter_selection_table($calendar); return $output; }
function show_month_detailed($baseparams, $display, $m, $y, $courses, $groups, $users, $courseid, $activefilters, $waitlistedsessions, $events) { global $USER, $SESSION, $OUTPUT; global $timenow; $calendardays = calendar_get_days(); $weekend = CALENDAR_DEFAULT_WEEKEND; if (isset($CFG->calendar_weekend)) { $weekend = intval($CFG->calendar_weekend); } // Extract information: events vs. time calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses); echo $OUTPUT->container_start(null, 'calendarcontainer'); echo $OUTPUT->box_start('generalbox monthlycalendar'); $text = ''; echo $OUTPUT->container($text, 'header'); echo $OUTPUT->container(top_controls($m, $y), 'controls'); // Start calendar display echo html_writer::start_tag('table', array('class' => 'calendarmonth', 'summary' => get_string('calendar:tablesummary', 'block_facetoface'))); echo html_writer::start_tag('tr', array('class' => 'weekdays')); // Begin table. First row: day names // Print out the names of the weekdays for($i = $display->minwday; $i <= $display->maxwday; ++$i) { // This uses the % operator to get the correct weekday no matter what shift we have // applied to the $display->minwday : $display->maxwday range from the default 0 : 6 $day = $calendardays[$i % 7]; echo html_writer::tag('th', get_string($day, 'calendar'), array('scope' => 'col')); } echo html_writer::end_tag('tr') . html_writer::start_tag('tr'); // End of day names; prepare for day numbers // For the table display. $week is the row; $dayweek is the column. $week = 1; $dayweek = $display->startwday; // Paddding (the first week may have blank days in the beginning) for($i = $display->minwday; $i < $display->startwday; ++$i) { echo html_writer::tag('td', ' ', array('class' => 'nottoday')) . "\n"; } // Now display all the calendar for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) { if ($dayweek > $display->maxwday) { // We need to change week (table row) echo html_writer::end_tag('tr') . html_writer::start_tag('tr'); $dayweek = $display->minwday; ++$week; } // Reset vars $cell = ''; $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL.'view.php', array('view' => 'day', 'course' => $courseid)), $day, $m, $y); if ($weekend & (1 << ($dayweek % 7))) { // Weekend. This is true no matter what the exact range is. $class = 'weekend'; } else { // Normal working day. $class = ''; } // Special visual fx if an event is defined if (isset($eventsbyday[$day])) { if (count($eventsbyday[$day]) == 1) { $title = get_string('oneevent', 'calendar'); } else { $title = get_string('manyevents', 'calendar', count($eventsbyday[$day])); } $cell = $OUTPUT->container(html_writer::link($dayhref, $day, array('title' => $title)), array('class' => 'day')); } else { $cell = $OUTPUT->container($day, array('class' => 'day')); } // Special visual fx if an event spans many days if (isset($typesbyday[$day]['durationglobal'])) { $class .= ' duration_global'; } else if (isset($typesbyday[$day]['durationcourse'])) { $class .= ' duration_course'; } else if (isset($typesbyday[$day]['durationgroup'])) { $class .= ' duration_group'; } else if (isset($typesbyday[$day]['durationuser'])) { $class .= ' duration_user'; } // Special visual fx for today $today = strftime('%d', $timenow); if ($display->thismonth && $day == $today) { $class .= ' today'; } else { $class .= ' nottoday'; } // Just display it if (!empty($class)) { $class = array('class' => trim($class)); } else { $class = array(); } $cellid = sprintf('cell%d%02d%02d', $y, $m, $day);// outputs 'cellYYYYMMDD' string as intended echo html_writer::start_tag('td', array_merge(array('id' => $cellid), $class)) . $cell; if (isset($eventsbyday[$day])) { echo html_writer::start_tag('ul'); $i = 1; foreach ($eventsbyday[$day] as $eventindex) { if ($i < MAX_EVENTS_PER_DAY or count($eventsbyday[$day]) == MAX_EVENTS_PER_DAY) { // If event has a class set then add it to the event <li> tag $eventattributes = array(); if (!empty($events[$eventindex]->class)) { $eventattributes['class'] = $events[$eventindex]->class; } $day_string = $dayhref->out(); echo html_writer::tag('li', html_writer::link(new moodle_url($day_string. '#event_'.$events[$eventindex]->id), format_string($events[$eventindex]->name, true), $eventattributes)); $i++; } else { echo html_writer::tag('li', get_string('xevents', 'block_facetoface', count($eventsbyday[$day]) - MAX_EVENTS_PER_DAY + 1)); break; } } echo html_writer::end_tag('ul'); } echo html_writer::end_tag('td') . "\n"; } // Paddding (the last week may have blank days at the end) for($i = $dayweek; $i <= $display->maxwday; ++$i) { echo html_writer::tag('td', ' ', array('class' => 'nottoday')); } echo html_writer::end_tag('tr') . "\n"; // Last row ends echo html_writer::end_tag('table') . "\n"; // Tabular display of days ends echo $OUTPUT->box_end(); echo $OUTPUT->container_end(); // Advertising side-bar echo $OUTPUT->box_start('generalbox calendarsidebar'); print_waitlisted_content($waitlistedsessions); echo $OUTPUT->box_end(); }
/** * @method get_formatted Given scheduled report frequency and schedule data, output a human readable string. * * @param integer $frequent Frequency of the report scheduling * @param integer $schedule The scheduled date/time (either hour of day, day or week or day of month) * @param object $user User object belonging to the recipient (optional). Defaults to current user * @return string schedule desription */ public function get_formatted($frequent, $schedule, $user = false) { global $USER; if (!$user) $user = $USER; $timemonth = date('n', time()); $timeday = date('j', time()); $timeyear = date('Y', time()); $calendardays = calendar_get_days(); $dateformat = ($USER->lang == 'en') ? 'jS' : 'j'; $out = ''; switch ($frequent) { case self::DAILY: $out .= get_string('daily', 'block_cobalt_reports') . ' ' . get_string('at', 'block_cobalt_reports') . ' '; $out .= strftime('%I:%M%p', mktime($schedule, 0, 0, $timemonth, $timeday, $timeyear)); break; case self::WEEKLY: $out .= get_string('weekly', 'block_cobalt_reports') . ' ' . get_string('on', 'block_cobalt_reports') . ' '; $out .= get_string(strtolower($calendardays[$schedule]['fullname']), 'calendar'); break; case self::MONTHLY: $out .= get_string('monthly', 'block_cobalt_reports') . ' ' . get_string('onthe', 'block_cobalt_reports') . ' '; $out .= date($dateformat, mktime(0, 0, 0, 0, $schedule, $timeyear)); break; } return $out; }
function definition_after_data() { global $USER; $mform = $this->_form; $CALENDARDAYS = calendar_get_days(); //Daily selector $dailyselect = array(); for ($i = 0; $i < 24; $i++) { $dailyselect[$i] = date('H:i', mktime($i, 0, 0)); } //Weekly selector $weeklyselect = array(); for ($i = 0; $i < 7; $i++) { if (class_exists('\core_calendar\type_factory')) $weeklyselect[$i] = get_string(strtolower($CALENDARDAYS[$i]['shortname']), 'calendar'); else $weeklyselect[$i] = get_string(strtolower($CALENDARDAYS[$i]), 'calendar'); } $monthlyselect = array(); $dateformat = ($USER->lang == 'en') ? 'jS' : 'j'; for ($i = 1; $i <= 31; $i++) { $monthlyselect[$i] = date($dateformat, mktime(0, 0, 0, 0, $i)); } $formatvalue = $mform->getElementValue('frequency'); if (isset($formatvalue) AND ! empty($formatvalue[0])) { switch ($formatvalue[0]) { case 1: $daily = $mform->createElement('select', 'daily', null, $dailyselect); $mform->insertElementBefore($daily, 'frequentpos'); break; case 2: $weekly = $mform->createElement('select', 'weekly', null, $weeklyselect); $mform->insertElementBefore($weekly, 'frequentpos'); break; case 3: $monthly = $mform->createElement('select', 'monthly', null, $monthlyselect); $mform->insertElementBefore($monthly, 'frequentpos'); break; } } }