Exemple #1
0
 /**
  * Perform initialization that should
  * be done at the beginning of the export
  *
  * @param int $targetstarttime The timestamp representing the theoretical
  *                             time when this task was meant to be run
  * @param int $lastruntime     The last time the export was run
  *                             (required for incremental scheduled export)
  */
 public function init($targetstarttime = 0, $lastruntime = 0)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/user.class.php');
     require_once elispm::lib('data/student.class.php');
     require_once elispm::lib('data/pmclass.class.php');
     require_once elispm::lib('data/course.class.php');
     require_once elispm::lib('data/classmoodlecourse.class.php');
     // Columns that are always displayed.
     $columns = array(get_string('header_firstname', 'dhexport_version1'), get_string('header_lastname', 'dhexport_version1'), get_string('header_username', 'dhexport_version1'), get_string('header_useridnumber', 'dhexport_version1'), get_string('header_courseidnumber', 'dhexport_version1'), get_string('header_startdate', 'dhexport_version1'), get_string('header_enddate', 'dhexport_version1'), get_string('header_status', 'dhexport_version1elis'), get_string('header_grade', 'dhexport_version1'), get_string('header_letter', 'dhexport_version1'));
     // Query parameters.
     $params = array();
     // Track extra SQL and parameters needed for custom fields.
     $extra_joins = implode(" \n ", rlipexport_version1elis_extrafields::get_extra_joins());
     $extra_select = implode(', ', rlipexport_version1elis_extrafields::get_extra_select());
     if (!empty($extra_select)) {
         $extra_select = ', ' . $extra_select;
     }
     // Get columns.
     $columns = array_merge($columns, rlipexport_version1elis_extrafields::get_extra_columns());
     // Add passed as completion status requirement.
     $params[] = student::STUSTATUS_PASSED;
     // Sql time condition.
     $time_condition = '';
     // Determine if we're in incremental or non-incremental mode.
     $nonincremental = get_config('dhexport_version1elis', 'nonincremental');
     if (empty($nonincremental)) {
         if ($this->manual) {
             // Manual export incremental mode.
             // Get string delta.
             $incrementaldelta = get_config('dhexport_version1elis', 'incrementaldelta');
             // Convert to number of seconds.
             $numsecs = rlip_time_string_to_offset($incrementaldelta);
             // Add to query parameters.
             $params[] = time() - $numsecs;
             // Add query fragment.
             $time_condition = 'AND stu.completetime >= ?';
         } else {
             // Scheduled export incremental mode.
             // Set up the query fragment and parameters.
             $params[] = $lastruntime;
             $time_condition = 'AND stu.completetime >= ?';
         }
     }
     // Initialize our recordset to the core data.
     $sql = "SELECT u.id AS userid,\n                       u.firstname,\n                       u.lastname,\n                       u.username,\n                       u.idnumber,\n                       crs.idnumber AS crsidnumber,\n                       stu.enrolmenttime,\n                       stu.completetime,\n                       stu.grade,\n                       mdlcrs.id AS mdlcrsid\n                       {$extra_select}\n                FROM {" . user::TABLE . "} u\n                JOIN {" . student::TABLE . "} stu\n                  ON u.id = stu.userid\n                JOIN {" . pmclass::TABLE . "} cls\n                  ON stu.classid = cls.id\n                JOIN {" . course::TABLE . "} crs\n                  ON cls.courseid = crs.id\n                LEFT JOIN {" . classmoodlecourse::TABLE . "} clsmdl\n                  ON cls.id = clsmdl.classid\n                LEFT JOIN {course} mdlcrs\n                  ON clsmdl.moodlecourseid = mdlcrs.id\n                {$extra_joins}\n                WHERE stu.completestatusid = ?\n                {$time_condition}\n                ORDER BY u.idnumber ASC,\n                         crs.idnumber ASC,\n                         stu.completetime ASC,\n                         stu.grade DESC,\n                         cls.idnumber ASC,\n                         u.username ASC";
     $this->recordset = $DB->get_recordset_sql($sql, $params);
     // Write out header.
     $this->fileplugin->write($columns);
     // Load string to prevent calling get_string for every record.
     $this->completestatusstring = get_string('completestatusstring', 'dhexport_version1elis');
 }
 /**
  * Validate that converting time string to offset works for complex string
  * with hours, minutes and seconds
  */
 public function test_timestringtooffsetreturnscorrectoffsetforcomplexstring()
 {
     $result = rlip_time_string_to_offset('1d2h3m');
     $this->assertEquals($result, DAYSECS + 2 * HOURSECS + 3 * MINSECS);
 }
Exemple #3
0
 /**
  * Perform initialization that should
  * be done at the beginning of the export
  *
  * @param int $targetstarttime The timestamp representing the theoretical
  *                             time when this task was meant to be run
  * @param int $lastruntime     The last time the export was run
  *                             (required for incremental scheduled export)
  */
 function init($targetstarttime = 0, $lastruntime = 0)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/datahub/lib.php';
     $file = get_plugin_directory('dhexport', 'version1') . '/lib.php';
     require_once $file;
     //columns that are always displayed
     $columns = array(get_string('header_firstname', 'dhexport_version1'), get_string('header_lastname', 'dhexport_version1'), get_string('header_username', 'dhexport_version1'), get_string('header_useridnumber', 'dhexport_version1'), get_string('header_courseidnumber', 'dhexport_version1'), get_string('header_startdate', 'dhexport_version1'), get_string('header_enddate', 'dhexport_version1'), get_string('header_grade', 'dhexport_version1'), get_string('header_letter', 'dhexport_version1'));
     //track extra SQL and parameters needed for custom fields
     $extra_select = '';
     $extra_joins = '';
     $extra_params = array();
     //query to fetch all configured profile fields
     $sql = "SELECT export.fieldid,\n                       export.header,\n                       field.datatype,\n                       field.defaultdata,\n                       field.param3\n                FROM {" . RLIPEXPORT_VERSION1_FIELD_TABLE . "} export\n                JOIN {user_info_field} field\n                  ON export.fieldid = field.id\n                ORDER BY export.fieldorder";
     if ($recordset = $DB->get_recordset_sql($sql)) {
         foreach ($recordset as $record) {
             /**
              * Calculate information we'll need to format / transform records
              */
             //field id used to index stored information
             $fieldid = $record->fieldid;
             //store the data type
             $this->datatypes[$fieldid] = $record->datatype;
             //store the default value
             $this->defaultdata[$fieldid] = $record->defaultdata;
             //track which fields show date and time values
             if ($record->datatype == 'datetime' && $record->param3 == 1) {
                 $this->showtime[$record->fieldid] = 1;
             }
             /**
              * Calculate extra SQL fragments / parameters
              */
             //extra columns we'll need to display profile field values
             $extra_select .= ",\n                                   profile_data_{$record->fieldid}.data\n                                   AS profile_field_{$record->fieldid}";
             //extra joins we''l need to display profile filed values
             $extra_joins = "{$extra_joins}\n                                LEFT JOIN {user_info_data} profile_data_{$record->fieldid}\n                                  ON profile_data_{$record->fieldid}.fieldid = ?\n                                  AND u.id = profile_data_{$record->fieldid}.userid";
             //id of the appropriate custom field
             $extra_params[] = $fieldid;
             /**
              * Calculate extra column headers
              */
             $columns[] = $record->header;
         }
     }
     //initialize our recordset to the core data
     $sql = "SELECT u.firstname,\n                       u.lastname,\n                       u.username,\n                       u.idnumber AS usridnumber,\n                       c.shortname AS crsidnumber,\n                       c.startdate AS timestart,\n                       gg.finalgrade AS usergrade,\n                       gi.id AS gradeitemid\n                       {$extra_select}\n                FROM {grade_items} gi\n                JOIN {grade_grades} gg\n                  ON gg.itemid = gi.id\n                JOIN {user} u\n                  ON gg.userid = u.id\n                JOIN {course} c\n                  ON c.id = gi.courseid\n                {$extra_joins}\n                WHERE itemtype = 'course'\n                AND u.deleted = 0";
     /**
      * Handle the "incremental" offset, if necessary
      */
     //determine if we're in incremental or non-incremental mode
     $nonincremental = get_config('dhexport_version1', 'nonincremental');
     if (empty($nonincremental)) {
         if ($this->manual) {
             //manual export incremental mode
             //get string delta
             $incrementaldelta = get_config('dhexport_version1', 'incrementaldelta');
             //conver to number of seconds
             $numsecs = rlip_time_string_to_offset($incrementaldelta);
         } else {
             if (!$this->manual) {
                 //scheduled export incremental mode
                 //calculate number of seconds
                 $numsecs = $targetstarttime - $lastruntime;
             }
         }
         $extra_params[] = time() - $numsecs;
         //SQL and params
         $sql .= " AND gg.timemodified >= ?";
     }
     $this->recordset = $DB->get_recordset_sql($sql, $extra_params);
     //write out header
     $this->fileplugin->write($columns);
 }