original_string: public function guess_start() {
          global $DB;
  
          if (!$this->get_total_logs()) {
              // Can't guess.
              return 0;
          }
  
          if (!$logstore = \core_analytics\manager::get_analytics_logstore()) {
              return 0;
          }
  
          // We first try to find current course student logs.
          $firstlogs = array();
          foreach ($this->get_students() as $studentid) {
              // Grrr, we are limited by logging API, we could do this easily with a
              // select min(timecreated) from xx where courseid = yy group by userid.
  
              // Filters based on the premise that more than 90% of people will be using
              // standard logstore, which contains a userid, contextlevel, contextinstanceid index.
              $select = "userid = :userid AND contextlevel = :contextlevel AND contextinstanceid = :contextinstanceid";
              $params = array('userid' => $studentid, 'contextlevel' => CONTEXT_COURSE, 'contextinstanceid' => $this->get_id());
              $events = $logstore->get_events_select($select, $params, 'timecreated ASC', 0, 1);
              if ($events) {
                  $event = reset($events);
                  $firstlogs[] = $event->timecreated;
              }
          }
          if (empty($firstlogs)) {
              // Can't guess if no student accesses.
              return 0;
          }
  
          sort($firstlogs);
          $firstlogsmedian = $this->median($firstlogs);
  
          $studentenrolments = enrol_get_course_users($this->get_id(), $this->get_students());
          if (empty($studentenrolments)) {
              return 0;
          }
  
          $enrolstart = array();
          foreach ($studentenrolments as $studentenrolment) {
              $enrolstart[] = ($studentenrolment->uetimestart) ? $studentenrolment->uetimestart : $studentenrolment->uetimecreated;
          }
          sort($enrolstart);
          $enrolstartmedian = $this->median($enrolstart);
  
          return intval(($enrolstartmedian + $firstlogsmedian) / 2);
      }
code: public function guess_start() {
          global $DB;
  
          if (!$this->get_total_logs()) {
              // Can't guess.
              return 0;
          }
  
          if (!$logstore = \core_analytics\manager::get_analytics_logstore()) {
              return 0;
          }
  
          // We first try to find current course student logs.
          $firstlogs = array();
          foreach ($this->get_students() as $studentid) {
              // Grrr, we are limited by logging API, we could do this easily with a
              // select min(timecreated) from xx where courseid = yy group by userid.
  
              // Filters based on the premise that more than 90% of people will be using
              // standard logstore, which contains a userid, contextlevel, contextinstanceid index.
              $select = "userid = :userid AND contextlevel = :contextlevel AND contextinstanceid = :contextinstanceid";
              $params = array('userid' => $studentid, 'contextlevel' => CONTEXT_COURSE, 'contextinstanceid' => $this->get_id());
              $events = $logstore->get_events_select($select, $params, 'timecreated ASC', 0, 1);
              if ($events) {
                  $event = reset($events);
                  $firstlogs[] = $event->timecreated;
              }
          }
          if (empty($firstlogs)) {
              // Can't guess if no student accesses.
              return 0;
          }
  
          sort($firstlogs);
          $firstlogsmedian = $this->median($firstlogs);
  
          $studentenrolments = enrol_get_course_users($this->get_id(), $this->get_students());
          if (empty($studentenrolments)) {
              return 0;
          }
  
          $enrolstart = array();
          foreach ($studentenrolments as $studentenrolment) {
              $enrolstart[] = ($studentenrolment->uetimestart) ? $studentenrolment->uetimestart : $studentenrolment->uetimecreated;
          }
          sort($enrolstart);
          $enrolstartmedian = $this->median($enrolstart);
  
          return intval(($enrolstartmedian + $firstlogsmedian) / 2);
      }
code_tokens: public function guess_start ( ) { global $ DB ; if ( ! $ this -> get_total_logs ( ) ) { // Can't guess. return 0 ; } if ( ! $ logstore = \ core_analytics \ manager :: get_analytics_logstore ( ) ) { return 0 ; } // We first try to find current course student logs. $ firstlogs = array ( ) ; foreach ( $ this -> get_students ( ) as $ studentid ) { // Grrr, we are limited by logging API, we could do this easily with a // select min(timecreated) from xx where courseid = yy group by userid. // Filters based on the premise that more than 90% of people will be using // standard logstore, which contains a userid, contextlevel, contextinstanceid index. $ select = "userid = :userid AND contextlevel = :contextlevel AND contextinstanceid = :contextinstanceid" ; $ params = array ( 'userid' => $ studentid , 'contextlevel' => CONTEXT_COURSE , 'contextinstanceid' => $ this -> get_id ( ) ) ; $ events = $ logstore -> get_events_select ( $ select , $ params , 'timecreated ASC' , 0 , 1 ) ; if ( $ events ) { $ event = reset ( $ events ) ; $ firstlogs [ ] = $ event -> timecreated ; } } if ( empty ( $ firstlogs ) ) { // Can't guess if no student accesses. return 0 ; } sort ( $ firstlogs ) ; $ firstlogsmedian = $ this -> median ( $ firstlogs ) ; $ studentenrolments = enrol_get_course_users ( $ this -> get_id ( ) , $ this -> get_students ( ) ) ; if ( empty ( $ studentenrolments ) ) { return 0 ; } $ enrolstart = array ( ) ; foreach ( $ studentenrolments as $ studentenrolment ) { $ enrolstart [ ] = ( $ studentenrolment -> uetimestart ) ? $ studentenrolment -> uetimestart : $ studentenrolment -> uetimecreated ; } sort ( $ enrolstart ) ; $ enrolstartmedian = $ this -> median ( $ enrolstart ) ; return intval ( ( $ enrolstartmedian + $ firstlogsmedian ) / 2 ) ; }
docstring: Guesses the start of the course based on students' activity and enrolment start dates.
  
  @return int
docstring_tokens: Guesses the start of the course based on students activity and enrolment start dates .