protected function getJoinedQuery() { if (!$this->joinedQuery) { $this->joinedQuery = CourseQuery::create()->filterById($this->getCourseId())->join('Course.Dept')->join('Dept.Term')->join('Term.Campus')->join('Campus.School')->withColumn('Dept.Abbr', 'DeptAbbr')->withColumn('Course.Name', 'CourseName')->withColumn('Term.Slug', 'TermSlug')->withColumn('Campus.Slug', 'CampusSlug')->withColumn('School.Slug', 'SchoolSlug')->withColumn('School.NbCampuses', 'SchoolNbCampuses')->withColumn('Course.Num', 'CourseNum')->withColumn('Course.NbSections', 'CourseNbSections')->findOne(); } return $this->joinedQuery; }
public function getCourseSelect() { $this->ensureConsistency(); $courses = CourseQuery::create()->filterByDept($this)->withColumn('LPAD(Course.Num, 6, "0")', 'sortkey')->orderBy('sortkey', 'asc')->find(); $r = array(); foreach ($courses as $c) { $r[] = array('name' => $c->getName(), 'id' => $c->getId(), 'number' => $c->getTrimmedNum()); } return $r; }
public function sections($course) { $course = CourseQuery::create()->findPk($course); if ($course) { $course->spider(0); echo json_encode($course->getSectionSelect()); } else { throw new AjaxError("Expected item doesn't exist."); } }
deleteCookieFile(); echo $school->getSlug(); $sectionClass = str_replace('School', 'Section', get_class($school)); $sectionSpiderer = new $sectionClass(); $goodCount = 0; $itemsCount = 0; while (!$goodCount && $itemsCount <= 10) { // we should already be spidered down to the department level for all schools $dept = DeptQuery::create()->filterBySchool($school)->where('Dept.SpideredAt < ?', time() - 60)->orWhere('Dept.SpideredAt IS NULL')->withColumn('RAND()', 'rand')->orderBy('rand')->findOne(); if (!$dept) { echo "WTF\n"; break; } echo $dept->getAbbr(); Spiderer::spider($dept, true, 0); $course = CourseQuery::create()->filterByDept($dept)->where('Course.SpideredAt < ?', time() - 60)->orWhere('Course.SpideredAt IS NULL')->withColumn('RAND()', 'rand')->orderBy('rand')->findOne(); if (!$course) { echo "WTF\n"; break; } echo $course->getNum(); Spiderer::spider($course, true, 0); $section = SectionQuery::create()->filterByCourse($course)->where('Section.SpideredAt < ?', time() - 60)->orWhere('Section.SpideredAt IS NULL')->withColumn('RAND()', 'rand')->orderBy('rand')->findOne(); if (!$section) { echo "WTF\n"; break; } echo $section->getNum(); $sectionSpiderer->spider(array($section), 0); $shis = SectionHasItemQuery::create()->filterBySection($section)->joinWith('SectionHasItem.Item'); $goodCount = $shis->keepQuery()->where('Item.Isbn IS NOT NULL')->where('Item.Isbn != ?', '')->count();
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(CoursePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $ret = $this->preDelete($con); if ($ret) { CourseQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (PropelException $e) { $con->rollBack(); throw $e; } }
function updateCoursesAndSectionsNew() { global $courses; //need the dot instead of a more specific dash because there's a unicode dash occasionally $time = "/\\s*\\d{1,2}\\:\\d{1,2}\\s*.?\\s*\\d{1,2}\\:\\d{1,2}\\s*[paPA][mM]\\s*/"; //echo preg_match($time, "10:10 – 11:30 am"); $base = "http://inside.bard.edu/academic/courses/current/"; $pages = array("anthropology", "lit2courses", "music", "physics", "barc", "arthistory", "dance", "film", "photography", "studioart", "theater", "sequence", "writers", "lit3courses", "arabic", "chinese", "classic", "greek", "latin", "sanskrit", "french", "german", "hebrew", "italian", "japanese", "russian", "spanish", "biology", "chemistry", "computer", "mathematics", "hpsscience", "economics", "bgia", "history", "philosophy", "politicalstudies", "psychology", "religion", "socialstudies", "sociology", "amstudies", "asian_studies", "classic", "fstudies", "gstudies", "hrp", "istudies", "restudies", "sts", "sstudies", "africana", "cogsci", "envstudies", "gss", "gis", "hrp", "ics", "js", "lais", "meds", "middleeast.htm", "spolicy", "socialstudies", "sre", "theology", "vs"); foreach ($pages as $p) { $result = file_get_contents($base . $p . (preg_match("/\\.htm/", $p) ? "" : ".html")); $dom = new DOMDocument(); @$dom->loadHTML($result); $xpath = new DOMXPath($dom); $trs = $xpath->query('//tr'); foreach ($trs as $tr) { var_dump($tr); $professor = (string) current($xpath->query('/td[2]/p/b[0]', $tr)); echo $professor; $course = (string) current($xpath->query('/td[1]/p[0]/b/span', $tr)); $courseParts = explode(" ", $course); $name = (string) current($xpath->query('/td[1]/p[0]/b/span/span[1]', $tr)); $name .= (string) current($xpath->query('/td[1]/p[1]/b/span', $tr)); $course = CourseQuery::create()->filterByNum($courseParts[1])->useDeptQuery()->filterByAbbr($courseParts[0])->useTermQuery()->useCampusQuery()->useSchoolQuery()->filterBySlug('bard')->endUse()->endUse()->endUse()->endUse()->findOne(); if ($course) { $course->setName($name)->save(); $sections = SectionQuery::create()->filterByCourseId($course->getId()); if ($professor && $sections->keepQuery()->count() > 1) { foreach ($sections->find() as $s) { $s->reload()->setProfessor($professor)->save(); } } } } return; ////// $rows = explode("<tr", $result); unset($rows[0]); foreach ($rows as $r) { preg_match_all("/\\>\\s*([^\\>\\<]*[A-Za-z]+[^\\>\\<]*)\\s*\\</", $r, $matches, PREG_SET_ORDER); foreach ($matches as &$m) { $m = $m[1]; } reset($matches); preg_match("/\\s([A-Z]+)\\s*(\\d+)/", " " . $matches[0], $details); $deptAbbr = $details[1]; $courseNum = $details[2]; $hasSection = preg_match("/^[A-Z]+\$/", $matches[1], $sectionMatches); $sectionNum = $hasSection ? $sectionMatches[0] : "1"; $timeIndex = false; $timeCount = 0; foreach ($matches as $i => $m) { if (preg_match($time, $m)) { //echo "<b>$m</b>"; if (!$timeIndex) { $timeIndex = $i; } $timeCount++; } else { if (preg_match("/Lab\\s[A-Z]|\\(Lecture|Burton\\sBrody/", $m)) { echo "aa"; $timeCount++; } } } echo $timeIndex; echo $timeCount; $professor = $matches[2 + (int) $hasSection]; $courseName = $hasSection ? $matches[2] : $matches[1]; if ($timeIndex > 4 + (int) $hasSection + ($timeCount - 1)) { $courseName .= " " . $matches[2 + (int) $hasSection]; } $courseName = trim(preg_replace("/\\s+/", " ", $courseName)); $professor = preg_replace("/\\s+/", " ", $professor); if ($professor) { $courseName = str_replace(trim($professor), "", $courseName); } $courseName = trim(preg_replace("/:\\s*\$/", "", $courseName)); $course = CourseQuery::create()->filterByNum($courseNum)->useDeptQuery()->filterByAbbr($deptAbbr)->useTermQuery()->useCampusQuery()->useSchoolQuery()->filterBySlug('bard')->endUse()->endUse()->endUse()->endUse()->findOne(); if ($course) { $course->setName($courseName)->save(); $section = SectionQuery::create()->filterByCourse($course)->findOne(); if ($section && $professor) { $section->setProfessor($professor)->save(); } $sections = SectionQuery::create()->filterByCourse($course)->find(); foreach ($sections as $section) { $section->setName($section->makeName())->save(); } } } //die(); } foreach ($courses as $key => $name) { preg_match("/([^\\d]+)(.+)/", $key, $matches); print_r($matches); if ($key == 'FYSFSEM') { $matches[1] = 'FYS'; $matches[2] = 'FSEM'; } if ($key == 'FYSADD ON') { $matches[1] = 'FYS'; $matches[2] = 'ADD ON'; } $course = CourseQuery::create()->filterByNum($matches[2])->useDeptQuery()->filterByAbbr($matches[1])->useTermQuery()->useCampusQuery()->useSchoolQuery()->filterBySlug('bard')->endUse()->endUse()->endUse()->endUse()->findOne(); if ($course) { $course->setName($name)->save(); } } }
/** * Returns a new CourseQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return CourseQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof CourseQuery) { return $criteria; } $query = new CourseQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
public function updateSections($catalog, $sections = null) { decho("Updating sections... "); if (!$sections) { $sections = $catalog->getAllSections(); } // if metadata provider doesn't do mass section lookup if (!$sections) { $query = $this->filterByCatalog(new DeptQuery(), $catalog); $sections = array(); foreach ($query->find() as $dept) { if ($data = $catalog->getSectionsByDept($dept->getAbbr())) { $foo = array(); foreach ($data as $section) { $section['DeptAbbr'] = $dept->getAbbr(); $foo[] = $section; } $sections = array_merge($sections, $foo); } } } // if metadata provider doesn't do per-department section lookup either if (!$sections) { $query = CourseQuery::create()->join('Course.Dept')->withColumn('Dept.Abbr', 'DeptAbbr')->useDeptQuery(); $query = $this->filterByCatalog($query, $catalog)->endUse(); $sections = array(); foreach ($query->find() as $c) { if ($data = $catalog->getSectionsByCourse($c->getDeptAbbr(), $c->getNum())) { $foo = array(); foreach ($data as $section) { $section['DeptAbbr'] = $c->getDeptAbbr(); $section['CourseNum'] = $c->getNum(); $foo[] = $section; } $sections = array_merge($sections, $foo); } } } // if metadata provider doesn't do per-course section lookup either if (!$sections) { $query = SectionQuery::create()->join('Section.Course')->join('Course.Dept')->withColumn('Course.Num', 'CourseNum')->withColumn('Dept.Abbr', 'DeptAbbr')->useCourseQuery()->useDeptQuery(); $query = $this->filterByCatalog($query, $catalog)->endUse()->endUse(); $sections = array(); foreach ($query->find() as $s) { if ($data = $catalog->getSection($s->getDeptAbbr(), $s->getCourseNum(), $s->getNum())) { $data['DeptAbbr'] = $s->getDeptAbbr(); $data['CourseNum'] = $s->getCourseNum(); $sections[] = $data; } } } // if metadata provider doesn't do single section lookup either if (!$sections) { decho("fail\n"); } else { $depts = array(); $courses = array(); foreach ($sections as $section) { $s = SectionQuery::create()->filterByNum($section['Num'])->useCourseQuery()->filterByNum($section['CourseNum'])->useDeptQuery()->filterByAbbr($section['DeptAbbr']); $s = $this->filterByCatalog($s, $catalog)->endUse()->endUse()->findOne(); if (!$s) { decho("Unknown section: {$section['DeptAbbr']}:" . "{$section['CourseNum']}: {$section['Num']}\n"); } else { $s->setProfessor($section['Professor'])->save(); } if (isset($section['DeptName']) && $section['DeptName']) { $depts[] = array('Abbr' => $section['DeptAbbr'], 'Name' => $section['DeptName']); } if (isset($section['CourseName']) && $section['CourseName']) { $courses[] = array('DeptAbbr' => $section['DeptAbbr'], 'Num' => $section['CourseNum'], 'Name' => $section['CourseName']); } } decho("success\n"); if ($depts) { $this->updateDepts($catalog, $depts); } if ($courses) { $this->updateCourses($catalog, $courses); } } }
/** * Returns the number of related Course objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Course objects. * @throws PropelException */ public function countCourses(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if (null === $this->collCourses || null !== $criteria) { if ($this->isNew() && null === $this->collCourses) { return 0; } else { $query = CourseQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByDept($this)->count($con); } } else { return count($this->collCourses); } }
//var_dump($result); //die(); preg_match_all("/header\"\\>(.+?)\\</", $result, $matches); $matches = $matches[1]; print_r($matches); for ($i = 0; $i < count($matches); $i += 11) { $num = substr($matches[$i], strpos($matches[$i], '0'), 6); $section = curl_get("http://voyager.adminsvc.temple.edu/tucourses/tu_coursesdescrip.asp?name={$num}&Clear=Yes"); if (preg_match("/Instructor.+?descripNobold\"\\>([^<]+?),([^<]+?)\\</s", $section, $m)) { $prof = trim(preg_replace("/\\s+/", ' ', $m[2] . $m[1])); } else { $prof = null; } $cnum = ltrim($matches[$i + 1], '0'); $snum = $matches[$i + 3]; $cname = formatCourseName($matches[$i + 4]); $course = CourseQuery::create()->filterByDept($dept)->filterByNum($cnum)->findOne(); if ($course) { echo "setting {$cname}\n"; $course->setName($cname)->save(); if ($prof) { $section = SectionQuery::create()->filterByCourse($course)->filterByNum($snum)->findOne(); if ($section) { echo $prof . "\n"; $section->setProfessor($prof)->save(); } } } } } }
<?php $term = '201130'; require_once __DIR__ . '/../functions.php'; $school = SchoolQuery::create()->filterBySlug('northeastern')->findOne(); // update departments $depts = curl_post("https://bnr8ssbp.neu.edu/udcprod8/bwckctlg.p_disp_cat_term_date", array('call_proc_in' => 'bwckctlg.p_disp_dyn_ctlg', 'cat_term_in' => $term)); preg_match("/sel_dept.+?\\/SELECT/s", $depts, $matches); preg_match_all("/VALUE\\=\"(.+?)\"\\>(.+?)\\</s", $matches[0], $matches, PREG_SET_ORDER); foreach ($matches as $m) { $dept = DeptQuery::create()->filterBySchool($school)->filterByAbbr($m[1])->findOne(); if ($dept) { $dept->setName($m[2])->save(); } } $courses = CourseQuery::create()->filterBySchool($school)->find(); foreach ($courses as $c) { $result = curl_get("https://bnr8ssbp.neu.edu/udcprod8/bwckctlg.p_disp_course_detail?" . "cat_term_in={$term}&subj_code_in=" . $c->getDept()->getAbbr() . "&crse_numb_in=" . $c->getNum()); if (preg_match('/' . $c->getDept()->getAbbr() . '\\s' . $c->getNum() . '\\s\\-\\s(.+?)\\</', $result, $matches)) { echo $c->getDept()->getAbbr() . $c->getNum() . "\n"; $c->setName(htmlspecialchars_decode($matches[1]))->save(); } $url = "https://bnr8ssbp.neu.edu/udcprod8/bwckctlg.p_disp_listcrse?term_in={$term}&subj_in=" . $c->getDept()->getAbbr() . "&crse_in=" . $c->getNum() . "&schd_in="; $sections = curl_get($url); if (preg_match_all("/(\\d{5})\\s\\-\\s.+?Instructors\\:\\s\\<\\/SPAN\\>(.+?)(?:\\<|\\()/s", $sections, $matches, PREG_SET_ORDER)) { foreach ($matches as $m) { $section = SectionQuery::create()->filterByCourse($c)->filterByNum($m[1])->findOne(); if ($section) { $section->setProfessor(trim($m[2]))->save(); } }
$depts = DeptQuery::create()->filterBySchool($school)->find(); foreach ($depts as $d) { if (isset($departments[$d->getAbbr()])) { $d->setName($departments[$d->getAbbr()])->save(); } } // update courses $term = "Spring+2011"; $url1 = "http://fusionmx.babson.edu/CourseListing/index.cfm?fuseaction=CourseListing.DisplayCourseListing&blnShowHeader=false&program=Graduate&semester={$term}&sort_by=course_number&btnSubmit=Display+Courses"; $url2 = "http://fusionmx.babson.edu/CourseListing/index.cfm?fuseaction=CourseListing.DisplayCourseListing&blnShowHeader=false&program=Undergraduate&semester={$term}&sort_by=course_number&btnSubmit=Display+Courses"; $result = curl_get($url2) . curl_get($url1); preg_match_all("/85\"\\>([A-Z]+)(\\d+)\\-([A-Z\\d]+)\\<\\/td\\>.+?400\\);\"\\>(.+?)\\<\\/a.+?nowrap\"\\>(.+?),.+?\\<\\/span/s", $result, $matches, PREG_SET_ORDER); foreach ($matches as $m) { unset($m[0]); print_r($m); $dept = DeptQuery::create()->filterBySchool($school)->filterByAbbr($m[1])->findOne(); if (!$dept) { continue; } $course = CourseQuery::create()->filterByDept($dept)->filterByNum(ltrim($m[2], '0'))->findOne(); if (!$course) { continue; } $name = preg_replace("/\\(.+\\)\$/", "", $m[4]); $course->setName(formatCourseName($name))->save(); $section = SectionQuery::create()->filterByCourse($course)->filterByNum($m[3])->findOne(); if (!$section) { continue; } $section->setProfessor(trim($m[5]))->save(); }
/** * Get the associated Course object * * @param PropelPDO Optional Connection object. * @return Course The associated Course object. * @throws PropelException */ public function getCourse(PropelPDO $con = null) { if ($this->aCourse === null && ($this->course_b_id !== "" && $this->course_b_id !== null)) { $this->aCourse = CourseQuery::create()->filterByCourseMetadata($this)->findOne($con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aCourse->addCourseMetadatas($this); */ } return $this->aCourse; }
/** * Finds the related Course objects and keep them for later * * @param PropelPDO $con A connection object */ protected function findRelatedCourses($con) { $criteria = clone $this; if ($this->useAliasInSQL) { $alias = $this->getModelAlias(); $criteria->removeAlias($alias); } else { $alias = ''; } $this->courses = CourseQuery::create()->joinSection($alias)->mergeWith($criteria)->find($con); }