diff --git a/.gitignore b/.gitignore index bbf53b3..60ed38d 100755 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /bin/ /composer.phar /.idea/ +*~ diff --git a/.gitignore~ b/.gitignore~ index 34fb5f2..bbf53b3 100755 --- a/.gitignore~ +++ b/.gitignore~ @@ -9,4 +9,4 @@ /vendor/ /bin/ /composer.phar -/.idea/* +/.idea/ diff --git a/app/AppKernel.php b/app/AppKernel.php index c5c9eb6..c5e1e0c 100755 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -16,6 +16,8 @@ public function registerBundles() new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), + new Acme\StoreBundle\AcmeStoreBundle(), + new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), ); if (in_array($this->getEnvironment(), array('dev', 'test'))) { diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index bafd28d..f1ef139 100755 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -2,7 +2,7 @@ - {% block title %}Welcome!{% endblock %} + {% block title %}HomeWork6{% endblock %} {% block stylesheets %}{% endblock %} diff --git a/app/config/config.yml b/app/config/config.yml index 5490b59..718ef48 100755 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -39,6 +39,15 @@ assetic: #yui_css: # jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar + assets: + css: + inputs: + - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/css/bootstrap.css + - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/css/bootstrap-theme.min.css + filters: + - cssrewrite + output: mystyle.css + # Doctrine Configuration doctrine: dbal: diff --git a/app/config/routing.yml b/app/config/routing.yml index e69de29..b9975b8 100755 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -0,0 +1,4 @@ +acme_store: + resource: "@AcmeStoreBundle/Resources/config/routing.yml" + prefix: / + diff --git a/composer.json b/composer.json index 5705d76..dd3c3b8 100755 --- a/composer.json +++ b/composer.json @@ -18,7 +18,9 @@ "sensio/distribution-bundle": "2.3.*", "sensio/framework-extra-bundle": "2.3.*", "sensio/generator-bundle": "2.3.*", - "incenteev/composer-parameter-handler": "~2.0" + "incenteev/composer-parameter-handler": "~2.0", + "doctrine/doctrine-fixtures-bundle": "dev-master", + "twbs/bootstrap": "3.0.*@dev" }, "scripts": { "post-install-cmd": [ diff --git a/composer.lock b/composer.lock index bcedca1..31561ec 100755 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "e67df720e8a1a2e0e6df41d91d788e48", + "hash": "160a997aed852357e8004e54fbe83f98", "packages": [ { "name": "doctrine/annotations", @@ -294,6 +294,62 @@ ], "time": "2013-09-07 10:20:34" }, + { + "name": "doctrine/data-fixtures", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/data-fixtures.git", + "reference": "b4a135c7db56ecc4602b54a2184368f440cac33e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/b4a135c7db56ecc4602b54a2184368f440cac33e", + "reference": "b4a135c7db56ecc4602b54a2184368f440cac33e", + "shasum": "" + }, + "require": { + "doctrine/common": ">=2.2,<2.5-dev", + "php": ">=5.3.2" + }, + "require-dev": { + "doctrine/orm": ">=2.2,<2.5-dev" + }, + "suggest": { + "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", + "doctrine/orm": "For loading ORM fixtures", + "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\DataFixtures": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com", + "homepage": "http://www.jwage.com/", + "role": "Creator" + } + ], + "description": "Data Fixtures for all Doctrine Object Managers", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database" + ], + "time": "2013-07-10 17:04:07" + }, { "name": "doctrine/dbal", "version": "2.3.4", @@ -428,6 +484,64 @@ ], "time": "2013-03-25 20:13:59" }, + { + "name": "doctrine/doctrine-fixtures-bundle", + "version": "dev-master", + "target-dir": "Doctrine/Bundle/FixturesBundle", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineFixturesBundle.git", + "reference": "3caec4826e58fe47520b591f965b4adcdfc8a6c8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/3caec4826e58fe47520b591f965b4adcdfc8a6c8", + "reference": "3caec4826e58fe47520b591f965b4adcdfc8a6c8", + "shasum": "" + }, + "require": { + "doctrine/data-fixtures": "~1.0", + "doctrine/doctrine-bundle": "~1.0", + "php": ">=5.3.2", + "symfony/doctrine-bridge": "~2.1" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.2.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Bundle\\FixturesBundle": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Doctrine Project", + "homepage": "http://www.doctrine-project.org" + } + ], + "description": "Symfony DoctrineFixturesBundle", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "Fixture", + "persistence" + ], + "time": "2013-09-16 10:15:05" + }, { "name": "doctrine/inflector", "version": "v1.0", @@ -1413,6 +1527,48 @@ ], "time": "2013-11-14 07:58:51" }, + { + "name": "twbs/bootstrap", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/twbs/bootstrap.git", + "reference": "6ed5a844a8ca3582240ddda70d63a3d7bfea7c50" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twbs/bootstrap/zipball/6ed5a844a8ca3582240ddda70d63a3d7bfea7c50", + "reference": "6ed5a844a8ca3582240ddda70d63a3d7bfea7c50", + "shasum": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Jacob Thornton", + "email": "jacobthornton@gmail.com" + }, + { + "name": "Mark Otto", + "email": "markdotto@gmail.com" + } + ], + "description": "Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.", + "homepage": "http://getbootstrap.com", + "keywords": [ + "bootstrap", + "css" + ], + "time": "2013-11-19 22:15:09" + }, { "name": "twig/extensions", "version": "v1.0.1", @@ -1517,9 +1673,10 @@ ], "minimum-stability": "stable", - "stability-flags": [ - - ], + "stability-flags": { + "doctrine/doctrine-fixtures-bundle": 20, + "twbs/bootstrap": 20 + }, "platform": { "php": ">=5.3.3" }, diff --git a/src/Acme/StoreBundle/AcmeStoreBundle.php b/src/Acme/StoreBundle/AcmeStoreBundle.php new file mode 100755 index 0000000..1df80e4 --- /dev/null +++ b/src/Acme/StoreBundle/AcmeStoreBundle.php @@ -0,0 +1,9 @@ +render('AcmeStoreBundle:Default:home.html.twig', array('tasklist' => $taskArray)); + } + + public function createAction() + { + $em = $this->getDoctrine()->getManager(); + + $product = new Product(); + $product->setName("Guitar4"); + $product->setPrice(888); + $product->setDescription("To play black metal for the Satan's glory"); + + $category = $em + ->getRepository("AcmeStoreBundle:Category") + ->findOneBy(array('id'=>2)); + + $product->setCategory($category); + + $em->persist($product); + $em->persist($category); + $em->flush(); + + return new Response('item #'.$product->getId()." was added to ".$category->getId().'th category' ); + #$this->render('AcmeStoreBundle:Default:index.html.twig', array('name' => $name)); + } + + public function showAction($id) + { + $repository = $this->getDoctrine() + ->getRepository("AcmeStoreBundle:Product"); + + $product = $repository + ->findOneBy(array('id'=>$id)); + + if(!$product) { + throw $this->createNotFoundException( + "Couldn't find item" + ); + } + + return $this->render('AcmeStoreBundle:Default:show.html.twig', array( + 'product' => $product, + 'category' => $product->getCategory() + )); + } + + public function showDescriptionAction($id) + { + $repository = $this->getDoctrine() + ->getRepository("AcmeStoreBundle:Product"); + + $product = $repository + ->findOneBy(array('id'=>$id)); + + return $this->render('AcmeStoreBundle:Default:showDescription.html.twig', array('product' => $product)); + } + + public function updateAction($id) + { + $em = $this->getDoctrine()->getManager(); + $product = $em->getRepository("AcmeStoreBundle:Product") + ->find($id); + $product->setName("Booze"); + $em->flush(); + + #return new Response('updated'); + return $this->redirect($this->generateURL("_show_route", array("id" => $id))); + } + + public function removeAction($id) + { + + $em = $this->getDoctrine()->getManager(); + $product = $em->getRepository("AcmeStoreBundle:Product") + ->find($id); + $em->remove($product); + $em->flush(); + + return new Response('Deleted'); + } +} diff --git a/src/Acme/StoreBundle/DataFixtures/ORM/LoadCategoryData.php b/src/Acme/StoreBundle/DataFixtures/ORM/LoadCategoryData.php new file mode 100755 index 0000000..b6f647d --- /dev/null +++ b/src/Acme/StoreBundle/DataFixtures/ORM/LoadCategoryData.php @@ -0,0 +1,62 @@ +getCategoryArray() as $categoryName){ + $categoryObject = new Category(); + $categoryObject->setName($categoryName); + #$this->setReference($categoryObject->getId(), $categoryObject); + $manager->persist($categoryObject); + }*/ + $categoryObject1 = new Category(); + $categoryObject1->setName("Guitar"); + $this->setReference('1',$categoryObject1); + $manager->persist($categoryObject1); + + $categoryObject2 = new Category(); + $categoryObject2->setName("Drums"); + $this->setReference('2',$categoryObject2); + $manager->persist($categoryObject2); + + $categoryObject3 = new Category(); + $categoryObject3->setName("Keyboard"); + $this->setReference('3',$categoryObject3); + $manager->persist($categoryObject3); + + + $manager->flush(); + } + + /**public function getCategoryArray() + { + return array( + 'Guitar', + 'Drums', + 'Keyboard' + ); + }*/ + + public function getOrder() + { + return 1; + } +} \ No newline at end of file diff --git a/src/Acme/StoreBundle/DataFixtures/ORM/LoadProductData.php b/src/Acme/StoreBundle/DataFixtures/ORM/LoadProductData.php new file mode 100755 index 0000000..3c5ad0e --- /dev/null +++ b/src/Acme/StoreBundle/DataFixtures/ORM/LoadProductData.php @@ -0,0 +1,49 @@ +getProductFile()); + + foreach($productArray['products'] as $productItem){ + $productObject = new Product(); + + $productObject + ->setName($productItem['name']) + ->setPrice($productItem['price']) + ->setDescription($productItem['description']) + ->setCategory($this->getReference((int)$productItem['category'])); + + $manager->persist($productObject); + } + $manager->flush(); + } + + public function getProductFile() + { + return __DIR__.'/../data/product.yml'; + } + + public function getOrder() + { + return 2; + } +} \ No newline at end of file diff --git a/src/Acme/StoreBundle/DataFixtures/data/product.yml b/src/Acme/StoreBundle/DataFixtures/data/product.yml new file mode 100755 index 0000000..446b33d --- /dev/null +++ b/src/Acme/StoreBundle/DataFixtures/data/product.yml @@ -0,0 +1,21 @@ +products: + Gibson: + name: Gibson + price: 1000 + description: To play rock + category: 1 + Jackson: + name: Jackson + price: 1200 + description: To play metal + category: 1 + Tama: + name: Tama + price: 500 + description: To play anything you want + category: 2 + Some_keys: + name: KeyBoard1 + price: 400 + description: To play anything you want + category: 3 \ No newline at end of file diff --git a/src/Acme/StoreBundle/DependencyInjection/AcmeStoreExtension.php b/src/Acme/StoreBundle/DependencyInjection/AcmeStoreExtension.php new file mode 100755 index 0000000..e0b2f16 --- /dev/null +++ b/src/Acme/StoreBundle/DependencyInjection/AcmeStoreExtension.php @@ -0,0 +1,28 @@ +processConfiguration($configuration, $configs); + + $loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.php'); + } +} diff --git a/src/Acme/StoreBundle/DependencyInjection/Configuration.php b/src/Acme/StoreBundle/DependencyInjection/Configuration.php new file mode 100755 index 0000000..85bc4cb --- /dev/null +++ b/src/Acme/StoreBundle/DependencyInjection/Configuration.php @@ -0,0 +1,29 @@ +root('acme_store'); + + // Here you should define the parameters that are allowed to + // configure your bundle. See the documentation linked above for + // more information on that topic. + + return $treeBuilder; + } +} diff --git a/src/Acme/StoreBundle/Entity/Category.php b/src/Acme/StoreBundle/Entity/Category.php new file mode 100755 index 0000000..5336df6 --- /dev/null +++ b/src/Acme/StoreBundle/Entity/Category.php @@ -0,0 +1,108 @@ +products = new ArrayCollection(); + } + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set name + * + * @param string $name + * @return Category + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Add products + * + * @param \Acme\StoreBundle\Entity\Product $products + * @return Category + */ + public function addProduct(\Acme\StoreBundle\Entity\Product $products) + { + $this->products[] = $products; + + return $this; + } + + /** + * Remove products + * + * @param \Acme\StoreBundle\Entity\Product $products + */ + public function removeProduct(\Acme\StoreBundle\Entity\Product $products) + { + $this->products->removeElement($products); + } + + /** + * Get products + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getProducts() + { + return $this->products; + } +} \ No newline at end of file diff --git a/src/Acme/StoreBundle/Entity/Product.php b/src/Acme/StoreBundle/Entity/Product.php new file mode 100755 index 0000000..a66c6e2 --- /dev/null +++ b/src/Acme/StoreBundle/Entity/Product.php @@ -0,0 +1,153 @@ +id; + } + + /** + * Set name + * + * @param string $name + * @return Product + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set price + * + * @param float $price + * @return Product + */ + public function setPrice($price) + { + $this->price = $price; + + return $this; + } + + /** + * Get price + * + * @return float + */ + public function getPrice() + { + return $this->price; + } + + /** + * Set description + * + * @param string $description + * @return Product + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * Get description + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set category + * + * @param \Acme\StoreBundle\Entity\Category $category + * @return Product + */ + public function setCategory(\Acme\StoreBundle\Entity\Category $category = null) + { + $this->category = $category; + + return $this; + } + + /** + * Get category + * + * @return \Acme\StoreBundle\Entity\Category + */ + public function getCategory() + { + return $this->category; + } +} \ No newline at end of file diff --git a/src/Acme/StoreBundle/Resources/config/routing.yml b/src/Acme/StoreBundle/Resources/config/routing.yml new file mode 100755 index 0000000..3b76709 --- /dev/null +++ b/src/Acme/StoreBundle/Resources/config/routing.yml @@ -0,0 +1,23 @@ +_home_route: + pattern: / + defaults: { _controller: AcmeStoreBundle:Default:home } + +_create_route: + pattern: /create + defaults: { _controller: AcmeStoreBundle:Default:create } + +_show_route: + pattern: /show/{id} + defaults: { _controller: AcmeStoreBundle:Default:show, id: 1 } + +_show_description_route: + pattern: /showdescription/{id} + defaults: { _controller: AcmeStoreBundle:Default:showDescription, id: 1 } + +_update_route: + pattern: /update/{id} + defaults: { _controller: AcmeStoreBundle:Default:update } + +_remove_route: + pattern: /remove/{id} + defaults: { _controller: AcmeStoreBundle:Default:remove } \ No newline at end of file diff --git a/src/Acme/StoreBundle/Resources/config/services.php b/src/Acme/StoreBundle/Resources/config/services.php new file mode 100755 index 0000000..001e497 --- /dev/null +++ b/src/Acme/StoreBundle/Resources/config/services.php @@ -0,0 +1,21 @@ +setDefinition( + 'acme_store.example', + new Definition( + 'Acme\StoreBundle\Example', + array( + new Reference('service_id'), + "plain_value", + new Parameter('parameter_name'), + ) + ) +); + +*/ \ No newline at end of file diff --git a/src/Acme/StoreBundle/Resources/views/Default/home.html.twig b/src/Acme/StoreBundle/Resources/views/Default/home.html.twig new file mode 100755 index 0000000..fdbc154 --- /dev/null +++ b/src/Acme/StoreBundle/Resources/views/Default/home.html.twig @@ -0,0 +1,10 @@ +{% extends 'AcmeStoreBundle:Default:layout.html.twig' %} + +{% block content %} +
+ Tasks + {% for task in tasklist %} +

{{ task }}

+ {% endfor %} +
+{% endblock %} \ No newline at end of file diff --git a/src/Acme/StoreBundle/Resources/views/Default/index.html.twig b/src/Acme/StoreBundle/Resources/views/Default/index.html.twig new file mode 100755 index 0000000..3cbd38c --- /dev/null +++ b/src/Acme/StoreBundle/Resources/views/Default/index.html.twig @@ -0,0 +1 @@ +{{ object }} diff --git a/src/Acme/StoreBundle/Resources/views/Default/layout.html.twig b/src/Acme/StoreBundle/Resources/views/Default/layout.html.twig new file mode 100755 index 0000000..09cea86 --- /dev/null +++ b/src/Acme/StoreBundle/Resources/views/Default/layout.html.twig @@ -0,0 +1,36 @@ +{% extends "::base.html.twig" %} + +{% block stylesheets %} + +{% endblock %} + +{% block body %} + {% block navbar %} + + {% endblock %} + {% block content %}{% endblock %} +{% endblock %} + +{% block javascripts %} + +{% endblock %} \ No newline at end of file diff --git a/src/Acme/StoreBundle/Resources/views/Default/show.html.twig b/src/Acme/StoreBundle/Resources/views/Default/show.html.twig new file mode 100755 index 0000000..a72e9d8 --- /dev/null +++ b/src/Acme/StoreBundle/Resources/views/Default/show.html.twig @@ -0,0 +1,7 @@ +{% extends 'AcmeStoreBundle:Default:layout.html.twig' %} + +{% block content %} +
+

Product #{{ product.id }} {{ product.name }} belongs to {{ category.name }} category

+
+{% endblock %} \ No newline at end of file diff --git a/src/Acme/StoreBundle/Resources/views/Default/showDescription.html.twig b/src/Acme/StoreBundle/Resources/views/Default/showDescription.html.twig new file mode 100644 index 0000000..db8cced --- /dev/null +++ b/src/Acme/StoreBundle/Resources/views/Default/showDescription.html.twig @@ -0,0 +1,8 @@ +{% extends 'AcmeStoreBundle:Default:layout.html.twig' %} + +{% block content %} +
+

Here is description for {{ product.name }}:

+

{{ product.description }}

+
+{% endblock %} \ No newline at end of file diff --git a/src/Acme/StoreBundle/Tests/Controller/DefaultControllerTest.php b/src/Acme/StoreBundle/Tests/Controller/DefaultControllerTest.php new file mode 100755 index 0000000..477d487 --- /dev/null +++ b/src/Acme/StoreBundle/Tests/Controller/DefaultControllerTest.php @@ -0,0 +1,17 @@ +request('GET', '/hello/Fabien'); + + $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); + } +} diff --git a/web/.htaccess b/web/.htaccess index 0c5f37d..d0c145b 100755 --- a/web/.htaccess +++ b/web/.htaccess @@ -3,7 +3,7 @@ # mod_rewrite). Additionally, this reduces the matching process for the # start page (path "/") because otherwise Apache will apply the rewriting rules # to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl). -DirectoryIndex app.php +DirectoryIndex app_dev.php RewriteEngine On @@ -38,7 +38,7 @@ DirectoryIndex app.php RewriteRule .? - [L] # Rewrite all other queries to the front controller. - RewriteRule .? %{ENV:BASE}/app.php [L] + RewriteRule .? %{ENV:BASE}/app_dev.php [L] @@ -46,7 +46,7 @@ DirectoryIndex app.php # When mod_rewrite is not available, we instruct a temporary redirect of # the start page to the front controller explicitly so that the website # and the generated links can still be used. - RedirectMatch 302 ^/$ /app.php/ + RedirectMatch 302 ^/$ /app_dev.php/ # RedirectTemp cannot be used instead