function doMinimalTest($schools)
{
    $badSchools = $goodSchools = $unsureSchools = array();
    foreach ($schools as $school) {
        $shis = SectionHasItemQuery::create()->filterBySchool($school)->joinWith('SectionHasItem.Item');
        $count = $shis->keepQuery()->where('Item.Isbn != ?', '')->where('Item.Isbn IS NOT NULL')->count();
        $slug = $school->getSlug();
        if ($count > 0) {
            echo "{$slug}: found a suitable item\n";
            $goodSchools[] = $school;
        } else {
            if ($shis->keepQuery()->count() >= 10) {
                echo "{$slug}: didn't find a suitable item, adding to bad schools\n";
                $badSchools[] = $school;
            } else {
                $unsureSchools[] = $school;
            }
        }
    }
    return array($goodSchools, $badSchools, $unsureSchools);
}
Exemplo n.º 2
0
 protected function fetchData()
 {
     $this->allIsbns = $this->isbns;
     $this->items = array();
     if ($this->sectionSlugs) {
         $this->shis = SectionHasItemQuery::create()->rightJoinWith('SectionHasItem.Section')->leftJoinWith('SectionHasItem.Item')->leftJoinWith('Item.Book')->where('Section.SchoolSlug = ?', $this->schoolSlug);
         if ($this->campusSlug) {
             $this->shis->where('Section.CampusSlug = ?', $this->campusSlug);
         }
         $this->shis = $this->shis->where('Section.TermSlug = ?', $this->termSlug)->where('Section.Slug IN ?', $this->sectionSlugs)->where('SectionHasItem.RequiredStatus > 0')->orWhere('SectionHasItem.RequiredStatus IS NULL')->withColumn('Section.NbItems != 0', 'HasItems')->orderBy('HasItems', 'desc')->orderBy('Section.Slug', 'asc')->orderBy('SectionHasItem.RequiredStatus', 'desc')->orderBy('Item.Title', 'asc')->find();
         foreach ($this->shis as $shi) {
             if ($item = $shi->getItem()) {
                 $isbn = $item->getIsbn() ?: $item->getId();
                 $this->items[$isbn] = $item;
                 $this->allIsbns[] = $isbn;
                 if ($item->getIsPackage()) {
                     $packageIds[] = $isbn;
                     $components = Item::getComponents(array($item->getId()));
                     // 1 query per package
                     foreach ($components as $c) {
                         $isbn = $c->getIsbn() ?: $c->getId();
                         $this->items[$isbn] = $c;
                         $this->allIsbns[] = $isbn;
                         $this->excludeIds[] = $isbn;
                     }
                 }
                 if ($shi->getRequiredStatus() <= SectionHasItem::GO_TO_CLASS_FIRST) {
                     $this->excludeIds[] = $isbn;
                 }
             }
         }
     }
     self::fetchPrices($this->allIsbns);
     // populate loose books
     if ($this->isbns) {
         $this->books = BookQuery::create()->filterByIsbn($this->isbns)->find();
     }
 }
 /**
  * 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(SectionHasItemPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = SectionHasItemQuery::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;
     }
 }
Exemplo n.º 4
0
 /**
  * Sets a collection of Section objects related by a many-to-many relationship
  * to the current object by way of the section_has_item cross-reference table.
  * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
  * and new objects from the given Propel collection.
  *
  * @param      PropelCollection $sections A Propel collection.
  * @param      PropelPDO $con Optional connection object
  */
 public function setSections(PropelCollection $sections, PropelPDO $con = null)
 {
     $sectionHasItems = SectionHasItemQuery::create()->filterBySection($sections)->filterByItem($this)->find($con);
     $this->sectionsScheduledForDeletion = $this->getSectionHasItems()->diff($sectionHasItems);
     $this->collSectionHasItems = $sectionHasItems;
     foreach ($sections as $section) {
         // Fix issue with collection modified by reference
         if ($section->isNew()) {
             $this->doAddSection($section);
         } else {
             $this->addSection($section);
         }
     }
     $this->collSections = $sections;
 }
 /**
  * Returns a new SectionHasItemQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return    SectionHasItemQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof SectionHasItemQuery) {
         return $criteria;
     }
     $query = new SectionHasItemQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }