Esempio n. 1
0
 /**
  * Add a competency to this template.
  *
  * @param int $templateid The id of the template
  * @param int $competencyid The id of the competency
  * @return bool
  */
 public static function add_competency_to_template($templateid, $competencyid)
 {
     static::require_enabled();
     // First we do a permissions check.
     $template = new template($templateid);
     if (!$template->can_manage()) {
         throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage', 'nopermissions', '');
     }
     $record = new stdClass();
     $record->templateid = $templateid;
     $record->competencyid = $competencyid;
     $competency = new competency($competencyid);
     // Can not add a competency that belong to a hidden framework.
     if ($competency->get_framework()->get_visible() == false) {
         throw new coding_exception('A competency belonging to hidden framework can not be added');
     }
     $exists = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyid));
     if (!$exists) {
         $templatecompetency = new template_competency(0, $record);
         $templatecompetency->create();
         return true;
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Create a template competency.
  *
  * @param array|stdClass $record
  * @return template_competency
  */
 public function create_template_competency($record = null)
 {
     $record = (object) $record;
     if (!isset($record->competencyid)) {
         throw new coding_exception('Property competencyid is required.');
     }
     if (!isset($record->templateid)) {
         throw new coding_exception('Property templateid is required.');
     }
     $relation = new template_competency(0, $record);
     $relation->create();
     return $relation;
 }