protected function proceed() { switch ($this->action) { case 'get': $this->succeed(CompositionsService::get($this->params['id'])); break; case 'getAll': $this->succeed(CompositionsService::getAll()); break; } }
static function get($id) { $pdo = PDOBuilder::getPDO(); $comp = null; $sql = "SELECT * FROM PRODUCTS LEFT JOIN PRODUCTS_CAT ON PRODUCT = ID " . "WHERE CATEGORY = :cat AND ID = :id"; $stmt = $pdo->prepare($sql); $stmt->bindValue(":cat", CompositionsService::CAT_ID); $stmt->bindParam(":id", $id); $stmt->execute(); if ($row = $stmt->fetch()) { $comp = CompositionsService::build($row); return $comp; } else { return null; } }
protected function setUp() { $this->products = array(); $this->compositions = array(); // Setup tax and categories $taxCat = new TaxCat("Tax"); $tax = new Tax(null, "Tax", stdtimefstr("2001-01-01 00:00:00"), 0.1); $taxCat->addTax($tax); $taxCat->id = TaxesService::createCat($taxCat); $pdo = PDOBuilder::getPDO(); $id = CompositionsService::CAT_ID; $catCmp = new Category(null, "Compositions", false, 1); $sql = "INSERT INTO CATEGORIES (ID, NAME, PARENTID, DISPORDER, IMAGE) " . "VALUES (:id, :name, :pid, :order, null)"; $stmt = $pdo->prepare($sql); $stmt->bindParam(":name", $catCmp->label, \PDO::PARAM_STR); $stmt->bindParam(":pid", $catCmp->parentId, \PDO::PARAM_INT); $stmt->bindParam(":id", $id, \PDO::PARAM_INT); $stmt->bindParam(":order", $catCmp->dispOrder, \PDO::PARAM_INT); $stmt->execute(); $cat = new Category(null, "Category", false, 2); $cat->id = CategoriesService::createCat($cat); // Set up products $prd = new Product("REF", "product", 1.0, $cat->id, null, 1, $taxCat->id, true, true, 0.3, null, "12345", false, true, 0.2); $prd->id = ProductsService::create($prd, null); $this->products[] = $prd; $prd2 = new Product("REF2", "product2", 2.0, $cat->id, null, 3, $taxCat->id, true, false); $prd2->id = ProductsService::create($prd2, null); $this->products[] = $prd2; $cmp = new Composition("CMP", "composition", 1.0, $id, 1, $taxCat->id, true, true, 0.3, null, "12345", false, true, 0.2); $subgrp = new Subgroup(null, "Subgroup", 1, false); $subgrp->addProduct(new SubgroupProduct($prd->id, null, 1)); $subgrp->addProduct(new SubgroupProduct($prd2->id, null, 2)); $cmp->addGroup($subgrp); $cmp->id = CompositionsService::create($cmp, null, null); $this->compositions[] = $cmp; }