예제 #1
0
 /**
  * Approve a plan.
  *
  * This means making the plan active.
  *
  * @param  int|plan $planorid The plan, or its ID.
  * @return bool
  */
 public static function approve_plan($planorid)
 {
     static::require_enabled();
     $plan = $planorid;
     if (!is_object($plan)) {
         $plan = new plan($plan);
     }
     // We need to be able to view the plan at least.
     if (!$plan->can_read()) {
         throw new required_capability_exception($plan->get_context(), 'moodle/competency:planview', 'nopermissions', '');
     }
     // We can approve a plan that is either a draft, in review, or waiting for review.
     if ($plan->is_based_on_template()) {
         throw new coding_exception('Template plans are already approved.');
         // This should never happen.
     } else {
         if (!$plan->is_draft()) {
             throw new coding_exception('The plan cannot be approved at this stage.');
         } else {
             if (!$plan->can_review()) {
                 throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
             }
         }
     }
     $plan->set_status(plan::STATUS_ACTIVE);
     $plan->set_reviewerid(null);
     $result = $plan->update();
     // Trigger approved event.
     \core\event\competency_plan_approved::create_from_plan($plan)->trigger();
     return $result;
 }