/** * Generates the HTML for a miniature calendar * * @param array $courses list of course to list events from * @param array $groups list of group * @param array $users user's info * @param int|bool $calmonth calendar month in numeric, default is set to false * @param int|bool $calyear calendar month in numeric, default is set to false * @param string|bool $placement the place/page the calendar is set to appear - passed on the the controls function * @param int|bool $courseid id of the course the calendar is displayed on - passed on the the controls function * @param int $time the unixtimestamp representing the date we want to view, this is used instead of $calmonth * and $calyear to support multiple calendars * @return string $content return html table for mini calendar */ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyear = false, $placement = false, $courseid = false, $time = 0) { global $CFG, $OUTPUT; // Get the calendar type we are using. $calendartype = \core_calendar\type_factory::get_calendar_instance(); $display = new stdClass(); // Assume we are not displaying this month for now. $display->thismonth = false; $content = ''; // Do this check for backwards compatibility. The core should be passing a timestamp rather than month and year. // If a month and year are passed they will be in Gregorian. if (!empty($calmonth) && !empty($calyear)) { // Ensure it is a valid date, else we will just set it to the current timestamp. if (checkdate($calmonth, 1, $calyear)) { $time = make_timestamp($calyear, $calmonth, 1); } else { $time = time(); } $date = usergetdate($time); if ($calmonth == $date['mon'] && $calyear == $date['year']) { $display->thismonth = true; } // We can overwrite date now with the date used by the calendar type, if it is not Gregorian, otherwise // there is no need as it is already in Gregorian. if ($calendartype->get_name() != 'gregorian') { $date = $calendartype->timestamp_to_date_array($time); } } else { if (!empty($time)) { // Get the specified date in the calendar type being used. $date = $calendartype->timestamp_to_date_array($time); $thisdate = $calendartype->timestamp_to_date_array(time()); if ($date['month'] == $thisdate['month'] && $date['year'] == $thisdate['year']) { $display->thismonth = true; // If we are the current month we want to set the date to the current date, not the start of the month. $date = $thisdate; } } else { // Get the current date in the calendar type being used. $time = time(); $date = $calendartype->timestamp_to_date_array($time); $display->thismonth = true; } } list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display. // 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 max number of days in this month for this calendar type. $display->maxdays = calendar_days_in_month($m, $y); // Get the starting week day for this month. $startwday = dayofweek(1, $m, $y); // Get the days in a week. $daynames = calendar_get_days(); // Store the number of days in a week. $numberofdaysinweek = $calendartype->get_num_weekdays(); // Set the min and max weekday. $display->minwday = calendar_get_starting_weekday(); $display->maxwday = $display->minwday + ($numberofdaysinweek - 1); // 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 the events matching our criteria. Don't forget to offset the timestamps for the user's TZ! $events = calendar_get_events($display->tstart, $display->tend, $users, $groups, $courses); // Set event course class for course events if (!empty($events)) { foreach ($events as $eventid => $event) { if (!empty($event->modulename)) { $cm = get_coursemodule_from_instance($event->modulename, $event->instance); if (!groups_course_module_visible($cm)) { unset($events[$eventid]); } } } } // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra // arguments to this function. $hrefparams = array(); if (!empty($courses)) { $courses = array_diff($courses, array(SITEID)); if (count($courses) == 1) { $hrefparams['course'] = reset($courses); } } // We want to have easy access by day, since the display is on a per-day basis. calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses); // Accessibility: added summary and <abbr> elements. $summary = get_string('calendarheading', 'calendar', userdate($display->tstart, get_string('strftimemonthyear'))); $content .= '<table class="minicalendar calendartable" summary="' . $summary . '">'; // Begin table. if ($placement !== false && $courseid !== false) { $content .= '<caption>' . calendar_top_controls($placement, array('id' => $courseid, 'time' => $time)) . '</caption>'; } $content .= '<tr class="weekdays">'; // Header row: day names // Print out the names of the weekdays. for ($i = $display->minwday; $i <= $display->maxwday; ++$i) { $pos = $i % $numberofdaysinweek; $content .= '<th scope="col"><abbr title="' . $daynames[$pos]['fullname'] . '">' . $daynames[$pos]['shortname'] . "</abbr></th>\n"; } $content .= '</tr><tr>'; // End of day names; prepare for day numbers // For the table display. $week is the row; $dayweek is the column. $dayweek = $startwday; // Paddding (the first week may have blank days in the beginning) for ($i = $display->minwday; $i < $startwday; ++$i) { $content .= '<td class="dayblank"> </td>' . "\n"; } $weekend = CALENDAR_DEFAULT_WEEKEND; if (isset($CFG->calendar_weekend)) { $weekend = intval($CFG->calendar_weekend); } // Now display all the calendar $daytime = $display->tstart - DAYSECS; for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) { $daytime += DAYSECS; if ($dayweek > $display->maxwday) { // We need to change week (table row) $content .= '</tr><tr>'; $dayweek = $display->minwday; } // Reset vars. if ($weekend & 1 << $dayweek % $numberofdaysinweek) { // Weekend. This is true no matter what the exact range is. $class = 'weekend day'; } else { // Normal working day. $class = 'day'; } // Special visual fx if an event is defined if (isset($eventsbyday[$day])) { $class .= ' hasevent'; $hrefparams['view'] = 'day'; $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', $hrefparams), 0, 0, 0, $daytime); $popupcontent = ''; foreach ($eventsbyday[$day] as $eventid) { if (!isset($events[$eventid])) { continue; } $event = new calendar_event($events[$eventid]); $popupalt = ''; $component = 'moodle'; if (!empty($event->modulename)) { $popupicon = 'icon'; $popupalt = $event->modulename; $component = $event->modulename; } else { if ($event->courseid == SITEID) { // Site event. $popupicon = 'i/siteevent'; } else { if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { // Course event. $popupicon = 'i/courseevent'; } else { if ($event->groupid) { // Group event. $popupicon = 'i/groupevent'; } else { // Must be a user event. $popupicon = 'i/userevent'; } } } } $dayhref->set_anchor('event_' . $event->id); $popupcontent .= html_writer::start_tag('div'); $popupcontent .= $OUTPUT->pix_icon($popupicon, $popupalt, $component); $name = format_string($event->name, true); // Show ical source if needed. if (!empty($event->subscription) && $CFG->calendar_showicalsource) { $a = new stdClass(); $a->name = $name; $a->source = $event->subscription->name; $name = get_string('namewithsource', 'calendar', $a); } $popupcontent .= html_writer::link($dayhref, $name); $popupcontent .= html_writer::end_tag('div'); } //Accessibility: functionality moved to calendar_get_popup. if ($display->thismonth && $day == $d) { $popupid = calendar_get_popup(true, $events[$eventid]->timestart, $popupcontent); } else { $popupid = calendar_get_popup(false, $events[$eventid]->timestart, $popupcontent); } // Class and cell content if (isset($typesbyday[$day]['startglobal'])) { $class .= ' calendar_event_global'; } else { if (isset($typesbyday[$day]['startcourse'])) { $class .= ' calendar_event_course'; } else { if (isset($typesbyday[$day]['startgroup'])) { $class .= ' calendar_event_group'; } else { if (isset($typesbyday[$day]['startuser'])) { $class .= ' calendar_event_user'; } } } } $cell = html_writer::link($dayhref, $day, array('id' => $popupid)); } else { $cell = $day; } $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) { $class .= ' duration ' . $durationclass; } // If event has a class set then add it to the table day <td> tag // Note: only one colour for minicalendar if (isset($eventsbyday[$day])) { foreach ($eventsbyday[$day] as $eventid) { if (!isset($events[$eventid])) { continue; } $event = $events[$eventid]; if (!empty($event->class)) { $class .= ' ' . $event->class; } break; } } // Special visual fx for today //Accessibility: hidden text for today, and popup. if ($display->thismonth && $day == $d) { $class .= ' today'; $today = get_string('today', 'calendar') . ' ' . userdate(time(), get_string('strftimedayshort')); if (!isset($eventsbyday[$day])) { $class .= ' eventnone'; $popupid = calendar_get_popup(true, false); $cell = html_writer::link('#', $day, array('id' => $popupid)); } $cell = get_accesshide($today . ' ') . $cell; } // Just display it if (!empty($class)) { $class = ' class="' . $class . '"'; } $content .= '<td' . $class . '>' . $cell . "</td>\n"; } // Paddding (the last week may have blank days at the end) for ($i = $dayweek; $i <= $display->maxwday; ++$i) { $content .= '<td class="dayblank"> </td>'; } $content .= '</tr>'; // Last row ends $content .= '</table>'; // Tabular display of days ends return $content; }
function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid) { global $CFG, $SESSION, $USER, $CALENDARDAYS; global $day, $mon, $yr; $getvars = 'from=month&cal_d=' . $day . '&cal_m=' . $mon . '&cal_y=' . $yr; // For filtering $display =& new stdClass(); $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY); $display->maxwday = $display->minwday + 6; if (!empty($m) && !empty($y)) { $thisdate = usergetdate(time()); // Time and day at the user's location if ($m == $thisdate['mon'] && $y == $thisdate['year']) { // Navigated to this month $date = $thisdate; $display->thismonth = true; } else { // Navigated to other month, let's do a nice trick and save us a lot of work... if (!checkdate($m, 1, $y)) { $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']); $display->thismonth = true; } else { $date = array('mday' => 1, 'mon' => $m, 'year' => $y); $display->thismonth = false; } } } else { $date = usergetdate(time()); $display->thismonth = true; } // Fill in the variables we 're going to use, nice and tidy list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display $display->maxdays = calendar_days_in_month($m, $y); $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, $m, 1, $y); // This is GMT $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // 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, $m, 1, $y); $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y); $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), $users, $groups, $courses); if (!empty($events)) { foreach ($events as $eventid => $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, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses); $text = ''; if (!isguest() && !empty($USER->id) && calendar_user_can_add_event()) { $text .= '<div class="buttons"><form action="' . CALENDAR_URL . 'event.php" method="get">'; $text .= '<div>'; $text .= '<input type="hidden" name="action" value="new" />'; $text .= '<input type="hidden" name="course" value="' . $courseid . '" />'; $text .= '<input type="hidden" name="cal_m" value="' . $m . '" />'; $text .= '<input type="hidden" name="cal_y" value="' . $y . '" />'; $text .= '<input type="submit" value="' . get_string('newevent', 'calendar') . '" />'; $text .= '</div></form></div>'; } $text .= '<label for="cal_course_flt_jump">' . get_string('detailedmonthview', 'calendar') . ':</label>' . calendar_course_filter_selector($getvars); echo '<div class="header">' . $text . '</div>'; echo '<div class="controls">'; echo calendar_top_controls('month', array('id' => $courseid, 'm' => $m, 'y' => $y)); echo '</div>'; // Start calendar display echo '<table class="calendarmonth"><tr 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 echo '<th scope="col">' . get_string($CALENDARDAYS[$i % 7], 'calendar') . '</th>'; } echo '</tr><tr>'; // End of day names; prepare for day numbers // For the table display. $week is the row; $dayweek is the column. $week = 1; $dayweek = $startwday; // Paddding (the first week may have blank days in the beginning) for ($i = $display->minwday; $i < $startwday; ++$i) { echo '<td class="nottoday"> </td>' . "\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 "</tr>\n<tr>"; $dayweek = $display->minwday; ++$week; } // Reset vars $cell = ''; $dayhref = calendar_get_link_href(CALENDAR_URL . 'view.php?view=day&course=' . $courseid . '&', $day, $m, $y); if (CALENDAR_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 = '<div class="day"><a href="' . $dayhref . '" title="' . $title . '">' . $day . '</a></div>'; } else { $cell = '<div class="day">' . $day . '</div>'; } // 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 if ($display->thismonth && $day == $d) { $class .= ' today'; } else { $class .= ' nottoday'; } // Just display it if (!empty($class)) { $class = ' class="' . trim($class) . '"'; } echo '<td' . $class . '>' . $cell; if (isset($eventsbyday[$day])) { echo '<ul class="events-new">'; foreach ($eventsbyday[$day] as $eventindex) { // If event has a class set then add it to the event <li> tag $eventclass = ''; if (!empty($events[$eventindex]->class)) { $eventclass = ' class="' . $events[$eventindex]->class . '"'; } echo '<li' . $eventclass . '><a href="' . $dayhref . '#event_' . $events[$eventindex]->id . '">' . format_string($events[$eventindex]->name, true) . '</a></li>'; } echo '</ul>'; } if (isset($durationbyday[$day])) { echo '<ul class="events-underway">'; foreach ($durationbyday[$day] as $eventindex) { echo '<li>[' . format_string($events[$eventindex]->name, true) . ']</li>'; } echo '</ul>'; } echo "</td>\n"; } // Paddding (the last week may have blank days at the end) for ($i = $dayweek; $i <= $display->maxwday; ++$i) { echo '<td class="nottoday"> </td>'; } echo "</tr>\n"; // Last row ends echo "</table>\n"; // Tabular display of days ends // OK, now for the filtering display echo '<div class="filters"><table><tr>'; // Global events if ($SESSION->cal_show_global) { echo '<td class="event_global" style="width: 8px;"></td><td><strong>' . get_string('globalevents', 'calendar') . ':</strong> '; echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showglobal&' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n"; } else { echo '<td style="width: 8px;"></td><td><strong>' . get_string('globalevents', 'calendar') . ':</strong> '; echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showglobal&' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n"; } // Course events if (!empty($SESSION->cal_show_course)) { echo '<td class="event_course" style="width: 8px;"></td><td><strong>' . get_string('courseevents', 'calendar') . ':</strong> '; echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showcourses&' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n"; } else { echo '<td style="width: 8px;"></td><td><strong>' . get_string('courseevents', 'calendar') . ':</strong> '; echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showcourses&' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n"; } echo "</tr>\n"; if (!empty($USER->id) && !isguest()) { echo '<tr>'; // Group events if ($SESSION->cal_show_groups) { echo '<td class="event_group" style="width: 8px;"></td><td><strong>' . get_string('groupevents', 'calendar') . ':</strong> '; echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showgroups&' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n"; } else { echo '<td style="width: 8px;"></td><td><strong>' . get_string('groupevents', 'calendar') . ':</strong> '; echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showgroups&' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n"; } // User events if ($SESSION->cal_show_user) { echo '<td class="event_user" style="width: 8px;"></td><td><strong>' . get_string('userevents', 'calendar') . ':</strong> '; echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showuser&' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n"; } else { echo '<td style="width: 8px;"></td><td><strong>' . get_string('userevents', 'calendar') . ':</strong> '; echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showuser&' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n"; } echo "</tr>\n"; } echo '</table></div>'; }
/** * Filters events that a user cannot see due to grouping constraints * * @param array $events The possible events that can occur for modules * @param array $userid The user's id * @param string $coursecontext the context value of the course * @param string $course the course for filtering visibility * @return array The array with restricted events removed */ function block_progress_filter_visibility($events, $userid, $coursecontext, $course = 0) { global $CFG, $USER; $filteredevents = array(); // Check if the events are empty or none are selected. if ($events === 0) { return 0; } if ($events === null) { return null; } // Keep only events that are visible. foreach ($events as $key => $event) { // Determine the correct user info to check. if ($userid == $USER->id) { $coursemodule = $event['cm']; } else { $coursemodule = block_progress_get_coursemodule($event['type'], $event['id'], $course->id, $userid); } // Check visibility in course. if (!$coursemodule->visible && !has_capability('moodle/course:viewhiddenactivities', $coursecontext, $userid)) { continue; } // Check availability, allowing for visible, but not accessible items. if (!empty($CFG->enableavailability)) { if (isset($coursemodule->available) && !$coursemodule->available && empty($coursemodule->availableinfo) && !has_capability('moodle/course:viewhiddenactivities', $coursecontext, $userid)) { continue; } } // Check visibility by grouping constraints (includes capability check). if (!empty($CFG->enablegroupmembersonly)) { if (isset($coursemodule->uservisible)) { if ($coursemodule->uservisible != 1 && empty($coursemodule->availableinfo)) { continue; } } else { if (!groups_course_module_visible($coursemodule, $userid)) { continue; } } } // Save the visible event. $filteredevents[] = $event; } return $filteredevents; }
/** * Determine whether a module instance is visible within a course * * Given a valid module object with info about the id and course, * and the module's type (eg "forum") returns whether the object * is visible or not * * @uses $CFG * @param $moduletype Name of the module eg 'forum' * @param $module Object which is the instance of the module * @return bool */ function instance_is_visible($moduletype, $module) { global $CFG; if (!empty($module->id)) { if ($records = get_records_sql("SELECT cm.instance, cm.visible, cm.groupingid, cm.id, cm.groupmembersonly, cm.course\n FROM {$CFG->prefix}course_modules cm,\n {$CFG->prefix}modules m\n WHERE cm.course = '{$module->course}' AND\n cm.module = m.id AND\n m.name = '{$moduletype}' AND\n cm.instance = '{$module->id}'")) { foreach ($records as $record) { // there should only be one - use the first one return $record->visible && groups_course_module_visible($record); } } } return true; // visible by default! }
function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { // Returns a number of useful structures for course displays $mods = array(); // course modules indexed by id $modnames = array(); // all course module names (except resource!) $modnamesplural = array(); // all course module names (plural form) $modnamesused = array(); // course module names used if ($allmods = get_records("modules")) { foreach ($allmods as $mod) { if ($mod->visible) { $modnames[$mod->name] = get_string("modulename", "{$mod->name}"); $modnamesplural[$mod->name] = get_string("modulenameplural", "{$mod->name}"); } } asort($modnames, SORT_LOCALE_STRING); } else { error("No modules are installed!"); } if ($rawmods = get_course_mods($courseid)) { foreach ($rawmods as $mod) { // Index the mods if (empty($modnames[$mod->modname])) { continue; } $mods[$mod->id] = $mod; $mods[$mod->id]->modfullname = $modnames[$mod->modname]; if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid))) { continue; } // Check groupings if (!groups_course_module_visible($mod)) { continue; } $modnamesused[$mod->modname] = $modnames[$mod->modname]; } if ($modnamesused) { asort($modnamesused, SORT_LOCALE_STRING); } } }
function workshop_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $workshop = "0", $user = "", $groupid = "") { // Returns all workshop posts since a given time. If workshop is specified then // this restricts the results global $CFG; if ($workshop) { $workshopselect = " AND cm.id = '{$workshop}'"; } else { $workshopselect = ""; } if ($user) { $userselect = " AND u.id = '{$user}'"; } else { $userselect = ""; } $posts = get_records_sql("SELECT s.*, u.firstname, u.lastname,\n u.picture, cm.instance, w.name, cm.section, cm.groupmode,\n cm.course, cm.groupingid, cm.groupmembersonly, cm.id as cmid\n FROM {$CFG->prefix}workshop_submissions s,\n {$CFG->prefix}user u,\n {$CFG->prefix}course_modules cm,\n {$CFG->prefix}workshop w\n WHERE s.timecreated > '{$sincetime}' {$workshopselect}\n AND s.userid = u.id {$userselect}\n AND w.course = '{$courseid}'\n AND cm.instance = w.id\n AND cm.course = w.course\n AND s.workshopid = w.id\n ORDER BY s.id"); if (empty($posts)) { return; } foreach ($posts as $post) { if ((empty($groupid) || groups_is_member($groupid, $post->userid)) && groups_course_module_visible($post)) { $tmpactivity = new Object(); $tmpactivity->type = "workshop"; $tmpactivity->defaultindex = $index; $tmpactivity->instance = $post->instance; $tmpactivity->name = $post->name; $tmpactivity->section = $post->section; $tmpactivity->content->id = $post->id; $tmpactivity->content->title = $post->title; $tmpactivity->user->userid = $post->userid; $tmpactivity->user->fullname = fullname($post); $tmpactivity->user->picture = $post->picture; $tmpactivity->cmid = $post->cmid; $tmpactivity->timestamp = $post->timecreated; $activities[] = $tmpactivity; $index++; } } return; }
function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_year = false) { global $CFG, $USER; $display = new stdClass(); $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY); $display->maxwday = $display->minwday + 6; $content = ''; if (!empty($cal_month) && !empty($cal_year)) { $thisdate = usergetdate(time()); // Date and time the user sees at his location if ($cal_month == $thisdate['mon'] && $cal_year == $thisdate['year']) { // Navigated to this month $date = $thisdate; $display->thismonth = true; } else { // Navigated to other month, let's do a nice trick and save us a lot of work... if (!checkdate($cal_month, 1, $cal_year)) { $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']); $display->thismonth = true; } else { $date = array('mday' => 1, 'mon' => $cal_month, 'year' => $cal_year); $display->thismonth = false; } } } else { $date = usergetdate(time()); // Date and time the user sees at his location $display->thismonth = true; } // Fill in the variables we 're going to use, nice and tidy list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display $display->maxdays = calendar_days_in_month($m, $y); 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, $m, 1, $y); // This is GMT $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT } else { // no timezone info specified $display->tstart = mktime(0, 0, 0, $m, 1, $y); $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y); } $startwday = dayofweek(1, $m, $y); // Align the starting weekday to fall in our display range // This is simple, not foolproof. if ($startwday < $display->minwday) { $startwday += 7; } // TODO: THIS IS TEMPORARY CODE! // [pj] I was just reading through this and realized that I when writing this code I was probably // asking for trouble, as all these time manipulations seem to be unnecessary and a simple // make_timestamp would accomplish the same thing. So here goes a test: //$test_start = make_timestamp($y, $m, 1); //$test_end = make_timestamp($y, $m, $display->maxdays, 23, 59, 59); //if($test_start != usertime($display->tstart) - dst_offset_on($display->tstart)) { //notify('Failed assertion in calendar/lib.php line 126; display->tstart = '.$display->tstart.', dst_offset = '.dst_offset_on($display->tstart).', usertime = '.usertime($display->tstart).', make_t = '.$test_start); //} //if($test_end != usertime($display->tend) - dst_offset_on($display->tend)) { //notify('Failed assertion in calendar/lib.php line 130; display->tend = '.$display->tend.', dst_offset = '.dst_offset_on($display->tend).', usertime = '.usertime($display->tend).', make_t = '.$test_end); //} // Get the events matching our criteria. Don't forget to offset the timestamps for the user's TZ! $events = calendar_get_events(usertime($display->tstart) - dst_offset_on($display->tstart), usertime($display->tend) - dst_offset_on($display->tend), $users, $groups, $courses); // Set event course class for course events if (!empty($events)) { foreach ($events as $eventid => $event) { if (!empty($event->modulename)) { $cm = get_coursemodule_from_instance($event->modulename, $event->instance); if (!groups_course_module_visible($cm)) { unset($events[$eventid]); } } } } // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra // arguments to this function. $morehref = ''; if (!empty($courses)) { $courses = array_diff($courses, array(SITEID)); if (count($courses) == 1) { $morehref = '&course=' . reset($courses); } } // We want to have easy access by day, since the display is on a per-day basis. // Arguments passed by reference. //calendar_events_by_day($events, $display->tstart, $eventsbyday, $durationbyday, $typesbyday); calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses); //Accessibility: added summary and <abbr> elements. ///global $CALENDARDAYS; appears to be broken. $days_title = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); $summary = get_string('calendarheading', 'calendar', userdate(make_timestamp($y, $m), get_string('strftimemonthyear'))); $summary = get_string('tabledata', 'access', $summary); $content .= '<table class="minicalendar" summary="' . $summary . '">'; // Begin table $content .= '<tr class="weekdays">'; // Header row: day names // Print out the names of the weekdays $days = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'); 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 $content .= '<th scope="col"><abbr title="' . get_string($days_title[$i % 7], 'calendar') . '">' . get_string($days[$i % 7], 'calendar') . "</abbr></th>\n"; } $content .= '</tr><tr>'; // End of day names; prepare for day numbers // For the table display. $week is the row; $dayweek is the column. $dayweek = $startwday; // Paddding (the first week may have blank days in the beginning) for ($i = $display->minwday; $i < $startwday; ++$i) { $content .= '<td class="dayblank"> </td>' . "\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) $content .= '</tr><tr>'; $dayweek = $display->minwday; } // Reset vars $cell = ''; if (CALENDAR_WEEKEND & 1 << $dayweek % 7) { // Weekend. This is true no matter what the exact range is. $class = 'weekend day'; } else { // Normal working day. $class = 'day'; } // Special visual fx if an event is defined if (isset($eventsbyday[$day])) { $dayhref = calendar_get_link_href(CALENDAR_URL . 'view.php?view=day' . $morehref . '&', $day, $m, $y); // OverLib popup $popupcontent = ''; foreach ($eventsbyday[$day] as $eventid) { if (!isset($events[$eventid])) { continue; } $event = $events[$eventid]; if (!empty($event->modulename)) { $popupicon = $CFG->modpixpath . '/' . $event->modulename . '/icon.gif'; $popupalt = $event->modulename; } else { if ($event->courseid == SITEID) { // Site event $popupicon = $CFG->pixpath . '/c/site.gif'; $popupalt = ''; } else { if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { // Course event $popupicon = $CFG->pixpath . '/c/course.gif'; $popupalt = ''; } else { if ($event->groupid) { // Group event $popupicon = $CFG->pixpath . '/c/group.gif'; $popupalt = ''; } else { if ($event->userid) { // User event $popupicon = $CFG->pixpath . '/c/user.gif'; $popupalt = ''; } } } } } $popupcontent .= '<div><img class="icon" src="' . $popupicon . '" alt="' . $popupalt . '" /><a href="' . $dayhref . '#event_' . $event->id . '">' . format_string($event->name, true) . '</a></div>'; } //Accessibility: functionality moved to calendar_get_popup. if ($display->thismonth && $day == $d) { $popup = calendar_get_popup(true, $events[$eventid]->timestart, $popupcontent); } else { $popup = calendar_get_popup(false, $events[$eventid]->timestart, $popupcontent); } // Class and cell content if (isset($typesbyday[$day]['startglobal'])) { $class .= ' event_global'; } else { if (isset($typesbyday[$day]['startcourse'])) { $class .= ' event_course'; } else { if (isset($typesbyday[$day]['startgroup'])) { $class .= ' event_group'; } else { if (isset($typesbyday[$day]['startuser'])) { $class .= ' event_user'; } } } } $cell = '<a href="' . $dayhref . '" ' . $popup . '>' . $day . '</a>'; } else { $cell = $day; } 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'; } } } } // If event has a class set then add it to the table day <td> tag // Note: only one colour for minicalendar if (isset($eventsbyday[$day])) { foreach ($eventsbyday[$day] as $eventid) { if (!isset($events[$eventid])) { continue; } $event = $events[$eventid]; if (!empty($event->class)) { $class .= ' ' . $event->class; } break; } } // Special visual fx for today //Accessibility: hidden text for today, and popup. if ($display->thismonth && $day == $d) { $class .= ' today'; $today = get_string('today', 'calendar') . ' ' . userdate(time(), get_string('strftimedayshort')); if (!isset($eventsbyday[$day])) { $class .= ' eventnone'; $popup = calendar_get_popup(true, false); $cell = '<a href="#" ' . $popup . '>' . $day . '</a>'; } $cell = get_accesshide($today . ' ') . $cell; } // Just display it if (!empty($class)) { $class = ' class="' . $class . '"'; } $content .= '<td' . $class . '>' . $cell . "</td>\n"; } // Paddding (the last week may have blank days at the end) for ($i = $dayweek; $i <= $display->maxwday; ++$i) { $content .= '<td class="dayblank"> </td>'; } $content .= '</tr>'; // Last row ends $content .= '</table>'; // Tabular display of days ends return $content; }
/** * TODO document */ function forum_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $cmid = "0", $user = "", $groupid = "") { // Returns all forum posts since a given time. If forum is specified then // this restricts the results global $CFG; if ($cmid) { $forumselect = " AND cm.id = '{$cmid}'"; } else { $forumselect = ""; } if ($user) { $userselect = " AND u.id = '{$user}'"; } else { $userselect = ""; } $posts = get_records_sql("SELECT p.*, d.name, u.firstname, u.lastname,\n u.picture, d.groupid, cm.instance, f.name,\n cm.section, cm.id AS cmid\n FROM {$CFG->prefix}forum_posts p,\n {$CFG->prefix}forum_discussions d,\n {$CFG->prefix}user u,\n {$CFG->prefix}course_modules cm,\n {$CFG->prefix}forum f\n WHERE p.modified > '{$sincetime}' {$forumselect}\n AND p.userid = u.id {$userselect}\n AND d.course = '{$courseid}'\n AND p.discussion = d.id\n AND cm.instance = f.id\n AND cm.course = d.course\n AND cm.course = f.course\n AND f.id = d.forum\n ORDER BY p.discussion ASC,p.created ASC"); if (empty($posts)) { return; } foreach ($posts as $post) { $modcontext = get_context_instance(CONTEXT_MODULE, $post->cmid); $canviewallgroups = has_capability('moodle/site:accessallgroups', $modcontext); if ($groupid and ($post->groupid != -1 and $groupid != $post->groupid and !$canviewallgroups)) { continue; } if (!groups_course_module_visible($post->cmid)) { continue; } $tmpactivity = new Object(); $tmpactivity->type = "forum"; $tmpactivity->defaultindex = $index; $tmpactivity->instance = $post->instance; $tmpactivity->name = $post->name; $tmpactivity->section = $post->section; $tmpactivity->content->id = $post->id; $tmpactivity->content->discussion = $post->discussion; $tmpactivity->content->subject = $post->subject; $tmpactivity->content->parent = $post->parent; $tmpactivity->user->userid = $post->userid; $tmpactivity->user->fullname = fullname($post); $tmpactivity->user->picture = $post->picture; $tmpactivity->timestamp = $post->modified; $activities[] = $tmpactivity; $index++; } return; }
/** * Get Calendar events * * @param array $events A list of events * @package array $options various options * @return array Array of event details * @since Moodle 2.5 */ public static function get_calendar_events($events = array(), $options = array()) { global $SITE, $DB, $USER, $CFG; require_once $CFG->dirroot . "/calendar/lib.php"; // Parameter validation. $params = self::validate_parameters(self::get_calendar_events_parameters(), array('events' => $events, 'options' => $options)); $funcparam = array('courses' => array(), 'groups' => array()); $hassystemcap = has_capability('moodle/calendar:manageentries', context_system::instance()); $warnings = array(); // Let us findout courses that we can return events from. if (!$hassystemcap) { foreach ($params['events']['courseids'] as $id) { try { $context = context_course::instance($id); self::validate_context($context); $funcparam['courses'][] = $id; } catch (Exception $e) { $warnings[] = array('item' => 'course', 'itemid' => $id, 'warningcode' => 'nopermissions', 'message' => 'No access rights in course context ' . $e->getMessage() . $e->getTraceAsString()); continue; } } } else { $courses = $params['events']['courseids']; $funcparam['courses'] = $courses; } // Let us findout groups that we can return events from. if (!$hassystemcap) { $groups = groups_get_my_groups(); $groups = array_keys($groups); foreach ($params['events']['groupids'] as $id) { if (in_array($id, $groups)) { $funcparam['groups'][] = $id; } else { $warnings[] = array('item' => $id, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to access this group'); } } } else { $groups = $params['events']['groupids']; $funcparam['groups'] = $groups; } // Do we need user events? if (!empty($params['options']['userevents'])) { $funcparam['users'] = array($USER->id); } else { $funcparam['users'] = false; } // Do we need site events? if (!empty($params['options']['siteevents'])) { $funcparam['courses'][] = $SITE->id; } $eventlist = calendar_get_events($params['options']['timestart'], $params['options']['timeend'], $funcparam['users'], $funcparam['groups'], $funcparam['courses'], true, $params['options']['ignorehidden']); // WS expects arrays. $events = array(); foreach ($eventlist as $id => $event) { $events[$id] = (array) $event; } // We need to get events asked for eventids. $eventsbyid = calendar_get_events_by_id($params['events']['eventids']); foreach ($eventsbyid as $eventid => $eventobj) { $event = (array) $eventobj; if (isset($events[$eventid])) { continue; } if ($hassystemcap) { // User can see everything, no further check is needed. $events[$eventid] = $event; } else { if (!empty($eventobj->modulename)) { $cm = get_coursemodule_from_instance($eventobj->modulename, $eventobj->instance); if (groups_course_module_visible($cm)) { $events[$eventid] = $event; } } else { // Can the user actually see this event? $eventobj = calendar_event::load($eventobj); if ($eventobj->courseid == $SITE->id || !empty($eventobj->groupid) && in_array($eventobj->groupid, $groups) || !empty($eventobj->courseid) && in_array($eventobj->courseid, $courses) || $USER->id == $eventobj->userid || calendar_edit_event_allowed($eventid)) { $events[$eventid] = $event; } else { $warnings[] = array('item' => $eventid, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to view this event'); } } } } return array('events' => $events, 'warnings' => $warnings); }
function get_sessions($display, $groups, $users, $courses, $activefilters, &$events, &$sessionids) { global $cfgcalendarfilters; // Get events from database. $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses); if (!empty($events)) { // Check if any filters has been selected. if ($cfgcalendarfilters) { $defaultfieldsessionids = get_matches_defaultfields($events); foreach ($defaultfieldsessionids as $defaultfield) { $sessiondata['sessionids'][] = $defaultfield->sessionid; $sessiondata['timestart'][] = (int)$defaultfield->timestart; $sessiondata['timefinish'][] = (int)$defaultfield->timefinish; } } foreach ($events as $eventid => $event) { if (empty($event->modulename)) { continue; // Nothing to check. } // Check that facetoface events match all filters. $sessionid = (int)$event->uuid; if ('facetoface' == $event->modulename and $sessionid > 0) { $matchesallfilters = true; // Check if there are active filters and they are not empty. if ($cfgcalendarfilters && count($activefilters['defaultfields'])) { if (!count($defaultfieldsessionids) || !matches_defaultfield_filters($sessiondata, $event)) { unset($events[$eventid]); continue; } } foreach ($activefilters['customfields'] as $fieldid => $fieldvalue) { if (!matches_filter($fieldid, $fieldvalue, $sessionid)) { // Different value => no match. $matchesallfilters = false; break; } } if ($matchesallfilters) { $sessionids[] = $sessionid; } else { unset($events[$eventid]); continue; // Move to next event. } } // Group checks. $cm = get_coursemodule_from_instance($event->modulename, $event->instance); if (!groups_course_module_visible($cm)) { unset($events[$eventid]); } } } }
/** * Given a course and a (current) coursemodule * This function returns a small popup menu with all the * course activity modules in it, as a navigation menu * The data is taken from the serialised array stored in * the course record * * @param course $course A {@link $COURSE} object. * @param course $cm A {@link $COURSE} object. * @param string $targetwindow ? * @return string * @todo Finish documenting this function */ function navmenu($course, $cm = NULL, $targetwindow = 'self') { global $CFG, $THEME, $USER; if (empty($THEME->navmenuwidth)) { $width = 50; } else { $width = $THEME->navmenuwidth; } if ($cm) { $cm = $cm->id; } if ($course->format == 'weeks') { $strsection = get_string('week'); } else { $strsection = get_string('topic'); } $strjumpto = get_string('jumpto'); /// Casting $course->modinfo to string prevents one notice when the field is null if (!($modinfo = unserialize((string) $course->modinfo))) { return ''; } $context = get_context_instance(CONTEXT_COURSE, $course->id); $section = -1; $selected = ''; $url = ''; $previousmod = NULL; $backmod = NULL; $nextmod = NULL; $selectmod = NULL; $logslink = NULL; $flag = false; $menu = array(); $menustyle = array(); $sections = get_records('course_sections', 'course', $course->id, 'section', 'section,visible,summary'); if (!empty($THEME->makenavmenulist)) { /// A hack to produce an XHTML navmenu list for use in themes $THEME->navmenulist = navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $width, $cm); } foreach ($modinfo as $mod) { if ($mod->mod == 'label') { continue; } if ($mod->section > $course->numsections) { /// Don't show excess hidden sections break; } $mod->id = $mod->cm; $mod->course = $course->id; if (!groups_course_module_visible($mod)) { continue; } if ($mod->section > 0 and $section != $mod->section) { $thissection = $sections[$mod->section]; if ($thissection->visible or !$course->hiddensections or has_capability('moodle/course:viewhiddensections', $context)) { $thissection->summary = strip_tags(format_string($thissection->summary, true)); if ($course->format == 'weeks' or empty($thissection->summary)) { $menu[] = '--' . $strsection . " " . $mod->section; } else { if (strlen($thissection->summary) < $width - 3) { $menu[] = '--' . $thissection->summary; } else { $menu[] = '--' . substr($thissection->summary, 0, $width) . '...'; } } } } $section = $mod->section; //Only add visible or teacher mods to jumpmenu if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->cm))) { $url = $mod->mod . '/view.php?id=' . $mod->cm; if ($flag) { // the current mod is the "next" mod $nextmod = $mod; $flag = false; } if ($cm == $mod->cm) { $selected = $url; $selectmod = $mod; $backmod = $previousmod; $flag = true; // set flag so we know to use next mod for "next" $mod->name = $strjumpto; $strjumpto = ''; } else { $mod->name = strip_tags(format_string(urldecode($mod->name), true)); if (strlen($mod->name) > $width + 5) { $mod->name = substr($mod->name, 0, $width) . '...'; } if (!$mod->visible) { $mod->name = '(' . $mod->name . ')'; } } $menu[$url] = $mod->name; if (empty($THEME->navmenuiconshide)) { $menustyle[$url] = 'style="background-image: url(' . $CFG->modpixpath . '/' . $mod->mod . '/icon.gif);"'; // Unfortunately necessary to do this here } $previousmod = $mod; } } //Accessibility: added Alt text, replaced > < with 'silent' character and 'accesshide' text. if ($selectmod and has_capability('moodle/site:viewreports', $context)) { $logstext = get_string('alllogs'); $logslink = '<li>' . "\n" . '<a title="' . $logstext . '" ' . $CFG->frametarget . 'onclick="this.target=\'' . $CFG->framename . '\';"' . ' href="' . $CFG->wwwroot . '/course/report/log/index.php?chooselog=1&user=0&date=0&id=' . $course->id . '&modid=' . $selectmod->cm . '">' . '<img class="icon log" src="' . $CFG->pixpath . '/i/log.gif" alt="' . $logstext . '" /></a>' . "\n" . '</li>'; } if ($backmod) { $backtext = get_string('activityprev', 'access'); $backmod = '<li><form action="' . $CFG->wwwroot . '/mod/' . $backmod->mod . '/view.php" ' . 'onclick="this.target=\'' . $CFG->framename . '\';"' . '><fieldset class="invisiblefieldset">' . '<input type="hidden" name="id" value="' . $backmod->cm . '" />' . '<button type="submit" title="' . $backtext . '">' . link_arrow_left($backtext, $url = '', $accesshide = true) . '</button></fieldset></form></li>'; } if ($nextmod) { $nexttext = get_string('activitynext', 'access'); $nextmod = '<li><form action="' . $CFG->wwwroot . '/mod/' . $nextmod->mod . '/view.php" ' . 'onclick="this.target=\'' . $CFG->framename . '\';"' . '><fieldset class="invisiblefieldset">' . '<input type="hidden" name="id" value="' . $nextmod->cm . '" />' . '<button type="submit" title="' . $nexttext . '">' . link_arrow_right($nexttext, $url = '', $accesshide = true) . '</button></fieldset></form></li>'; } return '<div class="navigation">' . "\n" . '<ul>' . $logslink . $backmod . '<li>' . popup_form($CFG->wwwroot . '/mod/', $menu, 'navmenupopup', $selected, $strjumpto, '', '', true, $targetwindow, '', $menustyle) . '</li>' . $nextmod . '</ul>' . "\n" . '</div>'; }
/** * 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 (!groups_course_module_visible($cm)) { 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')); if (calendar_user_can_add_event($calendar->course)) { $output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time); } $output .= $this->course_filter_selector($returnurl, get_string('detailedmonthviewfor', 'calendar')); $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 = strtotime('-1 day', $display->tstart); for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) { $daytime = strtotime('+1 day', $daytime); 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; }
/** * Checks if an activity is visible to the given user. * * Unlike other checks in the availability system, this check includes the * $cm->visible flag and also (if enabled) the groupmembersonly feature. * It is equivalent to $cm->uservisible. * * If you have already checked (or do not care whether) the user has access * to the course, you can set $checkcourse to false to save it checking * course access. * * When checking for the current user, you should generally not call * this function. Instead, use get_fast_modinfo to get a cm_info object, * then simply check the $cm->uservisible flag. This function is intended * to obtain that information for a separate course-module object that * wasn't loaded with get_fast_modinfo, or for a different user. * * This function has a performance cost unless the availability system is * disabled, and you supply a $cm object with necessary fields, and you * don't check course access. * * @param int|\stdClass|\cm_info $cmorid Object or id representing activity * @param int $userid User id (0 = current user) * @param bool $checkcourse If true, checks whether the user has course access * @return bool True if the activity is visible to the specified user * @throws \moodle_exception If the cmid doesn't exist */ public static function is_user_visible($cmorid, $userid = 0, $checkcourse = true) { global $USER, $DB, $CFG; // Evaluate user id. if (!$userid) { $userid = $USER->id; } // If this happens to be already called with a cm_info for the right user // then just return uservisible. if ($cmorid instanceof \cm_info && $cmorid->get_modinfo()->userid == $userid) { return $cmorid->uservisible; } // If the $cmorid isn't an object or doesn't have required fields, load it. if (is_object($cmorid) && isset($cmorid->course) && isset($cmorid->visible)) { $cm = $cmorid; } else { if (is_object($cmorid)) { $cmorid = $cmorid->id; } $cm = $DB->get_record('course_modules', array('id' => $cmorid), '*', MUST_EXIST); } // Check the groupmembersonly feature. if (!groups_course_module_visible($cm, $userid)) { return false; } // If requested, check user can access the course. if ($checkcourse) { $coursecontext = \context_course::instance($cm->course); if (!is_enrolled($coursecontext, $userid, '', true) && !has_capability('moodle/course:view', $coursecontext, $userid)) { return false; } } // If availability is disabled, then all we need to do is check the visible flag. if (!$CFG->enableavailability && $cm->visible) { return true; } // When availability is enabled, access can depend on 3 things: // 1. $cm->visible // 2. $cm->availability // 3. $section->availability (for activity section and possibly for // parent sections) // As a result we cannot take short cuts any longer and must get // standard modinfo. $modinfo = get_fast_modinfo($cm->course, $userid); return $modinfo->get_cm($cm->id)->uservisible; }
function print_section($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%") { /// Prints a section full of activity modules global $CFG, $USER; static $groupbuttons; static $groupbuttonslink; static $isteacher; static $isediting; static $ismoving; static $strmovehere; static $strmovefull; static $strunreadpostsone; static $untracked; static $usetracking; $labelformatoptions = new stdClass(); if (!isset($isteacher)) { $groupbuttons = ($course->groupmode or !$course->groupmodeforce); $groupbuttonslink = !$course->groupmodeforce; $isediting = isediting($course->id); $ismoving = $isediting && ismoving($course->id); if ($ismoving) { $strmovehere = get_string("movehere"); $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'")); } include_once $CFG->dirroot . '/mod/forum/lib.php'; if ($usetracking = forum_tp_can_track_forums()) { $strunreadpostsone = get_string('unreadpostsone', 'forum'); $untracked = forum_tp_get_untracked_forums($USER->id, $course->id); } } $labelformatoptions->noclean = true; /// Casting $course->modinfo to string prevents one notice when the field is null $modinfo = unserialize((string) $course->modinfo); $groupings = groups_get_all_groupings($course->id); //Acccessibility: replace table with list <ul>, but don't output empty list. if (!empty($section->sequence)) { // Fix bug #5027, don't want style=\"width:$width\". echo "<ul class=\"section img-text\">\n"; $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if (($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $course->id))) && (!$ismoving || $mod->id != $USER->activitycopy) && groups_course_module_visible($mod)) { echo '<li class="activity ' . $mod->modname . '" id="module-' . $modnumber . '">'; // Unique ID if ($ismoving) { echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br /> '; } $instancename = urldecode($modinfo[$modnumber]->name); $instancename = format_string($instancename, true, $course->id); if (!empty($modinfo[$modnumber]->extra)) { $extra = urldecode($modinfo[$modnumber]->extra); } else { $extra = ""; } if (!empty($modinfo[$modnumber]->icon)) { $icon = "{$CFG->pixpath}/" . urldecode($modinfo[$modnumber]->icon); } else { $icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif"; } if ($mod->indent) { print_spacer(12, 20 * $mod->indent, false); } if ($mod->modname == "label") { if (!$mod->visible) { echo "<span class=\"dimmed_text\">"; } echo format_text($extra, FORMAT_HTML, $labelformatoptions); if (!$mod->visible) { echo "</span>"; } } else { // Normal activity //Accessibility: for files get description via icon. $altname = ''; if ('resource' == $mod->modname) { if (!empty($modinfo[$modnumber]->icon)) { $possaltname = $modinfo[$modnumber]->icon; $mimetype = mimeinfo_from_icon('type', $possaltname); $altname = get_mimetype_description($mimetype); } else { $altname = $mod->modfullname; } } else { $altname = $mod->modfullname; } // Avoid unnecessary duplication. if (false !== stripos($instancename, $altname)) { $altname = ''; } // File type after name, for alphabetic lists (screen reader). if ($altname) { $altname = get_accesshide(' ' . $altname); } $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>'; if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { echo " <span class=\"groupinglabel\"> - " . format_string($groupings[$mod->groupingid]->name) . '</span>'; } } if ($usetracking && $mod->modname == 'forum') { $groupmode = groups_get_course_groupmode($course, $mod); $groupid = $groupmode == SEPARATEGROUPS && !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id)) ? groups_get_course_group($course, true) : false; if (forum_tp_can_track_forums() && !isset($untracked[$mod->instance])) { $unread = forum_tp_count_forum_unread_posts($USER->id, $mod->instance, $groupid); if ($unread) { echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">'; if ($unread == 1) { echo $strunreadpostsone; } else { print_string('unreadpostsnumber', 'forum', $unread); } echo '</a> </span>'; } } } if ($isediting) { // TODO: we must define this as mod property! if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') { if (!($mod->groupmodelink = $groupbuttonslink)) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } echo ' '; echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section); } echo "</li>\n"; } } } elseif ($ismoving) { echo "<ul class=\"section\">\n"; } if ($ismoving) { echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a></li> '; } if (!empty($section->sequence) || $ismoving) { echo "</ul><!--class='section'-->\n\n"; } }
if ($course->id != SITEID) { // Only real courses have learning forums // Add extra field for section number, at the front if ($course->format == 'weeks' or $course->format == 'weekscss') { array_unshift($learningtable->head, $strweek); } else { array_unshift($learningtable->head, $strsection); } array_unshift($learningtable->align, "center"); if ($learningforums) { $currentsection = ""; foreach ($learningforums as $key => $forum) { $forum->visible = instance_is_visible("forum", $forum) || has_capability('moodle/course:view', $coursecontext); $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!groups_course_module_visible($cm)) { continue; } $currentgroup = groups_get_activity_group($cm); $groupmode = groups_get_activity_groupmode($cm); $cantaccessagroup = $groupmode and !has_capability('moodle/site:accessallgroups', $context) and !mygroupid($course->id); if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { $count = count_records("forum_discussions", "forum", "{$forum->id}", "groupid", $currentgroup); } else { $count = count_records("forum_discussions", "forum", "{$forum->id}"); } if ($usetracking) { if ($forum->trackingtype == FORUM_TRACKING_ON || !isset($untracked[$forum->id])) { $groupid = $groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context) ? $currentgroup : false; $unread = forum_tp_count_forum_unread_posts($USER->id, $forum->id, $groupid); if ($unread > 0) {
/** * Determine whether a course module is visible within a course, * this is different from instance_is_visible() - faster and visibility for user * * @param object $cm object * @param int $userid empty means current user * @return bool */ function coursemodule_visible_for_user($cm, $userid = 0) { global $USER; if (empty($cm->id)) { debugging("Incorrect course module parameter!", DEBUG_DEVELOPER); return false; } if (empty($userid)) { $userid = $USER->id; } if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) { return false; } return groups_course_module_visible($cm, $userid); }
/** * Returns a number of useful structures for course displays */ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { global $CFG, $DB, $COURSE; $mods = array(); // course modules indexed by id $modnames = array(); // all course module names (except resource!) $modnamesplural = array(); // all course module names (plural form) $modnamesused = array(); // course module names used if ($allmods = $DB->get_records("modules")) { foreach ($allmods as $mod) { if (!file_exists("{$CFG->dirroot}/mod/{$mod->name}/lib.php")) { continue; } if ($mod->visible) { $modnames[$mod->name] = get_string("modulename", "{$mod->name}"); $modnamesplural[$mod->name] = get_string("modulenameplural", "{$mod->name}"); } } collatorlib::asort($modnames); } else { print_error("nomodules", 'debug'); } $course = $courseid == $COURSE->id ? $COURSE : $DB->get_record('course', array('id' => $courseid)); $modinfo = get_fast_modinfo($course); if ($rawmods = $modinfo->cms) { foreach ($rawmods as $mod) { // Index the mods if (empty($modnames[$mod->modname])) { continue; } $mods[$mod->id] = $mod; $mods[$mod->id]->modfullname = $modnames[$mod->modname]; if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid))) { continue; } // Check groupings if (!groups_course_module_visible($mod)) { continue; } $modnamesused[$mod->modname] = $modnames[$mod->modname]; } if ($modnamesused) { collatorlib::asort($modnamesused); } } }
/** * 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; }
/** * Load a list of users enrolled in the current course with the specified permission and group. * 0 for no group. * * @param int $currentgroup * @param bool $idsonly * @return array List of user records */ public function list_participants($currentgroup, $idsonly) { if ($idsonly) { $users = get_enrolled_users($this->context, 'mod/assign:submit', $currentgroup, 'u.id', null, null, null, $this->show_only_active_users()); } else { $users = get_enrolled_users($this->context, 'mod/assign:submit', $currentgroup, 'u.*', null, null, null, $this->show_only_active_users()); } $cm = $this->get_course_module(); foreach ($users as $userid => $user) { if (!groups_course_module_visible($cm, $userid)) { unset($users[$userid]); } } return $users; }
function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime = 0) { global $CFG; $display =& new stdClass(); $display->range = $daysinfuture; // How many days in the future we 'll look $display->maxevents = $maxevents; $output = array(); // Prepare "course caching", since it may save us a lot of queries $coursecache = array(); $processed = 0; $now = time(); // We 'll need this later $usermidnighttoday = usergetmidnight($now); if ($fromtime) { $display->tstart = $fromtime; } else { $display->tstart = $usermidnighttoday; } // This works correctly with respect to the user's DST, but it is accurate // only because $fromtime is always the exact midnight of some day! $display->tend = usergetmidnight($display->tstart + DAYSECS * $display->range + 3 * HOURSECS) - 1; // Get the events matching our criteria $events = calendar_get_events($display->tstart, $display->tend, $users, $groups, $courses); // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra // arguments to this function. $morehref = ''; if (!empty($courses)) { $courses = array_diff($courses, array(SITEID)); if (count($courses) == 1) { $morehref = '&course=' . reset($courses); } } if ($events !== false) { foreach ($events as $event) { if (!empty($event->modulename)) { $mod = get_coursemodule_from_instance($event->modulename, $event->instance); if (!groups_course_module_visible($mod)) { continue; } } if ($event->modulename == 'assignment') { if (!calendar_edit_event_allowed($event)) { // cannot manage entries, eg. student if (!($assignment = get_record('assignment', 'id', $event->instance))) { // error("assignment ID was incorrect"); continue; } // assign assignment to assignment object to use hidden_is_hidden method require_once $CFG->dirroot . '/mod/assignment/lib.php'; if (!file_exists($CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php')) { continue; } require_once $CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php'; $assignmentclass = 'assignment_' . $assignment->assignmenttype; $assignmentinstance = new $assignmentclass($mod->id, $assignment); if ($assignmentinstance->description_is_hidden()) { //force not to show description before availability $event->description = get_string('notavailableyet', 'assignment'); } } } if ($processed >= $display->maxevents) { break; } $event->time = calendar_format_event_time($event, $now, $morehref); $output[] = $event; ++$processed; } } return $output; }
/** * Determine whether a course module is visible within a course, * this is different from instance_is_visible() - faster and visibility for user * * @global object * @global object * @uses DEBUG_DEVELOPER * @uses CONTEXT_MODULE * @uses CONDITION_MISSING_EXTRATABLE * @param object $cm object * @param int $userid empty means current user * @return bool Success */ function coursemodule_visible_for_user($cm, $userid = 0) { global $USER, $CFG; if (empty($cm->id)) { debugging("Incorrect course module parameter!", DEBUG_DEVELOPER); return false; } if (empty($userid)) { $userid = $USER->id; } if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) { return false; } if ($CFG->enableavailability) { require_once $CFG->libdir . '/conditionlib.php'; $ci = new condition_info($cm, CONDITION_MISSING_EXTRATABLE); if (!$ci->is_available($cm->availableinfo, false, $userid) and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) { return false; } } return groups_course_module_visible($cm, $userid); }
function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime = 0) { global $CFG; $display =& new stdClass(); $display->range = $daysinfuture; // How many days in the future we 'll look $display->maxevents = $maxevents; $output = array(); // Prepare "course caching", since it may save us a lot of queries $coursecache = array(); $processed = 0; $now = time(); // We 'll need this later $usermidnighttoday = usergetmidnight($now); if ($fromtime) { $display->tstart = $fromtime; } else { $display->tstart = $usermidnighttoday; } // This works correctly with respect to the user's DST, but it is accurate // only because $fromtime is always the exact midnight of some day! $display->tend = usergetmidnight($display->tstart + DAYSECS * $display->range + 3 * HOURSECS) - 1; // Get the events matching our criteria $whereclause = calendar_sql_where($display->tstart, $display->tend, $users, $groups, $courses); if ($whereclause === false) { $events = false; } else { $events = get_records_select('event', $whereclause, 'timestart'); } // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra // arguments to this function. $morehref = ''; if (!empty($courses)) { $courses = array_diff($courses, array(SITEID)); if (count($courses) == 1) { $morehref = '&course=' . reset($courses); } } if ($events !== false) { foreach ($events as $event) { if (!empty($event->modulename)) { $mod = get_coursemodule_from_instance($event->modulename, $event->instance); if (!groups_course_module_visible($mod)) { continue; } } if ($processed >= $display->maxevents) { break; } $event->time = calendar_format_event_time($event, $now, $morehref); $output[] = $event; ++$processed; } } return $output; }