original_string: public static function finish_attempt($lessonid, $password = '', $outoftime = false, $review = false) {
  
          $params = array('lessonid' => $lessonid, 'password' => $password, 'outoftime' => $outoftime, 'review' => $review);
          $params = self::validate_parameters(self::finish_attempt_parameters(), $params);
  
          $warnings = array();
  
          list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']);
  
          // Update timer so the validation can check the time restrictions.
          $timer = $lesson->update_timer();
  
          // Return the validation to avoid exceptions in case the user is out of time.
          $params['pageid'] = LESSON_EOL;
          $validation = self::validate_attempt($lesson, $params, true);
  
          if (array_key_exists('eolstudentoutoftime', $validation)) {
              // Maybe we run out of time just now.
              $params['outoftime'] = true;
              unset($validation['eolstudentoutoftime']);
          }
          // Check if there are more errors.
          if (!empty($validation)) {
              reset($validation);
              throw new moodle_exception(key($validation), 'lesson', '', current($validation));   // Throw first error.
          }
  
          // Set out of time to normal (it is the only existing mode).
          $outoftimemode = $params['outoftime'] ? 'normal' : '';
          $result = $lesson->process_eol_page($outoftimemode);
  
          // Return the data.
           $validmessages = array(
              'notenoughtimespent', 'numberofpagesviewed', 'youshouldview', 'numberofcorrectanswers',
              'displayscorewithessays', 'displayscorewithoutessays', 'yourcurrentgradeisoutof', 'eolstudentoutoftimenoanswers',
              'welldone', 'displayofgrade', 'modattemptsnoteacher', 'progresscompleted');
  
          $data = array();
          foreach ($result as $el => $value) {
              if ($value !== false) {
                  $message = '';
                  if (in_array($el, $validmessages)) { // Check if the data comes with an informative message.
                      $a = (is_bool($value)) ? null : $value;
                      $message = get_string($el, 'lesson', $a);
                  }
                  // Return the data.
                  $data[] = array(
                      'name' => $el,
                      'value' => (is_bool($value)) ? 1 : json_encode($value), // The data can be a php object.
                      'message' => $message
                  );
              }
          }
  
          $result = array(
              'data'     => $data,
              'messages' => self::format_lesson_messages($lesson),
              'warnings' => $warnings,
          );
          return $result;
      }
code: public static function finish_attempt($lessonid, $password = '', $outoftime = false, $review = false) {
  
          $params = array('lessonid' => $lessonid, 'password' => $password, 'outoftime' => $outoftime, 'review' => $review);
          $params = self::validate_parameters(self::finish_attempt_parameters(), $params);
  
          $warnings = array();
  
          list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']);
  
          // Update timer so the validation can check the time restrictions.
          $timer = $lesson->update_timer();
  
          // Return the validation to avoid exceptions in case the user is out of time.
          $params['pageid'] = LESSON_EOL;
          $validation = self::validate_attempt($lesson, $params, true);
  
          if (array_key_exists('eolstudentoutoftime', $validation)) {
              // Maybe we run out of time just now.
              $params['outoftime'] = true;
              unset($validation['eolstudentoutoftime']);
          }
          // Check if there are more errors.
          if (!empty($validation)) {
              reset($validation);
              throw new moodle_exception(key($validation), 'lesson', '', current($validation));   // Throw first error.
          }
  
          // Set out of time to normal (it is the only existing mode).
          $outoftimemode = $params['outoftime'] ? 'normal' : '';
          $result = $lesson->process_eol_page($outoftimemode);
  
          // Return the data.
           $validmessages = array(
              'notenoughtimespent', 'numberofpagesviewed', 'youshouldview', 'numberofcorrectanswers',
              'displayscorewithessays', 'displayscorewithoutessays', 'yourcurrentgradeisoutof', 'eolstudentoutoftimenoanswers',
              'welldone', 'displayofgrade', 'modattemptsnoteacher', 'progresscompleted');
  
          $data = array();
          foreach ($result as $el => $value) {
              if ($value !== false) {
                  $message = '';
                  if (in_array($el, $validmessages)) { // Check if the data comes with an informative message.
                      $a = (is_bool($value)) ? null : $value;
                      $message = get_string($el, 'lesson', $a);
                  }
                  // Return the data.
                  $data[] = array(
                      'name' => $el,
                      'value' => (is_bool($value)) ? 1 : json_encode($value), // The data can be a php object.
                      'message' => $message
                  );
              }
          }
  
          $result = array(
              'data'     => $data,
              'messages' => self::format_lesson_messages($lesson),
              'warnings' => $warnings,
          );
          return $result;
      }
code_tokens: public static function finish_attempt ( $ lessonid , $ password = '' , $ outoftime = false , $ review = false ) { $ params = array ( 'lessonid' => $ lessonid , 'password' => $ password , 'outoftime' => $ outoftime , 'review' => $ review ) ; $ params = self :: validate_parameters ( self :: finish_attempt_parameters ( ) , $ params ) ; $ warnings = array ( ) ; list ( $ lesson , $ course , $ cm , $ context , $ lessonrecord ) = self :: validate_lesson ( $ params [ 'lessonid' ] ) ; // Update timer so the validation can check the time restrictions. $ timer = $ lesson -> update_timer ( ) ; // Return the validation to avoid exceptions in case the user is out of time. $ params [ 'pageid' ] = LESSON_EOL ; $ validation = self :: validate_attempt ( $ lesson , $ params , true ) ; if ( array_key_exists ( 'eolstudentoutoftime' , $ validation ) ) { // Maybe we run out of time just now. $ params [ 'outoftime' ] = true ; unset ( $ validation [ 'eolstudentoutoftime' ] ) ; } // Check if there are more errors. if ( ! empty ( $ validation ) ) { reset ( $ validation ) ; throw new moodle_exception ( key ( $ validation ) , 'lesson' , '' , current ( $ validation ) ) ; // Throw first error. } // Set out of time to normal (it is the only existing mode). $ outoftimemode = $ params [ 'outoftime' ] ? 'normal' : '' ; $ result = $ lesson -> process_eol_page ( $ outoftimemode ) ; // Return the data. $ validmessages = array ( 'notenoughtimespent' , 'numberofpagesviewed' , 'youshouldview' , 'numberofcorrectanswers' , 'displayscorewithessays' , 'displayscorewithoutessays' , 'yourcurrentgradeisoutof' , 'eolstudentoutoftimenoanswers' , 'welldone' , 'displayofgrade' , 'modattemptsnoteacher' , 'progresscompleted' ) ; $ data = array ( ) ; foreach ( $ result as $ el => $ value ) { if ( $ value !== false ) { $ message = '' ; if ( in_array ( $ el , $ validmessages ) ) { // Check if the data comes with an informative message. $ a = ( is_bool ( $ value ) ) ? null : $ value ; $ message = get_string ( $ el , 'lesson' , $ a ) ; } // Return the data. $ data [ ] = array ( 'name' => $ el , 'value' => ( is_bool ( $ value ) ) ? 1 : json_encode ( $ value ) , // The data can be a php object. 'message' => $ message ) ; } } $ result = array ( 'data' => $ data , 'messages' => self :: format_lesson_messages ( $ lesson ) , 'warnings' => $ warnings , ) ; return $ result ; }
docstring: Finishes the current attempt.
  
  @param int $lessonid lesson instance id
  @param string $password optional password (the lesson may be protected)
  @param bool $outoftime optional if the user run out of time
  @param bool $review if we want to review just after finishing (1 hour margin)
  @return array of warnings and information about the finished attempt
  @since Moodle 3.3
  @throws moodle_exception
docstring_tokens: Finishes the current attempt .