/** * @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); }
/** * * @param Usuario $usuario * @return int Key for Inventario */ public function verificar(Usuario $usuario) { $inventarios = $usuario->getInventario()->toArray(); $inventario = null; $key = null; foreach ($inventarios as $k => $i) { if ($i->getItem()->getId() == $this->item->getId()) { $inventario = $i; $key = $k; } } if (is_null($inventario)) { throw new \Exception('Não possui o item: ' . $this->item->getNome()); } return $key; }
public function getId($plain = false) { if ($plain) { return parent::getId(); } return 'gallery' . parent::getId(); }
/** * Test right the execution of an item callback. * * @covers ::__construct * @covers ::getId * @return void */ public function testGetId() { $str = 'HoLa MuNdo'; $item = new Item(function ($string) { return strtolower($string); }, $str); $this->assertNotNull($item->getId()); }
/** * @param Item $item * @return void **/ public function addItem(Item $item) { $id = $item->getId(); if (!array_key_exists($id, $this->items)) { $this->items[$id] = array('object' => $item, 'amount' => 0); $this->items[$id]['amount']++; } }
public function addItem(Item $item) { $id = $item->getId(); if (!array_key_exists($id, $this->items)) { $this->items[$id]['object'] = $item; $this->items[$id]['amount'] = 0; } $this->items[$id]['amount']++; }
public function add(Item $item) { //ak uz existuje, pripocita pocet $old_item = $this->mapper->find($item->getId()); if ($old_item) { $count = $old_item->count + $count; } $this->mapper->save($item, $count); return $item; }
/** * @return void **/ public function __construct() { $fp = fopen(ROOT . '/data/AbstractFactory/item.csv', 'r'); while ($data = fgetcsv($fp, 1000, ',')) { $item = new Item(); $item->setId($data[0]); $item->setName($data[1]); $this->items[$item->getId()] = $item; } fclose($fp); }
function test_find() { //Arrange $name = "Hello Kitty"; $name2 = "Pokemon"; $test_Item = new Item($name); $test_Item->save(); $test_Item2 = new Item($name2); $test_Item2->save(); //Act $result = Item::find($test_Item2->getId()); //Assert $this->assertEquals($test_Item2, $result); }
/** * * @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 Item $item * @return mixed * @throws Exception */ public function findPhotosByItem(Item $item) { $id_item = $item->getId(); $query = "SELECT * FROM photo_item WHERE id_item = " . $id_item; $data = $this->db->query($query); if ($data) { $photos = $data->fetchAll(PDO::FETCH_CLASS, "Item", array($this->db)); if ($photos) { return $photos; } else { throw new Exception('Fetch error'); } } else { throw new Exception('Query error'); } }
private function __construct() { $fp = fopen('item_data.txt', 'r'); /** * */ $dummy = fgets($fp, 4096); $this->item = array(); while ($buffer = fgets($fp, 4096)) { $item_id = trim(substr($buffer, 0, 10)); $item_name = trim(substr($buffer, 10, 20)); $item_price = trim(substr($buffer, 30)); //echo 'id:'.$item_id. "\n"; $item = new Item($item_id, $item_name, $item_price); $this->items[$item->getId()] = $item; } fclose($fp); }
public function save(Item $item, $count) { $count = (int) $count; if ($item->getId() === NULL) { // insert $data = $this->itemToData($item); // vytáhne data z entity a vrátí jako pole $id = $this->conn->insert('shopping_cart', $data)->execute(); $this->setIdentity($item, $id); } else { // update $data = $this->itemToData($item); // vytáhne data z entity a vrátí jako pole // tady se velice hodí logika, která porovná v jakém stavu byla entita při načtení // a v jakém je teď, aby se nemuselo posílat všechno, ale to jsou hodně pokročílé funkce // a optimalizace se má dělat až když je potřeba, že :) $this->conn->update('shopping_cart', $data)->where('id = %i', $item->getId())->execute(); } }
private function __construct() { $fp = fopen(dirname(__DIR__) . '/item_data.txt', 'r'); /** * ヘッダ行を抜く */ $dummy = fgets($fp, 4096); $this->items = array(); while (($buffer = fgets($fp, 4096)) !== false) { $data = explode("\t", trim($buffer)); if (count($data) !== 3) { continue; } list($item_id, $item_name, $item_price) = $data; $item = new Item($item_id, $item_name, $item_price); $this->items[$item->getId()] = $item; } fclose($fp); }
public function addToCart(User $user, Item $item, $quantity) { $idItem = intval($item->getId()); if (ctype_digit($quantity)) { if ($quantity > 0) { if ($quantity <= $item->getStock()) { $quantity = intval($quantity); } else { $quantity = intval($item->getStock()); } if ($quantity) { if (isset($_SESSION['id'])) { $idCart = intval($user->getCart()->getId()); $query = "INSERT INTO order (id_cart, id_item, quantity) VALUES (" . $idCart . ", " . $idItem . ", " . $quantity . ")"; $result = $this->database->exec($query); if ($result) { $id = $this->database->lastInsertId(); if ($id) { return $user->getCart(); } else { throw new Exception("Catastrophe serveur."); } } else { throw new Exception("Catastrophe base de données."); } } else { throw new Exception("Erreur vraiment bizarre, là, je peux pas aider."); } } else { throw new Exception("Pas de quantité, sérieusement ? ON ENVOIE AU HASARD ?"); } } else { throw new Exception("La quantité doit être supérieure à 0, vilain violeur de poules."); } } else { throw new Exception("La quantité doit être un nombre, vilain lutin violeur de lapins."); } }
/** * Exclude object from result * * @param Item $item Object to remove from the list of results * * @return ItemQuery The current query, for fluid interface */ public function prune($item = null) { if ($item) { $this->addUsingAlias(ItemPeer::ID, $item->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Add/update Item in cart * * @param Item * @return Cart */ public function setItem(Item $item) { $key = Item::getKey($item->getId()); $this->_items[$key] = $item; return $this; }
/** * @return int */ public function getItemId() { return $this->item->getId(); }
/** * @brief Update the item after its status has changed * @returns The item whose status has changed. */ public function update(Item $item) { $itemid = $item->getId(); $status = $item->getStatus(); $stmt = \OCP\DB::prepare(' UPDATE ' . self::tableName . ' SET status = ? WHERE id = ? '); $params = array($status, $itemid); $result = $stmt->execute($params); return true; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param Item $value A Item object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(Item $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
function testFind() { //Arrange $description = "Pliny the Elder"; $cost = 5.0; $id = null; $test_item = new Item($description, $cost, $id); $test_item->save(); $description2 = "Lagunitas IPA"; $cost2 = 7.0; $test_item2 = new Item($description2, $cost2, $id); $test_item2->save(); //Act $result = Item::find($test_item2->getId()); //Assert $this->assertEquals($test_item2, $result); }
/** * Add an Item to this Discount * * @param Item $item * @param int $qty * @return Discount */ public function setItem(Item $item) { $key = Item::getKey($item->getId()); if (!in_array($key, $this->getItems())) { $this->_items[] = $key; } return $this; }
public function delete(Item $item) { $id = $item->getId(); $query = 'DELETE FROM item WHERE id=' . $id; $res = $this->db->exec($query); if ($res) { return true; } else { throw new Exception('Database error'); } }
$tab_retour_lot = LotManager::updateBdd($obj_lot); if (isset($http_request['edit_type'])) { switch ($tab_retour_lot[0]) { case 0: //Succès de la mise à jour setFlashData('message', "Mise à jour effectuée avec succès !"); break; default: //Problème de mise à jour setFlashData('message', $tab_retour_lot[1]); break; } } } else { if ($prix != "" || $http_request['valide_lot'] == "on") { $obj_lot = new Lot($obj_item->getId()); $obj_lot->setPrix($prix); if ($http_request['valide_lot'] == "on") { $obj_lot->setValideLot(1); } else { $obj_lot->setValideLot(0); } $tab_retour_lot = LotManager::insertBdd($obj_lot); } } if (ItemFlotteManager::get($id) != null) { $obj_flotte = new ItemFlotte($id); $obj_flotte->setImage($imageFlotte); $obj_flotte->setImageBis($imageBisFlotte); $obj_flotte->setImageVignette($imageVignetteFlotte); $obj_flotte->setIdCategorie($flotteCat);
/** * Declares an association between this object and a Item object. * * @param Item $v * @return ShoppingCart The current object (for fluent API support) * @throws PropelException */ public function setItem(Item $v = null) { if ($v === null) { $this->setItemId(NULL); } else { $this->setItemId($v->getId()); } $this->aItem = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the Item object, it will not be re-added. if ($v !== null) { $v->addShoppingCart($this); } return $this; }
<h1>Definovanie výrobku:<?php echo $vyrobok->getName(); ?> </h1> <ul id="zoznam_skladov"> <?php //nacitame sklady na prepinac, prednastaveny bude aktivny sklad $query = $database->select("SELECT * FROM sklad WHERE organizacia_id = '" . $uzivatel->getIdOrganizacie() . "'"); while ($vysl = $database->fetch_array($query)) { //prebehne vsetky nacitane sklady uzivatela //kontrola na aktualnost skladu if ($aktivny_sklad->getId() == $vysl["id"]) { // pri aktivnom sklade vypiseme len nazov echo "<li>" . $vysl["name"] . "</li>"; } else { echo "<li><form><input type='submit' name='submit' value='" . $vysl["name"] . "' >\r\n <input type='hidden' name='sklad_id' value='" . $vysl["id"] . "' >\r\n <input type='hidden' name='vyrobok_id' value='" . $vyrobok->getId() . "' > \r\n <input type='hidden' name='action' value='aktivuj_sklad' > \r\n <input type='hidden' name='pageaction' value='definuj_vyrobok'>\r\n </form></li>"; } } ?> </ul> <?php //pokial uz bol definovany ako vyrobok predtym, nahrame jeho uz v databaze ulozene udaje, ale len ked este nemame aktivovane session if (!isset($_SESSION["zoznam_poloziek_definicia"]) && $vyrobok->zistiCiSomVyrobok()) { $vyrobok = new Vyrobok(); //premazanie udajov $vyrobok->loadItem($vyrobok_id); //nahra zakladne udaje o vyrobku $vyrobok->loadTovarFromDatabase(); //nahra tovary do vyrobku $vyrobok->nahrajPolozkyDoSession("zoznam_poloziek_definicia"); //nahra uz predtym zvolene udaje do Session
/** * Set article data * * @param Article $article * @param Newscoop\News\Item $item * @return void */ private function setArticleData(\Article $article, Item $item) { $data = $this->getArticleData($article); $data->setProperty('Fguid', $item->getId()); $data->setProperty('Fversion', $item->getVersion()); $data->setProperty('Furgency', $item->getContentMeta()->getUrgency()); $data->setProperty('Fcopyright', $item->getRightsInfo()->first()->getCopyrightNotice()); $data->setProperty('Fprovider', $item->getItemMeta()->getProvider()); $data->setProperty('Fdescription', $item->getContentMeta()->getDescription()); $data->setProperty('Fdateline', $item->getContentMeta()->getDateline()); $data->setProperty('Fbyline', $item->getContentMeta()->getByline()); $data->setProperty('Fcreditline', $item->getContentMeta()->getCreditline()); $data->setProperty('Finlinecontent', (string) $item->getContentSet()->getInlineContent()); $data->create(); }
public function updateItem(Item $item, $quantity) { if ($quantity <= 0) { $query = "\tDELETE FROM link_order_item\n\t\t\t\t\t\tWHERE id_order='" . $this->id . "'\n\t\t\t\t\t\tAND id_item='" . $item->getId() . "'"; $res = $this->db->exec($query); if ($res) { $this->items = array(); return $this->getItems(); } else { throw new Exception('Database error'); } } else { $items = $this->getItems(); for ($i = 0, $c = count($items); $i < $c; $i++) { if ($items[$i]->getId() == $item->getId()) { $query = "\tUPDATE link_order_item\n\t\t\t\t\t\t\t\tSET quantity='" . intval($quantity) . "'\n\t\t\t\t\t\t\t\tWHERE id_order='" . $this->id . "'\n\t\t\t\t\t\t\t\tAND id_item='" . $item->getId() . "'"; $res = $this->db->exec($query); if ($res) { $this->items = array(); return $this->getItems(); } else { throw new Exception('Database error'); } } } $query = "\tINSERT INTO link_order_item (id_order, id_item, quantity)\n\t\t\t\t\t\tVALUES('" . $this->id . "', '" . $item->getId() . "', '" . intval($quantity) . "')"; $res = $this->db->exec($query); if ($res) { $this->items = array(); return $this->getItems(); } else { throw new Exception('Database error'); } } }
private function __construct() { $fp = fopen('item_data.txt', 'r'); //ヘッダ行を抜く $dummy = fgets($fp, 4096); //1行1行読みだして、インスタンス化。 //10byteでid/name/priceを区切ったデータを想定している $this->items = array(); while ($buffer = fgets($fp, 4096)) { $item_id = trim(substr($buffer, 0, 10)); $item_name = trim(substr($buffer, 10, 20)); $item_price = trim(substr($buffer, 30)); $item = new Item($item_id, $item_name, $item_price); $this->items[$item->getId()] = $item; } fclose($fp); }
public function delete(Item $item) { unset($this->session[$item->getId()]); }