Пример #1
0
 public function createAction()
 {
     $product = new Product();
     $product->setName('A Foo Bar');
     $product->setPrice('19.99');
     $product->setDescription('Lorem ipsum dolor');
     $em = $this->getDoctrine()->getEntityManager();
     $em->persist($product);
     $em->flush();
     return new Response('Created product id ' . $product->getId());
 }
Пример #2
0
 /**
  * Добавление данных
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function createAction()
 {
     $product = new Product();
     $product->setName('A Foo Bar');
     $product->setPrice('19.99');
     $product->setDescription("Lorem ipsum");
     //Менеджер ответственный за управление процессами сохранения и получения обьектов БД
     $em = $this->getDoctrine()->getManager();
     //Сообщает команду на "управление обьектом" $product
     $em->persist($product);
     //Просматривает все обьекты которыми управляет, чтобы узнать, надо ли сохранять их в БД и выполняет запросы
     $em->flush();
     return $this->render('AcmeStoreBundle:Default:insert.html.twig', array('id' => $product->getId()));
 }
Пример #3
0
 public function createProductAction()
 {
     $category = new Category();
     $category->setName('Main Products');
     $product = new Product();
     $product->setName('Foo');
     $product->setDescription('Bar');
     $product->setPrice(19.99);
     // relate this product to the category
     $product->setCategory($category);
     $em = $this->get('doctrine')->getEntityManager();
     $em->persist($category);
     $em->persist($product);
     $em->flush();
     return new Response('Created product id: ' . $product->getId() . ' and category id: ' . $category->getId());
 }
Пример #4
0
 public function createAction()
 {
     $product = new Product();
     $product->setName('A Foo Bar');
     $product->setPrice('19.99');
     $product->setDescription('Lorem ipsum dolor');
     $em = $this->getDoctrine()->getManager();
     $em->persist($product);
     $em->flush();
     $user = new User();
     $user->setName('Joan');
     $user->setLogin('joan');
     $user->setEmail('*****@*****.**');
     $em = $this->getDoctrine()->getManager();
     $em->persist($user);
     $em->flush();
     return new Response('Created product id ' . $product->getId() . 'Created user id ' . $user->getId());
 }
Пример #5
0
 public function createProductAction()
 {
     $category = new Category();
     $category->setName("Rowery");
     $product = new Product();
     $product->setName("Rower biegowy");
     $product->setPrice(230.44);
     $product->setDescription("opis rowerka");
     $product->setCategory($category);
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->persist($product);
     $em->flush();
     return $this->render("AcmeStoreBundle:Default:Product.html.twig", array("product" => $product));
 }
Пример #6
0
 /**
  * Creates a form to delete a Product entity.
  *
  * @param Product $product The Product entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Product $product)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('product_delete', array('id' => $product->getId())))->setMethod('DELETE')->getForm();
 }
Пример #7
0
 public function searchAction(Request $request)
 {
     if ($request->getMethod() == 'GET') {
         $keywords = $request->get('keywords');
         if ($keywords != '') {
             $order_by = '';
             $em = $this->get('doctrine.orm.entity_manager');
             $repository = $em->getRepository('Acme\\StoreBundle\\Entity\\Product');
             $languagesCount = $repository->getIdCount();
             $paginator = new Product($languagesCount);
             $strPaginator = $paginator->RenderPaginator();
             $sort_direction = "asc";
             $products = $em->createQueryBuilder()->select('b')->from('AcmeStoreBundle:Product', 'b')->where("b.name = :name")->setParameter('name', $keywords)->addOrderBy('b.id', 'DESC')->getQuery()->getResult();
             return $this->render('AcmeStoreBundle:Default:index.html.twig', array('products' => $products, 'sort_dir' => $sort_direction, 'paginator' => $strPaginator));
         } else {
             $order_by = '';
             $em = $this->get('doctrine.orm.entity_manager');
             $repository = $em->getRepository('Acme\\StoreBundle\\Entity\\Product');
             $languagesCount = $repository->getIdCount();
             $paginator = new Product($languagesCount);
             $strPaginator = $paginator->RenderPaginator();
             $sort_direction = "asc";
             $products = $repository->getProductListWithPagination($sort_direction, $paginator->getOffset(), $paginator->getLimit());
             return $this->render('AcmeStoreBundle:Default:index.html.twig', array('products' => $products, 'sort_dir' => $sort_direction, 'paginator' => $strPaginator));
         }
     }
 }
Пример #8
0
 public function editAction(Request $request)
 {
     $user = $this->container->get('security.context')->getToken()->getUser();
     $userId = $user->getId();
     $userName = $user->getUsername();
     if ($userName == 'admin') {
         $category = $this->get('doctrine')->getRepository('AcmeCategoryBundle:Category')->findAll();
     } else {
         $category = $this->get('doctrine')->getRepository('AcmeCategoryBundle:Category')->findBy(array('userid' => $userId));
     }
     //$category= $this->get('doctrine')->getRepository('AcmeCategoryBundle:Category')->findAll();
     foreach ($category as $key => $data) {
         $cateArray[$data->getId()] = $data->getName();
     }
     $queue = $cateArray;
     array_unshift($queue, "select category");
     $cate = $queue;
     $id = $request->get('id');
     $em = $this->getDoctrine()->getManager();
     $product = $em->getRepository('AcmeStoreBundle:Product')->find($id);
     $oldimg = $product->getImage();
     $products = new \Acme\StoreBundle\Entity\Product();
     $products->setCategory('');
     $products->setName('');
     $products->setPrice('');
     $products->setDescription('');
     $products->setImage('');
     $form = $this->createFormBuilder($products)->add('category', 'choice', array('choices' => $cateArray, 'preferred_choices' => array($product->getCategory())))->add('name', 'text')->add('price', 'text')->add('description', 'textarea')->add('image', 'file', array('error_bubbling' => TRUE))->getForm();
     $form->handleRequest($request);
     $validator = $this->get('validator');
     $errors = $validator->validate($products);
     if ($request->getMethod() == 'POST') {
         if (count($errors) > 1) {
             return $this->render('AcmeStoreBundle:Default:edit.html.twig', array('form' => $form->createView(), 'products' => $products, 'product' => $product, 'id' => $id, 'image' => $oldimg));
         } else {
             $a = $request->request->get('form');
             $products = $em->getRepository('AcmeStoreBundle:Product')->find($id);
             if ($_FILES['form']['name']['image'] != NULL) {
                 $products->setImage($_FILES['form']['name']['image']);
                 if (is_file($_SERVER['DOCUMENT_ROOT'] . '/uploads/products/' . $id . '/' . $oldimg)) {
                     unlink($_SERVER['DOCUMENT_ROOT'] . '/uploads/products/' . $id . '/' . $oldimg);
                     rmdir($_SERVER['DOCUMENT_ROOT'] . '/uploads/products/' . $id);
                     $img = $form['image']->getData()->getClientOriginalName();
                     $dir = $_SERVER['DOCUMENT_ROOT'] . '/uploads/products/' . $products->getId();
                     mkdir($dir);
                     $form->get('image')->getData()->move($dir, $img);
                 }
             } else {
                 $products->setImage($oldimg);
             }
             $products->setName($a['name']);
             $products->setCategory($a['category']);
             $products->setPrice($a['price']);
             $products->setDescription($a['description']);
             $products->setStatus('1');
             $em->persist($products);
             $em->flush();
         }
         return $this->redirect($this->generateUrl('acme_store'));
     }
     return $this->render('AcmeStoreBundle:Default:edit.html.twig', array('form' => $form->createView(), 'products' => $products, 'product' => $product, 'id' => $id, 'image' => $oldimg));
 }
 /**
  * {@inheritDoc}
  */
 public function getOffset()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getOffset', array());
     return parent::getOffset();
 }