function get_content()
 {
     global $CFG, $USER, $DB, $OUTPUT;
     // shortcut -  only for logged in users!
     if (!isloggedin() || isguestuser()) {
         return false;
     }
     // according to start_jump_session,
     // remote users can't on-jump
     // so don't show this block to them
     if (is_mnet_remote_user($USER)) {
         if (debugging() and !empty($CFG->debugdisplay)) {
             $this->content = new stdClass();
             $this->content->footer = html_writer::tag('span', get_string('error_localusersonly', 'block_mnet_hosts'), array('class' => 'error'));
             return $this->content;
         } else {
             return '';
         }
     }
     if (!is_enabled_auth('mnet')) {
         if (debugging() and !empty($CFG->debugdisplay)) {
             $this->content = new stdClass();
             $this->content->footer = html_writer::tag('span', get_string('error_authmnetneeded', 'block_mnet_hosts'), array('class' => 'error'));
             return $this->content;
         } else {
             return '';
         }
     }
     if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
         if (debugging() and !empty($CFG->debugdisplay)) {
             $this->content = new stdClass();
             $this->content->footer = html_writer::tag('span', get_string('error_roamcapabilityneeded', 'block_mnet_hosts'), array('class' => 'error'));
             return $this->content;
         } else {
             return '';
         }
     }
     if ($this->content !== NULL) {
         return $this->content;
     }
     // TODO: Test this query - it's appropriate? It works?
     // get the hosts and whether we are doing SSO with them
     $sql = "\n             SELECT DISTINCT\n                 h.id,\n                 h.name,\n                 h.wwwroot,\n                 a.name as application,\n                 a.display_name\n             FROM\n                 {mnet_host} h,\n                 {mnet_application} a,\n                 {mnet_host2service} h2s_IDP,\n                 {mnet_service} s_IDP,\n                 {mnet_host2service} h2s_SP,\n                 {mnet_service} s_SP\n             WHERE\n                 h.id <> ? AND\n                 h.id <> ? AND\n                 h.id = h2s_IDP.hostid AND\n                 h.deleted = 0 AND\n                 h.applicationid = a.id AND\n                 h2s_IDP.serviceid = s_IDP.id AND\n                 s_IDP.name = 'sso_idp' AND\n                 h2s_IDP.publish = '1' AND\n                 h.id = h2s_SP.hostid AND\n                 h2s_SP.serviceid = s_SP.id AND\n                 s_SP.name = 'sso_idp' AND\n                 h2s_SP.publish = '1'\n             ORDER BY\n                 a.display_name,\n                 h.name";
     $hosts = $DB->get_records_sql($sql, array($CFG->mnet_localhost_id, $CFG->mnet_all_hosts_id));
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if ($hosts) {
         foreach ($hosts as $host) {
             $icon = '<img src="' . $OUTPUT->pix_url('i/' . $host->application . '_host') . '"' . ' class="icon" alt="' . get_string('server', 'block_mnet_hosts') . '" />&nbsp;';
             if ($host->id == $USER->mnethostid) {
                 $this->content->items[] = "<a title=\"" . s($host->name) . "\" href=\"{$host->wwwroot}\">" . $icon . s($host->name) . "</a>";
             } else {
                 $this->content->items[] = "<a title=\"" . s($host->name) . "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . $icon . s($host->name) . "</a>";
             }
         }
     }
     return $this->content;
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  *
  * @param array $authsequence The enabled sequence of authentication plugins.
  * @param string $username The username to display.
  */
 public function __construct(array $authsequence, $username = '')
 {
     global $CFG, $SESSION;
     $this->username = $username;
     $this->canloginasguest = $CFG->guestloginbutton and !isguestuser();
     $this->canloginbyemail = !empty($CFG->authloginviaemail);
     $this->cansignup = $CFG->registerauth == 'email' || !empty($CFG->registerauth);
     $this->cookieshelpicon = new help_icon('cookiesenabled', 'core');
     $this->autofocusform = !empty($CFG->loginpageautofocus);
     $this->passwordautocomplete = !empty($CFG->loginpasswordautocomplete);
     $this->rememberusername = isset($CFG->rememberusername) and $CFG->rememberusername == 2;
     $this->forgotpasswordurl = new moodle_url($CFG->httpswwwroot . '/login/forgot_password.php');
     $this->loginurl = new moodle_url($CFG->httpswwwroot . '/login/index.php');
     $this->signupurl = new moodle_url('/login/signup.php');
     // Authentication instructions.
     $this->instructions = $CFG->auth_instructions;
     if (is_enabled_auth('none')) {
         $this->instructions = get_string('loginstepsnone');
     } else {
         if ($CFG->registerauth == 'email' && empty($this->instructions)) {
             $this->instructions = get_string('loginsteps', 'core', 'signup.php');
         }
     }
     // Identity providers.
     $identityproviders = [];
     foreach ($authsequence as $authname) {
         $authplugin = get_auth_plugin($authname);
         $identityproviders = array_merge($identityproviders, $authplugin->loginpage_idp_list($SESSION->wantsurl));
     }
     $this->identityproviders = $identityproviders;
 }
Exemplo n.º 3
0
 /**
  * Observe the events, and dispatch them if necessary.
  *
  * @param \core\event\base $event The event.
  * @return void
  */
 public static function observer(\core\event\base $event)
 {
     if ($event->component === 'block_xp') {
         // Skip own events.
     } else {
         if (!$event->userid || isguestuser($event->userid) || is_siteadmin($event->userid)) {
             // Skip non-logged in users and guests.
         } else {
             if ($event->contextlevel !== CONTEXT_COURSE && $event->contextlevel !== CONTEXT_MODULE) {
                 // Ignore events outside a course.
             } else {
                 if ($event->edulevel !== \core\event\base::LEVEL_PARTICIPATING) {
                     // Ignore events that are not participating.
                 } else {
                     if (!has_capability('block/xp:earnxp', $event->get_context(), $event->userid)) {
                         // Skip the events if the user does not have the capability to earn XP, or if it is the admin.
                     } else {
                         // Keep the event, and proceed.
                         $manager = block_xp_manager::get($event->courseid);
                         $manager->capture_event($event);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
 public function create_instance($record = null, array $options = null)
 {
     global $CFG, $USER;
     require_once $CFG->dirroot . '/mod/scorm/lib.php';
     require_once $CFG->dirroot . '/mod/scorm/locallib.php';
     $cfgscorm = get_config('scorm');
     // Add default values for scorm.
     $record = (array) $record + array('scormtype' => SCORM_TYPE_LOCAL, 'packagefile' => '', 'packagefilepath' => $CFG->dirroot . '/mod/scorm/tests/packages/singlescobasic.zip', 'packageurl' => '', 'updatefreq' => SCORM_UPDATE_NEVER, 'popup' => 0, 'width' => $cfgscorm->framewidth, 'height' => $cfgscorm->frameheight, 'skipview' => $cfgscorm->skipview, 'hidebrowse' => $cfgscorm->hidebrowse, 'displaycoursestructure' => $cfgscorm->displaycoursestructure, 'hidetoc' => $cfgscorm->hidetoc, 'nav' => $cfgscorm->nav, 'navpositionleft' => $cfgscorm->navpositionleft, 'navpositiontop' => $cfgscorm->navpositiontop, 'displayattemptstatus' => $cfgscorm->displayattemptstatus, 'timeopen' => 0, 'timeclose' => 0, 'grademethod' => GRADESCOES, 'maxgrade' => $cfgscorm->maxgrade, 'maxattempt' => $cfgscorm->maxattempt, 'whatgrade' => $cfgscorm->whatgrade, 'forcenewattempt' => $cfgscorm->forcenewattempt, 'lastattemptlock' => $cfgscorm->lastattemptlock, 'forcecompleted' => $cfgscorm->forcecompleted, 'auto' => $cfgscorm->auto);
     // The 'packagefile' value corresponds to the draft file area ID. If not specified, create from packagefilepath.
     if (empty($record['packagefile']) && $record['scormtype'] === SCORM_TYPE_LOCAL) {
         if (!isloggedin() || isguestuser()) {
             throw new coding_exception('Scorm generator requires a current user');
         }
         if (!file_exists($record['packagefilepath'])) {
             throw new coding_exception("File {$record['packagefilepath']} does not exist");
         }
         $usercontext = context_user::instance($USER->id);
         // Pick a random context id for specified user.
         $record['packagefile'] = file_get_unused_draft_itemid();
         // Add actual file there.
         $filerecord = array('component' => 'user', 'filearea' => 'draft', 'contextid' => $usercontext->id, 'itemid' => $record['packagefile'], 'filename' => basename($record['packagefilepath']), 'filepath' => '/');
         $fs = get_file_storage();
         $fs->create_file_from_pathname($filerecord, $record['packagefilepath']);
     }
     return parent::create_instance($record, (array) $options);
 }
/**
 * Check if an activity is configured to only show navbuttons when
 * complete and then check if the activity is complete
 * @param cm_info $cm the course module for the activity
 * @return boolean true if the navbuttons should be shown
 */
function navbuttons_activity_showbuttons($cm)
{
    $modname = $cm->modname;
    $show = get_config('block_navbuttons', 'activity' . $modname);
    if ($show === false || $show == NAVBUTTONS_ACTIVITY_ALWAYS) {
        return true;
        // No config or 'always show'
    }
    if ($show == NAVBUTTONS_ACTIVITY_NEVER) {
        return false;
    }
    if ($show == NAVBUTTONS_ACTIVITY_COMPLETE) {
        $completion = new completion_info($cm->get_course());
        if (!$completion->is_enabled($cm)) {
            return true;
            // No completion tracking - show the buttons
        }
        $cmcompletion = $completion->get_data($cm);
        if ($cmcompletion->completionstate == COMPLETION_INCOMPLETE) {
            return false;
        }
        return true;
    }
    if (!isloggedin() || isguestuser()) {
        return true;
        // Always show the buttons if not logged in
    }
    // NAVBUTTONS_ACTIVITY_CUSTOM
    $funcname = 'navbuttons_mod_' . $modname . '_showbuttons';
    if (!function_exists($funcname)) {
        return true;
        // Shouldn't have got to here, but allow the buttons anyway
    }
    return $funcname($cm);
}
Exemplo n.º 6
0
/**
 * OBU Apps - Provide left hand navigation links
 *
 * @package    obu_apps
 * @category   local
 * @copyright  2015, Oxford Brookes University {@link http://www.brookes.ac.uk/}
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function local_obu_apps_extend_navigation($navigation)
{
    global $CFG;
    if (!isloggedin() || isguestuser()) {
        return;
    }
    // Find the 'apps' node
    $nodeApps = $navigation->find(get_string('apps', 'local_obu_apps'), navigation_node::TYPE_SYSTEM);
    // If necessary, add the 'apps' node to 'home'
    if (!$nodeApps) {
        $nodeHome = $navigation->children->get('1')->parent;
        if ($nodeHome) {
            $nodeApps = $nodeHome->add(get_string('apps', 'local_obu_apps'), null, navigation_node::TYPE_SYSTEM);
        }
    }
    if ($nodeApps) {
        // BRISC
        if (get_config('local_obu_apps', 'showbrisc') == '1' && has_capability('moodle/blog:create', context_system::instance())) {
            $nodeApps->add('BRISC', '/local/obu_apps/brisc.php');
            // BRISC web app
        }
        // QuAK
        if (get_config('local_obu_apps', 'showquak') == '1' && !empty($CFG->navadduserpostslinks)) {
            $nodeApps->add('QuAK', '/local/obu_apps/quak.php');
            // QuAK web app
        }
        // Polls
        if (get_config('local_obu_apps', 'showpolls') == '1') {
            $nodeApps->add('polls.brookes', '/local/obu_apps/polls.php');
            // Polls web app
        }
    }
}
Exemplo n.º 7
0
 function get_content()
 {
     global $USER, $CFG, $SESSION;
     $wwwroot = '';
     $signup = '';
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (empty($CFG->loginhttps)) {
         $wwwroot = $CFG->wwwroot;
     } else {
         // This actually is not so secure ;-), 'cause we're
         // in unencrypted connection...
         $wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
     }
     if (!empty($CFG->registerauth)) {
         $authplugin = get_auth_plugin($CFG->registerauth);
         if ($authplugin->can_signup()) {
             $signup = $wwwroot . '/login/signup.php';
         }
     }
     // TODO: now that we have multiauth it is hard to find out if there is a way to change password
     $forgot = $wwwroot . '/login/forgot_password.php';
     if (!empty($CFG->loginpasswordautocomplete)) {
         $autocomplete = 'autocomplete="off"';
     } else {
         $autocomplete = '';
     }
     $username = get_moodle_cookie();
     $this->content = new stdClass();
     $this->content->footer = '';
     $this->content->text = '';
     if (!isloggedin() or isguestuser()) {
         // Show the block
         if (empty($CFG->authloginviaemail)) {
             $strusername = get_string('username');
         } else {
             $strusername = get_string('usernameemail');
         }
         $this->content->text .= "\n" . '<form class="loginform" id="login" method="post" action="' . get_login_url() . '" ' . $autocomplete . '>';
         $this->content->text .= '<div class="c1 fld username"><label for="login_username">' . $strusername . '</label>';
         $this->content->text .= '<input type="text" name="username" id="login_username" value="' . s($username) . '" /></div>';
         $this->content->text .= '<div class="c1 fld password"><label for="login_password">' . get_string('password') . '</label>';
         $this->content->text .= '<input type="password" name="password" id="login_password" value="" ' . $autocomplete . ' /></div>';
         if (isset($CFG->rememberusername) and $CFG->rememberusername == 2) {
             $checked = $username ? 'checked="checked"' : '';
             $this->content->text .= '<div class="c1 rememberusername"><input type="checkbox" name="rememberusername" id="rememberusername" value="1" ' . $checked . '/>';
             $this->content->text .= ' <label for="rememberusername">' . get_string('rememberusername', 'admin') . '</label></div>';
         }
         $this->content->text .= '<div class="c1 btn"><input type="submit" value="' . get_string('login') . '" /></div>';
         $this->content->text .= "</form>\n";
         if (!empty($signup)) {
             $this->content->footer .= '<div><a href="' . $signup . '">' . get_string('startsignup') . '</a></div>';
         }
         if (!empty($forgot)) {
             $this->content->footer .= '<div><a href="' . $forgot . '">' . get_string('forgotaccount') . '</a></div>';
         }
     }
     return $this->content;
 }
Exemplo n.º 8
0
 /**
  * Taken from /format/renderer.php
  * Generate a summary of the activites in a section
  *
  * @param stdClass $section The course_section entry from DB
  * @param stdClass $course the course record from DB
  * @param array    $mods (argument not used)
  * @return string HTML to output.
  */
 public static function section_activity_summary($section, $course, $mods)
 {
     global $CFG;
     require_once $CFG->libdir . '/completionlib.php';
     $modinfo = get_fast_modinfo($course);
     if (empty($modinfo->sections[$section->section])) {
         return '';
     }
     // Generate array with count of activities in this section.
     $sectionmods = array();
     $total = 0;
     $complete = 0;
     $cancomplete = isloggedin() && !isguestuser();
     $completioninfo = new completion_info($course);
     foreach ($modinfo->sections[$section->section] as $cmid) {
         $thismod = $modinfo->cms[$cmid];
         if ($thismod->uservisible) {
             if (isset($sectionmods[$thismod->modname])) {
                 $sectionmods[$thismod->modname]['name'] = $thismod->modplural;
                 $sectionmods[$thismod->modname]['count']++;
             } else {
                 $sectionmods[$thismod->modname]['name'] = $thismod->modfullname;
                 $sectionmods[$thismod->modname]['count'] = 1;
             }
             if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) {
                 $total++;
                 $completiondata = $completioninfo->get_data($thismod, true);
                 if ($completiondata->completionstate == COMPLETION_COMPLETE || $completiondata->completionstate == COMPLETION_COMPLETE_PASS) {
                     $complete++;
                 }
             }
         }
     }
     if (empty($sectionmods)) {
         // No sections.
         return '';
     }
     // Output section activities summary.
     $o = '';
     $o .= "<div class='section-summary-activities mdl-right'>";
     foreach ($sectionmods as $mod) {
         $o .= "<span class='activity-count'>";
         $o .= $mod['name'] . ': ' . $mod['count'];
         $o .= "</span>";
     }
     $o .= "</div>";
     $a = false;
     // Output section completion data.
     if ($total > 0) {
         $a = new stdClass();
         $a->complete = $complete;
         $a->total = $total;
         $a->percentage = $complete / $total * 100;
         $o .= "<div class='section-summary-activities mdl-right'>";
         $o .= "<span class='activity-count'>" . get_string('progresstotal', 'completion', $a) . "</span>";
         $o .= "</div>";
     }
     $retobj = (object) array('output' => $o, 'progress' => $a, 'complete' => $complete, 'total' => $total);
     return $retobj;
 }
Exemplo n.º 9
0
 function get_content()
 {
     global $CFG;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (!isloggedin()) {
         return $this->content;
     }
     //if(is_siteadmin()){
     //	return $this->content;
     //}
     //if(has_capability('local_collegestructure:manage', context_system::instance())){
     //	return $this->content;
     //}
     // Prep the content
     $this->content = new stdClass();
     if (!isloggedin() || isguestuser()) {
         $this->content = '';
     } else {
         require_once 'exams.php';
         $string = get_exams();
         $this->content->text = $string;
         return $this->content;
         // Prepare the footer for this block
         // No footer to display
         $this->content->footer = '';
         // Return the content object
         return $this->content;
     }
 }
Exemplo n.º 10
0
 /**
  * Figure out whether annotation is permitted here
  */
 function can_annotate($url)
 {
     global $USER;
     if (isguestuser() or !isloggedin()) {
         return false;
     }
     $handler = annotation_summary_query::handler_for_url($url);
     if (!$handler) {
         return false;
     }
     $handler->fetch_metadata();
     if ($handler->modulename && $handler->courseid) {
         $cm = get_coursemodule_from_instance($handler->modulename, $handler->modinstanceid, $handler->courseid);
         if ($cm) {
             $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
             if (!$handler->capannotate) {
                 return false;
             } else {
                 return has_capability($handler->capannotate, $modcontext);
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Exemplo n.º 11
0
 /**
  * Figure out whether annotation is permitted here
  */
 function can_annotate($url)
 {
     global $USER, $miagloberror;
     $miagloberror = "none";
     if (isguestuser() or !isloggedin()) {
         $miagloberror = "not logged in";
         return false;
     }
     $handler = annotation_summary_query::handler_for_url($url);
     if (!$handler) {
         $miagloberror = "not on this page " . $url;
         return false;
     }
     $handler->fetch_metadata();
     if ($handler->modulename && $handler->courseid) {
         $cm = get_coursemodule_from_instance($handler->modulename, $handler->modinstanceid, $handler->courseid);
         if ($cm) {
             $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
             if (!$handler->capannotate) {
                 $miagloberror = "never on this resource";
                 return false;
                 // annotation of this resource is never permitted
             } else {
                 return has_capability($handler->capannotate, $modcontext);
             }
         } else {
             $miagloberror = "no cm";
             return false;
         }
     } else {
         $miagloberror = "no handler";
         return false;
     }
 }
Exemplo n.º 12
0
 protected function render_custom_menu(custom_menu $menu)
 {
     global $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     //navigation mycourses is no supported since 2.4
     if (isloggedin() && !isguestuser() && ($mycourses = enrol_get_my_courses(NULL, 'visible DESC, fullname ASC'))) {
         $branchlabel = get_string('mycourses');
         $branchurl = new moodle_url('/course/index.php');
         $branchtitle = $branchlabel;
         $branchsort = 8000;
         $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
         foreach ($mycourses as $mycourse) {
             $branch->add($mycourse->shortname, new moodle_url('/course/view.php', array('id' => $mycourse->id)), $mycourse->fullname);
         }
     }
     $course_id = $this->page->course->id;
     if (isloggedin() && $course_id > 1) {
         $branchlabel = get_string('grades');
         $branchurl = new moodle_url('/grade/report/index.php?id=' . $this->page->course->id);
         $branchtitle = $branchlabel;
         $branchsort = 10000;
         $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
     }
     return parent::render_custom_menu($menu);
 }
Exemplo n.º 13
0
/**
 * Sends the parameters to JS module.
 *
 * @return array
 */
function atto_managefiles_params_for_js($elementid, $options, $fpoptions)
{
    global $CFG, $USER;
    require_once $CFG->dirroot . '/repository/lib.php';
    // Load constants.
    // Disabled if:
    // - Not logged in or guest.
    // - Files are not allowed.
    // - Only URL are supported.
    $disabled = !isloggedin() || isguestuser() || (!isset($options['maxfiles']) || $options['maxfiles'] == 0) || isset($options['return_types']) && !($options['return_types'] & ~FILE_EXTERNAL);
    $params = array('disabled' => $disabled, 'area' => array(), 'usercontext' => null);
    if (!$disabled) {
        $params['usercontext'] = context_user::instance($USER->id)->id;
        foreach (array('itemid', 'context', 'areamaxbytes', 'maxbytes', 'subdirs', 'return_types') as $key) {
            if (isset($options[$key])) {
                if ($key === 'context' && is_object($options[$key])) {
                    // Just context id is enough.
                    $params['area'][$key] = $options[$key]->id;
                } else {
                    $params['area'][$key] = $options[$key];
                }
            }
        }
    }
    return $params;
}
Exemplo n.º 14
0
 function get_content()
 {
     global $CFG, $USER, $PAGE, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (empty($this->instance)) {
         return null;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     if (isloggedin() && !isguestuser()) {
         // Show the block
         $this->content = new stdClass();
         //TODO: add capability check here!
         $renderer = $this->page->get_renderer('block_private_files');
         $this->content->text = $renderer->private_files_tree();
         if (has_capability('moodle/user:manageownfiles', $this->context)) {
             $this->content->text .= $OUTPUT->single_button(new moodle_url('/user/files.php', array('returnurl' => $PAGE->url->out())), get_string('myfilesmanage'), 'get');
         }
         $this->content->footer = '';
     }
     return $this->content;
 }
 /**
  * Render the badge element (message count)
  *
  * @param null $userid
  * @return string
  */
 public function badge($userid = null)
 {
     global $USER, $DB, $COURSE, $PAGE;
     // Only for logged in folks and when we are enabled.
     if (!isset($USER->message_badge_disabled)) {
         if (mr_off('badge', 'message') or !isloggedin() or isguestuser()) {
             $USER->message_badge_disabled = true;
         } else {
             $USER->message_badge_disabled = $DB->record_exists('message_processors', array('name' => 'badge', 'enabled' => 0));
         }
     }
     if ($USER->message_badge_disabled) {
         return '';
     }
     if ($this->is_mobile()) {
         return $this->mobile($userid);
     }
     $repo = new message_output_badge_repository_message();
     $forwardurl = new moodle_url('/message/output/badge/view.php', array('action' => 'forward', 'courseid' => $COURSE->id));
     $total = $repo->count_user_unread_messages($userid);
     $PAGE->requires->js_init_call('M.snap_message_badge.init_badge', array($forwardurl->out(false), $COURSE->id), false, $this->get_js_module());
     if (!empty($total)) {
         $countdiv = html_writer::tag('span', $total, array('id' => html_writer::random_id(), 'class' => 'message_badge_count'));
     } else {
         $countdiv = '';
     }
     return $countdiv;
 }
Exemplo n.º 16
0
 function get_content()
 {
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (empty($this->instance)) {
         return null;
     }
     $this->content->footer = '';
     $this->content->text = '';
     if (isloggedin() && !isguestuser()) {
         // Show the block
         $cmt = new stdclass();
         $cmt->context = $this->instance->context;
         $cmt->area = 'block_comments';
         $cmt->itemid = $this->instance->id;
         $cmt->course = $this->page->course;
         // this is a hack to adjust commenting UI
         // in block_comments
         $cmt->env = 'block_comments';
         $cmt->linktext = get_string('showcomments');
         $comment = new comment($cmt);
         $this->content = new stdClass();
         $this->content->text = $comment->init(true);
         $this->content->footer = '';
     }
     return $this->content;
 }
 public function get_content()
 {
     global $CFG, $USER, $DB, $OUTPUT;
     if ($this->content !== null) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     if (isloggedin() && !isguestuser()) {
         $userid = $USER->id;
         $mentees = $DB->get_records_sql('SELECT c.instanceid, ra.userid, ra.contextid, c.id AS cid, u.id AS id, u.firstname,
                                          u.lastname, u.lastaccess, u.picture, u.imagealt, u.email
                                          FROM {role_assignments} ra, {context} c, {user} u
                                          WHERE ra.userid = ?
                                            AND ra.contextid = c.id
                                            AND c.instanceid = u.id
                                            AND c.contextlevel = ' . CONTEXT_USER, array($userid));
         $timetoshowusers = 300;
         $timefrom = 100 * floor((time() - $timetoshowusers) / 100);
         $canshowmsgicon = false;
         $canshowblog = false;
         if (has_capability('moodle/site:sendmessage', $this->page->context) && !empty($CFG->messaging)) {
             $canshowmsgicon = true;
         }
         if ($CFG->bloglevel > 0) {
             $canshowblog = true;
         }
         foreach ($mentees as $record) {
             $this->content->text .= '<div class="mymentees_mentee">';
             $this->content->text .= '<div class="mymentees_pic">' . $OUTPUT->user_picture($record, array('size' => 30)) . '</div>';
             $this->content->text .= '<div class="mymentees_name"><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $record->instanceid . '&amp;course=' . SITEID . '">' . fullname($record) . '</a></div>';
             $this->content->text .= '<div>';
             $gradelinkcontents = '<input type="hidden" name="studentid" value="' . $record->id . '">' . '<input type="submit" class="mymentees_grades" value="" style="background-image:url(' . $OUTPUT->pix_url('t/grades') . ');" title="' . get_string('grades') . '">';
             $gradelink = '<form action="' . $CFG->wwwroot . '/blocks/mymentees/grades.php" method="post" style="display:inline">' . $gradelinkcontents . '</form>';
             $this->content->text .= $gradelink . ' | ';
             $postlinkcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('icon', 'forum') . '" alt="' . get_string('forumposts', 'forum') . '" />';
             $postlink = '<a href="' . $CFG->wwwroot . '/mod/forum/user.php?id=' . $record->id . '" title="' . get_string('forumposts', 'forum') . '">' . $postlinkcontents . '</a>';
             $this->content->text .= $postlink . ' | ';
             if ($canshowblog) {
                 $bloglinkcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('i/feedback') . '" alt="' . get_string('blogentries', 'blog') . '" />';
                 $bloglink = '<a class="mymentees_msg" href="' . $CFG->wwwroot . '/blog/index.php?userid=' . $record->id . '" title="' . get_string('blogentries', 'blog') . '">' . $bloglinkcontents . '</a>';
                 $this->content->text .= $bloglink . ' | ';
             }
             if ($canshowmsgicon) {
                 $msglinkcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/message') . '" alt="' . get_string('messageselectadd') . '" />';
                 $msglink = '<a class="mymentees_msg" href="' . $CFG->wwwroot . '/message/index.php?id=' . $record->id . '" title="' . get_string('messageselectadd') . '">' . $msglinkcontents . '</a>';
                 $this->content->text .= $msglink . ' | ';
             }
             if ($record->lastaccess > $timefrom) {
                 $this->content->text .= '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/go') . '" alt="' . get_string('online', 'block_mymentees') . '" title="' . get_string('online', 'block_mymentees') . '" />';
             } else {
                 $this->content->text .= '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/stop') . '" alt="' . get_string('offline', 'block_mymentees') . '" title="' . get_string('offline', 'block_mymentees') . '" />';
             }
             $this->content->text .= '</div></div>';
         }
     }
     $this->content->footer = '';
     return $this->content;
 }
Exemplo n.º 18
0
 private function useguestrole()
 {
     static $useguestrole = null;
     if ($useguestrole === null) {
         $useguestrole = isguestuser() || !isloggedin();
     }
     return $useguestrole;
 }
Exemplo n.º 19
0
 public function test_set_guest_user()
 {
     global $USER;
     $this->resetAfterTest(true);
     $this->setGuestUser();
     $this->assertEquals($USER->id, 1);
     $this->assertTrue(isguestuser());
 }
Exemplo n.º 20
0
 /**
  * @return bool
  */
 public static function validate($params)
 {
     $dataformid = $params['dataformid'];
     $df = \mod_dataform_dataform::instance($dataformid);
     // Cannot add in a view that does not allow submission.
     if (!empty($params['viewid'])) {
         $view = $df->view_manager->get_view_by_id($params['viewid']);
         if (!$view or !$view->allows_submission()) {
             return false;
         }
     }
     // User at max entries (per interval).
     if ($df->user_at_max_entries(true)) {
         // No more entries for you (come back next interval or so).
         return false;
     }
     // Early entries.
     if ($df->is_early()) {
         $params['capabilities'] = array('mod/dataform:entryearlyadd');
         if (!parent::validate($params)) {
             return false;
         }
     }
     // Late entries.
     if ($df->is_past_due()) {
         $params['capabilities'] = array('mod/dataform:entrylateadd');
         if (!parent::validate($params)) {
             return false;
         }
     }
     $entry = !empty($params['entry']) ? $params['entry'] : \mod_dataform\pluginbase\dataformentry::blank_instance($df);
     // Own entry.
     if (\mod_dataform\pluginbase\dataformentry::is_own($entry)) {
         $params['capabilities'] = array('mod/dataform:entryownadd');
         return parent::validate($params);
     }
     // Group entry.
     if (\mod_dataform\pluginbase\dataformentry::is_grouped($entry)) {
         if (groups_is_member($entry->groupid)) {
             $params['capabilities'] = array('mod/dataform:entrygroupadd');
             return parent::validate($params);
         }
     }
     // Anonymous entry.
     if (\mod_dataform\pluginbase\dataformentry::is_anonymous($entry)) {
         if ((isguestuser() or !isloggedin()) and $df->anonymous) {
             return true;
         }
         $params['capabilities'] = array('mod/dataform:entryanonymousadd');
         return parent::validate($params);
     }
     // Any entry.
     if (\mod_dataform\pluginbase\dataformentry::is_others($entry)) {
         $params['capabilities'] = array('mod/dataform:entryanyadd');
         return parent::validate($params);
     }
     return false;
 }
Exemplo n.º 21
0
function local_obu_forms_extend_navigation($navigation)
{
    global $CFG, $USER, $PAGE;
    if (!isloggedin() || isguestuser()) {
        return;
    }
    $context = context_system::instance();
    $staff_manager = has_capability('local/obu_forms:manage_pg', $context) || has_capability('local/obu_forms:manage_ump_staff', $context);
    $students_manager = has_capability('local/obu_forms:manage_pg', $context) || has_capability('local/obu_forms:manage_ump_students', $context);
    $manager = $staff_manager || $students_manager;
    $staff = is_staff($USER->username);
    // Has a 'p' number?
    $student = is_student($USER->id);
    // Enrolled on a PIP-based course (programme)?
    // Add the 'My Forms' option
    if ($manager || $staff || $student || !empty(get_form_data($USER->id))) {
        // Find the 'myprofile' node
        $nodeParent = $navigation->find('myprofile', navigation_node::TYPE_UNKNOWN);
        // Add the option to list their completed forms
        if ($nodeParent) {
            $node = $nodeParent->add(get_string('myforms', 'local_obu_forms'), '/local/obu_forms/index.php?userid=' . $USER->id);
        }
    }
    if (!$manager && !$staff && !$student) {
        // Move on now please, nothing more to see here...
        return;
    }
    // Find the 'forms' node
    $nodeParent = $navigation->find(get_string('forms', 'local_obu_forms'), navigation_node::TYPE_SYSTEM);
    // If necessary, add the 'forms' node to 'home'
    if (!$nodeParent) {
        $nodeHome = $navigation->children->get('1')->parent;
        if ($nodeHome) {
            $nodeParent = $nodeHome->add(get_string('forms', 'local_obu_forms'), null, navigation_node::TYPE_SYSTEM);
        }
    }
    if ($nodeParent) {
        // For form managers, add the privileged maintenance and enquiry options
        if ($manager) {
            $node = $nodeParent->add(get_string('settings_nav', 'local_obu_forms'), '/local/obu_forms/forms.php');
            $node = $nodeParent->add(get_string('template_nav', 'local_obu_forms'), '/local/obu_forms/template.php');
            $node = $nodeParent->add(get_string('auths_nav', 'local_obu_forms'), '/local/obu_forms/auths.php');
            $node = $nodeParent->add(get_string('sc_auths', 'local_obu_forms'), '/local/obu_forms/auths.php?authoriser=csa');
            $node = $nodeParent->add(get_string('list_users_forms', 'local_obu_forms'), '/local/obu_forms/list.php');
            $node = $nodeParent->add(get_string('formslist', 'local_obu_forms'), '/local/obu_forms/formslist.php');
        } else {
            // For other users, add the option(s) to list all the relevant forms
            if ($staff) {
                $node = $nodeParent->add(get_string('staff_forms', 'local_obu_forms'), '/local/obu_forms/formslist.php?type=staff');
            }
            $node = $nodeParent->add(get_string('student_forms', 'local_obu_forms'), '/local/obu_forms/formslist.php?type=student');
            // Both staff and students can view student forms
            if ($staff) {
                $node = $nodeParent->add(get_string('list_users_forms', 'local_obu_forms'), '/local/obu_forms/list.php');
            }
        }
    }
}
Exemplo n.º 22
0
 /**
  * Load data required for the export.
  */
 public function load_data()
 {
     global $DB, $USER;
     // Note that require_login() is normally called later as a part of
     // portfolio_export_pagesetup() in the portfolio/add.php file. But we
     // load various data depending of capabilities so it makes sense to
     // call it explicitly here, too.
     require_login($this->get('course'), false, $this->cm, false, true);
     if (isguestuser()) {
         throw new portfolio_caller_exception('guestsarenotallowed', 'core_error');
     }
     $workshoprecord = $DB->get_record('workshop', ['id' => $this->cm->instance], '*', MUST_EXIST);
     $this->workshop = new workshop($workshoprecord, $this->cm, $this->get('course'));
     $this->submission = $this->workshop->get_submission_by_id($this->submissionid);
     // Is the user exporting her/his own submission?
     $ownsubmission = $this->submission->authorid == $USER->id;
     // Does the user have permission to see all submissions (aka is it a teacher)?
     $canviewallsubmissions = has_capability('mod/workshop:viewallsubmissions', $this->workshop->context);
     $canviewallsubmissions = $canviewallsubmissions && $this->workshop->check_group_membership($this->submission->authorid);
     // Is the user exporting a submission that she/he has peer-assessed?
     $userassessment = $this->workshop->get_assessment_of_submission_by_user($this->submission->id, $USER->id);
     if ($userassessment) {
         $this->assessments[$userassessment->id] = $userassessment;
         $isreviewer = true;
     }
     if (!$ownsubmission and !$canviewallsubmissions and !$isreviewer) {
         throw new portfolio_caller_exception('nopermissions', 'core_error');
     }
     // Does the user have permission to see all assessments (aka is it a teacher)?
     $canviewallassessments = has_capability('mod/workshop:viewallassessments', $this->workshop->context);
     // Load other assessments eventually if the user can see them.
     if ($canviewallassessments or $ownsubmission and $this->workshop->assessments_available()) {
         foreach ($this->workshop->get_assessments_of_submission($this->submission->id) as $assessment) {
             if ($assessment->reviewerid == $USER->id) {
                 // User's own assessment is already loaded.
                 continue;
             }
             if (is_null($assessment->grade) and !$canviewallassessments) {
                 // Students do not see peer-assessment that are not graded.
                 continue;
             }
             $this->assessments[$assessment->id] = $assessment;
         }
     }
     // Prepare embedded and attached files for the export.
     $this->multifiles = [];
     $this->add_area_files('submission_content', $this->submission->id);
     $this->add_area_files('submission_attachment', $this->submission->id);
     foreach ($this->assessments as $assessment) {
         $this->add_area_files('overallfeedback_content', $assessment->id);
         $this->add_area_files('overallfeedback_attachment', $assessment->id);
     }
     $this->add_area_files('instructauthors', 0);
     // If there are no files to be exported, we can offer plain HTML file export.
     if (empty($this->multifiles)) {
         $this->add_format(PORTFOLIO_FORMAT_PLAINHTML);
     }
 }
 protected function render_custom_menu(custom_menu $menu)
 {
     /*
      * This code replaces adds the current enrolled
      * courses to the custommenu.
      */
     $hasdisplaymycourses = empty($this->page->theme->settings->displaymycourses) ? false : $this->page->theme->settings->displaymycourses;
     if (isloggedin() && !isguestuser() && $hasdisplaymycourses) {
         $mycoursetitle = $this->page->theme->settings->mycoursetitle;
         if ($mycoursetitle == 'module') {
             $branchtitle = get_string('mymodules', 'theme_evolved');
         } else {
             if ($mycoursetitle == 'unit') {
                 $branchtitle = get_string('myunits', 'theme_evolved');
             } else {
                 if ($mycoursetitle == 'class') {
                     $branchtitle = get_string('myclasses', 'theme_evolved');
                 } else {
                     $branchtitle = get_string('mycourses', 'theme_evolved');
                 }
             }
         }
         $branchlabel = '<i class="fa fa-briefcase"></i>' . $branchtitle;
         $branchurl = new moodle_url('/my/index.php');
         $branchsort = 10000;
         $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
         if ($courses = enrol_get_my_courses(NULL, 'fullname ASC')) {
             foreach ($courses as $course) {
                 if ($course->visible) {
                     $branch->add(format_string($course->fullname), new moodle_url('/course/view.php?id=' . $course->id), format_string($course->shortname));
                 }
             }
         } else {
             $noenrolments = get_string('noenrolments', 'theme_evolved');
             $branch->add('<em>' . $noenrolments . '</em>', new moodle_url('/'), $noenrolments);
         }
     }
     /*
      * This code replaces adds the My Dashboard
      * functionality to the custommenu.
      */
     $hasdisplaymydashboard = empty($this->page->theme->settings->displaymydashboard) ? false : $this->page->theme->settings->displaymydashboard;
     if (isloggedin() && !isguestuser() && $hasdisplaymydashboard) {
         $branchlabel = '<i class="fa fa-dashboard"></i>' . get_string('mydashboard', 'theme_evolved');
         $branchurl = new moodle_url('/my/index.php');
         $branchtitle = get_string('mydashboard', 'theme_evolved');
         $branchsort = 10000;
         $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
         $branch->add(get_string('profile') . '</em>', new moodle_url('/user/profile.php'), get_string('profile'));
         $branch->add(get_string('pluginname', 'block_calendar_month') . '</em>', new moodle_url('/calendar/view.php'), get_string('pluginname', 'block_calendar_month'));
         $branch->add(get_string('pluginname', 'block_messages') . '</em>', new moodle_url('/message/index.php'), get_string('pluginname', 'block_messages'));
         $branch->add(get_string('badges') . '</em>', new moodle_url('/badges/mybadges.php'), get_string('badges'));
         $branch->add(get_string('privatefiles', 'block_private_files') . '</em>', new moodle_url('/user/files.php'), get_string('privatefiles', 'block_private_files'));
         $branch->add(get_string('logout') . '</em>', new moodle_url('/login/logout.php'), get_string('logout'));
     }
     return parent::render_custom_menu($menu);
 }
Exemplo n.º 24
0
 protected function authorizePurchaseOnEschool()
 {
     global $CFG;
     $CFG->current_app->requireMoodle();
     $CFG->current_app->requireLogin();
     if (isguestuser()) {
         $this->redirect($CFG->current_app->getUrl() . '/eschool/login');
     }
 }
Exemplo n.º 25
0
 function get_content()
 {
     global $CFG;
     // detect if blog enabled
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (empty($CFG->enableblogs)) {
         $this->content = new stdClass();
         $this->content->text = '';
         if ($this->page->user_is_editing()) {
             $this->content->text = get_string('blogdisable', 'blog');
         }
         return $this->content;
     } else {
         if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) {
             $this->content = new stdClass();
             $this->content->text = '';
             return $this->content;
         }
     }
     // require necessary libs and get content
     require_once $CFG->dirroot . '/blog/lib.php';
     // Prep the content
     $this->content = new stdClass();
     $options = blog_get_all_options($this->page);
     if (count($options) == 0) {
         $this->content->text = '';
         return $this->content;
     }
     // Iterate the option types
     $menulist = array();
     foreach ($options as $types) {
         foreach ($types as $link) {
             $menulist[] = html_writer::link($link['link'], $link['string']);
         }
         $menulist[] = '<hr />';
     }
     // Remove the last element (will be an HR)
     array_pop($menulist);
     // Display the content as a list
     $this->content->text = html_writer::alist($menulist, array('class' => 'list'));
     // Prepare the footer for this block
     if (has_capability('moodle/blog:search', context_system::instance())) {
         // Full-text search field
         $form = html_writer::tag('label', get_string('search', 'admin'), array('for' => 'blogsearchquery', 'class' => 'accesshide'));
         $form .= html_writer::empty_tag('input', array('id' => 'blogsearchquery', 'type' => 'text', 'name' => 'search'));
         $form .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('search')));
         $this->content->footer = html_writer::tag('form', html_writer::tag('div', $form), array('class' => 'blogsearchform', 'method' => 'get', 'action' => new moodle_url('/blog/index.php')));
     } else {
         // No footer to display
         $this->content->footer = '';
     }
     // Return the content object
     return $this->content;
 }
Exemplo n.º 26
0
 /**
  *
  * @return bool
  */
 public static function is_anonymous($entry)
 {
     global $CFG;
     // Call isguestuser to make sure the $CFG->siteguest is set.
     isguestuser();
     if (!empty($entry->userid) and $entry->userid == $CFG->siteguest) {
         return true;
     }
     return empty($entry->userid) and empty($entry->groupid);
 }
Exemplo n.º 27
0
 /**
  * Should the event be ignored (== not logged)?
  * @param \core\event\base $event
  * @return bool
  */
 protected function is_event_ignored(\core\event\base $event)
 {
     if ((!CLI_SCRIPT or PHPUNIT_TEST) and !$this->logguests) {
         // Always log inside CLI scripts because we do not login there.
         if (!isloggedin() or isguestuser()) {
             return true;
         }
     }
     return false;
 }
 function definition()
 {
     global $CFG, $USER;
     $mform =& $this->_form;
     $mform->addElement('header', 'contact', get_string('contact', 'local_simple_contact_form'));
     $mform->addElement('hidden', 'sesskey', sesskey());
     if (isloggedin() && !isguestuser($USER)) {
         $mform->addElement('static', 'p_name', get_string('name', 'local_simple_contact_form'), fullname($USER));
         $mform->addElement('hidden', 'f_name', fullname($USER));
         $mform->addElement('static', 'p_email', get_string('email', 'local_simple_contact_form'), $USER->email);
         $mform->addElement('hidden', 'f_email', $USER->email);
     } else {
         $attributes = array('size' => '52');
         $mform->addElement('text', 'f_name', get_string('name', 'local_simple_contact_form'), $attributes);
         $mform->addRule('f_name', get_string('requiredname', 'local_simple_contact_form'), 'required', null, 'client');
         $mform->addElement('text', 'f_email', get_string('email', 'local_simple_contact_form'), $attributes);
         $mform->addRule('f_email', get_string('requiredemail', 'local_simple_contact_form'), 'required', null, 'client');
     }
     if (!empty($CFG->enable_city)) {
         $attributes = array('size' => '40');
         if (empty($CFG->cityes_list)) {
             $mform->addElement('text', 'f_city', get_string('city', 'local_simple_contact_form'), $attributes);
             $mform->addRule('f_city', get_string('requiredcity', 'local_simple_contact_form'), 'required', null, 'client');
         } else {
             $cityes = array_map('trim', explode("\n", $CFG->cityes_list));
             $select = mountSelect('f_city', get_string('city', 'local_simple_contact_form'), get_string('none_state', 'local_simple_contact_form'), $cityes);
             $select->addOption(get_string('option_another', 'local_simple_contact_form'), '-');
             $mform->addElement($select);
             $mform->addRule('f_city', get_string('requiredcity', 'local_simple_contact_form'), 'required', null, 'client');
             $mform->addElement('text', 'f_city_helper', '', $attributes);
             $mform->disabledIf('f_city_helper', 'f_city', 'neq', '-');
             // TODO: How to require only when enabled?
             //$mform->addRule('f_city_helper', get_string('requiredcity', 'local_simple_contact_form'), 'required', null, 'client');
         }
     }
     if (!empty($CFG->enable_region)) {
         if (empty($CFG->region_list)) {
             $attributes = array('size' => '40');
             $mform->addElement('text', 'f_region', get_string('region', 'local_simple_contact_form'), $attributes);
             $mform->addRule('f_region', get_string('requiredstate', 'local_simple_contact_form'), 'required', null, 'client');
         } else {
             $regions = array_map('trim', explode("\n", $CFG->region_list));
             $mform->addElement(mountSelect('f_region', get_string('state', 'local_simple_contact_form'), get_string('none_state', 'local_simple_contact_form'), $regions));
             $mform->addRule('f_region', get_string('requiredstate', 'local_simple_contact_form'), 'required', null, 'client');
         }
     }
     $asubjects = array(get_string('01_subject', 'local_simple_contact_form'), get_string('02_subject', 'local_simple_contact_form'), get_string('03_subject', 'local_simple_contact_form'), get_string('04_subject', 'local_simple_contact_form'));
     $mform->addElement(mountSelect('f_subject', get_string('subject', 'local_simple_contact_form'), get_string('none_subject', 'local_simple_contact_form'), $asubjects));
     $mform->addRule('f_subject', get_string('requiredsubject', 'local_simple_contact_form'), 'required', null, 'client');
     $attributes = array('wrap' => 'virtual', 'rows' => '10', 'cols' => '50');
     $mform->addElement('textarea', 'f_message', get_string('message', 'local_simple_contact_form'), $attributes);
     $mform->addRule('f_message', get_string('requiredmessage', 'local_simple_contact_form'), 'required', null, 'client');
     $this->add_action_buttons(true, get_string('send', 'local_simple_contact_form'));
 }
Exemplo n.º 29
0
 function get_content()
 {
     global $CFG, $USER, $PAGE, $DB, $OUTPUT;
     if (empty($this->config->recentbloginterval)) {
         $this->config->recentbloginterval = 8400;
     }
     if (empty($this->config->numberofrecentblogentries)) {
         $this->config->numberofrecentblogentries = 4;
     }
     if (empty($CFG->bloglevel) || $CFG->bloglevel < BLOG_GLOBAL_LEVEL && !(isloggedin() && !isguestuser())) {
         $this->content->text = '';
         if ($this->page->user_is_editing()) {
             $this->content->text = get_string('blogdisable', 'blog');
         }
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     $context = $this->page->context;
     $filter = array();
     if ($context->contextlevel == CONTEXT_MODULE) {
         $filter['module'] = $context->instanceid;
         $a = new stdClass();
         $a->type = get_string('modulename', $this->page->cm->modname);
         $strview = get_string('viewallmodentries', 'blog', $a);
     } else {
         if ($context->contextlevel == CONTEXT_COURSE) {
             $filter['course'] = $context->instanceid;
             $a = new stdClass();
             $a->type = get_string('course');
             $strview = get_string('viewblogentries', 'blog', $a);
         } else {
             $strview = get_string('viewsiteentries', 'blog');
         }
     }
     $filter['since'] = $this->config->recentbloginterval;
     $bloglisting = new blog_listing($filter);
     $entries = $bloglisting->get_entries(0, $this->config->numberofrecentblogentries, 4);
     $url = new moodle_url('/blog/index.php', $filter);
     if (!empty($entries)) {
         $entrieslist = array();
         $viewblogurl = new moodle_url('/blog/index.php');
         foreach ($entries as $entryid => $entry) {
             $viewblogurl->param('entryid', $entryid);
             $entrylink = html_writer::link($viewblogurl, shorten_text($entry->subject));
             $entrieslist[] = $entrylink;
         }
         $this->content->text .= html_writer::alist($entrieslist, array('class' => 'list'));
         $viewallentrieslink = html_writer::link($url, $strview);
         $this->content->text .= $viewallentrieslink;
     } else {
         $this->content->text .= get_string('norecentblogentries', 'block_blog_recent');
     }
 }
Exemplo n.º 30
0
 /**
  * Check that the user is logged-in and has permission to alter course settings.
  */
 function check_permission()
 {
     // Ensure the user logs in
     require_login($this->course->id);
     if (isguestuser()) {
         error(get_string('noguestaccess', 'sloodle'));
     }
     add_to_log($this->course->id, 'course', 'view sloodle data', '', "{$this->course->id}");
     // Ensure the user is allowed to update information on this course
     $this->course_context = get_context_instance(CONTEXT_COURSE, $this->course->id);
     require_capability('moodle/course:update', $this->course_context);
 }