original_string: public function update_timer($restart=false, $continue=false, $endreached =false) {
          global $USER, $DB;
  
          $cm = get_coursemodule_from_instance('lesson', $this->properties->id, $this->properties->course);
  
          // clock code
          // get time information for this user
          if (!$timer = $this->get_user_timers($USER->id, 'starttime DESC', '*', 0, 1)) {
              $this->start_timer();
              $timer = $this->get_user_timers($USER->id, 'starttime DESC', '*', 0, 1);
          }
          $timer = current($timer); // This will get the latest start time record.
  
          if ($restart) {
              if ($continue) {
                  // continue a previous test, need to update the clock  (think this option is disabled atm)
                  $timer->starttime = time() - ($timer->lessontime - $timer->starttime);
  
                  // Trigger lesson resumed event.
                  $event = \mod_lesson\event\lesson_resumed::create(array(
                      'objectid' => $this->properties->id,
                      'context' => context_module::instance($cm->id),
                      'courseid' => $this->properties->course
                  ));
                  $event->trigger();
  
              } else {
                  // starting over, so reset the clock
                  $timer->starttime = time();
  
                  // Trigger lesson restarted event.
                  $event = \mod_lesson\event\lesson_restarted::create(array(
                      'objectid' => $this->properties->id,
                      'context' => context_module::instance($cm->id),
                      'courseid' => $this->properties->course
                  ));
                  $event->trigger();
  
              }
          }
  
          $timenow = time();
          $timer->lessontime = $timenow;
          if (WS_SERVER) {
              $timer->timemodifiedoffline = $timenow;
          }
          $timer->completed = $endreached;
          $DB->update_record('lesson_timer', $timer);
  
          // Update completion state.
          $cm = get_coursemodule_from_instance('lesson', $this->properties()->id, $this->properties()->course,
              false, MUST_EXIST);
          $course = get_course($cm->course);
          $completion = new completion_info($course);
          if ($completion->is_enabled($cm) && $this->properties()->completiontimespent > 0) {
              $completion->update_state($cm, COMPLETION_COMPLETE);
          }
          return $timer;
      }
code: public function update_timer($restart=false, $continue=false, $endreached =false) {
          global $USER, $DB;
  
          $cm = get_coursemodule_from_instance('lesson', $this->properties->id, $this->properties->course);
  
          // clock code
          // get time information for this user
          if (!$timer = $this->get_user_timers($USER->id, 'starttime DESC', '*', 0, 1)) {
              $this->start_timer();
              $timer = $this->get_user_timers($USER->id, 'starttime DESC', '*', 0, 1);
          }
          $timer = current($timer); // This will get the latest start time record.
  
          if ($restart) {
              if ($continue) {
                  // continue a previous test, need to update the clock  (think this option is disabled atm)
                  $timer->starttime = time() - ($timer->lessontime - $timer->starttime);
  
                  // Trigger lesson resumed event.
                  $event = \mod_lesson\event\lesson_resumed::create(array(
                      'objectid' => $this->properties->id,
                      'context' => context_module::instance($cm->id),
                      'courseid' => $this->properties->course
                  ));
                  $event->trigger();
  
              } else {
                  // starting over, so reset the clock
                  $timer->starttime = time();
  
                  // Trigger lesson restarted event.
                  $event = \mod_lesson\event\lesson_restarted::create(array(
                      'objectid' => $this->properties->id,
                      'context' => context_module::instance($cm->id),
                      'courseid' => $this->properties->course
                  ));
                  $event->trigger();
  
              }
          }
  
          $timenow = time();
          $timer->lessontime = $timenow;
          if (WS_SERVER) {
              $timer->timemodifiedoffline = $timenow;
          }
          $timer->completed = $endreached;
          $DB->update_record('lesson_timer', $timer);
  
          // Update completion state.
          $cm = get_coursemodule_from_instance('lesson', $this->properties()->id, $this->properties()->course,
              false, MUST_EXIST);
          $course = get_course($cm->course);
          $completion = new completion_info($course);
          if ($completion->is_enabled($cm) && $this->properties()->completiontimespent > 0) {
              $completion->update_state($cm, COMPLETION_COMPLETE);
          }
          return $timer;
      }
code_tokens: public function update_timer ( $ restart = false , $ continue = false , $ endreached = false ) { global $ USER , $ DB ; $ cm = get_coursemodule_from_instance ( 'lesson' , $ this -> properties -> id , $ this -> properties -> course ) ; // clock code // get time information for this user if ( ! $ timer = $ this -> get_user_timers ( $ USER -> id , 'starttime DESC' , '*' , 0 , 1 ) ) { $ this -> start_timer ( ) ; $ timer = $ this -> get_user_timers ( $ USER -> id , 'starttime DESC' , '*' , 0 , 1 ) ; } $ timer = current ( $ timer ) ; // This will get the latest start time record. if ( $ restart ) { if ( $ continue ) { // continue a previous test, need to update the clock  (think this option is disabled atm) $ timer -> starttime = time ( ) - ( $ timer -> lessontime - $ timer -> starttime ) ; // Trigger lesson resumed event. $ event = \ mod_lesson \ event \ lesson_resumed :: create ( array ( 'objectid' => $ this -> properties -> id , 'context' => context_module :: instance ( $ cm -> id ) , 'courseid' => $ this -> properties -> course ) ) ; $ event -> trigger ( ) ; } else { // starting over, so reset the clock $ timer -> starttime = time ( ) ; // Trigger lesson restarted event. $ event = \ mod_lesson \ event \ lesson_restarted :: create ( array ( 'objectid' => $ this -> properties -> id , 'context' => context_module :: instance ( $ cm -> id ) , 'courseid' => $ this -> properties -> course ) ) ; $ event -> trigger ( ) ; } } $ timenow = time ( ) ; $ timer -> lessontime = $ timenow ; if ( WS_SERVER ) { $ timer -> timemodifiedoffline = $ timenow ; } $ timer -> completed = $ endreached ; $ DB -> update_record ( 'lesson_timer' , $ timer ) ; // Update completion state. $ cm = get_coursemodule_from_instance ( 'lesson' , $ this -> properties ( ) -> id , $ this -> properties ( ) -> course , false , MUST_EXIST ) ; $ course = get_course ( $ cm -> course ) ; $ completion = new completion_info ( $ course ) ; if ( $ completion -> is_enabled ( $ cm ) && $ this -> properties ( ) -> completiontimespent > 0 ) { $ completion -> update_state ( $ cm , COMPLETION_COMPLETE ) ; } return $ timer ; }
docstring: Updates the timer to the current time and returns the new timer object
  @param bool $restart If set to true the timer is restarted
  @param bool $continue If set to true AND $restart=true then the timer
  will continue from a previous attempt
  @return stdClass The new timer
docstring_tokens: Updates the timer to the current time and returns the new timer object