private function dispatchScrapeCatalogJob($subject, $row) { $column = $row->childNodes->item(0); $info = $column->childNodes->item(2)->childNodes->item(0)->attributes->getNamedItem('name')->textContent; $split = explode(' ', $info); if (Course::find(implode('', explode(' ', $info))) == null && in_array($info[strlen($info) - 1], ['H', 'X'])) { return; } \Queue::push('Courses\\Jobs\\Scraper\\ScrapeCatalog', ['subject' => $subject, 'level' => $split[1]]); }
private function extractCourseInfo(\DOMDocument $dom, $data) { $key = $dom->getElementsByTagName('h3')->item(0); preg_match('~\\s+([A-Z]+\\s+\\d+[A-Z]*)\\.\\s+([^\\n]+)\\s+\\((\\d+).*\\)\\.\\s+~', $key->textContent, $matches); $course_id = $data['subject'] . $data['level']; $course = Course::firstOrNew(['id' => $course_id]); $course_info = ['id' => $course_id, 'level' => $data['level'], 'title' => trim($matches[2]), 'description' => trim($key->nextSibling->wholeText), 'subject_id' => Subject::find($data['subject'])->id]; if (!is_null($dom->getElementById('ctl00_ContentPlaceHolder1_lblCoursePrereqs'))) { $course_info['prereqs'] = trim($dom->getElementById('ctl00_ContentPlaceHolder1_lblCoursePrereqs')->nextSibling->wholeText); } foreach ($course_info as $key => $value) { $course->{$key} = $value; } $course->save(); return $course_info; }
public function run() { foreach (Course::all() as $course) { $sections = $this->createSections($course); $course->sections()->saveMany($sections); } }
public function findBySubjectId($subject_id) { return Course::with('subject')->whereSubjectId($subject_id); }