コード例 #1
0
 function get_item_display_name($column, $item)
 {
     global $CFG, $USER;
     if (has_capability('moodle/user:viewdetails', get_context_instance(CONTEXT_USER, $USER->id))) {
         $moodle_link_begin = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . cm_get_moodleuserid($item->userid) . '" alt="Moodle profile" title="Moodle profile">';
         $moodle_link_end = ' <img src="' . $CFG->wwwroot . '/curriculum/pix/moodle.gif" alt="Moodle profile" title="Moodle profile" /></a>';
     } else {
         $moodle_link_begin = '';
         $moodle_link_end = '';
     }
     return $moodle_link_begin . $item->name . $moodle_link_end;
 }
コード例 #2
0
ファイル: student.class.php プロジェクト: jamesmcq/elis
 /**
  * Perform all necessary tasks to save a student enrolment.
  * @return bool true on success
  * @throws Exception
  * @uses $DB
  * @uses $USER
  * @uses events_trigger()
  */
 function save()
 {
     global $DB, $USER;
     try {
         validation_helper::is_unique_userid_classid($this);
     } catch (Exception $e) {
         // already enrolled -- pretend we succeeded
         // error_log('student.class::add() - student already enrolled!');
         // Note: this prevents Moodle Course enrolment when Moodle Course is
         // attached *after* initial student enrolment
         // forcing student to be unenroled then re-enroled to get enrolled
         // in the newly attached Moodle Course
         return true;
     }
     //set end time based on class duration
     if (empty($this->id) && empty($this->endtime) && !empty($this->classid)) {
         $studentclass = $this->pmclass;
         $duration = $studentclass->duration;
         if (!empty($duration)) {
             $this->endtime = $this->enrolmenttime + $duration;
         } else {
             // no class duration -> no end time
             $this->endtime = 0;
         }
     }
     if ($this->completestatusid != STUSTATUS_NOTCOMPLETE) {
         $this->update();
     } else {
         parent::save();
     }
     /// Enrol them into the Moodle class, if not already enrolled.
     if (empty($this->no_moodle_enrol) && ($moodlecourseid = moodle_get_course($this->classid))) {
         if ($mcourse = $this->_db->get_record('course', array('id' => $moodlecourseid))) {
             $plugin = enrol_get_plugin('elis');
             $enrol = $plugin->get_or_create_instance($mcourse);
             $user = $this->users;
             if (!($muser = $user->get_moodleuser())) {
                 if (!($muserid = $user->synchronize_moodle_user(true, true))) {
                     throw new Exception(get_string('errorsynchronizeuser', self::LANG_FILE));
                 }
             } else {
                 $muserid = $muser->id;
             }
             $context = context_course::instance($moodlecourseid);
             if (!is_enrolled($context, $muserid)) {
                 $flag = false;
                 if (empty($USER) || !isset($USER->id)) {
                     $flag = true;
                     if (!is_object($USER)) {
                         $saveuser = $USER;
                         $USER = new stdClass();
                     } else {
                         $saveuser = clone $USER;
                     }
                     $USER->id = get_admin()->id;
                 }
                 $caughtex = null;
                 try {
                     $plugin->enrol_user($enrol, $muserid, $enrol->roleid, $this->enrolmenttime, $this->endtime ? $this->endtime : 0);
                 } catch (Exception $e) {
                     $caughtex = $e;
                 }
                 if ($flag) {
                     $USER = $saveuser;
                 }
                 if ($caughtex) {
                     throw $caughtex;
                 }
             }
         }
     } else {
         $sturole = get_config('elisprogram_enrolrolesync', 'student_role');
         // ELIS-3397: must still trigger events for notifications
         $sturole = get_config('elisprogram_enrolrolesync', 'student_role');
         $ra = new stdClass();
         $ra->roleid = !empty($sturole) ? $sturole : $DB->get_field('role', 'id', array('shortname' => 'student'));
         $ra->contextid = \local_elisprogram\context\pmclass::instance($this->classid)->id;
         $ra->userid = cm_get_moodleuserid($this->userid);
         $ra->component = 'enrol_elis';
         $ra->timemodified = time();
         $ra->modifierid = empty($USER->id) ? 0 : $USER->id;
         events_trigger('role_assigned', $ra);
     }
     return;
 }
コード例 #3
0
 /**
  * Prints a detailed view of a specific record.
  */
 function action_view()
 {
     global $CFG;
     $id = required_param('id', PARAM_INT);
     $obj = new $this->data_class($id);
     $moodle_id = cm_get_moodleuserid($id);
     if (!empty($moodle_id)) {
         $obj->username = '******' . $CFG->wwwroot . '/user/view.php?id=' . $moodle_id . '">' . $obj->username . '</a>';
     }
     $form = new $this->form_class(null, array('obj' => $obj));
     $form->freeze();
     $this->print_tabs('view', array('id' => $id));
     $form->display();
     $this->print_delete_button($obj);
 }
コード例 #4
0
ファイル: user.class.php プロジェクト: remotelearner/elis.cm
 public function delete()
 {
     global $CFG;
     $result = false;
     $muser = cm_get_moodleuserid($this->id);
     if (empty($muser) || !is_primary_admin($muser)) {
         $level = context_level_base::get_custom_context_level('user', 'block_curr_admin');
         $result = attendance::delete_for_user($this->id);
         $result = $result && curriculumstudent::delete_for_user($this->id);
         $result = $result && instructor::delete_for_user($this->id);
         $result = $result && student::delete_for_user($this->id);
         $result = $result && student_grade::delete_for_user($this->id);
         $result = $result && usertrack::delete_for_user($this->id);
         $result = $result && usercluster::delete_for_user($this->id);
         $result = $result && clusterassignment::delete_for_user($this->id);
         $result = $result && waitlist::delete_for_user($this->id);
         $result = $result && delete_context($level, $this->id);
         // Delete Moodle user.
         if ($muser = get_record('user', 'idnumber', $this->idnumber, 'mnethostid', $CFG->mnet_localhost_id, 'deleted', 0)) {
             $result = $result && delete_user($muser);
         }
         $result = $result && parent::delete();
     }
     return $result;
 }
コード例 #5
0
 /**
  * Perform all necessary tasks to remove a student enrolment from the system.
  */
 function delete()
 {
     /// Remove any grade records for this enrolment.
     $result = student_grade::delete_for_user_and_class($this->userid, $this->classid);
     /// Unenrol them from the Moodle class.
     if (!empty($this->classid) && !empty($this->userid) && ($moodlecourseid = get_field('crlm_class_moodle', 'moodlecourseid', 'classid', $this->classid)) && ($muserid = cm_get_moodleuserid($this->userid))) {
         $context = get_context_instance(CONTEXT_COURSE, $moodlecourseid);
         if ($context && $context->id) {
             role_unassign(0, $muserid, 0, $context->id);
         }
     }
     $result = $result && $this->data_delete_record();
     if ($this->completestatusid == STUSTATUS_NOTCOMPLETE) {
         $cmclass = new cmclass($this->classid);
         if (empty($cmclass->maxstudents) || $cmclass->maxstudents > student::count_enroled($cmclass->id)) {
             $wlst = waitlist::get_next($this->classid);
             if (!empty($wlst)) {
                 $wlst->enrol();
             }
         }
     }
     return $result;
 }
コード例 #6
0
 protected function process_unassignment($data)
 {
     $context = $this->get_context();
     if (!user_can_assign($context, $data->role)) {
         print_error('nopermissions', 'error');
     }
     foreach ($data->_selection as $user) {
         role_unassign($data->role, cm_get_moodleuserid($user), 0, $context->id);
     }
     $tmppage = $this->get_basepage();
     redirect($tmppage->get_url(), get_string('users_removed_from_role', 'block_curr_admin', count($data->_selection)));
 }
コード例 #7
0
ファイル: lib.php プロジェクト: remotelearner/elis.alfresco
/**
 * Handle the event when a user is unassigned to a cluster.
 *
 * @uses $CFG
 * @param object $clusterinfo The Moodle role_assignment record object.
 * @return bool True on success or failure (event handlers must always return true).
 */
function block_repository_cluster_deassigned($clusterinfo)
{
    global $CFG;
    // Only proceed here if the Alfresco plug-in is actually enabled.
    if (!isset($CFG->repository_plugins_enabled) || strstr($CFG->repository_plugins_enabled, 'alfresco') === false || !($repo = repository_factory::factory('alfresco'))) {
        return true;
    }
    // Get the Moodle user ID from the CM user ID.
    if (!($muserid = cm_get_moodleuserid($clusterinfo->userid))) {
        return true;
    }
    if (!($username = get_field('user', 'username', 'id', $muserid))) {
        return true;
    }
    if (!($cluster = get_record('crlm_cluster', 'id', $clusterinfo->clusterid))) {
        return true;
    }
    // Does this organization have an Alfresco storage space?
    if (!($uuid = $repo->get_organization_store($cluster->id, false))) {
        return true;
    }
    $context = get_context_instance(context_level_base::get_custom_context_level('cluster', 'block_curr_admin'), $cluster->id);
    $sql = "SELECT rc.*\n            FROM {$CFG->prefix}role_capabilities rc\n            INNER JOIN {$CFG->prefix}role r ON r.id = rc.roleid\n            INNER JOIN {$CFG->prefix}role_assignments ra ON ra.roleid = r.id\n            WHERE ra.contextid = {$context->id}\n            AND ra.userid = {$muserid}\n            AND rc.capability = 'block/repository:createorganizationcontent'\n            AND rc.permission = " . CAP_ALLOW;
    // Check if the user has a specific role assignment on the cluster context with the editing capability
    if (!record_exists_sql($sql)) {
        // Remove all non-editing permissions for this user on the organization shared space.
        if ($permissions = alfresco_get_permissions($uuid, $username)) {
            foreach ($permissions as $permission) {
                // Do not remove editing permissions if this user still actually has a cluster membership.
                if ($permission == ALFRESCO_ROLE_COLLABORATOR) {
                    continue;
                }
                alfresco_set_permission($username, $uuid, $permission, ALFRESCO_CAPABILITY_DENIED);
            }
        }
        // Remove all permissions for this user on the organization shared space.
    } else {
        if ($permissions = alfresco_get_permissions($uuid, $username)) {
            foreach ($permissions as $permission) {
                // Do not remove view permissions if this user still actually has a cluster membership.
                if ($permission == ALFRESCO_ROLE_CONSUMER && record_exists('crlm_usercluster', 'userid', $clusterinfo->userid, 'clusterid', $cluster->id, 'leader', 0)) {
                    continue;
                }
                alfresco_set_permission($username, $uuid, $permission, ALFRESCO_CAPABILITY_DENIED);
            }
        }
    }
    return true;
}
コード例 #8
0
ファイル: rolepage.class.php プロジェクト: jamesmcq/elis
 protected function process_unassignment($data)
 {
     $this->session_selection_deletion();
     $context = $this->get_context();
     //make sure the current user can assign roles on the current context
     $assignableroles = get_assignable_roles($context, ROLENAME_BOTH);
     $roleids = array_keys($assignableroles);
     if (!in_array($data->role, $roleids)) {
         print_error('nopermissions', 'error');
     }
     //perform the role unassignments
     foreach ($data->_selection as $user) {
         role_unassign($data->role, cm_get_moodleuserid($user), $context->id);
     }
     //set up the redirect to the appropriate page
     $id = $this->required_param('id', PARAM_INT);
     $role = $this->required_param('role', PARAM_INT);
     $tmppage = $this->get_new_page(array('_assign' => 'unassign', 'id' => $id, 'role' => $role));
     redirect($tmppage->url, get_string('users_removed_from_role', 'local_elisprogram', count($data->_selection)));
 }