original_string: public static function reopen_plan($planorid) {
          global $DB;
          static::require_enabled();
  
          $plan = $planorid;
          if (!is_object($planorid)) {
              $plan = new plan($planorid);
          }
  
          // Validate that the plan as it is can be managed.
          if (!$plan->can_manage()) {
              $context = context_user::instance($plan->get('userid'));
              throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
          }
  
          $beforestatus = $plan->get('status');
          $plan->set('status', plan::STATUS_ACTIVE);
  
          // Validate if status can be changed.
          if (!$plan->can_manage()) {
              $context = context_user::instance($plan->get('userid'));
              throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
          }
  
          // Wrap the updates in a DB transaction.
          $transaction = $DB->start_delegated_transaction();
  
          // Delete archived user competencies if the status of the plan is changed from complete to another status.
          $mustremovearchivedcompetencies = ($beforestatus == plan::STATUS_COMPLETE && $plan->get('status') != plan::STATUS_COMPLETE);
          if ($mustremovearchivedcompetencies) {
              self::remove_archived_user_competencies_in_plan($plan);
          }
  
          // If duedate less than or equal to duedate_threshold unset it.
          if ($plan->get('duedate') <= time() + plan::DUEDATE_THRESHOLD) {
              $plan->set('duedate', 0);
          }
  
          $success = $plan->update();
  
          if (!$success) {
              $transaction->rollback(new moodle_exception('The plan could not be updated.'));
              return $success;
          }
  
          $transaction->allow_commit();
  
          // Trigger reopened event.
          \core\event\competency_plan_reopened::create_from_plan($plan)->trigger();
  
          return $success;
      }
code: public static function reopen_plan($planorid) {
          global $DB;
          static::require_enabled();
  
          $plan = $planorid;
          if (!is_object($planorid)) {
              $plan = new plan($planorid);
          }
  
          // Validate that the plan as it is can be managed.
          if (!$plan->can_manage()) {
              $context = context_user::instance($plan->get('userid'));
              throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
          }
  
          $beforestatus = $plan->get('status');
          $plan->set('status', plan::STATUS_ACTIVE);
  
          // Validate if status can be changed.
          if (!$plan->can_manage()) {
              $context = context_user::instance($plan->get('userid'));
              throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
          }
  
          // Wrap the updates in a DB transaction.
          $transaction = $DB->start_delegated_transaction();
  
          // Delete archived user competencies if the status of the plan is changed from complete to another status.
          $mustremovearchivedcompetencies = ($beforestatus == plan::STATUS_COMPLETE && $plan->get('status') != plan::STATUS_COMPLETE);
          if ($mustremovearchivedcompetencies) {
              self::remove_archived_user_competencies_in_plan($plan);
          }
  
          // If duedate less than or equal to duedate_threshold unset it.
          if ($plan->get('duedate') <= time() + plan::DUEDATE_THRESHOLD) {
              $plan->set('duedate', 0);
          }
  
          $success = $plan->update();
  
          if (!$success) {
              $transaction->rollback(new moodle_exception('The plan could not be updated.'));
              return $success;
          }
  
          $transaction->allow_commit();
  
          // Trigger reopened event.
          \core\event\competency_plan_reopened::create_from_plan($plan)->trigger();
  
          return $success;
      }
code_tokens: public static function reopen_plan ( $ planorid ) { global $ DB ; static :: require_enabled ( ) ; $ plan = $ planorid ; if ( ! is_object ( $ planorid ) ) { $ plan = new plan ( $ planorid ) ; } // Validate that the plan as it is can be managed. if ( ! $ plan -> can_manage ( ) ) { $ context = context_user :: instance ( $ plan -> get ( 'userid' ) ) ; throw new required_capability_exception ( $ context , 'moodle/competency:planmanage' , 'nopermissions' , '' ) ; } $ beforestatus = $ plan -> get ( 'status' ) ; $ plan -> set ( 'status' , plan :: STATUS_ACTIVE ) ; // Validate if status can be changed. if ( ! $ plan -> can_manage ( ) ) { $ context = context_user :: instance ( $ plan -> get ( 'userid' ) ) ; throw new required_capability_exception ( $ context , 'moodle/competency:planmanage' , 'nopermissions' , '' ) ; } // Wrap the updates in a DB transaction. $ transaction = $ DB -> start_delegated_transaction ( ) ; // Delete archived user competencies if the status of the plan is changed from complete to another status. $ mustremovearchivedcompetencies = ( $ beforestatus == plan :: STATUS_COMPLETE && $ plan -> get ( 'status' ) != plan :: STATUS_COMPLETE ) ; if ( $ mustremovearchivedcompetencies ) { self :: remove_archived_user_competencies_in_plan ( $ plan ) ; } // If duedate less than or equal to duedate_threshold unset it. if ( $ plan -> get ( 'duedate' ) <= time ( ) + plan :: DUEDATE_THRESHOLD ) { $ plan -> set ( 'duedate' , 0 ) ; } $ success = $ plan -> update ( ) ; if ( ! $ success ) { $ transaction -> rollback ( new moodle_exception ( 'The plan could not be updated.' ) ) ; return $ success ; } $ transaction -> allow_commit ( ) ; // Trigger reopened event. \ core \ event \ competency_plan_reopened :: create_from_plan ( $ plan ) -> trigger ( ) ; return $ success ; }
docstring: Reopen a plan.
  
  @param int|plan $planorid The plan, or its ID.
  @return bool
docstring_tokens: Reopen a plan .