/** * Create an array of info on a particular class of a particular year. */ function pullClass($class, $year = false, $classterm = 0, $override = false, $substitute = '') { $row = CourseRoadDB::getBestClassInfo($class, $year); if (!$row) { return array('error' => true, 'errorDesc' => 'No class'); } // Some returned columns are unhelpful and are thus discarded. unset($row['id']); unset($row['design_units']); unset($row['tuition_attr']); unset($row['supervisor_attr']); unset($row['hgn_code']); unset($row['hgn_except']); unset($row['last_modified']); unset($row['notes']); unset($row['exception']); // Format assorted other rows. While classes are usually considered as "8.01", // it's easier to keep refer to them as "8_01" [for classes, etc.] $row['id'] = str_replace('.', '_', $row['subject_id']); $row['divid'] = $row['id'] . '__' . rand(); $row['is_variable_units'] = !!$row['is_variable_units']; $row['offered_this_year'] = !!$row['offered_this_year']; $row['fall'] = !!$row['fall']; $row['iap'] = !!$row['iap']; $row['spring'] = !!$row['spring']; $row['summer'] = !!$row['summer']; $row['permission'] = strpos($row['reqs'], 'Permission') !== false; $row['reqs'] = json_decode($row['reqs']); $reqs = $row['reqs'] ? 'Reqs: [X]' : 'No reqs :D'; if ($row['reqstr']) { $row['reqstr'] = 'Requisites: ' . $row['reqstr'] . '<br>'; } $row['total_units'] = floatval($row['total_units']); // Occasionally, the Warehouse tries to say that a class has 0 units. Since // that doesn't make much sense, default these exceptions to 12 units. $default_unit_count = 12; if (!$row['total_units']) { $row['total_units'] = $default_unit_count; } // Build the class' HTML for the info box when it's selected. $row['info'] = makeClassInfoHTML($row); // Each class added to the page is a div; this string holds the space- // separated classes added to that div. (Apologies on the overloading of the // word "class".) $row['divclasses'] = 'classdiv bubble ' . $row['id']; // Joint subjects at MIT are labelled with a J suffix. This trims that off. $row['joint_subjects'] = explode(', ', $row['joint_subjects']); foreach ($row['joint_subjects'] as &$subj) { $subj = rtrim($subj, 'J'); } if (!$row['joint_subjects'][0]) { $row['joint_subjects'] = false; } $row['equiv_subjects'] = explode(', ', $row['equiv_subjects']); foreach ($row['equiv_subjects'] as &$subj) { $subj = rtrim($subj, 'J'); } if (!$row['equiv_subjects'][0]) { $row['equiv_subjects'] = false; } if ($row['joint_subjects']) { $joint_subjects_classes = implode(' ', $row['joint_subjects']); $joint_subjects_classes = str_replace('.', '_', $joint_subjects_classes); $row['divclasses'] .= ' ' . $joint_subjects_classes; } if ($row['gir'] && $row['gir'][0] === 'H') { $row['gir'] = ''; } if ($row['gir']) { $row['divclasses'] .= ' GIR ' . $row['gir']; } if ($row['ci']) { $row['divclasses'] .= ' CI ' . $row['ci']; } if ($row['hass']) { $row['divclasses'] .= ' HASS ' . $row['hass']; } // Extraclasses handles cases where a class universally also counts for // something else, like 18.100B and 18.100. This is set manually in the // warehouse_exceptions table. if ($row['extraclasses']) { $row['divclasses'] .= ' ' . str_replace('.', '_', $row['extraclasses']); } $row['special'] = $row['gir'] || $row['ci'] || $row['hass']; $row['classterm'] = $classterm; $row['override'] = $override; $row['substitute'] = $substitute; $row['custom'] = false; // year = 2013 --> year_range = '12-'13 $row['year_range'] = "'" . substr($row['year'] - 1, -2) . "-'" . substr($row['year'], -2); // year_desired holds the year the class attempted to match. This allows for // classes which will be in the '14-'15 cycle to be defined now with '13-'14, // but should '14-'15 become available, that version with be loaded instead. // Thus, year_desired holds the user's desired year. $row['year_desired'] = $year ? $year : date('Y') + (date('m') > 3); // Generate HTML for a dropdown list of the other offered years $row['otheryears'] = makeYearsOfferedHTML($row['subject_id'], $row['year']); $row['yearspan'] = '<span title="The data for this class is from the ' . $row['year_range'] . ' version of the subject. Click to use another year\'s version." ' . 'href="#" class="dummylink">' . $row['year_range'] . '</span>'; // $row['div'] actually stores the HTML of the class bubble. $row['div'] = <<<EOD <div id="{$row['divid']}" class="{$row['divclasses']}"> <div class="classdivlabel"> <div class="classdivcourse">{$row['subject_id']}: </div> <div class="classdivtitle" title="{$row['subject_title']}"> {$row['subject_title']} </div> </div> <div class="classdivinfo"> <div class="classdivyear">{$row['yearspan']}</div> <div class="reqs">{$reqs}</div> </div> </div> EOD; return $row; }