Skip to content

Commit

Permalink
Processing: creating XMLDB table
Browse files Browse the repository at this point in the history
* only the orgs table was created
  • Loading branch information
Gus-Amorim committed Sep 2, 2024
1 parent 177198c commit 8262fb6
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 25 deletions.
1 change: 1 addition & 0 deletions classes/local/csv_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class csv_client implements client_interface {
public function authenticate(): void {
return;
}

public function synchronise(?int $onlysincetime = NULL): void {
$result = new stdClass();
$result->response = [
Expand Down
14 changes: 14 additions & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,19 @@
<INDEX NAME="mappedid" UNIQUE="false" FIELDS="mappedid"/>
</INDEXES>
</TABLE>
<TABLE NAME="oneroster_orgs" COMMENT="Stores organization data from OneRoster">
<FIELDS>
<FIELD NAME="sourcedid" TYPE="char" LENGTH="36" NOTNULL="true" SEQUENCE="false" COMMENT="Unique id for the organization"/>
<FIELD NAME="status" TYPE="char" LENGTH="20" NOTNULL="false" SEQUENCE="false" COMMENT="Status of the organization"/>
<FIELD NAME="datelastmodified" TYPE="datetime" NOTNULL="true" SEQUENCE="false" COMMENT="The date that this record was last modified"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Name of the organization"/>
<FIELD NAME="type" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" COMMENT="Type of the organization"/>
<FIELD NAME="identifier" TYPE="char" LENGTH="20" NOTNULL="false" SEQUENCE="false" COMMENT="NCES ID for the school/district"/>
<FIELD NAME="parentsourcedid" TYPE="char" LENGTH="36" NOTNULL="false" SEQUENCE="false" COMMENT="SourcedId of the parent organization"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="sourcedid"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
25 changes: 23 additions & 2 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,29 @@ function xmldb_enrol_oneroster_upgrade($oldversion) {
}

// Oneroster savepoint reached.
upgrade_plugin_savepoint(true, 2020120700, 'enrol', 'oneroster');
}
upgrade_plugin_savepoint(true, 2020120700, 'enrol', 'oneroster');
}

if ($oldversion < 20201206) {

$table = new xmldb_table('oneroster_orgs');

$table->add_field('sourcedid', XMLDB_TYPE_CHAR, '36', null, XMLDB_NOTNULL, null, null);
$table->add_field('status', XMLDB_TYPE_CHAR, '20', null, null, null, null);
$table->add_field('datelastmodified', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
$table->add_field('identifier', XMLDB_TYPE_CHAR, '20', null, null, null, null);
$table->add_field('parentsourcedid', XMLDB_TYPE_CHAR, '36', null, null, null, null);


$table->add_key('primary', XMLDB_KEY_PRIMARY, ['sourcedid']);

if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}

upgrade_plugin_savepoint(true, 2023101000, 'enrol', 'oneroster');
}
return true;
}
4 changes: 4 additions & 0 deletions expected_csv_headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class expected_csv_headers {

// Define the expected headers for each CSV file
const HEADER_MANIFEST =['manifest.version', 'oneroster.version','file.academicSessions','file.categories','file.classes','file.classResources','file.courses','file.courseResources','file.demographics','file.enrollments','file.lineItems','file.orgs','file.resources','file.results','file.users'];
const HEADER_ACADEMIC_SESSIONS = ['sourcedId', 'status', 'dateLastModified', 'title', 'type', 'startDate', 'endDate', 'parentSourcedId', 'schoolYear'];
const HEADER_CATEGORIES = ['sourcedId', 'status', 'dateLastModified', 'title'];
const HEADER_CLASSES = ['sourcedId', 'status', 'dateLastModified', 'title', 'grades', 'courseSourcedId', 'classCode', 'classType', 'location', 'schoolSourcedId', 'termSourcedIds', 'subjects', 'subjectCodes', 'periods'];
Expand All @@ -19,6 +20,7 @@ class expected_csv_headers {

// Define the required files and their headers
const REQUIRED_FILES = [
'manifest.csv' => self::HEADER_MANIFEST,
'academicSessions.csv' => self::HEADER_ACADEMIC_SESSIONS,
'categories.csv' => self::HEADER_CATEGORIES,
'classes.csv' => self::HEADER_CLASSES,
Expand All @@ -37,6 +39,8 @@ class expected_csv_headers {
// Get the header for a specific file
public static function getHeader($file_name) {
switch ($file_name) {
case 'manifest.csv':
return self::HEADER_MANIFEST;
case 'academicSessions.csv':
return self::HEADER_ACADEMIC_SESSIONS;
case 'categories.csv':
Expand Down
1 change: 0 additions & 1 deletion oneroster_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,4 @@ public static function display_missing_and_invalid_files($missing_files) {
echo 'The following files have invalid or missing headers: ' . implode(', ', $missing_files['invalid_headers']) . '<br>';
}
}

}
1 change: 0 additions & 1 deletion processcsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
// CSV processing logic goes here
$csv_data = OneRosterHelper::extract_csvs_to_arrays($tempdir);


// Tests the data Array (can get rid of this later)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
foreach ($csv_data as $file_name => $data_array) {
Expand Down
41 changes: 20 additions & 21 deletions tests/client_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,30 @@
class client_csv_testcase extends advanced_testcase {

public function test_csv_client(): void {
global $DB;
$this->resetAfterTest(true);

$this->resetAfterTest(true);
// Include the helper file
require_once(__DIR__ . '/../csv_data_helper.php');

// Include the helper file
require_once(__DIR__ . '/../csv_data_helper.php');
// Setup fixtures here.

// Setup fixtures here.
// Get data from the helper
$manifest = csv_data_helper::get_manifest_data();
$users = csv_data_helper::get_users_data();
$classes = csv_data_helper::get_classes_data();
$courses = csv_data_helper::get_courses_data();
$orgs = csv_data_helper::get_orgs_data();
$enrollments = csv_data_helper::get_enrollments_data();
$academicsessions = csv_data_helper::get_academicSessions_data();

// Get data from the helper
$manifest = csv_data_helper::get_manifest_data();
$users = csv_data_helper::get_users_data();
$classes = csv_data_helper::get_classes_data();
$courses = csv_data_helper::get_courses_data();
$orgs = csv_data_helper::get_orgs_data();
$enrollments = csv_data_helper::get_enrollments_data();
$academicsessions = csv_data_helper::get_academicSessions_data();


$csvclient = client_helper::get_csv_client();
$csvclient->synchronise();

// Assert final state here
// $schools = $DB->get_records();
// $this->assertCount(3, $schools);;


$csvclient = client_helper::get_csv_client();
$csvclient->synchronise();

// Assert final state here.
// $schools = $DB->get_records();
// $this->assertCount(3, $schools);
}
}

Expand Down

0 comments on commit 8262fb6

Please sign in to comment.