|
| 1 | +<?php |
| 2 | +require_once __DIR__.'/../www/config.inc.php'; |
| 3 | + |
| 4 | +$cache = UNL_Peoplefinder_Cache::factory(); |
| 5 | + |
| 6 | +// This is the array that will store all of the data |
| 7 | +$students = array(); |
| 8 | + |
| 9 | +// First, load the bio info and create the initial structure |
| 10 | +$csv_bio_file = __DIR__.'/data/unl_sis_bio.txt'; |
| 11 | + |
| 12 | +if (!file_exists($csv_bio_file)) { |
| 13 | + // You must manually upload the file |
| 14 | + return; |
| 15 | +} |
| 16 | + |
| 17 | +$csv_bio_file = file_get_contents($csv_bio_file); |
| 18 | +$csv_bio_file = mb_convert_encoding($csv_bio_file, 'UTF-8'); //See note 'Parsing export from drupal webforms |
| 19 | +$csv_bio_rows = explode("\n", $csv_bio_file); |
| 20 | + |
| 21 | +// Remove the first row, which should be the column headers and not actual data. |
| 22 | +array_shift($csv_bio_rows); |
| 23 | + |
| 24 | +foreach ($csv_bio_rows as $row) { |
| 25 | + /** |
| 26 | + * [0] = NUID |
| 27 | + * [1] = CLASS_LEVEL |
| 28 | + * |
| 29 | + * ONLY non-ferpa protected records are included |
| 30 | + * |
| 31 | + */ |
| 32 | + $data = str_getcsv($row, ",", '"'); |
| 33 | + |
| 34 | + if (!isset($data[1])) { |
| 35 | + // This is likely a blank line at the end of the file |
| 36 | + continue; |
| 37 | + } |
| 38 | + |
| 39 | + $students[$data[0]] = array( |
| 40 | + 'unlsisclasslevel' => $data[1], |
| 41 | + 'unlsiscollege' => array(), |
| 42 | + 'unlsismajor' => array(), |
| 43 | + 'unlsisminor' => array(), // Minor data is not shown (not listed as public directory information in the policy) |
| 44 | + ); |
| 45 | +} |
| 46 | + |
| 47 | +// Second, load the college, major, and minor information and add it to the existing structure |
| 48 | +$csv_bio_file = __DIR__.'/data/unl_sis_prog.txt'; |
| 49 | + |
| 50 | +if (!file_exists($csv_bio_file)) { |
| 51 | + // You must manually upload the file |
| 52 | + return; |
| 53 | +} |
| 54 | + |
| 55 | +$csv_prog_file = file_get_contents($csv_prog_file); |
| 56 | +$csv_prog_file = mb_convert_encoding($csv_prog_file, 'UTF-8'); //See note 'Parsing export from drupal webforms |
| 57 | +$csv_prog_rows = explode("\n", $csv_prog_file); |
| 58 | + |
| 59 | +// Remove the first row, which should be the column headers and not actual data. |
| 60 | +array_shift($csv_prog_rows); |
| 61 | + |
| 62 | +foreach ($csv_prog_rows as $row) { |
| 63 | + /** |
| 64 | + * [0] = NUID |
| 65 | + * [1] = INSTITUTION |
| 66 | + * [2] = ACAD_PROG (program code "ARH-U" for example) |
| 67 | + * [3] = PROG_DESCR (college) |
| 68 | + * [4] = PLAN_DESCR (major/minor name) |
| 69 | + * [5] = ACAD_PLAN_TYPE ('MAJ' => 'Major', 'MIN' => 'Minor', 'COS' => 'Course of study') |
| 70 | + */ |
| 71 | + $data = str_getcsv($row, ",", '"'); |
| 72 | + |
| 73 | + if (!isset($data[1])) { |
| 74 | + // This is likely a blank line at the end of the file |
| 75 | + continue; |
| 76 | + } |
| 77 | + |
| 78 | + if (!isset($students[$data[0]])) { |
| 79 | + // Student is not tracked, likely do to a FERPA flag |
| 80 | + continue; |
| 81 | + } |
| 82 | + |
| 83 | + $students[$data[0]]['unlsiscollege'][] = $data[2]; |
| 84 | + |
| 85 | + if (isset($data[5])) { |
| 86 | + $plan_type = strtolower(trim($data[5])); |
| 87 | + |
| 88 | + // Display Course of Study as a major per Steve Booton |
| 89 | + if ($plan_type === 'maj' || $plan_type === 'cos') { |
| 90 | + $students[$data[0]]['unlsismajor'][] = $data[4]; |
| 91 | + } else { |
| 92 | + echo 'unknown plan type ' . $plan_type . PHP_EOL; |
| 93 | + } |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +// Clear all old memcache results if needed |
| 98 | +$existing_keys = $cache->get('unl_sis_keys'); |
| 99 | + |
| 100 | +// Save to Memcache |
| 101 | +$prefix = 'unl_sis_'; |
| 102 | +$unl_sis_keys = array(); // Keep track of all existing keys because Memcached->getAllKeys() is not reliable |
| 103 | +foreach ($students as $nuid => $data) { |
| 104 | + $cache_key = $prefix.$nuid; |
| 105 | + $unl_sis_keys[] = $cache_key; |
| 106 | + $cache->set($cache_key, serialize($data), false, true); |
| 107 | +} |
| 108 | +$cache->set('unl_sis_keys', serialize($unl_sis_keys), false, true); |
| 109 | + |
| 110 | + |
| 111 | +if ($existing_keys) { |
| 112 | + $existing_keys = unserialize($existing_keys); |
| 113 | + foreach ($existing_keys as $key) { |
| 114 | + if (!in_array($key, $unl_sis_keys)) { |
| 115 | + // only remove keys that don't exist in the new data (avoid a brief moment when data might be unavailable) |
| 116 | + $cache->remove($key); |
| 117 | + } |
| 118 | + } |
| 119 | +} |
0 commit comments