/**
  * Constructor
  *
  * @param string $elementName Element name
  * @param mixed $elementLabel Label(s) for an element
  * @param array $options Options to control the element's display
  * @param mixed $attributes Either a typical HTML attribute string or an associative array.
  */
 public function __construct($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
 {
     global $OUTPUT;
     if ($elementName == null) {
         // This is broken quickforms messing with the constructors.
         return;
     }
     if (!isset($options['courseid'])) {
         throw new coding_exception('Course id is required for the course_competencies form element');
     }
     $courseid = $options['courseid'];
     if (!empty($options['cmid'])) {
         $current = \core_competency\api::list_course_module_competencies_in_course_module($options['cmid']);
         $ids = array();
         foreach ($current as $coursemodulecompetency) {
             array_push($ids, $coursemodulecompetency->get_competencyid());
         }
         $this->setValue($ids);
     }
     $competencies = api::list_course_competencies($courseid);
     $validoptions = array();
     $context = context_course::instance($courseid);
     foreach ($competencies as $competency) {
         // We don't need to show the description as part of the options, so just set this to null.
         $competency['competency']->set_description(null);
         $exporter = new competency_exporter($competency['competency'], array('context' => $context));
         $templatecontext = array('competency' => $exporter->export($OUTPUT));
         $id = $competency['competency']->get_id();
         $validoptions[$id] = $OUTPUT->render_from_template('tool_lp/competency_summary', $templatecontext);
     }
     $attributes['tags'] = false;
     $attributes['multiple'] = 'multiple';
     parent::__construct($elementName, $elementLabel, $validoptions, $attributes);
 }
예제 #2
0
 /**
  * Construct this renderable.
  * @param int $courseid The course record for this page.
  */
 public function __construct($courseid)
 {
     $this->context = context_course::instance($courseid);
     $this->courseid = $courseid;
     $this->coursecompetencylist = api::list_course_competencies($courseid);
     $this->canmanagecoursecompetencies = has_capability('moodle/competency:coursecompetencymanage', $this->context);
     $this->canconfigurecoursecompetencies = has_capability('moodle/competency:coursecompetencyconfigure', $this->context);
     $this->cangradecompetencies = has_capability('moodle/competency:competencygrade', $this->context);
     $this->coursecompetencysettings = api::read_course_competency_settings($courseid);
     $this->coursecompetencystatistics = new course_competency_statistics($courseid);
     // Check the lowest level in which the user can manage the competencies.
     $this->manageurl = null;
     $this->canmanagecompetencyframeworks = false;
     $contexts = array_reverse($this->context->get_parent_contexts(true));
     foreach ($contexts as $context) {
         $canmanage = has_capability('moodle/competency:competencymanage', $context);
         if ($canmanage) {
             $this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $context->id));
             $this->canmanagecompetencyframeworks = true;
             break;
         }
     }
 }
예제 #3
0
파일: api_test.php 프로젝트: dg711/moodle
 /**
  * Test update ruleoutcome for course_competency.
  */
 public function test_set_ruleoutcome_course_competency()
 {
     $this->resetAfterTest(true);
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $u1 = $dg->create_user();
     $u2 = $dg->create_user();
     $course = $dg->create_course();
     $this->setAdminUser();
     $f = $lpg->create_framework();
     $c = $lpg->create_competency(array('competencyframeworkid' => $f->get_id()));
     $cc = api::add_competency_to_course($course->id, $c->get_id());
     // Check record was created with default rule value Evidence.
     $this->assertEquals(1, \core_competency\course_competency::count_records());
     $recordscc = api::list_course_competencies($course->id);
     $this->assertEquals(\core_competency\course_competency::OUTCOME_EVIDENCE, $recordscc[0]['coursecompetency']->get_ruleoutcome());
     // Check ruleoutcome value is updated to None.
     $this->assertTrue(api::set_course_competency_ruleoutcome($recordscc[0]['coursecompetency']->get_id(), \core_competency\course_competency::OUTCOME_NONE));
     $recordscc = api::list_course_competencies($course->id);
     $this->assertEquals(\core_competency\course_competency::OUTCOME_NONE, $recordscc[0]['coursecompetency']->get_ruleoutcome());
 }
예제 #4
0
파일: external.php 프로젝트: evltuma/moodle
 /**
  * List the competencies (visible to this user) in this course.
  *
  * @param int $courseid The course id to check.
  * @return array
  */
 public static function list_course_competencies($courseid)
 {
     global $PAGE;
     $params = self::validate_parameters(self::list_course_competencies_parameters(), array('id' => $courseid));
     $coursecontext = context_course::instance($params['id']);
     self::validate_context($coursecontext);
     $output = $PAGE->get_renderer('core');
     $competencies = api::list_course_competencies($params['id']);
     $result = array();
     $contextcache = array();
     foreach ($competencies as $competency) {
         if (!isset($contextcache[$competency['competency']->get_competencyframeworkid()])) {
             $contextcache[$competency['competency']->get_competencyframeworkid()] = $competency['competency']->get_context();
         }
         $context = $contextcache[$competency['competency']->get_competencyframeworkid()];
         $exporter = new competency_exporter($competency['competency'], array('context' => $context));
         $competencyrecord = $exporter->export($output);
         $exporter = new course_competency_exporter($competency['coursecompetency'], array('context' => $context));
         $coursecompetencyrecord = $exporter->export($output);
         $result[] = array('competency' => $competencyrecord, 'coursecompetency' => $coursecompetencyrecord);
     }
     return $result;
 }
 /**
  * Export the data.
  *
  * @param renderer_base $output
  * @return stdClass
  */
 public function export_for_template(renderer_base $output)
 {
     global $CFG, $DB, $PAGE;
     $context = context_course::instance($this->courseid);
     $data = new stdClass();
     $data->userid = $this->userid;
     $data->competencyid = $this->competencyid;
     $data->courseid = $this->courseid;
     $data->baseurl = $this->baseurl;
     $data->groupselector = '';
     if (has_any_capability(array('moodle/competency:usercompetencyview', 'moodle/competency:coursecompetencymanage'), $context)) {
         $course = $DB->get_record('course', array('id' => $this->courseid));
         $currentgroup = groups_get_course_group($course, true);
         if ($currentgroup !== false) {
             $select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup);
             $data->groupselector = $select;
         }
         // Fetch showactive.
         $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
         $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
         $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
         $users = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup, 'u.*', null, 0, 0, $showonlyactiveenrol);
         $data->users = array();
         foreach ($users as $user) {
             $exporter = new user_summary_exporter($user);
             $user = $exporter->export($output);
             if ($user->id == $this->userid) {
                 $user->selected = true;
             }
             $data->users[] = $user;
         }
         $data->hasusers = true;
     } else {
         $data->users = array();
         $data->hasusers = false;
     }
     $coursecompetencies = \core_competency\api::list_course_competencies($this->courseid);
     $data->competencies = array();
     $contextcache = array();
     foreach ($coursecompetencies as $coursecompetency) {
         $frameworkid = $coursecompetency['competency']->get_competencyframeworkid();
         if (!isset($contextcache[$frameworkid])) {
             $contextcache[$frameworkid] = $coursecompetency['competency']->get_context();
         }
         $context = $contextcache[$frameworkid];
         $coursecompetencycontext = $context;
         $exporter = new competency_exporter($coursecompetency['competency'], array('context' => $coursecompetencycontext));
         $competency = $exporter->export($output);
         if ($competency->id == $this->competencyid) {
             $competency->selected = true;
         }
         $data->competencies[] = $competency;
     }
     $data->hascompetencies = count($data->competencies);
     return $data;
 }
예제 #6
0
파일: report.php 프로젝트: evltuma/moodle
 /**
  * Export this data so it can be used as the context for a mustache template.
  *
  * @param \renderer_base $output
  * @return stdClass
  */
 public function export_for_template(renderer_base $output)
 {
     global $DB;
     $data = new stdClass();
     $data->courseid = $this->courseid;
     $course = $DB->get_record('course', array('id' => $this->courseid));
     $coursecontext = context_course::instance($course->id);
     $exporter = new course_summary_exporter($course, array('context' => $coursecontext));
     $coursecompetencysettings = api::read_course_competency_settings($course->id);
     $data->pushratingstouserplans = $coursecompetencysettings->get_pushratingstouserplans();
     $data->course = $exporter->export($output);
     $data->usercompetencies = array();
     $scalecache = array();
     $frameworkcache = array();
     $user = core_user::get_user($this->userid);
     $exporter = new user_summary_exporter($user);
     $data->user = $exporter->export($output);
     $data->usercompetencies = array();
     $coursecompetencies = api::list_course_competencies($this->courseid);
     $usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $user->id);
     foreach ($usercompetencycourses as $usercompetencycourse) {
         $onerow = new stdClass();
         $competency = null;
         foreach ($coursecompetencies as $coursecompetency) {
             if ($coursecompetency['competency']->get_id() == $usercompetencycourse->get_competencyid()) {
                 $competency = $coursecompetency['competency'];
                 break;
             }
         }
         if (!$competency) {
             continue;
         }
         // Fetch the framework.
         if (!isset($frameworkcache[$competency->get_competencyframeworkid()])) {
             $frameworkcache[$competency->get_competencyframeworkid()] = $competency->get_framework();
         }
         $framework = $frameworkcache[$competency->get_competencyframeworkid()];
         // Fetch the scale.
         $scaleid = $competency->get_scaleid();
         if ($scaleid === null) {
             $scaleid = $framework->get_scaleid();
             if (!isset($scalecache[$scaleid])) {
                 $scalecache[$competency->get_scaleid()] = $framework->get_scale();
             }
         } else {
             if (!isset($scalecache[$scaleid])) {
                 $scalecache[$competency->get_scaleid()] = $competency->get_scale();
             }
         }
         $scale = $scalecache[$competency->get_scaleid()];
         $exporter = new user_competency_course_exporter($usercompetencycourse, array('scale' => $scale));
         $record = $exporter->export($output);
         $onerow->usercompetencycourse = $record;
         $exporter = new competency_summary_exporter(null, array('competency' => $competency, 'framework' => $framework, 'context' => $framework->get_context(), 'relatedcompetencies' => array(), 'linkedcourses' => array()));
         $onerow->competency = $exporter->export($output);
         array_push($data->usercompetencies, $onerow);
     }
     return $data;
 }