예제 #1
0
 /**
  * Request the review of a plan.
  *
  * @param int|plan $planorid The plan, or its ID.
  * @return bool
  */
 public static function plan_request_review($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', '');
     }
     if ($plan->is_based_on_template()) {
         throw new coding_exception('Template plans cannot be reviewed.');
         // This should never happen.
     } else {
         if ($plan->get_status() != plan::STATUS_DRAFT) {
             throw new coding_exception('The plan cannot be sent for review at this stage.');
         } else {
             if (!$plan->can_request_review()) {
                 throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
             }
         }
     }
     $plan->set_status(plan::STATUS_WAITING_FOR_REVIEW);
     $result = $plan->update();
     // Trigger review requested event.
     \core\event\competency_plan_review_requested::create_from_plan($plan)->trigger();
     return $result;
 }