本文整理汇总了PHP中core_availability\info_module::is_user_visible方法的典型用法代码示例。如果您正苦于以下问题:PHP info_module::is_user_visible方法的具体用法?PHP info_module::is_user_visible怎么用?PHP info_module::is_user_visible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_availability\info_module
的用法示例。
在下文中一共展示了info_module::is_user_visible方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forum_user_can_see_post
/**
* @global object
* @global object
* @param object $forum
* @param object $discussion
* @param object $post
* @param object $user
* @param object $cm
* @return bool
*/
function forum_user_can_see_post($forum, $discussion, $post, $user = NULL, $cm = NULL)
{
global $CFG, $USER, $DB;
// Context used throughout function.
$modcontext = context_module::instance($cm->id);
// retrieve objects (yuk)
if (is_numeric($forum)) {
debugging('missing full forum', DEBUG_DEVELOPER);
if (!($forum = $DB->get_record('forum', array('id' => $forum)))) {
return false;
}
}
if (is_numeric($discussion)) {
debugging('missing full discussion', DEBUG_DEVELOPER);
if (!($discussion = $DB->get_record('forum_discussions', array('id' => $discussion)))) {
return false;
}
}
if (is_numeric($post)) {
debugging('missing full post', DEBUG_DEVELOPER);
if (!($post = $DB->get_record('forum_posts', array('id' => $post)))) {
return false;
}
}
if (!isset($post->id) && isset($post->parent)) {
$post->id = $post->parent;
}
if (!$cm) {
debugging('missing cm', DEBUG_DEVELOPER);
if (!($cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course))) {
print_error('invalidcoursemodule');
}
}
if (empty($user) || empty($user->id)) {
$user = $USER;
}
$canviewdiscussion = !empty($cm->cache->caps['mod/forum:viewdiscussion']) || has_capability('mod/forum:viewdiscussion', $modcontext, $user->id);
if (!$canviewdiscussion && !has_all_capabilities(array('moodle/user:viewdetails', 'moodle/user:readuserposts'), context_user::instance($post->userid))) {
return false;
}
if (isset($cm->uservisible)) {
if (!$cm->uservisible) {
return false;
}
} else {
if (!\core_availability\info_module::is_user_visible($cm, $user->id, false)) {
return false;
}
}
if (!forum_user_can_see_timed_discussion($discussion, $user, $modcontext)) {
return false;
}
if (!forum_user_can_see_group_discussion($discussion, $cm, $modcontext)) {
return false;
}
if ($forum->type == 'qanda') {
$firstpost = forum_get_firstpost_from_discussion($discussion->id);
$userfirstpost = forum_get_user_posted_time($discussion->id, $user->id);
return $userfirstpost !== false && time() - $userfirstpost >= $CFG->maxeditingtime || $firstpost->id == $post->id || $post->userid == $user->id || $firstpost->userid == $user->id || has_capability('mod/forum:viewqandawithoutposting', $modcontext, $user->id);
}
return true;
}
示例2: test_is_user_visible
/**
* Tests the is_user_visible() static function in info_module.
*/
public function test_is_user_visible()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/course/lib.php';
$this->resetAfterTest();
// Create a course and some pages:
// 0. Invisible due to visible=0.
// 1. Availability restriction (mock, set to fail).
// 2. Availability restriction on section (mock, set to fail).
// 3. Actually visible.
$generator = $this->getDataGenerator();
$course = $generator->create_course(array('numsections' => 1), array('createsections' => true));
$rec = array('course' => $course);
$pages = array();
$pagegen = $generator->get_plugin_generator('mod_page');
$pages[0] = $pagegen->create_instance($rec, array('visible' => 0));
$pages[1] = $pagegen->create_instance($rec);
$pages[2] = $pagegen->create_instance($rec);
$pages[3] = $pagegen->create_instance($rec);
$modinfo = get_fast_modinfo($course);
$section = $modinfo->get_section_info(1);
$cm = $modinfo->get_cm($pages[2]->cmid);
moveto_module($cm, $section);
// Set the availability restrictions in database. The enableavailability
// setting is off so these do not take effect yet.
$notavailable = '{"op":"|","show":true,"c":[{"type":"mock","a":false}]}';
$DB->set_field('course_sections', 'availability', $notavailable, array('id' => $section->id));
$DB->set_field('course_modules', 'availability', $notavailable, array('id' => $pages[1]->cmid));
get_fast_modinfo($course, 0, true);
// Set up 4 users - a teacher and student plus somebody who isn't even
// on the course. Also going to use admin user and a spare student to
// avoid cache problems.
$roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
$teacher = $generator->create_user();
$student = $generator->create_user();
$student2 = $generator->create_user();
$other = $generator->create_user();
$admin = $DB->get_record('user', array('username' => 'admin'));
$generator->enrol_user($teacher->id, $course->id, $roleids['teacher']);
$generator->enrol_user($student->id, $course->id, $roleids['student']);
$generator->enrol_user($student2->id, $course->id, $roleids['student']);
// Basic case when availability disabled, for visible item.
$this->assertTrue(info_module::is_user_visible($pages[3]->cmid, $student->id, false));
// Specifying as an object should not make any queries.
$cm = $DB->get_record('course_modules', array('id' => $pages[3]->cmid));
$beforequeries = $DB->perf_get_queries();
$this->assertTrue(info_module::is_user_visible($cm, $student->id, false));
$this->assertEquals($beforequeries, $DB->perf_get_queries());
// Specifying as cm_info for correct user should not make any more queries
// if we have already obtained dynamic data.
$modinfo = get_fast_modinfo($course, $student->id);
$cminfo = $modinfo->get_cm($cm->id);
// This will obtain dynamic data.
$name = $cminfo->name;
$beforequeries = $DB->perf_get_queries();
$this->assertTrue(info_module::is_user_visible($cminfo, $student->id, false));
$this->assertEquals($beforequeries, $DB->perf_get_queries());
// Function does not care if you are in the course (unless $checkcourse).
$this->assertTrue(info_module::is_user_visible($cm, $other->id, false));
// With $checkcourse, check for enrolled, not enrolled, and admin user.
$this->assertTrue(info_module::is_user_visible($cm, $student->id, true));
$this->assertFalse(info_module::is_user_visible($cm, $other->id, true));
$this->assertTrue(info_module::is_user_visible($cm, $admin->id, true));
// With availability off, the student can access all except the
// visible=0 one.
$this->assertFalse(info_module::is_user_visible($pages[0]->cmid, $student->id, false));
$this->assertTrue(info_module::is_user_visible($pages[1]->cmid, $student->id, false));
$this->assertTrue(info_module::is_user_visible($pages[2]->cmid, $student->id, false));
// Teacher and admin can even access the visible=0 one.
$this->assertTrue(info_module::is_user_visible($pages[0]->cmid, $teacher->id, false));
$this->assertTrue(info_module::is_user_visible($pages[0]->cmid, $admin->id, false));
// Now enable availability (and clear cache).
$CFG->enableavailability = true;
get_fast_modinfo($course, 0, true);
// Student cannot access the activity restricted by its own or by the
// section's availability.
$this->assertFalse(info_module::is_user_visible($pages[1]->cmid, $student->id, false));
$this->assertFalse(info_module::is_user_visible($pages[2]->cmid, $student->id, false));
}
示例3: 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(' ');
$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)
//.........这里部分代码省略.........
示例4: 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);
}
示例5: process_message
/**
* Process a message received and validated by the Inbound Message processor.
*
* @throws \core\message\inbound\processing_failed_exception
* @param \stdClass $messagedata The Inbound Message record
* @param \stdClass $messagedata The message data packet
* @return bool Whether the message was successfully processed.
*/
public function process_message(\stdClass $record, \stdClass $messagedata) {
global $DB, $USER;
// Load the post being replied to.
$post = $DB->get_record('forum_posts', array('id' => $record->datavalue));
if (!$post) {
mtrace("--> Unable to find a post matching with id {$record->datavalue}");
return false;
}
// Load the discussion that this post is in.
$discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion));
if (!$post) {
mtrace("--> Unable to find the discussion for post {$record->datavalue}");
return false;
}
// Load the other required data.
$forum = $DB->get_record('forum', array('id' => $discussion->forum));
$course = $DB->get_record('course', array('id' => $forum->course));
$cm = get_fast_modinfo($course->id)->instances['forum'][$forum->id];
$modcontext = \context_module::instance($cm->id);
$usercontext = \context_user::instance($USER->id);
// Make sure user can post in this discussion.
$canpost = true;
if (!forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext)) {
$canpost = false;
}
if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode;
} else {
$groupmode = $course->groupmode;
}
if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $modcontext)) {
if ($discussion->groupid == -1) {
$canpost = false;
} else {
if (!groups_is_member($discussion->groupid)) {
$canpost = false;
}
}
}
if (!$canpost) {
$data = new \stdClass();
$data->forum = $forum;
throw new \core\message\inbound\processing_failed_exception('messageinboundnopostforum', 'mod_forum', $data);
}
// And check the availability.
if (!\core_availability\info_module::is_user_visible($cm, $USER, true)) {
$data = new \stdClass();
$data->forum = $forum;
throw new \core\message\inbound\processing_failed_exception('messageinboundforumhidden', 'mod_forum', $data);
}
// Before we add this we must check that the user will not exceed the blocking threshold.
// This should result in an appropriate reply.
$thresholdwarning = forum_check_throttling($forum, $cm);
if (!empty($thresholdwarning) && !$thresholdwarning->canpost) {
$data = new \stdClass();
$data->forum = $forum;
$data->message = get_string($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional);
throw new \core\message\inbound\processing_failed_exception('messageinboundthresholdhit', 'mod_forum', $data);
}
$addpost = new \stdClass();
$addpost->course = $course->id;
$addpost->forum = $forum->id;
$addpost->discussion = $discussion->id;
$addpost->modified = $messagedata->timestamp;
$addpost->subject = clean_param($messagedata->envelope->subject, PARAM_TEXT);
$addpost->parent = $post->id;
$addpost->itemid = file_get_unused_draft_itemid();
if (!empty($messagedata->html)) {
$addpost->message = $messagedata->html;
$addpost->messageformat = FORMAT_HTML;
} else {
$addpost->message = $messagedata->plain;
$addpost->messageformat = FORMAT_PLAIN;
}
// We don't trust text coming from e-mail.
$addpost->messagetrust = false;
// Add attachments to the post.
if (!empty($messagedata->attachments['attachment']) && count($messagedata->attachments['attachment'])) {
$attachmentcount = count($messagedata->attachments['attachment']);
if (empty($forum->maxattachments) || $forum->maxbytes == 1 ||
//.........这里部分代码省略.........
示例6: 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;
}
示例7: moodle_url
$groupurl = new moodle_url('/group/overview.php', array('id' => $cm->course));
$overridedeleteurl = new moodle_url('/mod/lesson/overridedelete.php');
$overrideediturl = new moodle_url('/mod/lesson/overrideedit.php');
$hasinactive = false;
// Whether there are any inactive overrides.
foreach ($overrides as $override) {
$fields = array();
$values = array();
$active = true;
// Check for inactive overrides.
if (!$groupmode) {
if (!is_enrolled($context, $override->userid)) {
// User not enrolled.
$active = false;
} else {
if (!\core_availability\info_module::is_user_visible($cm, $override->userid)) {
// User cannot access the module.
$active = false;
}
}
}
// Format available.
if (isset($override->available)) {
$fields[] = get_string('lessonopens', 'lesson');
$values[] = $override->available > 0 ? userdate($override->available) : get_string('noopen', 'lesson');
}
// Format deadline.
if (isset($override->deadline)) {
$fields[] = get_string('lessoncloses', 'lesson');
$values[] = $override->deadline > 0 ? userdate($override->deadline) : get_string('noclose', 'lesson');
}
示例8: get_course_mods
function get_course_mods($id, $username = '')
{
global $CFG, $DB;
$username = utf8_decode($username);
$username = strtolower($username);
if ($username) {
$user = get_complete_user_data('username', $username);
}
$modinfo = get_fast_modinfo($id);
$sections = $modinfo->get_section_info_all();
$forum = forum_get_course_forum($id, 'news');
$news_forum_id = $forum->id;
$mods = get_fast_modinfo($id)->get_cms();
$modnames = get_module_types_names();
$modnamesplural = get_module_types_names(true);
$modnamesused = get_fast_modinfo($id)->get_used_module_names();
$rawmods = get_course_mods($id);
$context = context_course::instance($id);
// Kludge to use username param to get non visible sections and modules
$username_orig = $username;
if ($username_orig == 'joomdle_get_not_visible') {
$username = '';
}
$e = array();
foreach ($sections as $section) {
if ($username_orig != 'joomdle_get_not_visible') {
if (!$section->visible) {
continue;
}
}
$sectionmods = explode(",", $section->sequence);
foreach ($sectionmods as $modnumber) {
if (empty($mods[$modnumber])) {
continue;
}
$mod = $mods[$modnumber];
if ($username_orig != 'joomdle_get_not_visible') {
if (!$mod->visible) {
continue;
}
}
$resource['completion_info'] = '';
if ($username) {
$cm = get_coursemodule_from_id(false, $mod->id);
if (!\core_availability\info_module::is_user_visible($cm, $user->id)) {
if (empty($mod->availableinfo)) {
// Mod not visible, and no completion info to show
continue;
}
$resource['available'] = 0;
$ci = new condition_info($mod);
$resource['completion_info'] = $ci->get_full_information();
} else {
$resource['available'] = 1;
}
} else {
$resource['available'] = 1;
}
$e[$section->section]['section'] = $section->section;
$e[$section->section]['name'] = $section->name;
$e[$section->section]['summary'] = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id);
$e[$section->section]['summary'] = str_replace('pluginfile.php', '/auth/joomdle/pluginfile_joomdle.php', $e[$section->section]['summary']);
$resource['id'] = $mod->id;
$resource['name'] = $mod->name;
$resource['mod'] = $mod->modname;
// Get content
$resource['content'] = '';
$modname = $mod->modname;
$functionname = $modname . "_get_coursemodule_info";
if (file_exists("{$CFG->dirroot}/mod/{$modname}/lib.php")) {
include_once "{$CFG->dirroot}/mod/{$modname}/lib.php";
if ($hasfunction = function_exists($functionname)) {
if ($info = $functionname($rawmods[$modnumber])) {
$resource['content'] = $info->content;
}
}
}
// Format for mod->icon is: f/type-24
$type = substr($mod->icon, 2);
$parts = explode('-', $type);
$type = $parts[0];
$resource['type'] = $type;
//In forum, type is unused, so we use it for forum type: news/general
if ($mod->modname == 'forum') {
$cm = get_coursemodule_from_id('forum', $mod->id);
if ($cm->instance == $news_forum_id) {
$resource['type'] = 'news';
}
}
/*
if ($mod->modname == 'resource')
{
// Get display options for resource
$params = array ($mod->instance);
$query = "SELECT display from {$CFG->prefix}resource where id = ?";
$record = $DB->get_record_sql ($query, $params);
$resource['display'] = $record->display;
}
else $resource['display'] = 0;
//.........这里部分代码省略.........
示例9: coursemodule_visible_for_user
/**
* 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
* @param object $cm object
* @param int $userid empty means current user
* @return bool Success
* @deprecated Since Moodle 2.7
*/
function coursemodule_visible_for_user($cm, $userid = 0)
{
debugging('coursemodule_visible_for_user() deprecated since Moodle 2.7. ' . 'Replace with \\core_availability\\info_module::is_user_visible().');
return \core_availability\info_module::is_user_visible($cm, $userid, false);
}
示例10: time
$timeend = time() + $CFG->calendar_exportlookahead * DAYSECS;
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 (!\core_availability\info_module::is_user_visible($cm, 0, false)) {
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', clean_param($event->description, PARAM_NOTAGS));
$ev->add_property('class', 'PUBLIC');
// PUBLIC / PRIVATE / CONFIDENTIAL
$ev->add_property('last-modified', Bennu::timestamp_to_datetime($event->timemodified));
$ev->add_property('dtstamp', Bennu::timestamp_to_datetime());
// now
$ev->add_property('dtstart', Bennu::timestamp_to_datetime($event->timestart));
示例11: users_to_json
/**
* Get the JSON representation of the users.
*
* Note that when a limit is set and the exclude array is not empty, then the number of memberships
* returned may be less than the limit.
*
* @param \mod_lti\local\ltiservice\resource_base $resource Resource handling the request
* @param array $users Array of user records
* @param string $id Course ID
* @param object $tool Tool instance object
* @param array $exclude Array of user records to be excluded from the response
* @param int $limitfrom Position of first record to be returned
* @param int $limitnum Maximum number of records to be returned
* @param object $lti LTI instance record
* @param \core_availability\info_module $info Conditional availability information for LTI instance
*
* @return string
*/
private static function users_to_json($resource, $users, $id, $tool, $exclude, $limitfrom, $limitnum, $lti, $info)
{
$nextpage = 'null';
if ($limitnum > 0) {
$limitfrom += $limitnum;
$nextpage = "\"{$resource->get_endpoint()}?limit={$limitnum}&from={$limitfrom}\"";
}
$json = <<<EOD
{
"@context" : "http://purl.imsglobal.org/ctx/lis/v2/MembershipContainer",
"@type" : "Page",
"@id" : "{$resource->get_endpoint()}",
"nextPage" : {$nextpage},
"pageOf" : {
"@type" : "LISMembershipContainer",
"membershipSubject" : {
"@type" : "Context",
"contextId" : "{$id}",
"membership" : [
EOD;
$enabledcapabilities = lti_get_enabled_capabilities($tool);
$sep = ' ';
foreach ($users as $user) {
$include = !in_array($user->id, $exclude);
if ($include && !empty($info)) {
$include = $info->is_user_visible($info->get_course_module(), $user->id);
}
if ($include) {
$member = new \stdClass();
if (in_array('User.id', $enabledcapabilities)) {
$member->userId = $user->id;
}
if (in_array('Person.sourcedId', $enabledcapabilities)) {
$member->sourcedId = format_string($user->idnumber);
}
if (in_array('Person.name.full', $enabledcapabilities)) {
$member->name = format_string("{$user->firstname} {$user->lastname}");
}
if (in_array('Person.name.given', $enabledcapabilities)) {
$member->givenName = format_string($user->firstname);
}
if (in_array('Person.name.family', $enabledcapabilities)) {
$member->familyName = format_string($user->lastname);
}
if (in_array('Person.email.primary', $enabledcapabilities)) {
$member->email = format_string($user->email);
}
if (in_array('Result.sourcedId', $enabledcapabilities) && !empty($lti) && !empty($lti->servicesalt)) {
$member->resultSourcedId = json_encode(lti_build_sourcedid($lti->id, $user->id, $lti->servicesalt, $lti->typeid));
}
$roles = explode(',', lti_get_ims_role($user->id, null, $id, true));
$membership = new \stdClass();
$membership->status = 'Active';
$membership->member = $member;
$membership->role = $roles;
$json .= $sep . json_encode($membership);
$sep = ",\n ";
}
}
$json .= <<<EOD
]
}
}
}
EOD;
return $json;
}
示例12: fix_condition_targetid
//.........这里部分代码省略.........
// restrict results to current section, if we can
if ($sectionnum >= 0) {
$from .= ' LEFT JOIN {course_sections} cs ON cs.id = cm.section';
$where .= ' AND cs.section = ?';
$params[] = $sectionnum;
}
$gradedcms = $DB->get_records_sql("SELECT {$select} FROM {$from} WHERE {$where}", $params);
}
// are we searching for a PREVIOUS activity (usually we are)
$previous = $targetid == PREVIOUS_ANY_COURSE || $targetid == PREVIOUS_ANY_SECTION || $targetid == PREVIOUS_SAME_COURSE || $targetid == PREVIOUS_SAME_SECTION;
// get cm ids (reverse order if necessary)
$coursemoduleids = array_keys($modinfo->cms);
if ($previous) {
$coursemoduleids = array_reverse($coursemoduleids);
}
// search for next, previous or specific course module
$found = false;
foreach ($coursemoduleids as $coursemoduleid) {
if (method_exists($modinfo, 'get_cm')) {
$coursemodule = $modinfo->get_cm($coursemoduleid);
} else {
$coursemodule = $modinfo->cms[$coursemoduleid];
}
if ($id && $coursemoduleid != $id) {
continue;
// wrong activity
}
if ($sectionnum >= 0) {
if ($previous) {
if ($coursemodule->sectionnum > $sectionnum) {
continue;
// later section
}
if ($coursemodule->sectionnum < $sectionnum) {
return 0;
// previous section
}
} else {
if ($coursemodule->sectionnum < $sectionnum) {
continue;
// earlier section
}
if ($coursemodule->sectionnum > $sectionnum) {
return 0;
// later section
}
}
}
if ($requirecompletion && empty($coursemodule->completion)) {
continue;
// cm does not have completion conditions
}
if ($requiregraded && empty($gradedcms[$coursemoduleid])) {
continue;
// skip ungraded activity
}
if ($modname && $coursemodule->modname != $modname) {
continue;
// wrong module
}
if ($includelabels == false && in_array($coursemodule->modname, $labelmods)) {
continue;
// skip labels
}
if ($includeresources == false && in_array($coursemodule->modname, $resourcemods)) {
continue;
// skip resources
}
if ($found || $coursemoduleid == $id) {
if (class_exists('\\core_availability\\info_module')) {
// Moodle >= 2.7
$is_visible = \core_availability\info_module::is_user_visible($coursemodule);
} else {
// Moodle <= 2.6
// Indirect modification of overloaded property
// cm_info::$availableinfo has no effect
// lib/datalib.php on line 1588
$is_visible = coursemodule_visible_for_user($coursemodule);
}
if ($is_visible) {
if ($requirecompletion) {
// return cm id
return intval($coursemoduleid);
} else {
// return grade item id
return intval($gradedcms[$coursemoduleid]->gradeitemid);
}
}
if ($coursemoduleid == $id) {
// required cm is not visible to this user
return 0;
}
}
if ($coursemoduleid == $cm->id) {
$found = true;
}
}
// next/prev cm not found
return 0;
}
示例13: get_cm
/**
* get_cm
*
* @param xxx $type
* @return xxx
*/
public function get_cm($type)
{
// gets the next, previous or specific Moodle activity
// get entry/exit cm id
$cm_field = $type . 'cm';
$cmid = $this->{$cm_field};
if ($cmid == self::ACTIVITY_NONE) {
return false;
}
if (!($modinfo = get_fast_modinfo($this->course))) {
return false;
// no modinfo - shouldn't happen !!
}
if (method_exists($modinfo, 'get_cm')) {
if (!$modinfo->get_cm($this->cm->id)) {
return false;
// target cm not found - shouldn't happen !!
}
} else {
if (!isset($modinfo->cms[$this->cm->id])) {
return false;
// target cm not found - shouldn't happen !!
}
}
// set default search values
$id = 0;
$modname = '';
$sectionnum = -1;
// restrict search values
if ($cmid > 0) {
$id = $cmid;
} else {
if ($cmid == self::ACTIVITY_COURSE_HOTPOT || $cmid == self::ACTIVITY_SECTION_HOTPOT) {
$modname = 'hotpot';
}
if ($cmid == self::ACTIVITY_SECTION_ANY || $cmid == self::ACTIVITY_SECTION_HOTPOT) {
$sectionnum = $modinfo->get_cm($this->cm->id)->sectionnum;
}
}
// get cm ids (reverse order if necessary)
$cmids = array_keys($modinfo->cms);
if ($type == 'entry') {
$cmids = array_reverse($cmids);
}
// search for next, previous or specific course module
$found = false;
foreach ($cmids as $cmid) {
if (method_exists($modinfo, 'get_cm')) {
$cm = $modinfo->get_cm($cmid);
} else {
$cm = $modinfo->cms[$cmid];
}
if ($id && $cm->id != $id) {
continue;
// wrong activity
}
if ($sectionnum >= 0) {
if ($type == 'entry') {
if ($cm->sectionnum > $sectionnum) {
continue;
// later section
}
if ($cm->sectionnum < $sectionnum) {
return false;
// previous section
}
} else {
// exit (=next)
if ($cm->sectionnum < $sectionnum) {
continue;
// earlier section
}
if ($cm->sectionnum > $sectionnum) {
return false;
// later section
}
}
}
if ($modname && $cm->modname != $modname) {
continue;
// wrong module
}
if ($cm->modname == 'label') {
continue;
// skip labels
}
if ($found || $cm->id == $id) {
if (class_exists('\\core_availability\\info_module')) {
// Moodle >= 2.7
$is_visible = \core_availability\info_module::is_user_visible($cm);
} else {
// Moodle <= 2.6
$is_visible = coursemodule_visible_for_user($cm);
}
//.........这里部分代码省略.........