예제 #1
0
파일: lib.php 프로젝트: nadavkav/MoodleTAO
/**
 * Check course status and update editing rights for learning path authors 
 *
 * @param integer $status  
 * @param object $course  
 *
 * @return bool
 */
function update_learning_path_editing_access($status, $course)
{
    if (!($context = get_context_instance(CONTEXT_COURSE, $course->id))) {
        print_error('nocontext');
    }
    // get a list of our authors
    $authors = tao_get_lpauthors($context);
    if (!empty($authors)) {
        if ($course->approval_status_id == COURSE_STATUS_NOTSUBMITTED || $course->approval_status_id == COURSE_STATUS_NEEDSCHANGE) {
            // give editing rights to learning path authors
            foreach ($authors as $author) {
                tao_role_assign_by_shortname(ROLE_LPEDITOR, $author->id, $context->id);
            }
        } else {
            // remove editing rights to learning path authors
            foreach ($authors as $author) {
                tao_role_unassign_by_shortname(ROLE_LPEDITOR, $author->id, $context->id);
            }
        }
    }
    // force accessinfo refresh for users visiting this context.
    mark_context_dirty($context->path);
    // success!
    return true;
}
 function get_content()
 {
     global $CFG, $COURSE, $USER;
     $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     // first check whether rafl mode is valid
     if (!$CFG->raflmodeenabled) {
         $this->content = NULL;
         return $this->content;
     }
     if ($COURSE->learning_path_mode != LEARNING_PATH_MODE_RAFL) {
         $this->content = NULL;
         return $this->content;
     }
     if (!has_capability('moodle/local:viewlpcontributors', $context)) {
         $this->content = NULL;
         return $this->content;
     }
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (empty($this->instance)) {
         return '';
     }
     $this->content = new stdClass();
     // display the author of the course
     $users = tao_get_lpauthors($context);
     $this->content->text = '<b>' . get_string('lpleader', 'local') . ': </b>';
     $this->content->text .= '<ul>';
     foreach ($users as $user) {
         $this->content->text .= '<li><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '">' . $user->firstname . ' ' . $user->lastname . '</a>';
     }
     $this->content->text .= '</ul>';
     // display a list of contributors to the course
     $users = tao_get_lpcontributors($context);
     $this->content->text .= '<b>' . get_string('lpcontributors', 'local') . ': </b>';
     if (!empty($users)) {
         $this->content->text .= '<ul>';
         foreach ($users as $user) {
             $this->content->text .= '<li><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '">' . $user->firstname . ' ' . $user->lastname . '</a>';
         }
         $this->content->text .= '</ul>';
     } else {
         $this->content->text .= get_string('nocontributors', 'local');
     }
     // footer
     $this->content->footer = '';
     // if has capability then provide link to manage the list
     if (has_capability('moodle/local:managelpcontributors', $context)) {
         $roleid = get_field('role', 'id', 'shortname', ROLE_LPCONTRIBUTOR);
         $link = $CFG->wwwroot . '/admin/roles/assign.php?contextid=' . $context->id . '&roleid=' . $roleid;
         $this->content->footer .= '<br/><a href="' . $link . '">' . get_string('managelpcontributors', 'local') . '</a><br />';
     }
     return $this->content;
 }