public function terms($campus)
 {
     $campus = CampusQuery::create()->findPk($campus);
     if ($campus) {
         $campus->spider(1);
         echo json_encode($campus->getTermSelect());
     } else {
         throw new AjaxError("Expected item doesn't exist.");
     }
 }
Example #2
0
 public function postSave(PropelPDO $con = null)
 {
     global $skipCampusPostSave;
     if (isset($skipCampusPostSave) && $skipCampusPostSave) {
         return true;
     }
     // update campus slugs
     $siblingCampuses = CampusQuery::create()->filterBySchoolId($this->getSchoolId())->orderBy('Campus.BId', 'asc')->find();
     $skipCampusPostSave = true;
     $i = 1;
     foreach ($siblingCampuses as $campus) {
         $campus->setSlug($i++)->save();
     }
     $skipCampusPostSave = false;
     // update term statuses
     $current = false;
     $terms = array();
     foreach ($this->getTerms() as $term) {
         $terms[] = array($term, $term->guessDate());
     }
     usort($terms, function ($a, $b) {
         return $a[1] == $b[1] ? 0 : ($a[1] < $b[1] ? -1 : 1);
     });
     $seenCurrent = false;
     $now = new DateTime();
     foreach ($terms as $term) {
         $name = strtolower($term[0]->getName());
         $diff = $now->diff($term[1]);
         if (preg_match('/fall|spr/', $name) && abs($diff->days) <= 60) {
             foreach ($terms as $t) {
                 if ($t[0]->getStatus() == 0) {
                     $t[0]->setStatus(1)->save();
                     break;
                 }
             }
             $status = 0;
             $seenCurrent = true;
         } else {
             if (!$seenCurrent && abs($diff->days) <= 60) {
                 $status = 0;
                 $seenCurrent = true;
             } else {
                 if (abs($diff->days) <= 60) {
                     $status = 1;
                 } else {
                     $status = $now < $term[1] ? 1 : -1;
                 }
             }
         }
         $term[0]->setStatus($status)->save();
     }
     if (!$seenCurrent) {
         foreach ($terms as $term) {
             if ($term[0]->getStatus() === 1) {
                 $term[0]->setStatus(0)->save();
                 $seenCurrent = true;
                 break;
             }
         }
     }
     if (!$seenCurrent) {
         foreach ($terms as $term) {
             $term[0]->setStatus(0)->save();
             break;
         }
     }
     return true;
 }
Example #3
0
 public function getCampusSelect()
 {
     $this->ensureConsistency();
     if ($this->getNbCampuses() == 1) {
         return false;
     } else {
         $campuses = CampusQuery::create()->filterBySchool($this)->find();
         $ret = array();
         foreach ($campuses as $campus) {
             $ret[] = array('name' => $campus->getName(), 'id' => (string) $campus->getId(), 'slug' => $campus->getSlug());
         }
         return $ret;
     }
 }
Example #4
0
 /**
  * Returns the number of related Campus objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related Campus objects.
  * @throws     PropelException
  */
 public function countCampuss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if (null === $this->collCampuss || null !== $criteria) {
         if ($this->isNew() && null === $this->collCampuss) {
             return 0;
         } else {
             $query = CampusQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterBySchool($this)->count($con);
         }
     } else {
         return count($this->collCampuss);
     }
 }
Example #5
0
 /**
  * Get the associated Campus object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Campus The associated Campus object.
  * @throws     PropelException
  */
 public function getCampus(PropelPDO $con = null)
 {
     if ($this->aCampus === null && $this->campus_id !== null) {
         $this->aCampus = CampusQuery::create()->findPk($this->campus_id, $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->aCampus->addTerms($this);
         		 */
     }
     return $this->aCampus;
 }
 function render()
 {
     global $vendors;
     $args = func_get_args();
     if (count($args) == 1) {
         $school = $campus = $term = null;
         $ids = $args[0];
     } else {
         if (count($args) == 4) {
             $school = $args[0];
             $campus = $args[1];
             $term = $args[2];
             $ids = isset($args[3]) ? $args[3] : null;
         } else {
             $school = $args[0];
             $campus = null;
             $term = $args[1];
             $ids = isset($args[2]) ? $args[2] : null;
         }
     }
     if (defined('EMERGENCY') && $school) {
         $this->redirect_to_index();
     }
     if (!$school) {
         $isbnMode = true;
         unset($vendors[array_search('Bookstore', $vendors)]);
         $schoolSlug = $campusSlug = $termSlug = false;
     } else {
         $isbnMode = false;
         $school = School::findOneBySlug($school);
         if (!$school) {
             $this->redirect_to_index();
         }
         $vendors[array_search('Bookstore', $vendors)] = $school->getBookstoreType();
         $schoolSlug = $school->getSlug();
         if ($campus) {
             $campus = CampusQuery::create()->filterBySchool($school)->filterBySlug($campus)->findOne();
             if (!$campus) {
                 $this->redirect_to_index();
             }
             $campusSlug = $campus->getSlug();
         } else {
             $campusSlug = false;
         }
         $q = TermQuery::create();
         if ($campus) {
             $q->filterByCampus($campus);
         } else {
             $q->useCampusQuery()->filterBySchool($school)->endUse();
         }
         $term = $q->filterBySlug($term)->findOne();
         if (!$term) {
             $this->redirect_to_index();
         }
         $termSlug = $term->getSlug();
         $termName = $term->getName();
     }
     $this->setTitle('Your Books');
     $this->inlineJS[] = "Globals.SECTION_DELIMITER = '" . SECTION_DELIMITER . "';";
     $this->inlineJS[] = "Globals.SCHOOL_SLUG = " . ($schoolSlug ? "'{$schoolSlug}'" : "false") . ";";
     $this->inlineJS[] = "Globals.CAMPUS_SLUG = " . ($campusSlug ? "'{$campusSlug}'" : "false") . ";";
     $this->inlineJS[] = "Globals.TERM_SLUG = " . ($termSlug ? "'{$termSlug}'" : "false") . ";";
     $this->inlineJS[] = "Globals.IDS = '{$ids}';";
     $this->inlineJS[] = "Globals.THIS_PAGE_URL = '" . CURRENT_URL . "';";
     $this->overrideAnalyticsPageUrl("results");
     // If only one section, use its title as a FB Open Graph title (for share functionality)
     if ($school) {
         $sections = SectionQuery::create()->filterBySlug($ids)->filterBySchoolSlug($schoolSlug)->filterByTermSlug($termSlug);
         if ($campusSlug) {
             $sections->filterByCampusSlug($campusSlug);
         }
         $sections = $sections->find();
         if ($sections->count() == 1) {
             $courseName = $sections[0]->getName();
             $shortName = $school->getShortName();
             $term = $term->getName();
             global $siteName;
             $this->misc[] = "<meta property='og:title' content='{$courseName} &#8250; {$shortName} {$siteName} ({$termName})' />";
         }
     }
     if ($isbnMode) {
         $hashPrefix = "";
     } else {
         if ($campusSlug) {
             $hashPrefix = "{$campusSlug}/{$termSlug}/";
         } else {
             $hashPrefix = "{$termSlug}/";
         }
     }
     $this->renderPage('results', array('isbnMode' => $isbnMode, 'breadcrumbFormat' => 'results', 'schoolSlug' => $schoolSlug, 'ids' => $ids, 'hashPrefix' => $hashPrefix, 'tableClass' => 'vendor' . count($vendors), 'resultsURL' => ''));
 }
 /**
  * Returns a new CampusQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return    CampusQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof CampusQuery) {
         return $criteria;
     }
     $query = new CampusQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 function render()
 {
     global $app;
     $args = func_get_args();
     if (count($args) > 0) {
         $school = $args[0];
     } else {
         $school = null;
     }
     if ($school) {
         if (defined('EMERGENCY')) {
             $this->redirect_to_index();
         }
         $school = School::findOneBySlug($school);
         if (!$school) {
             $this->redirect_to_index();
         }
         // if the school is unspidered, spider it down to departments.
         // if it fails, continue onwards as long as there is old data,
         // otherwise rethrow, which will cause the error page to be
         // displayed
         try {
             $school->spider(2);
         } catch (BookstoreError $e) {
             $app->getLog()->warn($e->getMessage());
             if ($school->getNbCampuses() == 0) {
                 throw $e;
             }
         }
         $multiCampus = $school->getNbCampuses() > 1;
         $bardHACK = $school->getSlug() == "bard";
         if ($multiCampus) {
             $campusId = null;
             $campusSlug = null;
         } else {
             $campus = CampusQuery::create()->filterBySchool($school)->findOne();
             $campusSlug = $campus->getSlug();
             $campusId = $campus->getId();
         }
         $schoolSlug = $school->getSlug();
         $isbnMode = false;
         $itemName = "course";
     } else {
         $school = null;
         $schoolSlug = null;
         $campusSlug = null;
         $multiCampus = false;
         $isbnMode = true;
         $itemName = "book";
         $campusId = null;
         $bardHACK = false;
     }
     $this->inlineJS[] = "var Selection = {};";
     $this->inlineJS[] = "Globals.SECTION_DELIMITER = '" . SECTION_DELIMITER . "';";
     $this->inlineJS[] = "Globals.MULTICAMPUS = " . ($multiCampus ? "true" : "false") . ";";
     $this->inlineJS[] = "Globals.SCHOOL_SLUG = " . ($school ? "'" . addslashes($school->getSlug()) . "'" : "false") . ";";
     $this->inlineJS[] = "Globals.SCHOOL_NAME = " . ($school ? "'" . addslashes($school->getShortName()) . "'" : "false") . ";";
     $this->inlineJS[] = "Globals.campusId = " . ($campusId ? "'{$campusId}'" : 'null') . ";";
     $this->inlineJS[] = "Globals.CAMPUS_SLUG = " . ($campusSlug ? "'{$campusSlug}'" : 'null') . ";";
     $this->inlineJS[] = "Globals.termId = null;";
     $this->inlineJS[] = "Globals.TYPE = '" . ($isbnMode ? "ISBN" : "course") . "';";
     $this->inlineJS[] = "Globals.ITEM_NAME = '" . $itemName . "';";
     $this->overrideAnalyticsPageUrl("selection/" . ($isbnMode ? "isbn" : "course"));
     $this->setTitle($school ? 'Select Courses' : 'Enter Books');
     if ($school) {
         $description = "Just tell us your " . $school->getShortName() . " courses, " . "and we'll look up your books and find the cheapest prices.";
     } else {
         $description = "Input your books by ISBN and we'll do " . "the comparison shopping for you.";
     }
     $this->addMetaTag('description', "Textbooks made easy. {$description}");
     $this->renderPage('selection', array('breadcrumbFormat' => 'selection', 'schoolSlug' => $schoolSlug, 'isbnMode' => $isbnMode, 'multiCampus' => $multiCampus, 'bardHACK' => $bardHACK, 'school' => $school, 'campusWrapperDisplay' => $multiCampus ? 'inline' : 'none', 'topWrapperDisplay' => $multiCampus ? 'none' : 'inline'));
 }
Example #9
0
 /**
  * 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(CampusPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = CampusQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }