コード例 #1
0
ファイル: api.php プロジェクト: gabrielrosset/moodle
 /**
  * Archive user competencies in a plan.
  *
  * @param int $plan The plan object.
  * @return void
  */
 protected static function archive_user_competencies_in_plan($plan)
 {
     // Check if the plan was already completed.
     if ($plan->get_status() == plan::STATUS_COMPLETE) {
         throw new coding_exception('The plan is already completed.');
     }
     $competencies = $plan->get_competencies();
     $usercompetencies = user_competency::get_multiple($plan->get_userid(), $competencies);
     $i = 0;
     foreach ($competencies as $competency) {
         $found = false;
         foreach ($usercompetencies as $uckey => $uc) {
             if ($uc->get_competencyid() == $competency->get_id()) {
                 $found = true;
                 $ucprecord = $uc->to_record();
                 $ucprecord->planid = $plan->get_id();
                 $ucprecord->sortorder = $i;
                 unset($ucprecord->id);
                 unset($ucprecord->status);
                 unset($ucprecord->reviewerid);
                 $usercompetencyplan = new user_competency_plan(0, $ucprecord);
                 $usercompetencyplan->create();
                 unset($usercompetencies[$uckey]);
                 break;
             }
         }
         // If the user competency doesn't exist, we create a new relation in user_competency_plan.
         if (!$found) {
             $usercompetencyplan = user_competency_plan::create_relation($plan->get_userid(), $competency->get_id(), $plan->get_id());
             $usercompetencyplan->set_sortorder($i);
             $usercompetencyplan->create();
         }
         $i++;
     }
 }
コード例 #2
0
ファイル: lib.php プロジェクト: evltuma/moodle
 /**
  * Create a new user competency plan.
  *
  * @param array|stdClass $record
  * @return user_competency_plan
  */
 public function create_user_competency_plan($record = null)
 {
     $record = (object) $record;
     if (!isset($record->userid)) {
         throw new coding_exception('The userid value is required.');
     }
     if (!isset($record->competencyid)) {
         throw new coding_exception('The competencyid value is required.');
     }
     if (!isset($record->planid)) {
         throw new coding_exception('The planid value is required.');
     }
     if (!isset($record->sortorder)) {
         $record->sortorder = 0;
     }
     $usercompetencyplan = new user_competency_plan(0, $record);
     $usercompetencyplan->create();
     return $usercompetencyplan;
 }