コード例 #1
0
ファイル: products.php プロジェクト: NeroJz/ci_doctrine
 public function insert()
 {
     $isClicked = $this->input->post('insertProduct');
     if ($isClicked == "insert") {
         $productName = $this->input->post('productName');
         $product = new Product();
         $product->setName($productName);
         $this->em->persist($product);
         $this->em->flush();
         redirect('products/show', 'refresh');
     }
     $data['content'] = $this->load->view('product/insert', NULL, true);
     $this->load->view('main', $data);
 }
コード例 #2
0
ファイル: ProductBuilder.php プロジェクト: blackneck/EcoStore
 /**
  * @param Manufacturer[] $manufacturers
  * @param Category[] $categories
  * @param Image[] $images
  * @param object[] $productManufacturerBinds
  * @param object[] $productCategoryBinds
  * @param object[] $productImageBinds
  * @param object[] $productPrices
  * @param object[] $objects
  * 
  * @return Product[] 
  */
 function buildAll(array $manufacturers, array $categories, array $images, array $productManufacturerBinds, array $productCategoryBinds, array $productImageBinds, array $productPrices, array $objects)
 {
     $retval = array();
     //Задаем имена свойств, выражающих связи: поле со значением родительского элемента и поле со значением дочернего
     $categoryBindParentFieldName = getPropertyNameByNum($productCategoryBinds[0], 1);
     $categoryBindChildFieldName = getPropertyNameByNum($productCategoryBinds[0], 2);
     $manufacturerBindParentFieldName = getPropertyNameByNum($productManufacturerBinds[0], 1);
     $manufacturerBindChildFieldName = getPropertyNameByNum($productManufacturerBinds[0], 2);
     $imageBindParentFieldName = getPropertyNameByNum($productImageBinds[0], 1);
     $imageBindChildFieldName = getPropertyNameByNum($productImageBinds[0], 2);
     $priceProductIdFieldName = getPropertyNameByNum($productPrices[0], 1);
     $pricePriceFieldName = getPropertyNameByNum($productPrices[0], 3);
     foreach ($objects as $object) {
         if (property_exists($object, 'virtuemart_product_id') && property_exists($object, 'product_s_desc') && property_exists($object, 'product_desc') && property_exists($object, 'product_name')) {
             $product = new Product($object->virtuemart_product_id);
             $product->name = $object->product_name;
             $product->shortDescr = $object->product_s_desc;
             $product->fullDescr = $object->product_desc;
             //ищем объект связанной категории
             $categoryBind = findByProperty($productCategoryBinds, $categoryBindParentFieldName, $product->id);
             if ($categoryBind !== null) {
                 $product->category = findByProperty($categories, 'id', $categoryBind->{$categoryBindChildFieldName});
             } else {
                 echo NOTICE . " товар № {$product->id}: " . NO_CATEGORY . "\n";
             }
             //ищем объект связанного поставщика
             $manufacturerBind = findByProperty($productManufacturerBinds, $manufacturerBindParentFieldName, $product->id);
             if ($manufacturerBind !== null) {
                 $product->manufacturer = findByProperty($manufacturers, 'id', $manufacturerBind->{$manufacturerBindChildFieldName});
             } else {
                 echo NOTICE . " товар № {$product->id}: " . NO_MANUFACTURER . "\n";
             }
             //ищем объекты связанных картинок
             $imageBinds = findAllByProperty($productImageBinds, $imageBindParentFieldName, $product->id);
             foreach ($imageBinds as $imageBind) {
                 $product->addImage(findByProperty($images, 'id', $imageBind->{$imageBindChildFieldName}));
             }
             //задаем цену продукта
             $productPrice = findByProperty($productPrices, $priceProductIdFieldName, $product->id);
             if ($productPrice !== null) {
                 $product->price = $productPrice->{$pricePriceFieldName};
             }
         }
         /**
          * @todo что делать с полями Product::ingredients, Product::keywords, Product::sale, Product::otherSpecs ???
          */
         $retval[] = $product;
     }
     return $retval;
 }
コード例 #3
0
 public function __toString()
 {
     $this->__load();
     return parent::__toString();
 }
コード例 #4
0
<?php

use Entities\Product;
use MyApp\BootstrapDoc;
$paths = (require __DIR__ . '/app/paths.php');
require_once 'vendor/autoload.php';
//require_once $paths['src'] . '/bootstrap-doctrine.php';
$entityManager = BootstrapDoc::getEntityManager($paths);
$newProductName = $argv[1];
$product = new Product();
$product->setName($newProductName);
$entityManager->persist($product);
$entityManager->flush();
echo "Created Product with ID " . $product->getId() . "\n";
$id = $product->getId();
$productRepository = $entityManager->getRepository('Entities\\Product');
$products = $productRepository->findAll();
foreach ($products as $product) {
    echo sprintf("-%s\n", $product->getId() . '-' . $product->getName());
}
コード例 #5
0
ファイル: ProductController.php プロジェクト: elegos/PHPTest
 /**
  * Parses the POST request and creates the Product object
  * @param Request $request
  * @return Product
  */
 protected function productFromCreateEditForm(Request $request)
 {
     $product = new Product();
     $product->setId(intval($request->getParsedBodyParam('id', 0)))->setName($request->getParsedBodyParam('name', ''))->setDescription($request->getParsedBodyParam('description', ''));
     $tags = explode(',', $request->getParsedBodyParam('tags', ''));
     foreach ($tags as $tag) {
         $tag = trim($tag);
         // empty tag
         if (!$tag) {
             continue;
         }
         $product->addTag($tag);
     }
     return $product;
 }
コード例 #6
0
ファイル: Product.php プロジェクト: elegos/PHPTest
 /**
  * Compares this with another Product object
  * @param Product $other
  * @return boolean
  */
 public function equals(Product $other)
 {
     return $this->getId() === $other->getId();
 }
コード例 #7
0
ファイル: ProductService.php プロジェクト: elegos/PHPTest
 /**
  * @param Product $product the product to update
  * @return boolean true on success
  * @throws NotFoundException if not found
  */
 public function update($product)
 {
     $productId = $product->getId();
     if ($productId === null || $productId === 0) {
         $this->logger->error(__METHOD__ . ": Can't update a non-existing product (id: {$productId})");
         return false;
     }
     $repository = $this->getRepository();
     if ($repository == null) {
         $this->logger->error(__METHOD__ . ": No repository, impossible to proceed.");
         return false;
     }
     /** @var Product $dbOne */
     $dbOne = $repository->find($productId);
     if ($dbOne === null) {
         throw new NotFoundException("Product (id: {$productId}) was not found, impossible to update.");
     }
     $dbOne->setDescription($product->getDescription())->setName($product->getName())->setTags($product->getTags());
     $em = $this->getEntityManager();
     if ($em == null) {
         $this->logger->error(__METHOD__ . ": No entity manager, impossible to proceed.");
         return false;
     }
     try {
         $em->persist($dbOne);
         $em->flush();
         return true;
     } catch (ORMInvalidArgumentException $ex) {
         $this->logger->error(__METHOD__ . ": (" . $ex->getCode() . ") " . $ex->getMessage());
         return false;
     }
 }