当前位置: 首页>>代码示例>>PHP>>正文


PHP calendar_get_events函数代码示例

本文整理汇总了PHP中calendar_get_events函数的典型用法代码示例。如果您正苦于以下问题:PHP calendar_get_events函数的具体用法?PHP calendar_get_events怎么用?PHP calendar_get_events使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了calendar_get_events函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: calendar_get_upcoming

function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime = 0)
{
    global $CFG, $COURSE;
    $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) {
        $modinfo =& get_fast_modinfo($COURSE);
        foreach ($events as $event) {
            if (!empty($event->modulename)) {
                if ($event->courseid == $COURSE->id) {
                    if (isset($modinfo->instances[$event->modulename][$event->instance])) {
                        $cm = $modinfo->instances[$event->modulename][$event->instance];
                        if (!$cm->uservisible) {
                            continue;
                        }
                    }
                } else {
                    if (!($cm = get_coursemodule_from_instance($event->modulename, $event->instance))) {
                        continue;
                    }
                    if (!coursemodule_visible_for_user($cm)) {
                        continue;
                    }
                }
                if ($event->modulename == 'assignment') {
                    // TODO: rewrite this hack somehow
                    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($cm->id, $assignment, $cm);
                        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;
}
开发者ID:kai707,项目名称:ITSA-backup,代码行数:87,代码来源:lib.php

示例2: show_month_detailed

 /**
  * 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('&nbsp;');
         $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)
//.........这里部分代码省略.........
开发者ID:abhilash1994,项目名称:moodle,代码行数:101,代码来源:renderer.php

示例3: get_calendar_events

 /**
  * Get Calendar events
  *
  * @param array $events A list of events
  * @param 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) {
         $courses = enrol_get_my_courses();
         $courses = array_keys($courses);
         foreach ($params['events']['courseids'] as $id) {
             if (in_array($id, $courses)) {
                 $funcparam['courses'][] = $id;
             } else {
                 $warnings[] = array('item' => $id, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to access this course');
             }
         }
     } 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;
     }
     // We treat 0 and null as no end.
     if (empty($params['options']['timeend'])) {
         $params['options']['timeend'] = PHP_INT_MAX;
     }
     $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 (\core_availability\info_module::is_user_visible($cm, 0, false)) {
                     $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);
 }
开发者ID:nikitskynikita,项目名称:moodle,代码行数:96,代码来源:externallib.php

示例4: get_upcoming_deadlines

 /**
  * Return user's deadlines from the calendar.
  *
  * Usually called twice, once for all deadlines from today, then any from the next 12 months up to the
  * max requested.
  *
  * Based on the calender function calendar_get_upcoming.
  *
  * @param array $courses ids of all user's courses.
  * @param int $maxevents to return
  * @param bool $todayonly true if only the next 24 hours to be returned
  * @return array
  */
 private static function get_upcoming_deadlines($courses, $maxevents, $todayonly = false)
 {
     $now = time();
     if ($todayonly === true) {
         $starttime = usergetmidnight($now);
         $daysinfuture = 1;
     } else {
         $starttime = usergetmidnight($now + DAYSECS + 3 * HOURSECS);
         // Avoid rare DST change issues.
         $daysinfuture = 365;
     }
     $endtime = $starttime + $daysinfuture * DAYSECS - 1;
     $userevents = false;
     $groupevents = false;
     $events = calendar_get_events($starttime, $endtime, $userevents, $groupevents, $courses);
     $processed = 0;
     $output = array();
     foreach ($events as $event) {
         if ($event->eventtype === 'course') {
             // Not an activity deadline.
             continue;
         }
         if (!empty($event->modulename)) {
             $modinfo = get_fast_modinfo($event->courseid);
             $mods = $modinfo->get_instances_of($event->modulename);
             if (isset($mods[$event->instance])) {
                 $cminfo = $mods[$event->instance];
                 if (!$cminfo->uservisible) {
                     continue;
                 }
             }
         }
         $output[$event->id] = $event;
         ++$processed;
         if ($processed >= $maxevents) {
             break;
         }
     }
     return $output;
 }
开发者ID:nbartley,项目名称:moodle-theme_snap,代码行数:53,代码来源:local.php

示例5: calendar_get_upcoming

/**
 * Gets the calendar upcoming event
 *
 * @param array $courses array of courses
 * @param array|int|bool $groups array of groups, group id or boolean for all/no group events
 * @param array|int|bool $users array of users, user id or boolean for all/no user events
 * @param int $daysinfuture number of days in the future we 'll look
 * @param int $maxevents maximum number of events
 * @param int $fromtime start time
 * @return array $output array of upcoming events
 */
function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime = 0)
{
    global $CFG, $COURSE, $DB;
    $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.
    $hrefparams = array();
    if (!empty($courses)) {
        $courses = array_diff($courses, array(SITEID));
        if (count($courses) == 1) {
            $hrefparams['course'] = reset($courses);
        }
    }
    if ($events !== false) {
        $modinfo = get_fast_modinfo($COURSE);
        foreach ($events as $event) {
            if (!empty($event->modulename)) {
                if ($event->courseid == $COURSE->id) {
                    if (isset($modinfo->instances[$event->modulename][$event->instance])) {
                        $cm = $modinfo->instances[$event->modulename][$event->instance];
                        if (!$cm->uservisible) {
                            continue;
                        }
                    }
                } else {
                    if (!($cm = get_coursemodule_from_instance($event->modulename, $event->instance))) {
                        continue;
                    }
                    if (!\core_availability\info_module::is_user_visible($cm, 0, false)) {
                        continue;
                    }
                }
            }
            if ($processed >= $display->maxevents) {
                break;
            }
            $event->time = calendar_format_event_time($event, $now, $hrefparams);
            $output[] = $event;
            ++$processed;
        }
    }
    return $output;
}
开发者ID:bewanyk,项目名称:moodle,代码行数:76,代码来源:lib.php

示例6: get_events

 function get_events($username, $start_date, $end_date, $type, $course_id)
 {
     global $USER, $DB;
     $username = utf8_decode($username);
     $username = strtolower($username);
     $user = get_complete_user_data('username', $username);
     if ($username != 'guest') {
         if ($course_id) {
             if (!($course = $DB->get_record("course", array("id" => $course_id)))) {
                 return array();
             }
             $coursestoload = array($course_id => $course);
         } else {
             $coursestoload = enrol_get_users_courses($user->id, true);
         }
     } else {
         if (!($course = $DB->get_record("course", array("id" => 1)))) {
             return array();
         }
         $coursestoload = array(1 => $course);
     }
     $ws_user = $USER;
     // save $USER var to reset it after use. It holds web service user. I don't think it is needed, but just in case...
     $USER = $user;
     $ignorefilters = false;
     list($courses, $group, $user_id_not_used) = calendar_set_filters($coursestoload, $ignorefilters);
     $USER = $ws_user;
     // reset global var
     $events = calendar_get_events($start_date, $end_date, $user->id, $group, $courses);
     $es = array();
     foreach ($events as $event) {
         // We filter user and site events here
         if ($type == 'site' && $event->eventtype != 'site') {
             continue;
         } else {
             if ($type == 'user') {
                 //  We only show events with userid set as the user
                 if ($event->userid != $user->id) {
                     continue;
                 }
             }
         }
         $e = array();
         $e['id'] = $event->id;
         $e['name'] = $event->name;
         $e['description'] = $event->description;
         $e['timestart'] = $event->timestart;
         $e['timeduration'] = $event->timeduration;
         $es[] = $e;
     }
     return $es;
 }
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:52,代码来源:auth.php

示例7: calendar_show_month_detailed

function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid)
{
    global $CFG, $SESSION, $USER, $CALENDARDAYS;
    global $day, $mon, $yr;
    $getvars = 'from=month&amp;cal_d=' . $day . '&amp;cal_m=' . $mon . '&amp;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) {
//.........这里部分代码省略.........
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:101,代码来源:view.php

示例8: show_month_detailed

 /**
  * 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('&nbsp;');
         $cell->attributes = array('class' => 'nottoday');
         $row->cells[] = $cell;
     }
     // Now display all the calendar
     $weekend = CALENDAR_DEFAULT_WEEKEND;
     if (isset($CFG->calendar_weekend)) {
//.........这里部分代码省略.........
开发者ID:rosenclever,项目名称:moodle,代码行数:101,代码来源:renderer.php

示例9: make_timestamp

                $timestart = make_timestamp($nextyear, $nextmonth, 1);
                $timeend = make_timestamp($nextyear, $nextmonth, calendar_days_in_month($nextmonth, $nextyear), 23, 59, 59);
                break;
            case 'recentupcoming':
                //Events in the last 5 or next 60 days
                $timestart = time() - 432000;
                $timeend = time() + 5184000;
                break;
        }
    } else {
        // Parameters given but incorrect, redirect back to export page
        redirect($CFG->wwwroot . '/calendar/export.php');
        die;
    }
}
$events = calendar_get_events($timestart, $timeend, $users, $groups, array_keys($courses), false);
$ical = new iCalendar();
$ical->add_property('method', 'PUBLISH');
foreach ($events as $event) {
    if (!empty($event->modulename)) {
        $cm = get_coursemodule_from_instance($event->modulename, $event->instance);
        if (!groups_course_module_visible($cm)) {
            continue;
        }
    }
    $hostaddress = str_replace('http://', '', $CFG->wwwroot);
    $hostaddress = str_replace('https://', '', $hostaddress);
    $ev = new iCalendar_event();
    $ev->add_property('uid', $event->id . '@' . $hostaddress);
    $ev->add_property('summary', $event->name);
    $ev->add_property('description', $event->description);
开发者ID:raymondAntonio,项目名称:moodle,代码行数:31,代码来源:export_execute.php

示例10: get_sessions

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]);
            }
        }
    }
}
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:58,代码来源:calendar.php

示例11: test_calendar_get_events_with_disabled_module

 /**
  * Test the calendar_get_events() function only returns activity
  * events that are enabled.
  */
 public function test_calendar_get_events_with_disabled_module()
 {
     global $DB;
     $course = $this->getDataGenerator()->create_course();
     $events = [['name' => 'Start of assignment', 'description' => '', 'format' => 1, 'courseid' => $course->id, 'groupid' => 0, 'userid' => 2, 'modulename' => 'assign', 'instance' => 1, 'eventtype' => 'due', 'timestart' => time(), 'timeduration' => 86400, 'visible' => 1], ['name' => 'Start of lesson', 'description' => '', 'format' => 1, 'courseid' => $course->id, 'groupid' => 0, 'userid' => 2, 'modulename' => 'lesson', 'instance' => 1, 'eventtype' => 'end', 'timestart' => time(), 'timeduration' => 86400, 'visible' => 1]];
     foreach ($events as $event) {
         calendar_event::create($event, false);
     }
     $timestart = time() - 60;
     $timeend = time() + 60;
     // Get all events.
     $events = calendar_get_events($timestart, $timeend, true, 0, true);
     $this->assertCount(2, $events);
     // Disable the lesson module.
     $modulerecord = $DB->get_record('modules', ['name' => 'lesson']);
     $modulerecord->visible = 0;
     $DB->update_record('modules', $modulerecord);
     // Check that we only return the assign event.
     $events = calendar_get_events($timestart, $timeend, true, 0, true);
     $this->assertCount(1, $events);
     $event = reset($events);
     $this->assertEquals('assign', $event->modulename);
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:27,代码来源:lib_test.php

示例12: assert_event_absent

 private function assert_event_absent($userid, $time)
 {
     $events = calendar_get_events($time - MINSECS, $time + HOURSECS, $userid, false, false);
     $this->assertEquals(0, count($events), "Expecting no event at time {$time} for user {$userid}");
 }
开发者ID:ninelanterns,项目名称:moodle-mod_scheduler,代码行数:5,代码来源:slot_test.php

示例13: get_upcoming_deadlines

 /**
  * Return user's deadlines from the calendar.
  *
  * Usually called twice, once for all deadlines from today, then any from the next 12 months up to the
  * max requested.
  *
  * Based on the calender function calendar_get_upcoming.
  *
  * @param \stdClass|int $userorid
  * @param array $courses ids of all user's courses.
  * @param int $maxevents to return
  * @param bool $todayonly true if only the next 24 hours to be returned
  * @return array
  */
 private static function get_upcoming_deadlines($userorid, $courses, $maxevents, $todayonly = false)
 {
     $user = self::get_user($userorid);
     if (!$user) {
         return [];
     }
     // We need to do this so that we can calendar events and mod visibility for a specific user.
     self::swap_global_user($user);
     $tz = new \DateTimeZone(\core_date::get_user_timezone($user));
     $today = new \DateTime('today', $tz);
     $tomorrow = new \DateTime('tomorrow', $tz);
     if ($todayonly === true) {
         $starttime = $today->getTimestamp();
         $endtime = $tomorrow->getTimestamp() - 1;
     } else {
         $starttime = $tomorrow->getTimestamp();
         $endtime = $starttime + 365 * DAYSECS - 1;
     }
     $userevents = false;
     $groupevents = false;
     $events = calendar_get_events($starttime, $endtime, $userevents, $groupevents, $courses);
     $processed = 0;
     $output = array();
     foreach ($events as $event) {
         if ($event->eventtype === 'course') {
             // Not an activity deadline.
             continue;
         }
         if ($event->eventtype === 'open' && $event->timeduration == 0) {
             // Only the opening of multi-day event, not a deadline.
             continue;
         }
         if (!empty($event->modulename)) {
             $modinfo = get_fast_modinfo($event->courseid);
             $mods = $modinfo->get_instances_of($event->modulename);
             if (isset($mods[$event->instance])) {
                 $cminfo = $mods[$event->instance];
                 if (!$cminfo->uservisible) {
                     continue;
                 }
                 if ($event->eventtype === 'close') {
                     // Revert the addition of e.g. "(Quiz closes)" to the event name.
                     $event->name = $cminfo->name;
                 }
             }
         }
         $output[$event->id] = $event;
         ++$processed;
         if ($processed >= $maxevents) {
             break;
         }
     }
     self::swap_global_user(false);
     return $output;
 }
开发者ID:pramithkm,项目名称:moodle-theme_snap,代码行数:69,代码来源:local.php


注:本文中的calendar_get_events函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。