Example #1
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();
     }
 }
Example #2
0
/**
 * Prints the metadata and prices for an item
 * @param Item|Book $item   an Item (Section mode) or Book (ISBN mode) object
 * @param int $requiredStatus
 */
function printItemRow($item, $status = null)
{
    global $app;
    ?>
    <tr>
        <th>
            <span class="tooltip" style="display: none;">
                <img src="<?php 
    echo $item->getImageUrl();
    ?>
">
                <h1><?php 
    echo $item->getTitle();
    ?>
</h1>
                <h2><?php 
    echo $item->getAuthor();
    ?>
</h2>
                <?php 
    if ($edition = $item->getEdition()) {
        ?>
                    <div class="edition"><strong>Edition:</strong> <?php 
        echo $edition;
        ?>
</div>
                <?php 
    }
    if ($publisher = $item->getPublisher()) {
        ?>
                    <div class="publisher"><strong>Publisher:</strong> <?php 
        echo $publisher;
        ?>
</div>
                <?php 
    }
    if ($isbn = $item->getIsbn()) {
        ?>
                    <div class="isbn"><strong>ISBN:</strong> <span class="isbn"><?php 
        echo $isbn;
        ?>
</span></div>
                <?php 
    }
    ?>
            </span>
            <?php 
    $indented = $item->isPackageComponent() || $status === SectionHasItem::BOOKSTORE_RECOMMENDED;
    $class = $indented ? " packageComponent" : "";
    ?>

            <span class="bookdata <?php 
    echo $class;
    ?>
">
                <span class="title"><?php 
    echo $item->getTitle();
    ?>
</span><br>
                <?php 
    if ($edition || $item->getAuthor()) {
        ?>
                <span class="minimetadata"><?php 
        echo ($edition ? "{$edition}, " : "") . $item->getAuthor();
        ?>
</span>
                <?php 
    }
    ?>
                <?php 
    // e.g. (Recommended)
    if ($stat = Item::getStatusText($status)) {
        ?>
                    <br/><span class="minimetadata"><?php 
        echo $stat;
        ?>
</span>
                <?php 
    }
    // sentence about being a package or component
    if ($description = $item->getDescription($status)) {
        ?>
                    <br/><span class="minimetadata important"><?php 
        echo $description;
        ?>
</span>
                <?php 
    }
    ?>
            </span>
        </th>

    <?php 
    foreach ($item->prices as $v => $p) {
        if ($p === null) {
            if ($v === $GLOBALS['results']->bookstore) {
                ?>
                <td data-price="-1" class="empty" data-unknown="true">unknown</td>
            <?php 
            } else {
                ?>
                <td data-price="-1" class="empty">&mdash;</td>
            <?php 
            }
        } else {
            ?>

            <td data-price="<?php 
            echo money($p->total);
            ?>
"
                <?php 
            if ($p->asteriskPrice) {
                ?>
                    data-used="<?php 
                echo money($p->asteriskPrice);
                ?>
"
                <?php 
            }
            ?>
                data-subtotal="<?php 
            echo money($p->subtotal);
            ?>
"
                data-shipping="<?php 
            echo money($p->shipping + $p->tax);
            ?>
">

                <a href="<?php 
            echo $app->urlFor('redirect', array('url' => '', 'type' => 'single', 'vendor' => $p->vendorName)) . $p->url;
            ?>
"
                   data-confirm="<?php 
            echo $p->getDescription();
            ?>
">

                    <?php 
            if ($p->total == 0) {
                ?>
                        unknown
                    <?php 
            } else {
                ?>
                        $<?php 
                echo money($p->total);
                echo $p->asteriskPrice ? '*' : '';
                ?>
                    <?php 
            }
            ?>

                </a>
            </td>
        <?php 
        }
        ?>
    <?php 
    }
    // end: foreach $item->prices
    ?>
    </tr>
    <?php 
    if ($item->getIsPackage()) {
        $components = Item::getComponents(array($item->getId()));
        foreach ($components as $c) {
            printItemRow($c);
        }
    }
}