Example #1
0
 /**
  * @test
  */
 public function gettersShouldReturnTheAttributeValue()
 {
     $this->assertAttributeEquals($this->item->getId(), 'id', $this->item);
     $this->assertAttributeEquals($this->item->getDescription(), 'description', $this->item);
     $this->assertAttributeEquals($this->item->getAmount(), 'amount', $this->item);
     $this->assertAttributeEquals($this->item->getQuantity(), 'quantity', $this->item);
     $this->assertAttributeEquals($this->item->getShippingCost(), 'shippingCost', $this->item);
     $this->assertAttributeEquals($this->item->getWeight(), 'weight', $this->item);
 }
Example #2
0
 public function testSetGetDescription()
 {
     // Arrange
     $item = new Item();
     $item->setDescription('this is an item description');
     $expectedResult = 'this is an item description';
     // Act
     $result = $item->getDescription();
     // Assert
     $this->assertEquals($result, $expectedResult);
 }
 /**
  *
  * @param Item $item
  * @return type
  * @throws DaoException 
  */
 public function updateItem(Item $item)
 {
     try {
         $query = Doctrine_Query::create()->update('Item i');
         $query->set('i.name', '?', $item->getName());
         $query->set('i.sales_unit_price', '?', $item->getSalesUnitPrice());
         $query->set('i.purchase_unit_price', '?', $item->getPurchaseUnitPrice());
         $query->set('i.description', '?', $item->getDescription());
         $query->set('i.stock_available', '?', $item->getStockAvailable());
         $query->where('i.id = ?', $item->getId());
         return $query->execute();
     } catch (Exception $e) {
         throw new DaoException($e->getMessage(), $e->getCode(), $e);
     }
 }
 /**
  * @param Subcategory $subcategory
  * @param $name
  * @param $descr
  * @param $short_descr
  * @param $price
  * @param $stock
  * @return array
  * @throws Exception
  */
 public function create(Subcategory $subcategory, $name, $descr, $short_descr, $price, $stock)
 {
     $errors = array();
     $item = new Item($this->db);
     try {
         $item->setName($name);
         $item->setDescription($descr);
         $item->setShortDescription($short_descr);
         $item->setPrice($price);
         $item->setStock($stock);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if (count($errors) == 0) {
         $name = $this->db->quote($item->getName());
         $description = $this->db->quote($item->getDescription());
         $shortDescription = $this->db->quote($item->getShortDescription());
         $price = $this->db->quote($item->getPrice());
         $stock = $this->db->quote($item->getStock());
         $query = "  INSERT INTO item(id_subcategory, name, descr, short_descr, price, stock)\n                               VALUES(" . $subcategory->getId() . ", " . $name . ", " . $description . ", " . $shortDescription . ", " . $price . ", " . $stock . ")";
         $data = $this->db->exec($query);
         if ($data) {
             $id = $this->db->lastInsertId();
             if ($id) {
                 try {
                     return $this->findById($id);
                 } catch (Exception $e) {
                     $errors[] = $e->getMessage();
                     return $errors;
                 }
             } else {
                 throw new Exception('Last insert error');
             }
         } else {
             throw new Exception('Db error');
         }
     } else {
         return $errors;
     }
 }
Example #5
0
 function testUpdate()
 {
     //Arrange
     $description = "Pliny the Elder";
     $cost = 5.0;
     $id = null;
     $test_item = new Item($description, $cost, $id);
     $test_item->save();
     $new_description = "Pliny the Younger";
     $new_cost = 10.0;
     //Act
     $test_item->update($new_description, $new_cost);
     //Assert
     $this->assertEquals($new_description, $test_item->getDescription());
     $this->assertEquals($new_cost, $test_item->getCost());
 }
Example #6
0
 /**
  * @covers Debril\RssAtomBundle\Protocol\Parser\Item::setDescription
  */
 public function testSetDescription()
 {
     $newDescription = 'A brand new description';
     $this->object->setDescription($newDescription);
     $this->assertEquals($newDescription, $this->object->getDescription());
 }
Example #7
0
    public function update(Item $item)
    {
        $idCategory = $item->getCategory()->getId();
        $id = intval($id);
        $name = $this->db->quote($item->getName());
        $price = $this->db->quote($item->getPrice());
        $stock = $this->db->quote($item->getStock());
        $image = $this->db->quote($item->getImage());
        $description = $this->db->quote($item->getDescription());
        $query = '	UPDATE item
							SET name=' . $name . ',
								price=' . $price . ',
								stock=' . $stock . ',
								image=' . $image . ',
								description=' . $description . ',
								id_category=' . $idCategory . '
							WHERE id=' . $id;
        $res = $this->db->exec($query);
        if ($res) {
            $id = $this->db->lastInsertId();
            if ($id) {
                return $this->findByID($id);
            } else {
                throw new Exception('Internal server Error');
            }
        }
    }
Example #8
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);
        }
    }
}
 /**
  * Short description of method dolog
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Item item
  * @return mixed
  */
 public function dolog(Item $item)
 {
     // section 127-0-1-1--13fe8a1d:134184f8bc0:-8000:0000000000001852 begin
     if (is_null($this->filehandle)) {
         $this->initFile();
     }
     if ($this->filehandle !== false) {
         $map = array('%d' => date('Y-m-d H:i:s', $item->getDateTime()), '%m' => $item->getDescription(), '%s' => $item->getSeverityDescriptionString(), '%t' => $item->getDateTime(), '%r' => $item->getRequest(), '%f' => $item->getCallerFile(), '%l' => $item->getCallerLine());
         if (strpos($this->format, '%b')) {
             $map['%b'] = 'Backtrace not yet supported';
         }
         $str = strtr($this->format, $map) . "\n";
         @fwrite($this->filehandle, $str);
     }
     // section 127-0-1-1--13fe8a1d:134184f8bc0:-8000:0000000000001852 end
 }