/**
  * Adapt creating competency from framework idnumber or frameworkid.
  *
  * @param array $data
  * @return array
  */
 protected function preprocess_competency($data)
 {
     if (isset($data['framework'])) {
         $framework = competency_framework::get_record(array('idnumber' => $data['framework']));
         if ($framework) {
             $data['competencyframeworkid'] = $framework->get_id();
         } else {
             $framework = competency_framework::get_record(array('id' => $data['framework']));
             if ($framework) {
                 $data['competencyframeworkid'] = $framework->get_id();
             } else {
                 throw new Exception('Could not resolve framework with idnumber or id : "' . $data['category'] . '"');
             }
         }
     }
     unset($data['framework']);
     return $data;
 }
Esempio n. 2
0
 /**
  * Process a course module competency.
  *
  * @param array $data The data.
  */
 public function process_course_module_competency($data)
 {
     $data = (object) $data;
     // Mapping the competency by ID numbers.
     $framework = \core_competency\competency_framework::get_record(array('idnumber' => $data->frameworkidnumber));
     if (!$framework) {
         return;
     }
     $competency = \core_competency\competency::get_record(array('idnumber' => $data->idnumber, 'competencyframeworkid' => $framework->get_id()));
     if (!$competency) {
         return;
     }
     $params = array('competencyid' => $competency->get_id(), 'cmid' => $this->task->get_moduleid());
     $query = 'competencyid = :competencyid AND cmid = :cmid';
     $existing = \core_competency\course_module_competency::record_exists_select($query, $params);
     if (!$existing) {
         // Sortorder is ignored by precaution, anyway we should walk through the records in the right order.
         $record = (object) $params;
         $record->ruleoutcome = $data->ruleoutcome;
         $coursemodulecompetency = new \core_competency\course_module_competency(0, $record);
         $coursemodulecompetency->create();
     }
 }