/**
  * Performs the data importation from Moodle core tables (courses, enrolled users, logs). This importation is done only if
  * database_helper->has_data_to_be_imported() returns true.
  *
  * @param int $courseid The current course id for which the data has to be imported.
  */
 protected function import_data($courseid)
 {
     $courseyear = $this->db->get_course_start_week_and_year($courseid)['year'];
     $previouscourses = $this->db->find_course_previous_teaching_ids_core_tables($courseid, $courseyear);
     foreach ($previouscourses as $previouscourse) {
         $this->db->dump_previous_core_info_to_historic_tables($previouscourse);
     }
     $previouscourses = $this->db->find_course_previous_teachings_ids_historic_tables($courseid, $courseyear);
     $this->db->insert_courses_associations($courseid, $previouscourses);
 }
 /**
  * Determines if the course has had the minimum previous teachings in the past years.
  * First, looks into Moodle core tables for existing previous courses. If it doesn't find any, it tries luck in
  * plugin's historic table. If it doesn't found neither here, means that the course has not previous teachings.
  *
  * @see find_course_previous_teachings_ids($currentcourseid, $currentyear) in database_helper.php.
  * @param int $courseid The course to determine if has had the minimum teachings before.
  * @param int $currentyear The year the current course began in.
  * @param database_helper $db The object with deals with database.
  * @return boolean If the given course has had the minimum teachings before or not.
  */
 public static function meets_minimum_previous_courses($courseid, $currentyear, $db)
 {
     $previouscourses = $db->find_course_previous_teaching_ids_core_tables($courseid, $currentyear);
     $minimum = false;
     if (count($previouscourses) >= self::MINIMUM_PREVIOUS_COURSES) {
         $minimum = true;
     }
     if (!$minimum) {
         $previouscourses = $db->find_course_previous_teachings_ids_historic_tables($courseid, $currentyear);
         if (count($previouscourses) >= self::MINIMUM_PREVIOUS_COURSES) {
             $minimum = true;
         }
     }
     return $minimum;
 }