Ejemplo n.º 1
0
 public function definition()
 {
     global $DB, $USER;
     $form = $this->_form;
     $selectdata = enrol_get_all_users_courses($USER->id, true, ['id', 'fullname']);
     $coursearray = null;
     $coursearray[null] = '-- SELECT --';
     foreach ($selectdata as $val) {
         $coursearray[$val->id] = $val->fullname;
     }
     $form->addElement('select', 'courseid', get_string('courseselect', 'local_note'), $coursearray);
     $form->setType('courseid', PARAM_RAW);
     $form->addRule('courseid', get_string('err_courseselect', 'local_note'), 'required', null, 'server', false, false);
     $form->addElement('text', 'title', get_string('title', 'local_note'));
     $form->setType('title', PARAM_RAW);
     $form->addElement('htmleditor', 'content', get_string("content", "local_note"), 'wrap="virtual" rows="3" cols="20"');
     $form->setType('content', PARAM_RAW);
     $form->addElement('filemanager', 'attachment', get_string('attachment', 'local_note'), null, array('maxbytes' => '2097152', 'accepted_types' => '*'));
     $form->addElement('text', 'label', get_string('label', 'local_note'));
     $form->setType('label', PARAM_RAW);
     $form->addElement('select', 'status', get_string("status", "local_note"), array('1' => 'Active', '0' => 'In-active'));
     $form->setType('status', PARAM_RAW);
     $form->addElement('hidden', 'id', $this->noteid);
     $form->setType('id', PARAM_RAW);
     $this->add_action_buttons();
 }
 /**
  * Obtain enrolled courses for the specified user.
  *
  * @param integer $userid
  *
  * @return integer[]
  */
 protected static function get_enrolled_course_ids($userid)
 {
     $courses = enrol_get_all_users_courses($userid, false);
     $courseids = array_reduce($courses, function ($courseids, $course) {
         $courseids[] = $course->id;
         return $courseids;
     }, array());
     return $courseids;
 }
 /**
  * Enrol two users on one unique course each and one shared course
  * then merge them.
  */
 public function test_mergeenrolments()
 {
     global $DB;
     // Setup two users to merge.
     $user_remove = $this->getDataGenerator()->create_user();
     $user_keep = $this->getDataGenerator()->create_user();
     // Create three courses.
     $course1 = $this->getDataGenerator()->create_course();
     $course2 = $this->getDataGenerator()->create_course();
     $course3 = $this->getDataGenerator()->create_course();
     $maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $maninstance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $maninstance3 = $DB->get_record('enrol', array('courseid' => $course3->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $manual = enrol_get_plugin('manual');
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     // Enrol $user_remove on course 1 + 2 and $user_keep on course 2 + 3.
     $manual->enrol_user($maninstance1, $user_remove->id, $studentrole->id);
     $manual->enrol_user($maninstance2, $user_remove->id, $studentrole->id);
     $manual->enrol_user($maninstance2, $user_keep->id, $studentrole->id);
     $manual->enrol_user($maninstance3, $user_keep->id, $studentrole->id);
     // Check initial state of enrolments for $user_remove.
     $courses = enrol_get_all_users_courses($user_remove->id);
     ksort($courses);
     $this->assertCount(2, $courses);
     $this->assertEquals(array($course1->id, $course2->id), array_keys($courses));
     // Check initial state of enrolments for $user_keep.
     $courses = enrol_get_all_users_courses($user_keep->id);
     ksort($courses);
     $this->assertCount(2, $courses);
     $this->assertEquals(array($course2->id, $course3->id), array_keys($courses));
     $mut = new MergeUserTool();
     list($success, $log, $logid) = $mut->merge($user_keep->id, $user_remove->id);
     // Check $user_remove is suspended.
     $user_remove = $DB->get_record('user', array('id' => $user_remove->id));
     $this->assertEquals(1, $user_remove->suspended);
     // Check $user_keep is now enrolled on all three courses.
     $courses = enrol_get_all_users_courses($user_keep->id);
     ksort($courses);
     $this->assertCount(3, $courses);
     $this->assertEquals(array($course1->id, $course2->id, $course3->id), array_keys($courses));
 }
Ejemplo n.º 4
0
    }
    print_row(get_string('skypeid') . ':', '<a href="skype:' . urlencode($user->skype) . '?call">' . s($user->skype) . $statusicon . '</a>');
}
if ($user->yahoo && !isset($hiddenfields['yahooid'])) {
    print_row(get_string('yahooid') . ':', '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user->yahoo) . '&amp;.src=pg">' . s($user->yahoo) . " <img src=\"http://opi.yahoo.com/online?u=" . urlencode($user->yahoo) . "&m=g&t=0\" alt=\"\"></a>");
}
if ($user->aim && !isset($hiddenfields['aimid'])) {
    print_row(get_string('aimid') . ':', '<a href="aim:goim?screenname=' . urlencode($user->aim) . '">' . s($user->aim) . '</a>');
}
if ($user->msn && !isset($hiddenfields['msnid'])) {
    print_row(get_string('msnid') . ':', s($user->msn));
}
/// Print the Custom User Fields
profile_display_fields($user->id);
if (!isset($hiddenfields['mycourses'])) {
    if ($mycourses = enrol_get_all_users_courses($user->id, true, NULL, 'visible DESC,sortorder ASC')) {
        $shown = 0;
        $courselisting = '';
        foreach ($mycourses as $mycourse) {
            if ($mycourse->category) {
                context_helper::preload_from_record($mycourse);
                $ccontext = context_course::instance($mycourse->id);
                $class = '';
                if ($mycourse->visible == 0) {
                    if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
                        continue;
                    }
                    $class = 'class="dimmed"';
                }
                $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$mycourse->id}\" {$class} >" . $ccontext->get_context_name(false) . "</a>, ";
            }
    public function promoted_courses($type)
    {
        global $CFG, $OUTPUT, $DB, $PAGE, $USER;
        if ($type == '') {
            return false;
        }
        $featuredcontent = '';
        $featuredids = '';
        /* Get Featured courses id from DB */
        if ($type == 'tags') {
            $sql = "SELECT DISTINCT itemid FROM {tag_instance} WHERE itemtype = 'course' AND tagid IN(SELECT tagid FROM {tag_instance} WHERE itemtype = 'user' AND itemid = " . $USER->id . ")";
            $featuredidsarray = $DB->get_records_sql($sql, array());
            $featuredids = '';
            $promotedtitle = theme_pioneer_get_setting('promotedtagtitle', 'format_text');
            $promotedlinktext = theme_pioneer_get_setting('promotedtaglinktext', 'format_text');
            $promotedlink = theme_pioneer_get_setting('promotedtaglink', 'format_text');
            $personaltextbox = theme_pioneer_get_setting('promotedtagtextbox', 'format_html');
            foreach ($featuredidsarray as $fid) {
                $featuredids .= $fid->itemid . ',';
            }
        }
        if ($type == 'setting') {
            $featuredids = theme_pioneer_get_setting('promotedcourses');
            $promotedtitle = theme_pioneer_get_setting('promotedtitle', 'format_text');
            $promotedlinktext = theme_pioneer_get_setting('promotedlinktext', 'format_text');
            $promotedlink = theme_pioneer_get_setting('promotedlink', 'format_text');
            $personaltextbox = '';
        }
        if ($type == 'my') {
            $promotedtitle = theme_pioneer_get_setting('promotedmytitle', 'format_text');
            $promotedlinktext = theme_pioneer_get_setting('promotedmylinktext', 'format_text');
            $promotedlink = theme_pioneer_get_setting('promotedmylink', 'format_text');
            $personaltextbox = theme_pioneer_get_setting('promotedmytextbox', 'format_html');
            $courses = enrol_get_all_users_courses($USER->id);
            foreach ($courses as $fid) {
                $featuredids .= $fid->id . ',';
            }
        }
        /* Get Featured courses id from DB */
        $rcourseids = !empty($featuredids) ? explode(",", $featuredids, 30) : array();
        if (empty($rcourseids)) {
            return false;
        }
        $hcourseids = theme_pioneer_hidden_courses_ids();
        if (!empty($hcourseids)) {
            foreach ($rcourseids as $key => $val) {
                if (in_array($val, $hcourseids)) {
                    unset($rcourseids[$key]);
                }
            }
        }
        foreach ($rcourseids as $key => $val) {
            $ccourse = $DB->get_record('course', array('id' => $val));
            if (empty($ccourse)) {
                unset($rcourseids[$key]);
                continue;
            }
        }
        if (empty($rcourseids)) {
            return false;
        }
        $fcourseids = array_chunk($rcourseids, 30);
        $totalfcourse = count($fcourseids);
        $featuredheader = '<div class="custom-courses-list" id="Promoted-Courses">
							  <div class="container-fluid">
								<div class="titlebar with-felements">
									<h2>' . $promotedtitle . '</h2>
									<div class="clearfix"></div>
								</div>
								<div class="promoted_courses" data-crow="' . $totalfcourse . '">';
        $featuredfooter = ' <p style="float:right;"> <a href="' . $promotedlink . '">' . $promotedlinktext . '</a></p>
                            <div class="clearfix"></div>
                            </div>
                            </div>
                            </div>';
        if (!empty($fcourseids)) {
            foreach ($fcourseids as $courseids) {
                $rowcontent = '<p>' . $personaltextbox . '</p><div><div class="row-fluid carousel">';
                foreach ($courseids as $courseid) {
                    $course = get_course($courseid);
                    $no = get_config('theme_pioneer', 'patternselect');
                    $nimgp = empty($no) || $no == "default" ? 'no-image' : 'cs0' . $no . '/no-image';
                    $noimgurl = $OUTPUT->pix_url($nimgp, 'theme');
                    $courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
                    if ($course instanceof stdClass) {
                        require_once $CFG->libdir . '/coursecatlib.php';
                        $course = new course_in_list($course);
                    }
                    $imgurl = '';
                    $summary = theme_pioneer_strip_html_tags($course->summary);
                    $summary = theme_pioneer_course_trim_char($summary, 110);
                    $trimtitle = theme_pioneer_course_trim_char($course->fullname, 25);
                    $context = context_course::instance($course->id);
                    $nostudents = count_role_users(5, $context);
                    foreach ($course->get_course_overviewfiles() as $file) {
                        $isimage = $file->is_valid_image();
                        $imgurl = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
                        if (!$isimage) {
                            $imgurl = $noimgurl;
                        }
                    }
                    if (empty($imgurl)) {
                        $imgurl = $PAGE->theme->setting_file_url('headerbackgroundimage', 'headerbackgroundimage', true);
                        if (!$imgurl) {
                            $imgurl = $noimgurl;
                        }
                    }
                    $coursehtml = '
                        <div class="promowrap">
                        <div class="fp-coursebox">
                        <div class="fp-coursethumb">
                        <a href="' . $courseurl . '">
                        <img src="' . $imgurl . '" width="100%" height="125" title="' . $course->fullname . '">
                        </a>
                        <div class="fp-courseinfo">
                        <h5><a href="' . $courseurl . '" id="button" data-toggle="tooltip" data-placement="bottom" title="' . $course->fullname . '" >' . $trimtitle . '</a></h5>
                        </div>
                        <div class="promo-summary">' . $summary . '</div>
                        </div>
                        </div>
                        </div>';
                    $rowcontent .= $coursehtml;
                }
                $rowcontent .= '</div></div>';
                $featuredcontent .= $rowcontent;
            }
        }
        $featuredcourses = $featuredheader . $featuredcontent . $featuredfooter;
        return $featuredcourses;
    }
Ejemplo n.º 6
0
 public static function all_ungraded($userid)
 {
     $courses = enrol_get_all_users_courses($userid);
     $capability = 'gradereport/grader:view';
     foreach ($courses as $course) {
         if (has_capability($capability, \context_course::instance($course->id), $userid)) {
             $courseids[] = $course->id;
         }
     }
     if (empty($courseids)) {
         return array();
     }
     $mods = \core_plugin_manager::instance()->get_installed_plugins('mod');
     $mods = array_keys($mods);
     $grading = [];
     foreach ($mods as $mod) {
         $class = '\\theme_snap\\activity';
         $method = $mod . '_ungraded';
         if (method_exists($class, $method)) {
             $grading = array_merge($grading, call_user_func([$class, $method], $courseids));
         }
     }
     usort($grading, array('self', 'sort_graded'));
     return $grading;
 }
Ejemplo n.º 7
0
/**
 * Can user access at least one enrolled course?
 *
 * Cheat if necessary, but find out as fast as possible!
 *
 * @param int|stdClass $user null means use current user
 * @return bool
 */
function enrol_user_sees_own_courses($user = null)
{
    global $USER;
    if ($user === null) {
        $user = $USER;
    }
    $userid = is_object($user) ? $user->id : $user;
    // Guest account does not have any courses
    if (isguestuser($userid) or empty($userid)) {
        return false;
    }
    // Let's cheat here if this is the current user,
    // if user accessed any course recently, then most probably
    // we do not need to query the database at all.
    if ($USER->id == $userid) {
        if (!empty($USER->enrol['enrolled'])) {
            foreach ($USER->enrol['enrolled'] as $until) {
                if ($until > time()) {
                    return true;
                }
            }
        }
    }
    // Now the slow way.
    $courses = enrol_get_all_users_courses($userid, true);
    foreach ($courses as $course) {
        if ($course->visible) {
            return true;
        }
        context_helper::preload_from_record($course);
        $context = context_course::instance($course->id);
        if (has_capability('moodle/course:viewhiddencourses', $context, $user)) {
            return true;
        }
    }
    return false;
}
Ejemplo n.º 8
0
 public function test_enrol_get_all_users_courses()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $this->assertNotEmpty($studentrole);
     $teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
     $this->assertNotEmpty($teacherrole);
     $admin = get_admin();
     $user1 = $this->getDataGenerator()->create_user();
     $user2 = $this->getDataGenerator()->create_user();
     $user3 = $this->getDataGenerator()->create_user();
     $user4 = $this->getDataGenerator()->create_user();
     $user5 = $this->getDataGenerator()->create_user();
     $category1 = $this->getDataGenerator()->create_category(array('visible' => 0));
     $category2 = $this->getDataGenerator()->create_category();
     $course1 = $this->getDataGenerator()->create_course(array('category' => $category1->id));
     $course2 = $this->getDataGenerator()->create_course(array('category' => $category2->id));
     $course3 = $this->getDataGenerator()->create_course(array('category' => $category2->id, 'visible' => 0));
     $course4 = $this->getDataGenerator()->create_course(array('category' => $category2->id));
     $maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $DB->set_field('enrol', 'status', ENROL_INSTANCE_DISABLED, array('id' => $maninstance1->id));
     $maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $maninstance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $maninstance3 = $DB->get_record('enrol', array('courseid' => $course3->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $maninstance4 = $DB->get_record('enrol', array('courseid' => $course4->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $manual = enrol_get_plugin('manual');
     $this->assertNotEmpty($manual);
     $manual->enrol_user($maninstance1, $user1->id, $teacherrole->id);
     $manual->enrol_user($maninstance1, $user2->id, $studentrole->id);
     $manual->enrol_user($maninstance1, $user4->id, $teacherrole->id, 0, 0, ENROL_USER_SUSPENDED);
     $manual->enrol_user($maninstance1, $admin->id, $studentrole->id);
     $manual->enrol_user($maninstance2, $user1->id);
     $manual->enrol_user($maninstance2, $user2->id);
     $manual->enrol_user($maninstance2, $user3->id, 0, 1, time() + 60 * 60);
     $manual->enrol_user($maninstance3, $user1->id);
     $manual->enrol_user($maninstance3, $user2->id);
     $manual->enrol_user($maninstance3, $user3->id, 0, 1, time() - 60 * 60);
     $manual->enrol_user($maninstance3, $user4->id, 0, 0, 0, ENROL_USER_SUSPENDED);
     $courses = enrol_get_all_users_courses($CFG->siteguest);
     $this->assertSame(array(), $courses);
     $courses = enrol_get_all_users_courses(0);
     $this->assertSame(array(), $courses);
     // Results are sorted by visibility, sortorder by default (in our case order of creation)
     $courses = enrol_get_all_users_courses($admin->id);
     $this->assertCount(1, $courses);
     $this->assertEquals(array($course1->id), array_keys($courses));
     $courses = enrol_get_all_users_courses($admin->id, true);
     $this->assertCount(0, $courses);
     $this->assertEquals(array(), array_keys($courses));
     $courses = enrol_get_all_users_courses($user1->id);
     $this->assertCount(3, $courses);
     $this->assertEquals(array($course2->id, $course1->id, $course3->id), array_keys($courses));
     $courses = enrol_get_all_users_courses($user1->id, true);
     $this->assertCount(2, $courses);
     $this->assertEquals(array($course2->id, $course3->id), array_keys($courses));
     $courses = enrol_get_all_users_courses($user2->id);
     $this->assertCount(3, $courses);
     $this->assertEquals(array($course2->id, $course1->id, $course3->id), array_keys($courses));
     $courses = enrol_get_all_users_courses($user2->id, true);
     $this->assertCount(2, $courses);
     $this->assertEquals(array($course2->id, $course3->id), array_keys($courses));
     $courses = enrol_get_all_users_courses($user3->id);
     $this->assertCount(2, $courses);
     $this->assertEquals(array($course2->id, $course3->id), array_keys($courses));
     $courses = enrol_get_all_users_courses($user3->id, true);
     $this->assertCount(1, $courses);
     $this->assertEquals(array($course2->id), array_keys($courses));
     $courses = enrol_get_all_users_courses($user4->id);
     $this->assertCount(2, $courses);
     $this->assertEquals(array($course1->id, $course3->id), array_keys($courses));
     $courses = enrol_get_all_users_courses($user4->id, true);
     $this->assertCount(0, $courses);
     $this->assertEquals(array(), array_keys($courses));
     // Make sure sorting and columns work.
     $basefields = array('id', 'category', 'sortorder', 'shortname', 'fullname', 'idnumber', 'startdate', 'visible', 'groupmode', 'groupmodeforce');
     $courses = enrol_get_all_users_courses($user2->id, true);
     $course = reset($courses);
     context_helper::preload_from_record($course);
     $course = (array) $course;
     $this->assertEquals($basefields, array_keys($course), '', 0, 10, true);
     $courses = enrol_get_all_users_courses($user2->id, false, 'modinfo');
     $course = reset($courses);
     $this->assertTrue(property_exists($course, 'modinfo'));
     $courses = enrol_get_all_users_courses($user2->id, false, null, 'id DESC');
     $this->assertEquals(array($course3->id, $course2->id, $course1->id), array_keys($courses));
 }
Ejemplo n.º 9
0
/**
 * Defines core nodes for my profile navigation tree.
 *
 * @param \core_user\output\myprofile\tree $tree Tree object
 * @param stdClass $user user object
 * @param bool $iscurrentuser is the user viewing profile, current user ?
 * @param stdClass $course course object
 *
 * @return bool
 */
function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course)
{
    global $CFG, $USER, $DB;
    $usercontext = context_user::instance($user->id, MUST_EXIST);
    $systemcontext = context_system::instance();
    $context = !empty($course) ? context_course::instance($course->id) : $systemcontext;
    $courseid = !empty($course) ? $course->id : SITEID;
    $contactcategory = new core_user\output\myprofile\category('contact', get_string('userdetails'));
    $coursedetailscategory = new core_user\output\myprofile\category('coursedetails', get_string('coursedetails'), 'contact');
    $miscategory = new core_user\output\myprofile\category('miscellaneous', get_string('miscellaneous'), 'coursedetails');
    $reportcategory = new core_user\output\myprofile\category('reports', get_string('reports'), 'miscellaneous');
    $admincategory = new core_user\output\myprofile\category('administration', get_string('administration'), 'reports');
    $loginactivitycategory = new core_user\output\myprofile\category('loginactivity', get_string('loginactivity'), 'administration');
    // Add categories.
    $tree->add_category($contactcategory);
    $tree->add_category($coursedetailscategory);
    $tree->add_category($miscategory);
    $tree->add_category($reportcategory);
    $tree->add_category($admincategory);
    $tree->add_category($loginactivitycategory);
    // Add core nodes.
    // Full profile node.
    if (!empty($course)) {
        if (empty($CFG->forceloginforprofiles) || $iscurrentuser || has_capability('moodle/user:viewdetails', context_user::instance($user->id)) || has_coursecontact_role($user->id)) {
            $url = new moodle_url('/user/profile.php', array('id' => $user->id));
            $node = new core_user\output\myprofile\node('miscellaneous', 'fullprofile', get_string('fullprofile'), null, $url);
            $tree->add_node($node);
        }
    }
    // Edit profile.
    if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
        if (($iscurrentuser || is_siteadmin($USER) || !is_siteadmin($user)) && has_capability('moodle/user:update', $systemcontext)) {
            $url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => $courseid));
            $node = new core_user\output\myprofile\node('contact', 'editprofile', get_string('editmyprofile'), null, $url);
            $tree->add_node($node);
        } else {
            if (has_capability('moodle/user:editprofile', $usercontext) && !is_siteadmin($user) || $iscurrentuser && has_capability('moodle/user:editownprofile', $systemcontext)) {
                $userauthplugin = false;
                if (!empty($user->auth)) {
                    $userauthplugin = get_auth_plugin($user->auth);
                }
                if ($userauthplugin && $userauthplugin->can_edit_profile()) {
                    $url = $userauthplugin->edit_profile_url();
                    if (empty($url)) {
                        if (empty($course)) {
                            $url = new moodle_url('/user/edit.php', array('userid' => $user->id));
                        } else {
                            $url = new moodle_url('/user/edit.php', array('userid' => $user->id, 'course' => $course->id));
                        }
                    }
                    $node = new core_user\output\myprofile\node('contact', 'editprofile', get_string('editmyprofile'), null, $url);
                    $tree->add_node($node);
                }
            }
        }
    }
    // Preference page. Only visible by administrators.
    if (is_siteadmin()) {
        $url = new moodle_url('/user/preferences.php', array('userid' => $user->id));
        $title = $iscurrentuser ? get_string('mypreferences') : get_string('userspreferences', 'moodle', fullname($user));
        $node = new core_user\output\myprofile\node('administration', 'preferences', $title, null, $url);
        $tree->add_node($node);
    }
    // Login as ...
    if (!$user->deleted && !$iscurrentuser && !\core\session\manager::is_loggedinas() && has_capability('moodle/user:loginas', $context) && !is_siteadmin($user->id)) {
        $url = new moodle_url('/course/loginas.php', array('id' => $courseid, 'user' => $user->id, 'sesskey' => sesskey()));
        $node = new core_user\output\myprofile\node('administration', 'loginas', get_string('loginas'), null, $url);
        $tree->add_node($node);
    }
    // Contact details.
    if (has_capability('moodle/user:viewhiddendetails', $usercontext)) {
        $hiddenfields = array();
    } else {
        $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
    }
    if (has_capability('moodle/site:viewuseridentity', $context)) {
        $identityfields = array_flip(explode(',', $CFG->showuseridentity));
    } else {
        $identityfields = array();
    }
    if (is_mnet_remote_user($user)) {
        $sql = "SELECT h.id, h.name, h.wwwroot,\n                       a.name as application, a.display_name\n                  FROM {mnet_host} h, {mnet_application} a\n                 WHERE h.id = ? AND h.applicationid = a.id";
        $remotehost = $DB->get_record_sql($sql, array($user->mnethostid));
        $remoteuser = new stdclass();
        $remoteuser->remotetype = $remotehost->display_name;
        $hostinfo = new stdclass();
        $hostinfo->remotename = $remotehost->name;
        $hostinfo->remoteurl = $remotehost->wwwroot;
        $node = new core_user\output\myprofile\node('contact', 'mnet', get_string('remoteuser', 'mnet', $remoteuser), null, null, get_string('remoteuserinfo', 'mnet', $hostinfo), null, 'remoteuserinfo');
        $tree->add_node($node);
    }
    if (isset($identityfields['email']) and ($iscurrentuser or $user->maildisplay == 1 or has_capability('moodle/course:useremail', $usercontext) or $user->maildisplay == 2 and enrol_sharing_course($user, $USER))) {
        $node = new core_user\output\myprofile\node('contact', 'email', get_string('email'), null, null, obfuscate_mailto($user->email, ''));
        $tree->add_node($node);
    }
    if (!isset($hiddenfields['country']) && $user->country) {
        $node = new core_user\output\myprofile\node('contact', 'country', get_string('country'), null, null, get_string($user->country, 'countries'));
        $tree->add_node($node);
    }
    if (!isset($hiddenfields['city']) && $user->city) {
        $node = new core_user\output\myprofile\node('contact', 'city', get_string('city'), null, null, $user->city);
        $tree->add_node($node);
    }
    if (isset($identityfields['address']) && $user->address) {
        $node = new core_user\output\myprofile\node('contact', 'address', get_string('address'), null, null, $user->address);
        $tree->add_node($node);
    }
    if (isset($identityfields['phone1']) && $user->phone1) {
        $node = new core_user\output\myprofile\node('contact', 'phone1', get_string('phone'), null, null, $user->phone1);
        $tree->add_node($node);
    }
    if (isset($identityfields['phone2']) && $user->phone2) {
        $node = new core_user\output\myprofile\node('contact', 'phone2', get_string('phone2'), null, null, $user->phone2);
        $tree->add_node($node);
    }
    if (isset($identityfields['institution']) && $user->institution) {
        $node = new core_user\output\myprofile\node('contact', 'institution', get_string('institution'), null, null, $user->institution);
        $tree->add_node($node);
    }
    if (isset($identityfields['department']) && $user->department) {
        $node = new core_user\output\myprofile\node('contact', 'department', get_string('department'), null, null, $user->institution);
        $tree->add_node($node);
    }
    if (isset($identityfields['idnumber']) && $user->idnumber) {
        $node = new core_user\output\myprofile\node('contact', 'idnumber', get_string('idnumber'), null, null, $user->institution);
        $tree->add_node($node);
    }
    if ($user->url && !isset($hiddenfields['webpage'])) {
        $url = $user->url;
        if (strpos($user->url, '://') === false) {
            $url = 'http://' . $url;
        }
        $webpageurl = new moodle_url($url);
        $node = new core_user\output\myprofile\node('contact', 'webpage', get_string('webpage'), null, null, html_writer::link($url, $webpageurl));
        $tree->add_node($node);
    }
    // Printing tagged interests. We want this only for full profile.
    if (!empty($CFG->usetags) && empty($course)) {
        if ($interests = tag_get_tags_csv('user', $user->id)) {
            $node = new core_user\output\myprofile\node('contact', 'interests', get_string('interests'), null, null, $interests);
            $tree->add_node($node);
        }
    }
    if (!isset($hiddenfields['mycourses'])) {
        $showallcourses = optional_param('showallcourses', 0, PARAM_INT);
        if ($mycourses = enrol_get_all_users_courses($user->id, true, null, 'visible DESC, sortorder ASC')) {
            $shown = 0;
            $courselisting = html_writer::start_tag('ul');
            foreach ($mycourses as $mycourse) {
                if ($mycourse->category) {
                    context_helper::preload_from_record($mycourse);
                    $ccontext = context_course::instance($mycourse->id);
                    if (!isset($course) || $mycourse->id != $course->id) {
                        $linkattributes = null;
                        if ($mycourse->visible == 0) {
                            if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
                                continue;
                            }
                            $linkattributes['class'] = 'dimmed';
                        }
                        $params = array('id' => $user->id, 'course' => $mycourse->id);
                        if ($showallcourses) {
                            $params['showallcourses'] = 1;
                        }
                        $url = new moodle_url('/user/view.php', $params);
                        $courselisting .= html_writer::tag('li', html_writer::link($url, $ccontext->get_context_name(false), $linkattributes));
                    } else {
                        $courselisting .= html_writer::tag('li', $course->fullname);
                    }
                }
                $shown++;
                if (!$showallcourses && $shown == $CFG->navcourselimit) {
                    $url = null;
                    if (isset($course)) {
                        $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id, 'showallcourses' => 1));
                    } else {
                        $url = new moodle_url('/user/profile.php', array('id' => $user->id, 'showallcourses' => 1));
                    }
                    $courselisting .= html_writer::tag('li', html_writer::link($url, get_string('viewmore'), array('title' => get_string('viewmore'))));
                    break;
                }
            }
            $courselisting .= html_writer::end_tag('ul');
            if (!empty($mycourses)) {
                // Add this node only if there are courses to display.
                $node = new core_user\output\myprofile\node('coursedetails', 'courseprofiles', get_string('courseprofiles'), null, null, rtrim($courselisting, ', '));
                $tree->add_node($node);
            }
        }
    }
    if (!empty($course)) {
        // Show roles in this course.
        if ($rolestring = get_user_roles_in_course($user->id, $course->id)) {
            $node = new core_user\output\myprofile\node('coursedetails', 'roles', get_string('roles'), null, null, $rolestring);
            $tree->add_node($node);
        }
        // Show groups this user is in.
        if (!isset($hiddenfields['groups']) && !empty($course)) {
            $accessallgroups = has_capability('moodle/site:accessallgroups', $context);
            if ($usergroups = groups_get_all_groups($course->id, $user->id)) {
                $groupstr = '';
                foreach ($usergroups as $group) {
                    if ($course->groupmode == SEPARATEGROUPS and !$accessallgroups and $user->id != $USER->id) {
                        if (!groups_is_member($group->id, $user->id)) {
                            continue;
                        }
                    }
                    if ($course->groupmode != NOGROUPS) {
                        $groupstr .= ' <a href="' . $CFG->wwwroot . '/user/index.php?id=' . $course->id . '&amp;group=' . $group->id . '">' . format_string($group->name) . '</a>,';
                    } else {
                        // The user/index.php shows groups only when course in group mode.
                        $groupstr .= ' ' . format_string($group->name);
                    }
                }
                if ($groupstr !== '') {
                    $node = new core_user\output\myprofile\node('coursedetails', 'groups', get_string('group'), null, null, rtrim($groupstr, ', '));
                    $tree->add_node($node);
                }
            }
        }
        if (!isset($hiddenfields['suspended'])) {
            if ($user->suspended) {
                $node = new core_user\output\myprofile\node('coursedetails', 'suspended', null, null, null, get_string('suspended', 'auth'));
                $tree->add_node($node);
            }
        }
        echo html_writer::end_tag('dl');
    }
    if ($user->icq && !isset($hiddenfields['icqnumber'])) {
        $imurl = new moodle_url('http://web.icq.com/wwp', array('uin' => $user->icq));
        $iconurl = new moodle_url('http://web.icq.com/whitepages/online', array('icq' => $user->icq, 'img' => '5'));
        $statusicon = html_writer::tag('img', '', array('src' => $iconurl, 'class' => 'icon icon-post', 'alt' => get_string('status')));
        $node = new core_user\output\myprofile\node('contact', 'icqnumber', get_string('icqnumber'), null, null, html_writer::link($imurl, s($user->icq) . $statusicon));
        $tree->add_node($node);
    }
    if ($user->skype && !isset($hiddenfields['skypeid'])) {
        $imurl = 'skype:' . urlencode($user->skype) . '?call';
        $iconurl = new moodle_url('http://mystatus.skype.com/smallicon/' . urlencode($user->skype));
        if (is_https()) {
            // Bad luck, skype devs are lazy to set up SSL on their servers - see MDL-37233.
            $statusicon = '';
        } else {
            $statusicon = html_writer::empty_tag('img', array('src' => $iconurl, 'class' => 'icon icon-post', 'alt' => get_string('status')));
        }
        $node = new core_user\output\myprofile\node('contact', 'skypeid', get_string('skypeid'), null, null, html_writer::link($imurl, s($user->skype) . $statusicon));
        $tree->add_node($node);
    }
    if ($user->yahoo && !isset($hiddenfields['yahooid'])) {
        $imurl = new moodle_url('http://edit.yahoo.com/config/send_webmesg', array('.target' => $user->yahoo, '.src' => 'pg'));
        $iconurl = new moodle_url('http://opi.yahoo.com/online', array('u' => $user->yahoo, 'm' => 'g', 't' => '0'));
        $statusicon = html_writer::tag('img', '', array('src' => $iconurl, 'class' => 'iconsmall icon-post', 'alt' => get_string('status')));
        $node = new core_user\output\myprofile\node('contact', 'yahooid', get_string('yahooid'), null, null, html_writer::link($imurl, s($user->yahoo) . $statusicon));
        $tree->add_node($node);
    }
    if ($user->aim && !isset($hiddenfields['aimid'])) {
        $imurl = 'aim:goim?screenname=' . urlencode($user->aim);
        $node = new core_user\output\myprofile\node('contact', 'aimid', get_string('aimid'), null, null, html_writer::link($imurl, s($user->aim)));
        $tree->add_node($node);
    }
    if ($user->msn && !isset($hiddenfields['msnid'])) {
        $node = new core_user\output\myprofile\node('contact', 'msnid', get_string('msnid'), null, null, s($user->msn));
        $tree->add_node($node);
    }
    if ($categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) {
        foreach ($categories as $category) {
            if ($fields = $DB->get_records('user_info_field', array('categoryid' => $category->id), 'sortorder ASC')) {
                foreach ($fields as $field) {
                    require_once $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php';
                    $newfield = 'profile_field_' . $field->datatype;
                    $formfield = new $newfield($field->id, $user->id);
                    if ($formfield->is_visible() and !$formfield->is_empty()) {
                        $node = new core_user\output\myprofile\node('contact', $formfield->field->shortname, format_string($formfield->field->name), null, null, $formfield->display_data());
                        $tree->add_node($node);
                    }
                }
            }
        }
    }
    // First access. (Why only for sites ?)
    if (!isset($hiddenfields['firstaccess']) && empty($course)) {
        if ($user->firstaccess) {
            $datestring = userdate($user->firstaccess) . "&nbsp; (" . format_time(time() - $user->firstaccess) . ")";
        } else {
            $datestring = get_string("never");
        }
        $node = new core_user\output\myprofile\node('loginactivity', 'firstaccess', get_string('firstsiteaccess'), null, null, $datestring);
        $tree->add_node($node);
    }
    // Last access.
    if (!isset($hiddenfields['lastaccess'])) {
        if (empty($course)) {
            $string = get_string('lastsiteaccess');
            if ($user->lastaccess) {
                $datestring = userdate($user->lastaccess) . "&nbsp; (" . format_time(time() - $user->lastaccess) . ")";
            } else {
                $datestring = get_string("never");
            }
        } else {
            $string = get_string('lastcourseaccess');
            if ($lastaccess = $DB->get_record('user_lastaccess', array('userid' => $user->id, 'courseid' => $course->id))) {
                $datestring = userdate($lastaccess->timeaccess) . "&nbsp; (" . format_time(time() - $lastaccess->timeaccess) . ")";
            } else {
                $datestring = get_string("never");
            }
        }
        $node = new core_user\output\myprofile\node('loginactivity', 'lastaccess', $string, null, null, $datestring);
        $tree->add_node($node);
    }
    // Last ip.
    if (has_capability('moodle/user:viewlastip', $usercontext) && !isset($hiddenfields['lastip'])) {
        if ($user->lastip) {
            $iplookupurl = new moodle_url('/iplookup/index.php', array('ip' => $user->lastip, 'user' => $USER->id));
            $ipstring = html_writer::link($iplookupurl, $user->lastip);
        } else {
            $ipstring = get_string("none");
        }
        $node = new core_user\output\myprofile\node('loginactivity', 'lastip', get_string('lastip'), null, null, $ipstring);
        $tree->add_node($node);
    }
}
            }
        }
        if ($availableRecord == Null) {
            // Add one button for return
            die("No Valid Record!");
        }
    }
}
// When user is staff and doing update
if (in_array("staff", $identity) && (array_key_exists("submitType", $_POST) && $_POST['submitType'] == "update")) {
    // register_id not null
    $userId = $availableRecord['register_id'];
} else {
    $userId = $USER->id;
}
$selectedCourses = enrol_get_all_users_courses($userId);
$courseTeacherMap = obtainCourseTeacherMap($userId, $selectedCourses);
$courseTeacherMapJson = json_encode($courseTeacherMap);
echo $OUTPUT->header();
?>
<link rel="stylesheet" type="text/css"
	href="<?php 
echo $CFG->wwwroot;
?>
/lib/jquery/ui-1.10.4/css/base/jquery-ui.min.css">
<link rel="stylesheet" type="text/css"
	href="<?php 
echo $CFG->wwwroot;
?>
/testreservation/css/testReservationForm.css">
Ejemplo n.º 11
0
$teacherroleid = 3;
$logged = false;
$PAGE->set_context(context_system::instance());
// Id of the exam to be deleted.
$activityid = required_param('id', PARAM_INT);
$check = optional_param('create', 0, PARAM_INT);
$forkingUrl = new moodle_url($CFG->wwwroot . '/mod/emarking/activities/forking.php', array('id' => $activityid));
$editUrl = new moodle_url($CFG->wwwroot . '/mod/emarking/activities/edit.php', array('id' => $activityid));
$pdfUrl = new moodle_url($CFG->wwwroot . '/mod/emarking/activities/pdfcreator.php', array('id' => $activityid));
if (isset($check) && $check == 1) {
    $message = "eMarking creado exitosamente.";
    echo "<script type='text/javascript'>alert('{$message}');</script>";
}
if (isloggedin()) {
    $logged = true;
    $courses = enrol_get_all_users_courses($USER->id);
    $countcourses = count($courses);
    foreach ($courses as $course) {
        $context = context_course::instance($course->id);
        $roles = get_user_roles($context, $USER->id, true);
        foreach ($roles as $rol) {
            if ($rol->roleid == $teacherroleid) {
                $asteachercourses[$course->id] = $course->fullname;
            }
        }
    }
}
$activity = $DB->get_record('emarking_activities', array('id' => $activityid));
$user_object = $DB->get_record('user', array('id' => $activity->userid));
$rubric = $DB->get_records_sql("SELECT grl.id,\n\t\t\t\t\t\t\t\t\t gd.description as des,\n\t\t\t\t\t\t\t\t\t grc.id as grcid,\n\t\t\t\t\t\t\t\t\t grl.score,\n\t\t\t\t\t\t\t\t\t grl.definition, \n\t\t\t\t\t\t\t\t\t grc.description, \n\t\t\t\t\t\t\t\t\t grc.sortorder, \n\t\t\t\t\t\t\t\t\t gd.name as name\n\t\t\t\t\t\t\t  FROM {gradingform_rubric_levels} as grl,\n\t \t\t\t\t\t\t\t   {gradingform_rubric_criteria} as grc,\n    \t\t\t\t\t\t\t   {grading_definitions} as gd\n\t\t\t\t\t\t\t  WHERE gd.id=? AND grc.definitionid=gd.id AND grc.id=grl.criterionid\n\t\t\t\t\t\t\t  ORDER BY grcid, grl.id", array($activity->rubricid));
foreach ($rubric as $data) {
Ejemplo n.º 12
0
 /**
  * In moodle a course is owned by an INTUITEL user if he has the permission block/intuitel:externallyedit
  * @see \intuitel\IntuitelAdaptor::getCoursesOwnedByUser()
  * @global type $CFG
  * @param \intuitel\UserId $user_id
  * @return array
  */
 public function getCoursesOwnedByUser(UserId $user_id)
 {
     global $CFG;
     require_once $CFG->libdir . '/accesslib.php';
     $user = $this->getNativeUserFromUId($user_id);
     //Get courses enrolled
     $mycourses = enrol_get_all_users_courses($user->id, true, NULL, 'visible DESC,sortorder ASC');
     $editable_courses = array();
     foreach ($mycourses as $mycourse) {
         \context_helper::preload_from_record($mycourse);
         $ccontext = \context_course::instance($mycourse->id);
         if (has_capability('block/intuitel:externallyedit', $ccontext, $user)) {
             $course_info = get_fast_modinfo($mycourse->id, $user->id);
             $editable_courses[] = $this->createLOFromNative($course_info, 'course');
         }
     }
     return $editable_courses;
 }
Ejemplo n.º 13
0
/**
 * returns the list of courses related to a user with id of $id
 * 
 * @global type $DB
 * @param type $id
 * @param type $role = {"student" , "teacher"}
 * @param type $cyear
 * @param type $csem
 * @return type
 */
function coursesas($id, $role)
{
    global $DB;
    $allcourses = enrol_get_all_users_courses($id);
    $courses = array();
    $i = 0;
    $cohortids = getcohortids();
    $cohortcourses = array();
    if (count($cohortids) > 0) {
        $query = "select distinct e.courseid from {enrol} e, {cohort} co where " . "e.customint1 = co.id and (co.idnumber like '" . current($cohortids)->term_id . "%'";
        for ($i = 1; $i < count($cohortids); $i++) {
            $query .= " or co.idnumber like '" . next($cohortids)->term_id . "%'";
        }
        $query .= ")";
        $cohortcourses = $DB->get_records_sql($query);
    }
    foreach ($allcourses as $course) {
        $isin = false;
        foreach ($cohortcourses as $cohortcourse) {
            if ($cohortcourse->courseid == $course->id) {
                $isin = true;
            }
        }
        if (!$isin) {
            continue;
        }
        if ($role == 'student') {
            if (isstudentincourse($id, $course->id)) {
                array_push($courses, $course);
            }
        }
        if ($role == 'teacher') {
            if (isteacherincourse($id, $course->id)) {
                array_push($courses, $course);
            }
        }
    }
    return $courses;
}
Ejemplo n.º 14
0
/**
 * Returns list of courses user is enrolled into.
 * (Note: use enrol_get_all_users_courses if you want to use the list wihtout any cap checks )
 *
 * - $fields is an array of fieldnames to ADD
 *   so name the fields you really need, which will
 *   be added and uniq'd
 *
 * @param int $userid
 * @param bool $onlyactive return only active enrolments in courses user may see
 * @param string|array $fields
 * @param string $sort
 * @return array
 */
function enrol_get_users_courses($userid, $onlyactive = false, $fields = NULL, $sort = 'visible DESC,sortorder ASC')
{
    global $DB;
    $courses = enrol_get_all_users_courses($userid, $onlyactive, $fields, $sort);
    // preload contexts and check visibility
    if ($onlyactive) {
        foreach ($courses as $id => $course) {
            context_instance_preload($course);
            if (!$course->visible) {
                if (!($context = context_course::instance($id))) {
                    unset($courses[$id]);
                    continue;
                }
                if (!has_capability('moodle/course:viewhiddencourses', $context, $userid)) {
                    unset($courses[$id]);
                    continue;
                }
            }
        }
    }
    return $courses;
}
Ejemplo n.º 15
0
 /**
  * Get courses where user has the ability to view the gradebook.
  *
  * @param int $userid
  * @return array
  * @throws \coding_exception
  */
 public static function gradeable_courseids($userid)
 {
     $courses = enrol_get_all_users_courses($userid);
     $courseids = [];
     $capability = 'gradereport/grader:view';
     foreach ($courses as $course) {
         if (has_capability($capability, \context_course::instance($course->id), $userid)) {
             $courseids[] = $course->id;
         }
     }
     return $courseids;
 }
Ejemplo n.º 16
0
 /**
  * Render all grading CTAs for markers
  * @return string
  */
 protected function render_grading()
 {
     global $USER;
     if (!$this->feedback_toggle_enabled()) {
         return '';
     }
     $courses = enrol_get_all_users_courses($USER->id);
     $capability = 'gradereport/grader:view';
     foreach ($courses as $course) {
         if (has_capability($capability, \context_course::instance($course->id), $USER->id)) {
             $courseids[] = $course->id;
         }
     }
     if (empty($courseids)) {
         return '';
     }
     $gradingheading = get_string('grading', 'theme_snap');
     $o = "<h2>{$gradingheading}</h2>";
     $o .= '<div id="snap-personal-menu-grading"></div>';
     return $o;
 }