Skip to content

Commit

Permalink
Processing: synchronize completion
Browse files Browse the repository at this point in the history
* synchronize is able to process csv data and stores it into the database
* Fixed comments and added proper headers
  • Loading branch information
Gus-Amorim committed Sep 19, 2024
1 parent 9588836 commit 6a6fb0a
Show file tree
Hide file tree
Showing 10 changed files with 490 additions and 1,116 deletions.
794 changes: 221 additions & 573 deletions classes/local/csv_client.php

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion classes/local/endpoints/rostering.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ protected static function get_command_data(string $command): array {
if (array_key_exists($command, self::$commands)) {
return self::$commands[$command];
}

return parent::get_command_data($command);
}

Expand Down
3 changes: 2 additions & 1 deletion classes/local/v1p1/oneroster_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public function sync_roster(?int $onlysincetime = null): void {
// Most systems do not have many organisations in them.
// Fetch all organisations to add them to the cache.
$this->fetch_organisation_list();

$schoolidstosync = explode(',', get_config('enrol_oneroster', 'datasync_schools'));
$countofschools = count($schoolidstosync);

Expand Down Expand Up @@ -466,7 +467,7 @@ protected function update_or_create_category(coursecat_representation $entity):
$localcategory = core_course_category::create($remotecategory);
$this->add_metric('coursecat', 'create');
}

return $localcategory;
}

Expand Down
145 changes: 81 additions & 64 deletions csv_data_helper.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace enrol_oneroster;

/**
* Class csv_data_helper
*
* This class provides sample data for the CSV files that are used in the unit tests.
*
* @package enrol_oneroster
* @copyright Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class csv_data_helper {
/**
* Returns the manifest data.
*
* @return array
*/
public static function get_manifest_data() {
return array(
array(
Expand Down Expand Up @@ -75,6 +104,11 @@ public static function get_manifest_data() {
);
}

/**
* Returns the academic sessions data.
*
* @return array
*/
public static function get_academicsessions_data() {
return array(
array(
Expand Down Expand Up @@ -103,6 +137,11 @@ public static function get_academicsessions_data() {
);
}

/**
* Returns the categories data.
*
* @return array
*/
public static function get_categories_data() {
return array(
array(
Expand All @@ -120,6 +159,11 @@ public static function get_categories_data() {
);
}

/**
* Returns the classes data.
*
* @return array
*/
public static function get_classes_data() {
return array(
array(
Expand All @@ -138,10 +182,6 @@ public static function get_classes_data() {
),
'subjects' => array('Science'), // List of Strings, Optional
'periods' => array('B'), // List of Strings, Optional
'metadata' => array( // Optional metadata
'department_0' => 'org-dpt-222-3456',
'lead_section' => 'cls-222-123456'
)
),
array(
'sourcedId' => 'cls-222-123478', // GUID, Required
Expand All @@ -159,14 +199,15 @@ public static function get_classes_data() {
),
'subjects' => array('History'), // List of Strings, Optional
'periods' => array('D'), // List of Strings, Optional
'metadata' => array( // Optional metadata
'department_0' => 'org-dpt-222-3456',
'lead_section' => 'cls-222-123477'
)
)
);
}

/**
* Returns the courses data.
*
* @return array
*/
public static function get_courses_data() {
return array(
array(
Expand All @@ -180,9 +221,6 @@ public static function get_courses_data() {
'orgSourcedId' => 'org-sch-222-456', // GUID Reference, Required
'subjects' => array('Science'), // List of Strings, Optional
'subjectCodes' => null, // List of Strings, Optional (null for now)
'metadata' => array( // Optional metadata
'department_0' => 'org-dpt-222-3456'
)
),
array(
'sourcedId' => 'crs-222-123654', // GUID, Required
Expand All @@ -195,13 +233,15 @@ public static function get_courses_data() {
'orgSourcedId' => 'org-sch-222-456', // GUID Reference, Required
'subjects' => array('History'), // List of Strings, Optional
'subjectCodes' => null, // List of Strings, Optional (null for now)
'metadata' => array( // Optional metadata
'department_0' => 'org-dpt-222-4567'
)
)
);
}

/**
* Returns the demographics data.
*
* @return array
*/
public static function get_demographics_data() {
return array(
array(
Expand All @@ -221,11 +261,6 @@ public static function get_demographics_data() {
'countryOfBirthCode' => null, // String, Optional
'stateOfBirthAbbreviation' => null, // String, Optional
'publicSchoolResidenceStatus' => null, // String, Optional
'metadata' => array( // Optional metadata
'iepStatus' => 'true',
'ellStatus' => 'false',
'frlStatus' => 'Reduced'
)
),
array(
'sourcedId' => 'usr-222-66778896', // GUID Reference, Required
Expand All @@ -244,15 +279,15 @@ public static function get_demographics_data() {
'countryOfBirthCode' => null, // String, Optional
'stateOfBirthAbbreviation' => null, // String, Optional
'publicSchoolResidenceStatus' => null, // String, Optional
'metadata' => array( // Optional metadata
'iepStatus' => 'false',
'ellStatus' => 'true',
'frlStatus' => 'Free'
)
)
);
}

/**
* Returns the enrollments data.
*
* @return array
*/
public static function get_enrollments_data() {
return array(
array(
Expand Down Expand Up @@ -282,6 +317,11 @@ public static function get_enrollments_data() {
);
}

/**
* Returns the line items data.
*
* @return array
*/
public static function get_line_items_data() {
return array(
array(
Expand Down Expand Up @@ -315,6 +355,11 @@ public static function get_line_items_data() {
);
}

/**
* Returns the orgs data.
*
* @return array
*/
public static function get_orgs_data() {
return array(
array(
Expand All @@ -324,30 +369,25 @@ public static function get_orgs_data() {
'name' => 'Upper School', // String, Required
'type' => 'school', // Enumeration, Required
'identifier' => 'US', // String, Optional
'parentSourcedId' => null, // GUID Reference, Optional
'metadata' => array( // Optional metadata
'address1' => '1234 Elm Street',
'address2' => 'Building 101',
'address3' => 'Main Campus',
'city' => 'Manchester',
'state' => 'NH',
'postCode' => '03101-1001',
'gradeRange' => '09, 10, 11, 12'
)
'parentSourcedId' => 'org-dpt-222-456', // GUID Reference, Optional
),
array(
'sourcedId' => 'org_sch-222-7654', // GUID, Required
'status' => null, // Enumeration, Null for Bulk mode
'dateLastModified' => null, // DateTime, Null for Bulk mode
'dateLastModified' => null, // DateTime, Null forBulk mode
'name' => 'US History', // String, Required
'type' => 'department', // Enumeration, Required
'identifier' => 'US History', // String, Optional
'parentSourcedId' => 'org-sch-222-3456', // GUID Reference, Optional
'metadata' => null // No metadata in this case
)
);
}

/**
* Returns the results data.
*
* @return array
*/
public static function get_results_data() {
return array(
array(
Expand Down Expand Up @@ -375,6 +415,11 @@ public static function get_results_data() {
);
}

/**
* Returns the users data.
*
* @return array
*/
public static function get_users_data() {
return array(
array(
Expand All @@ -396,14 +441,6 @@ public static function get_users_data() {
'agentSourcedIds' => null, // List of GUID References, Optional
'grades' => null, // String, Optional (for students)
'password' => null, // String, Optional
'metadata' => array( // Optional metadata
'stateId' => 'NH-987-654',
'address1' => '5555 Main Street',
'address2' => 'Apartment 255',
'city' => 'Nashua',
'state' => 'NH',
'postCode' => '03060-6006'
)
),
array(
'sourcedId' => 'usr-222-66778899', // GUID, Required
Expand All @@ -427,17 +464,6 @@ public static function get_users_data() {
'agentSourcedIds' => array('usr-222-66778900'), // List of GUID References, Optional
'grades' => '12', // String, Optional
'password' => null, // String, Optional
'metadata' => array( // Optional metadata
'grade' => '12th Grade',
'stateId' => 'NH-345-678',
'address1' => '1234 Elm Street',
'address2' => 'Apartment 3C',
'address3' => 'basement',
'city' => 'Manchester',
'state' => 'NH',
'postCode' => '03101-1001',
'microsoft.userFlags' => 'iep,ell,freeLunch'
)
),
array(
'sourcedId' => 'usr-222-66778900', // GUID, Required
Expand All @@ -458,15 +484,6 @@ public static function get_users_data() {
'agentSourcedIds' => array('usr-222-66778899'), // List of GUID References, Optional
'grades' => null, // String, Optional
'password' => null, // String, Optional
'metadata' => array( // Optional metadata
'stateId' => 'NH-345-678',
'address1' => '1234 Elm Street',
'address2' => 'Apartment 3C',
'address3' => 'basement',
'city' => 'Manchester',
'state' => 'NH',
'postCode' => '03101-1001'
)
)
);
}
Expand Down
24 changes: 24 additions & 0 deletions expected_csv_headers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This class defines the expected headers for each CSV file.
*
* @package enrol_oneroster
* @copyright Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace enrol_oneroster;

class expected_csv_headers {

// Define the expected headers for each CSV file
Expand Down
22 changes: 22 additions & 0 deletions oneroster_csv_form.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

require_once($CFG->libdir . '/formslib.php');

/**
* One Roster Enrolment Client.
*
* @package enrol_oneroster
* @copyright Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class oneroster_csv_form extends moodleform {
protected function definition() {
$mform = $this->_form;
Expand Down
Loading

0 comments on commit 6a6fb0a

Please sign in to comment.