• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP is_viewing函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: local_compile_extends_settings_navigation

/**
 * Add a "Compile" menu link to the Course Admin block as the top link.
 *
 * @author Gerald Albion
 * date 2014-10-31
 * @copyright 2014 Royal Roads University
 * @param object $settingsnav Main navigation object.
 * @param object $context Course context.
 */
function local_compile_extends_settings_navigation($settingsnav, $context)
{
    // Context must be course.
    if ($context->contextlevel != CONTEXT_COURSE) {
        return;
    }
    // Must be in a valid course: Cannot be course id 0.
    if ($context->instanceid == 0) {
        return;
    }
    // Must be in a valid course: Course must be retrievable.
    if (!($course = get_course($context->instanceid))) {
        return;
    }
    // Must be enrolled or otherwise allowed to view the course.
    if (!(is_enrolled($context) || is_viewing($context))) {
        return;
    }
    // Must have a course admin menu in which to add link.
    if (!($coursenode = $settingsnav->find('courseadmin', navigation_node::TYPE_COURSE))) {
        return;
    }
    // Good to go.  Build the menu item.
    $url = new moodle_url('/local/compile/list_modules.php', array('id' => $course->id));
    $newnode = navigation_node::create(get_string('menucaption', 'local_compile'), $url, navigation_node::NODETYPE_LEAF, 'compile', 'compile', new pix_icon('i/settings', ''));
    // We want to put this link at the top: find the existing top (first) node.
    $firstnode = $coursenode->get_children_key_list()[0];
    // Add the menu item to the menu, before the first node.
    $coursenode->add_node($newnode, $firstnode);
}
开发者ID:royalroads,项目名称:RRU-Moodle,代码行数:39,代码来源:lib.php


示例2: get_file_info

 /**
  * Return information about this specific context level
  *
  * @param $component
  * @param $filearea
  * @param $itemid
  * @param $filepath
  * @param $filename
  */
 public function get_file_info($component, $filearea, $itemid, $filepath, $filename)
 {
     if (!is_enrolled($this->context) and !is_viewing($this->context)) {
         // no peaking here if not enrolled or inspector
         return null;
     }
     if (empty($component)) {
         return $this;
     }
     if ($component == 'mod_' . $this->modname and $filearea === 'intro') {
         return $this->get_area_intro($itemid, $filepath, $filename);
     } else {
         if ($component == 'backup' and $filearea === 'activity') {
             return $this->get_area_backup($itemid, $filepath, $filename);
         }
     }
     $functionname = 'mod_' . $this->modname . '_get_file_info';
     $functionname_old = $this->modname . '_get_file_info';
     if (function_exists($functionname)) {
         return $functionname($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
     } else {
         if (function_exists($functionname_old)) {
             return $functionname_old($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
         }
     }
     return null;
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:36,代码来源:file_info_context_module.php


示例3: get_file_info

 /**
  * Return information about this specific context level
  *
  * @param $component
  * @param $filearea
  * @param $itemid
  * @param $filepath
  * @param $filename
  */
 public function get_file_info($component, $filearea, $itemid, $filepath, $filename)
 {
     // try to emulate require_login() tests here
     if (!isloggedin()) {
         return null;
     }
     $coursecontext = get_course_context($this->context);
     if (!$this->course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
         return null;
     }
     if (!is_viewing($this->context) and !is_enrolled($this->context)) {
         // no peaking here if not enrolled or inspector
         return null;
     }
     $modinfo = get_fast_modinfo($this->course);
     $cminfo = $modinfo->get_cm($this->cm->id);
     if (!$cminfo->uservisible) {
         // activity hidden sorry
         return null;
     }
     if (empty($component)) {
         return $this;
     }
     if ($component == 'mod_' . $this->modname and $filearea === 'intro') {
         return $this->get_area_intro($itemid, $filepath, $filename);
     } else {
         if ($component == 'backup' and $filearea === 'activity') {
             return $this->get_area_backup($itemid, $filepath, $filename);
         }
     }
     $functionname = 'mod_' . $this->modname . '_get_file_info';
     $functionname_old = $this->modname . '_get_file_info';
     if (function_exists($functionname)) {
         return $functionname($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
     } else {
         if (function_exists($functionname_old)) {
             return $functionname_old($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
         }
     }
     return null;
 }
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:50,代码来源:file_info_context_module.php


示例4: report_outline_can_access_user_report

/**
 * Is current user allowed to access this report
 *
 * @private defined in lib.php for performance reasons
 *
 * @param stdClass $user
 * @param stdClass $course
 * @return bool
 */
function report_outline_can_access_user_report($user, $course)
{
    global $USER;
    $coursecontext = context_course::instance($course->id);
    $personalcontext = context_user::instance($user->id);
    if (has_capability('report/outline:view', $coursecontext)) {
        return true;
    }
    if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
        if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
            return true;
        }
    } else {
        if ($user->id == $USER->id) {
            if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
                return true;
            }
        }
    }
    return false;
}
开发者ID:Hirenvaghasiya,项目名称:moodle,代码行数:30,代码来源:lib.php


示例5: get_file_info

 /**
  * Return information about this specific context level
  *
  * @param string $component component
  * @param string $filearea file area
  * @param int $itemid item ID
  * @param string $filepath file path
  * @param string $filename file name
  * @return file_info|null file_info instance or null if not found or access not allowed
  */
 public function get_file_info($component, $filearea, $itemid, $filepath, $filename)
 {
     // try to emulate require_login() tests here
     if (!isloggedin()) {
         return null;
     }
     if (!$this->course->visible and !has_capability('moodle/course:viewhiddencourses', $this->context)) {
         return null;
     }
     if (!is_viewing($this->context) and !is_enrolled($this->context)) {
         // no peaking here if not enrolled or inspector
         return null;
     }
     if (empty($component)) {
         return $this;
     }
     $methodname = "get_area_{$component}_{$filearea}";
     if (method_exists($this, $methodname)) {
         return $this->{$methodname}($itemid, $filepath, $filename);
     }
     return null;
 }
开发者ID:nmicha,项目名称:moodle,代码行数:32,代码来源:file_info_context_course.php


示例6: blog_get_options_for_module

/**
 * Get the blog options relating to the given module for the given user
 *
 * @staticvar array $moduleoptions Cache
 * @param stdClass|cm_info $module The module to get options for
 * @param stdClass $user The user to get options for null == currentuser
 * @return array
 */
function blog_get_options_for_module($module, $user = null)
{
    global $CFG, $USER;
    // Cache
    static $moduleoptions = array();
    $options = array();
    // User must be logged in, blogs must be enabled
    if (!blog_is_enabled_for_user()) {
        return $options;
    }
    // Check the user can associate with the module
    $modcontext = context_module::instance($module->id);
    $sitecontext = context_system::instance();
    if (!has_capability('moodle/blog:associatemodule', $modcontext)) {
        return $options;
    }
    // Generate the cache key
    $key = $module->id . ':';
    if (!empty($user)) {
        $key .= $user->id;
    } else {
        $key .= $USER->id;
    }
    if (array_key_exists($key, $moduleoptions)) {
        // Serve from the cache so we don't have to regenerate
        return $moduleoptions[$module->id];
    }
    $canparticipate = (is_enrolled($modcontext) or is_viewing($modcontext));
    if (has_capability('moodle/blog:view', $modcontext)) {
        // Save correct module name for later usage.
        $modulename = get_string('modulename', $module->modname);
        // We can view!
        if ($CFG->bloglevel >= BLOG_SITE_LEVEL) {
            // View all entries about this module
            $a = new stdClass();
            $a->type = $modulename;
            $options['moduleview'] = array('string' => get_string('viewallmodentries', 'blog', $a), 'link' => new moodle_url('/blog/index.php', array('modid' => $module->id)));
        }
        // View MY entries about this module
        $options['moduleviewmine'] = array('string' => get_string('viewmyentriesaboutmodule', 'blog', $modulename), 'link' => new moodle_url('/blog/index.php', array('modid' => $module->id, 'userid' => $USER->id)));
        if (!empty($user) && $CFG->bloglevel >= BLOG_SITE_LEVEL) {
            // View the given users entries about this module
            $a = new stdClass();
            $a->mod = $modulename;
            $a->user = fullname($user);
            $options['moduleviewuser'] = array('string' => get_string('blogentriesbyuseraboutmodule', 'blog', $a), 'link' => new moodle_url('/blog/index.php', array('modid' => $module->id, 'userid' => $user->id)));
        }
    }
    if (has_capability('moodle/blog:create', $sitecontext) and $canparticipate) {
        // The user can blog about this module
        $options['moduleadd'] = array('string' => get_string('blogaboutthismodule', 'blog', $modulename), 'link' => new moodle_url('/blog/edit.php', array('action' => 'add', 'modid' => $module->id)));
    }
    // Cache the options
    $moduleoptions[$key] = $options;
    // Return the options
    return $options;
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:65,代码来源:lib.php


示例7: require_login


//.........这里部分代码省略.........
    }
    // If the site is currently under maintenance, then print a message
    if (!empty($CFG->maintenance_enabled) and !has_capability('moodle/site:config', $sysctx)) {
        if ($preventredirect) {
            throw new require_login_exception('Maintenance in progress');
        }
        print_maintenance_message();
    }
    // make sure the course itself is not hidden
    if ($course->id == SITEID) {
        // frontpage can not be hidden
    } else {
        if (is_role_switched($course->id)) {
            // when switching roles ignore the hidden flag - user had to be in course to do the switch
        } else {
            if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
                // originally there was also test of parent category visibility,
                // BUT is was very slow in complex queries involving "my courses"
                // now it is also possible to simply hide all courses user is not enrolled in :-)
                if ($preventredirect) {
                    throw new require_login_exception('Course is hidden');
                }
                notice(get_string('coursehidden'), $CFG->wwwroot . '/');
            }
        }
    }
    // is the user enrolled?
    if ($course->id == SITEID) {
        // everybody is enrolled on the frontpage
    } else {
        if (session_is_loggedinas()) {
            // Make sure the REAL person can access this course first
            $realuser = session_get_realuser();
            if (!is_enrolled($coursecontext, $realuser->id, '', true) and !is_viewing($coursecontext, $realuser->id) and !is_siteadmin($realuser->id)) {
                if ($preventredirect) {
                    throw new require_login_exception('Invalid course login-as access');
                }
                echo $OUTPUT->header();
                notice(get_string('studentnotallowed', '', fullname($USER, true)), $CFG->wwwroot . '/');
            }
        }
        // very simple enrolment caching - changes in course setting are not reflected immediately
        if (!isset($USER->enrol)) {
            $USER->enrol = array();
            $USER->enrol['enrolled'] = array();
            $USER->enrol['tempguest'] = array();
        }
        $access = false;
        if (is_viewing($coursecontext, $USER)) {
            // ok, no need to mess with enrol
            $access = true;
        } else {
            if (isset($USER->enrol['enrolled'][$course->id])) {
                if ($USER->enrol['enrolled'][$course->id] == 0) {
                    $access = true;
                } else {
                    if ($USER->enrol['enrolled'][$course->id] > time()) {
                        $access = true;
                    } else {
                        //expired
                        unset($USER->enrol['enrolled'][$course->id]);
                    }
                }
            }
            if (isset($USER->enrol['tempguest'][$course->id])) {
                if ($USER->enrol['tempguest'][$course->id] == 0) {
开发者ID:hitphp,项目名称:moodle,代码行数:67,代码来源:moodlelib.php


示例8: enrol_add_course_navigation


//.........这里部分代码省略.........
            $url = new moodle_url('/enrol/instances.php', array('id' => $course->id));
        } else {
            $url = NULL;
        }
        $instancesnode = $usersnode->add(get_string('enrolmentinstances', 'enrol'), $url, navigation_node::TYPE_SETTING, null, 'manageinstances');
        // each instance decides how to configure itself or how many other nav items are exposed
        foreach ($instances as $instance) {
            if (!isset($plugins[$instance->enrol])) {
                continue;
            }
            $plugins[$instance->enrol]->add_course_navigation($instancesnode, $instance);
        }
        if (!$url) {
            $instancesnode->trim_if_empty();
        }
    }
    // Manage groups in this course or even frontpage
    if (($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $coursecontext)) {
        $url = new moodle_url('/group/index.php', array('id' => $course->id));
        $usersnode->add(get_string('groups'), $url, navigation_node::TYPE_SETTING, null, 'groups', new pix_icon('i/group', ''));
    }
    if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:review'), $coursecontext)) {
        // Override roles
        if (has_capability('moodle/role:review', $coursecontext)) {
            $url = new moodle_url('/admin/roles/permissions.php', array('contextid' => $coursecontext->id));
        } else {
            $url = NULL;
        }
        $permissionsnode = $usersnode->add(get_string('permissions', 'role'), $url, navigation_node::TYPE_SETTING, null, 'override');
        // Add assign or override roles if allowed
        if ($course->id == SITEID or !empty($CFG->adminsassignrolesincourse) and is_siteadmin()) {
            if (has_capability('moodle/role:assign', $coursecontext)) {
                $url = new moodle_url('/admin/roles/assign.php', array('contextid' => $coursecontext->id));
                $permissionsnode->add(get_string('assignedroles', 'role'), $url, navigation_node::TYPE_SETTING, null, 'roles', new pix_icon('i/assignroles', ''));
            }
        }
        // Check role permissions
        if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $coursecontext)) {
            $url = new moodle_url('/admin/roles/check.php', array('contextid' => $coursecontext->id));
            $permissionsnode->add(get_string('checkpermissions', 'role'), $url, navigation_node::TYPE_SETTING, null, 'permissions', new pix_icon('i/checkpermissions', ''));
        }
    }
    // Deal somehow with users that are not enrolled but still got a role somehow
    if ($course->id != SITEID) {
        //TODO, create some new UI for role assignments at course level
        if (has_capability('moodle/role:assign', $coursecontext)) {
            /* Added for Subadmin */
            $context = get_context_instance(CONTEXT_SYSTEM);
            $roles = get_user_roles($context, $USER->id, false);
            $role = key($roles);
            $currentuserrolename = $roles[$role]->shortname;
            /* End of Subadmin */
            if ($currentuserrolename != "subadmin") {
                $url = new moodle_url('/enrol/otherusers.php', array('id' => $course->id));
                $usersnode->add(get_string('notenrolledusers', 'enrol'), $url, navigation_node::TYPE_SETTING, null, 'otherusers', new pix_icon('i/assignroles', ''));
            }
        }
    }
    // just in case nothing was actually added
    $usersnode->trim_if_empty();
    if ($course->id != SITEID) {
        if (isguestuser() or !isloggedin()) {
            // guest account can not be enrolled - no links for them
        } else {
            if (is_enrolled($coursecontext)) {
                // unenrol link if possible
                foreach ($instances as $instance) {
                    if (!isset($plugins[$instance->enrol])) {
                        continue;
                    }
                    $plugin = $plugins[$instance->enrol];
                    if ($unenrollink = $plugin->get_unenrolself_link($instance)) {
                        $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
                        $coursenode->add(get_string('unenrolme', 'core_enrol', $shortname), $unenrollink, navigation_node::TYPE_SETTING, null, 'unenrolself', new pix_icon('i/user', ''));
                        break;
                        //TODO. deal with multiple unenrol links - not likely case, but still...
                    }
                }
            } else {
                // enrol link if possible
                if (is_viewing($coursecontext)) {
                    // better not show any enrol link, this is intended for managers and inspectors
                } else {
                    foreach ($instances as $instance) {
                        if (!isset($plugins[$instance->enrol])) {
                            continue;
                        }
                        $plugin = $plugins[$instance->enrol];
                        if ($plugin->show_enrolme_link($instance)) {
                            $url = new moodle_url('/enrol/index.php', array('id' => $course->id));
                            $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
                            $coursenode->add(get_string('enrolme', 'core_enrol', $shortname), $url, navigation_node::TYPE_SETTING, null, 'enrolself', new pix_icon('i/user', ''));
                            break;
                        }
                    }
                }
            }
        }
    }
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:101,代码来源:enrollib.php


示例9: report_comments_can_access_user_report

/**
 * Is current user allowed to access this report
 *
 * @private defined in lib.php for performance reasons
 *
 * @param stdClass $user
 * @param stdClass $course
 * @return bool
 */
function report_comments_can_access_user_report($user, $course)
{
    global $USER, $CFG;
    if (empty($CFG->enablecomments)) {
        return false;
    }
    if ($course->id != SITEID and !$course->enablecomments) {
        return false;
    }
    $coursecontext = context_course::instance($course->id);
    if (has_capability('report/comments:view', $coursecontext)) {
        return true;
    }
    $personalcontext = context_user::instance($user->id);
    if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
        if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
            return true;
        }
    } else {
        if ($user->id == $USER->id) {
            if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
                return true;
            }
        }
    }
    return false;
}
开发者ID:ewallah,项目名称:moodle-report_comments,代码行数:36,代码来源:lib.php


示例10: require_costcenter_login

/**
 * this function used checked logged in user having costcenter privileges or not
 *
 * @package custom
 * @method require_costcenter_login
 * @param int $courseodir (holds the course id)
 * @return int
 */
function require_costcenter_login($courseorid) {
    global $CFG, $SESSION, $USER, $PAGE, $SITE, $DB, $OUTPUT, $COSTCENTER;

    if (!empty($courseorid)) {
        if (is_object($courseorid)) {
            $course = $courseorid;
        } else if ($courseorid == SITEID) {
            $course = clone($SITE);
        } else {
            $course = $DB->get_record('course', array('id' => $courseorid), '*', MUST_EXIST);
        }
        $coursecontext = context_course::instance($course->id, MUST_EXIST);
        if ($COSTCENTER) {
            if (!in_array($course->id, $COSTCENTER->courses))
                throw new coding_exception('course  is not belongs to your costcenter, Dont have permission to access');

            else if (\core\session\manager::is_loggedinas()) {
                // Make sure the REAL person can access this course first.
                $realuser = \core\session\manager::get_realuser();
                if (!is_enrolled($coursecontext, $realuser->id, '', true) and ! is_viewing($coursecontext, $realuser->id) and ! is_siteadmin($realuser->id)) {
                    if ($preventredirect) {
                        throw new require_login_exception('Invalid course login-as access');
                    }
                    echo $OUTPUT->header();
                    notice(get_string('studentnotallowed', '', fullname($USER, true)), $CFG->wwwroot . '/');
                }
            }
            //    else if(! in_array($course->id,$COSTCENTER->enroledcourses)){
            // throw new coding_exception('Dont have permission to access'); 
            //  }
            else {

                return true;
            }
        }
    }
    return true;
}
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:46,代码来源:costcenter_contextlib.php


示例11: forum_get_posts_by_user

/**
 * Returns posts made by the selected user in the requested courses.
 *
 * This method can be used to return all of the posts made by the requested user
 * within the given courses.
 * For each course the access of the current user and requested user is checked
 * and then for each post access to the post and forum is checked as well.
 *
 * This function is safe to use with usercapabilities.
 *
 * @global moodle_database $DB
 * @param stdClass $user The user whose posts we want to get
 * @param array $courses The courses to search
 * @param bool $musthaveaccess If set to true errors will be thrown if the user
 *                             cannot access one or more of the courses to search
 * @param bool $discussionsonly If set to true only discussion starting posts
 *                              will be returned.
 * @param int $limitfrom The offset of records to return
 * @param int $limitnum The number of records to return
 * @return stdClass An object the following properties
 *               ->totalcount: the total number of posts made by the requested user
 *                             that the current user can see.
 *               ->courses: An array of courses the current user can see that the
 *                          requested user has posted in.
 *               ->forums: An array of forums relating to the posts returned in the
 *                         property below.
 *               ->posts: An array containing the posts to show for this request.
 */
function forum_get_posts_by_user($user, array $courses, $musthaveaccess = false, $discussionsonly = false, $limitfrom = 0, $limitnum = 50) {
    global $DB, $USER, $CFG;

    $return = new stdClass;
    $return->totalcount = 0;    // The total number of posts that the current user is able to view
    $return->courses = array(); // The courses the current user can access
    $return->forums = array();  // The forums that the current user can access that contain posts
    $return->posts = array();   // The posts to display

    // First up a small sanity check. If there are no courses to check we can
    // return immediately, there is obviously nothing to search.
    if (empty($courses)) {
        return $return;
    }

    // A couple of quick setups
    $isloggedin = isloggedin();
    $isguestuser = $isloggedin && isguestuser();
    $iscurrentuser = $isloggedin && $USER->id == $user->id;

    // Checkout whether or not the current user has capabilities over the requested
    // user and if so they have the capabilities required to view the requested
    // users content.
    $usercontext = context_user::instance($user->id, MUST_EXIST);
    $hascapsonuser = !$iscurrentuser && $DB->record_exists('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id));
    $hascapsonuser = $hascapsonuser && has_all_capabilities(array('moodle/user:viewdetails', 'moodle/user:readuserposts'), $usercontext);

    // Before we actually search each course we need to check the user's access to the
    // course. If the user doesn't have the appropraite access then we either throw an
    // error if a particular course was requested or we just skip over the course.
    foreach ($courses as $course) {
        $coursecontext = context_course::instance($course->id, MUST_EXIST);
        if ($iscurrentuser || $hascapsonuser) {
            // If it is the current user, or the current user has capabilities to the
            // requested user then all we need to do is check the requested users
            // current access to the course.
            // Note: There is no need to check group access or anything of the like
            // as either the current user is the requested user, or has granted
            // capabilities on the requested user. Either way they can see what the
            // requested user posted, although its VERY unlikely in the `parent` situation
            // that the current user will be able to view the posts in context.
            if (!is_viewing($coursecontext, $user) && !is_enrolled($coursecontext, $user)) {
                // Need to have full access to a course to see the rest of own info
                if ($musthaveaccess) {
                    print_error('errorenrolmentrequired', 'forum');
                }
                continue;
            }
        } else {
            // Check whether the current user is enrolled or has access to view the course
            // if they don't we immediately have a problem.
            if (!can_access_course($course)) {
                if ($musthaveaccess) {
                    print_error('errorenrolmentrequired', 'forum');
                }
                continue;
            }

            // Check whether the requested user is enrolled or has access to view the course
            // if they don't we immediately have a problem.
            if (!can_access_course($course, $user)) {
                if ($musthaveaccess) {
                    print_error('notenrolled', 'forum');
                }
                continue;
            }

            // If groups are in use and enforced throughout the course then make sure
            // we can meet in at least one course level group.
            // Note that we check if either the current user or the requested user have
            // the capability to access all groups. This is because with that capability
            // a user in group A could post in the group B forum. Grrrr.
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:lib.php


示例12: define_execution

 protected function define_execution()
 {
     global $CFG, $DB;
     if (!($userid = $this->task->get_userid())) {
         return;
     }
     if (empty($CFG->restorernewroleid)) {
         // Bad luck, no fallback role for restorers specified
         return;
     }
     $courseid = $this->get_courseid();
     $context = context_course::instance($courseid);
     if (is_enrolled($context, $userid, 'moodle/course:update', true) or is_viewing($context, $userid, 'moodle/course:update')) {
         // Current user may access the course (admin, category manager or restored teacher enrolment usually)
         return;
     }
     // Try to add role only - we do not need enrolment if user has moodle/course:view or is already enrolled
     role_assign($CFG->restorernewroleid, $userid, $context);
     if (is_enrolled($context, $userid, 'moodle/course:update', true) or is_viewing($context, $userid, 'moodle/course:update')) {
         // Extra role is enough, yay!
         return;
     }
     // The last chance is to create manual enrol if it does not exist and and try to enrol the current user,
     // hopefully admin selected suitable $CFG->restorernewroleid ...
     if (!enrol_is_enabled('manual')) {
         return;
     }
     if (!($enrol = enrol_get_plugin('manual'))) {
         return;
     }
     if (!$DB->record_exists('enrol', array('enrol' => 'manual', 'courseid' => $courseid))) {
         $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
         $fields = array('status' => ENROL_INSTANCE_ENABLED, 'enrolperiod' => $enrol->get_config('enrolperiod', 0), 'roleid' => $enrol->get_config('roleid', 0));
         $enrol->add_instance($course, $fields);
     }
     enrol_try_internal_enrol($courseid, $userid);
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:37,代码来源:restore_stepslib.php


示例13: file_pluginfile


//.........这里部分代码省略.........
                            // Unlock session during file serving.
                            send_stored_file($file, 60 * 60, 0, $forcedownload, array('preview' => $preview));
                        } else {
                            if ($filearea === 'event_description' and $context->contextlevel == CONTEXT_USER) {
                                // Must be logged in, if they are not then they obviously can't be this user
                                require_login();
                                // Don't want guests here, potentially saves a DB call
                                if (isguestuser()) {
                                    send_file_not_found();
                                }
                                // Get the event if from the args array
                                $eventid = array_shift($args);
                                // Load the event from the database - user id must match
                                if (!($event = $DB->get_record('event', array('id' => (int) $eventid, 'userid' => $USER->id, 'eventtype' => 'user')))) {
                                    send_file_not_found();
                                }
                                // Get the file and serve if successful
                                $filename = array_pop($args);
                                $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
                                if (!($file = $fs->get_file($context->id, $component, $filearea, $eventid, $filepath, $filename)) or $file->is_directory()) {
                                    send_file_not_found();
                                }
                                \core\session\manager::write_close();
                                // Unlock session during file serving.
                                send_stored_file($file, 0, 0, true, array('preview' => $preview));
                            } else {
                                if ($filearea === 'event_description' and $context->contextlevel == CONTEXT_COURSE) {
                                    // Respect forcelogin and require login unless this is the site.... it probably
                                    // should NEVER be the site
                                    if ($CFG->forcelogin || $course->id != SITEID) {
                                        require_login($course);
                                    }
                                    // Must be able to at least view the course. This does not apply to the front page.
                                    if ($course->id != SITEID && !is_enrolled($context) && !is_viewing($context)) {
                                        //TODO: hmm, do we really want to block guests here?
                                        send_file_not_found();
                                    }
                                    // Get the event id
                                    $eventid = array_shift($args);
                                    // Load the event from the database we need to check whether it is
                                    // a) valid course event
                                    // b) a group event
                                    // Group events use the course context (there is no group context)
                                    if (!($event = $DB->get_record('event', array('id' => (int) $eventid, 'courseid' => $course->id)))) {
                                        send_file_not_found();
                                    }
                                    // If its a group event require either membership of view all groups capability
                                    if ($event->eventtype === 'group') {
                                        if (!has_capability('moodle/site:accessallgroups', $context) && !groups_is_member($event->groupid, $USER->id)) {
                                            send_file_not_found();
                                        }
                                    } else {
                                        if ($event->eventtype === 'course' || $event->eventtype === 'site') {
                                            // Ok. Please note that the event type 'site' still uses a course context.
                                        } else {
                                            // Some other type.
                                            send_file_not_found();
                                        }
                                    }
                                    // If we get this far we can serve the file
                                    $filename = array_pop($args);
                                    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
                                    if (!($file = $fs->get_file($context->id, $component, $filearea, $eventid, $filepath, $filename)) or $file->is_directory()) {
                                        send_file_not_found();
                                    }
                                    \core\session\manager::write_close();
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:67,代码来源:filelib.php


示例14: approve

 /**
  * This function approves the request turning it into a course
  *
  * This function converts the course request into a course, at the same time
  * transferring any files used in the summary to the new course and then removing
  * the course request and the files associated with it.
  *
  * @return int The id of the course that was created from this request
  */
 public function approve()
 {
     global $CFG, $DB, $USER;
     $user = $DB->get_record('user', array('id' => $this->properties->requester, 'deleted' => 0), '*', MUST_EXIST);
     $category = get_course_category($CFG->defaultrequestcategory);
     $courseconfig = get_config('moodlecourse');
     // Transfer appropriate settings
     $data = clone $this->properties;
     unset($data->id);
     unset($data->reason);
     unset($data->requester);
     // Set category
     $data->category = $category->id;
     $data->sortorder = $category->sortorder;
     // place as the first in category
     // Set misc settings
     $data->requested = 1;
     // Apply course default settings
     $data->format = $courseconfig->format;
     $data->numsections = $courseconfig->numsections;
     $data->hiddensections = $courseconfig->hiddensections;
     $data->newsitems = $courseconfig->newsitems;
     $data->showgrades = $courseconfig->showgrades;
     $data->showreports = $courseconfig->showreports;
     $data->maxbytes = $courseconfig->maxbytes;
     $data->groupmode = $courseconfig->groupmode;
     $data->groupmodeforce = $courseconfig->groupmodeforce;
     $data->visible = $courseconfig->visible;
     $data->visibleold = $data->visible;
     $data->lang = $courseconfig->lang;
     $course = create_course($data);
     $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
     // add enrol instances
     if (!$DB->record_exists('enrol', array('courseid' => $course->id, 'enrol' => 'manual'))) {
         if ($manual = enrol_get_plugin('manual')) {
             $manual->add_default_instance($course);
         }
     }
     // enrol the requester as teacher if necessary
     if (!empty($CFG->creatornewroleid) and !is_viewing($context, $user, 'moodle/role:assign') and !is_enrolled($context, $user, 'moodle/role:assign')) {
         enrol_try_internal_enrol($course->id, $user->id, $CFG->creatornewroleid);
     }
     $this->delete();
     $a = new stdClass();
     $a->name = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
     $a->url = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
     $this->notify($user, $USER, 'courserequestapproved', get_string('courseapprovedsubject'), get_string('courseapprovedemail2', 'moodle', $a));
     return $course->id;
 }
开发者ID:numbas,项目名称:moodle,代码行数:58,代码来源:lib.php


示例15: get_content

 /**
  * block contents
  *
  * @return object
  */
 public function get_content()
 {
     global $CFG, $USER, $DB, $OUTPUT, $PAGE;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (!isloggedin()) {
         return '';
         // Never useful unless you are logged in
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     $course = $this->page->course;
     if ($PAGE->context->contextlevel == CONTEXT_USER) {
         $user = $DB->get_record('user', array('id' => $PAGE->context->instanceid));
     } else {
         $user = $USER;
     }
     if ($course->id == SITEID) {
         $coursecontext = get_context_instance(CONTEXT_SYSTEM);
     } else {
         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
         // Course context
         // Make sure they can view the course
         if (!is_viewing($coursecontext)) {
             return '';
         }
     }
     // TODO: clean up the following even more
     if (!isset($this->config->display_picture) || $this->config->display_picture == 1) {
         $this->content->text .= '<div class="myprofileitem picture">';
         $this->content->text .= $OUTPUT->user_picture($user, array('courseid' => $course->id, 'size' => '100', 'class' => 'profilepicture'));
         // The new class makes CSS easier
         $this->content->text .= '</div>';
     }
     $this->content->text .= '<div class="myprofileitem fullname">' . fullname($user) . '</div>';
     if (!isset($this->config->display_country) || $this->config->display_country == 1) {
         $countries = get_string_manager()->get_list_of_countries();
         if (isset($countries[$user->country])) {
             $this->content->text .= '<div class="myprofileitem country">';
             $this->content->text .= get_string('country') . ': ' . $countries[$user->country];
             $this->content->text .= '</div>';
         }
     }
     if (!isset($this->config->display_city) || $this->config->display_city == 1) {
         $this->content->text .= '<div class="myprofileitem city">';
         $this->content->text .= get_string('city') . ': ' . $user->city;
         $this->content->text .= '</div>';
     }
     if (!isset($this->config->display_email) || $this->config->display_email == 1) {
         $this->content->text .= '<div class="myprofileitem email">';
         $this->content->text .= obfuscate_mailto($user->email, '');
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_icq) && !empty($user->icq)) {
         $this->content->text .= '<div class="myprofileitem icq">';
         $this->content->text .= 'ICQ: ' . $user->icq;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_skype) && !empty($user->skype)) {
         $this->content->text .= '<div class="myprofileitem skype">';
         $this->content->text .= 'Skype: ' . $user->skype;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_yahoo) && !empty($user->yahoo)) {
         $this->content->text .= '<div class="myprofileitem yahoo">';
         $this->content->text .= 'Yahoo: ' . $user->yahoo;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_aim) && !empty($user->aim)) {
         $this->content->text .= '<div class="myprofileitem aim">';
         $this->content->text .= 'AIM: ' . $user->aim;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_msn) && !empty($user->msn)) {
         $this->content->text .= '<div class="myprofileitem msn">';
         $this->content->text .= 'MSN: ' . $user->msn;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_phone1) && !empty($user->phone1)) {
         $this->content->text .= '<div class="myprofileitem phone1">';
         $this->content->text .= get_string('phone') . ': ' . $user->phone1;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_phone2) && !empty($user->phone2)) {
         $this->content->text .= '<div class="myprofileitem phone2">';
         $this->content->text .= get_string('phone') . ': ' . $user->phone2;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_institution) && !empty($user->institution)) {
         $this->content->text .= '<div class="myprofileitem institution">';
         $this->content->text .= $user->institution;
         $this->content->text .= '</div>';
     }
//.........这里部分代码省略.........

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP is_voided_display函数代码示例发布时间:2022-05-15
下一篇:
PHP is_validaliasname函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap