From 3246a755943df67107e3f52bd2a5d737c9124b7c Mon Sep 17 00:00:00 2001 From: spitd1 Date: Mon, 10 Oct 2016 20:10:21 +0200 Subject: [PATCH 1/5] readmeee --- readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 readme.md diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..9e4c16e --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +ahoj codecampe \ No newline at end of file From 5b02d123220b054085ac04d2970149fd920e57f3 Mon Sep 17 00:00:00 2001 From: spitd1 Date: Wed, 12 Oct 2016 21:54:50 +0200 Subject: [PATCH 2/5] sdfsfds --- .gitignore | 1 + bin/symfony_requirements | 13 ++++--- var/SymfonyRequirements.php | 74 ++++++++++++++++++++++++++++--------- web/config.php | 12 +++--- 4 files changed, 72 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index dc9c2f2..947ec6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea /app/config/parameters.yml /build/ /phpunit.xml diff --git a/bin/symfony_requirements b/bin/symfony_requirements index 8825a96..a7bf65a 100755 --- a/bin/symfony_requirements +++ b/bin/symfony_requirements @@ -22,7 +22,6 @@ echo '> Checking Symfony requirements:'.PHP_EOL.' '; $messages = array(); foreach ($symfonyRequirements->getRequirements() as $req) { - /** @var $req Requirement */ if ($helpText = get_error_message($req, $lineSize)) { echo_style('red', 'E'); $messages['error'][] = $helpText; @@ -121,10 +120,14 @@ function echo_block($style, $title, $message) echo PHP_EOL.PHP_EOL; - echo_style($style, str_repeat(' ', $width).PHP_EOL); - echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT).PHP_EOL); - echo_style($style, str_pad($message, $width, ' ', STR_PAD_RIGHT).PHP_EOL); - echo_style($style, str_repeat(' ', $width).PHP_EOL); + echo_style($style, str_repeat(' ', $width)); + echo PHP_EOL; + echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT)); + echo PHP_EOL; + echo_style($style, $message); + echo PHP_EOL; + echo_style($style, str_repeat(' ', $width)); + echo PHP_EOL; } function has_color_support() diff --git a/var/SymfonyRequirements.php b/var/SymfonyRequirements.php index 0a5de54..7e7723a 100644 --- a/var/SymfonyRequirements.php +++ b/var/SymfonyRequirements.php @@ -168,6 +168,9 @@ public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $ */ class RequirementCollection implements IteratorAggregate { + /** + * @var Requirement[] + */ private $requirements = array(); /** @@ -265,7 +268,7 @@ public function addCollection(RequirementCollection $collection) /** * Returns both requirements and recommendations. * - * @return array Array of Requirement instances + * @return Requirement[] */ public function all() { @@ -275,7 +278,7 @@ public function all() /** * Returns all mandatory requirements. * - * @return array Array of Requirement instances + * @return Requirement[] */ public function getRequirements() { @@ -292,7 +295,7 @@ public function getRequirements() /** * Returns the mandatory requirements that were not met. * - * @return array Array of Requirement instances + * @return Requirement[] */ public function getFailedRequirements() { @@ -309,7 +312,7 @@ public function getFailedRequirements() /** * Returns all optional recommendations. * - * @return array Array of Requirement instances + * @return Requirement[] */ public function getRecommendations() { @@ -326,7 +329,7 @@ public function getRecommendations() /** * Returns the recommendations that were not met. * - * @return array Array of Requirement instances + * @return Requirement[] */ public function getFailedRecommendations() { @@ -376,7 +379,8 @@ public function getPhpIniConfigPath() */ class SymfonyRequirements extends RequirementCollection { - const REQUIRED_PHP_VERSION = '5.3.3'; + const LEGACY_REQUIRED_PHP_VERSION = '5.3.3'; + const REQUIRED_PHP_VERSION = '5.5.9'; /** * Constructor that initializes the requirements. @@ -386,16 +390,26 @@ public function __construct() /* mandatory requirements follow */ $installedPhpVersion = phpversion(); + $requiredPhpVersion = $this->getPhpRequiredVersion(); - $this->addRequirement( - version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>='), - sprintf('PHP version must be at least %s (%s installed)', self::REQUIRED_PHP_VERSION, $installedPhpVersion), - sprintf('You are running PHP version "%s", but Symfony needs at least PHP "%s" to run. - Before using Symfony, upgrade your PHP installation, preferably to the latest version.', - $installedPhpVersion, self::REQUIRED_PHP_VERSION), - sprintf('Install PHP %s or newer (installed version is %s)', self::REQUIRED_PHP_VERSION, $installedPhpVersion) + $this->addRecommendation( + $requiredPhpVersion, + 'Vendors should be installed in order to check all requirements.', + 'Run the composer install command.', + 'Run the "composer install" command.' ); + if (false !== $requiredPhpVersion) { + $this->addRequirement( + version_compare($installedPhpVersion, $requiredPhpVersion, '>='), + sprintf('PHP version must be at least %s (%s installed)', $requiredPhpVersion, $installedPhpVersion), + sprintf('You are running PHP version "%s", but Symfony needs at least PHP "%s" to run. + Before using Symfony, upgrade your PHP installation, preferably to the latest version.', + $installedPhpVersion, $requiredPhpVersion), + sprintf('Install PHP %s or newer (installed version is %s)', $requiredPhpVersion, $installedPhpVersion) + ); + } + $this->addRequirement( version_compare($installedPhpVersion, '5.3.16', '!='), 'PHP version must not be 5.3.16 as Symfony won\'t work properly with it', @@ -433,7 +447,7 @@ public function __construct() ); } - if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) { + if (false !== $requiredPhpVersion && version_compare($installedPhpVersion, $requiredPhpVersion, '>=')) { $timezones = array(); foreach (DateTimeZone::listAbbreviations() as $abbreviations) { foreach ($abbreviations as $abbreviation) { @@ -689,7 +703,7 @@ function_exists('posix_isatty'), $this->addRecommendation( \Symfony\Component\Intl\Intl::getIcuDataVersion() === \Symfony\Component\Intl\Intl::getIcuVersion(), sprintf('intl ICU version installed on your system (%s) does not match the ICU data bundled with Symfony (%s)', \Symfony\Component\Intl\Intl::getIcuVersion(), \Symfony\Component\Intl\Intl::getIcuDataVersion()), - 'To avoid internationalization data incosistencies upgrade the symfony/intl component.' + 'To avoid internationalization data inconsistencies upgrade the symfony/intl component.' ); } } @@ -725,9 +739,9 @@ function_exists('posix_isatty'), if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $this->addRecommendation( - $this->getRealpathCacheSize() > 1000, - 'realpath_cache_size should be above 1024 in php.ini', - 'Set "realpath_cache_size" to e.g. "1024" in php.ini* to improve performance on windows.' + $this->getRealpathCacheSize() >= 5 * 1024 * 1024, + 'realpath_cache_size should be at least 5M in php.ini', + 'Setting "realpath_cache_size" to e.g. "5242880" or "5M" in php.ini* may improve performance on Windows significantly in some cases.' ); } @@ -778,4 +792,28 @@ protected function getRealpathCacheSize() return (int) $size; } } + + /** + * Defines PHP required version from Symfony version. + * + * @return string|false The PHP required version or false if it could not be guessed + */ + protected function getPhpRequiredVersion() + { + if (!file_exists($path = __DIR__.'/../composer.lock')) { + return false; + } + + $composerLock = json_decode(file_get_contents($path), true); + foreach ($composerLock['packages'] as $package) { + $name = $package['name']; + if ('symfony/symfony' !== $name && 'symfony/http-kernel' !== $name) { + continue; + } + + return (int) $package['version'][1] > 2 ? self::REQUIRED_PHP_VERSION : self::LEGACY_REQUIRED_PHP_VERSION; + } + + return false; + } } diff --git a/web/config.php b/web/config.php index 5e36d79..1368c8a 100644 --- a/web/config.php +++ b/web/config.php @@ -28,6 +28,8 @@ $majorProblems = $symfonyRequirements->getFailedRequirements(); $minorProblems = $symfonyRequirements->getFailedRecommendations(); +$hasMajorProblems = (bool) count($majorProblems); +$hasMinorProblems = (bool) count($minorProblems); ?> @@ -158,7 +160,7 @@ ready to run Symfony applications.

- +

Major problems

Major problems have been detected and must be fixed before continuing:

    @@ -170,10 +172,10 @@
- +

Recommendations

- Additionally, toTo enhance your Symfony experience, + Additionally, toTo enhance your Symfony experience, it’s recommended that you fix the following:

    @@ -195,12 +197,12 @@

    - +

    All checks passed successfully. Your system is ready to run Symfony applications.

    From 7dd2b5aad349a59c37b8476bf6e5cd03b24dfc8c Mon Sep 17 00:00:00 2001 From: spitd1 Date: Sat, 22 Oct 2016 20:51:41 +0200 Subject: [PATCH 3/5] Add adress entity, rebuild user entity --- src/AppBundle/Entity/Adress.php | 187 ++++++++++++++ src/AppBundle/Entity/Adress.php~ | 164 ++++++++++++ src/AppBundle/Entity/Category.php | 2 +- src/AppBundle/Entity/Category.php~ | 239 ++++++++++++++++++ src/AppBundle/Entity/Product.php | 2 +- src/AppBundle/Entity/Product.php~ | 175 +++++++++++++ src/AppBundle/Entity/ProductCategory.php | 2 +- src/AppBundle/Entity/ProductCategory.php~ | 72 ++++++ src/AppBundle/Entity/User.php | 104 +++++++- src/AppBundle/Entity/User.php~ | 200 +++++++++++++++ src/AppBundle/Repository/AdressRepository.php | 13 + 11 files changed, 1156 insertions(+), 4 deletions(-) create mode 100644 src/AppBundle/Entity/Adress.php create mode 100644 src/AppBundle/Entity/Adress.php~ create mode 100644 src/AppBundle/Entity/Category.php~ create mode 100644 src/AppBundle/Entity/Product.php~ create mode 100644 src/AppBundle/Entity/ProductCategory.php~ create mode 100644 src/AppBundle/Entity/User.php~ create mode 100644 src/AppBundle/Repository/AdressRepository.php diff --git a/src/AppBundle/Entity/Adress.php b/src/AppBundle/Entity/Adress.php new file mode 100644 index 0000000..61bdb82 --- /dev/null +++ b/src/AppBundle/Entity/Adress.php @@ -0,0 +1,187 @@ +id; + } + + /** + * Set street + * + * @param string $street + * + * @return Adress + */ + public function setStreet($street) + { + $this->street = $street; + + return $this; + } + + /** + * Get street + * + * @return string + */ + public function getStreet() + { + return $this->street; + } + + /** + * Set city + * + * @param string $city + * + * @return Adress + */ + public function setCity($city) + { + $this->city = $city; + + return $this; + } + + /** + * Get city + * + * @return string + */ + public function getCity() + { + return $this->city; + } + + /** + * Set postcode + * + * @param string $postcode + * + * @return Adress + */ + public function setPostcode($postcode) + { + $this->postcode = $postcode; + + return $this; + } + + /** + * Get postcode + * + * @return string + */ + public function getPostcode() + { + return $this->postcode; + } + + /** + * Set country + * + * @param string $country + * + * @return Adress + */ + public function setCountry($country) + { + $this->country = $country; + + return $this; + } + + /** + * Get country + * + * @return string + */ + public function getCountry() + { + return $this->country; + } + + /** + * Set user + * + * @param \AppBundle\Entity\User $user + * + * @return Adress + */ + public function setUser(\AppBundle\Entity\User $user = null) + { + $this->user = $user; + + return $this; + } + + /** + * Get user + * + * @return \AppBundle\Entity\User + */ + public function getUser() + { + return $this->user; + } +} diff --git a/src/AppBundle/Entity/Adress.php~ b/src/AppBundle/Entity/Adress.php~ new file mode 100644 index 0000000..492aba2 --- /dev/null +++ b/src/AppBundle/Entity/Adress.php~ @@ -0,0 +1,164 @@ +id; + } + + /** + * Set street + * + * @param string $street + * + * @return Adress + */ + public function setStreet($street) + { + $this->street = $street; + + return $this; + } + + /** + * Get street + * + * @return string + */ + public function getStreet() + { + return $this->street; + } + + /** + * Set city + * + * @param string $city + * + * @return Adress + */ + public function setCity($city) + { + $this->city = $city; + + return $this; + } + + /** + * Get city + * + * @return string + */ + public function getCity() + { + return $this->city; + } + + /** + * Set postcode + * + * @param string $postcode + * + * @return Adress + */ + public function setPostcode($postcode) + { + $this->postcode = $postcode; + + return $this; + } + + /** + * Get postcode + * + * @return string + */ + public function getPostcode() + { + return $this->postcode; + } + + /** + * Set country + * + * @param string $country + * + * @return Adress + */ + public function setCountry($country) + { + $this->country = $country; + + return $this; + } + + /** + * Get country + * + * @return string + */ + public function getCountry() + { + return $this->country; + } +} + diff --git a/src/AppBundle/Entity/Category.php b/src/AppBundle/Entity/Category.php index 2074d06..1b04ac1 100644 --- a/src/AppBundle/Entity/Category.php +++ b/src/AppBundle/Entity/Category.php @@ -236,4 +236,4 @@ public function isLowestLevel() return ($this->getRight() - $this->getLeft()) === 1; } -} \ No newline at end of file +} diff --git a/src/AppBundle/Entity/Category.php~ b/src/AppBundle/Entity/Category.php~ new file mode 100644 index 0000000..2074d06 --- /dev/null +++ b/src/AppBundle/Entity/Category.php~ @@ -0,0 +1,239 @@ + + * @author Jan Klat + * + * @ORM\Entity(repositoryClass="AppBundle\Repository\CategoryRepository") + */ +class Category +{ + + /** + * @var int + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + private $id; + + /** + * @var string + * @ORM\Column(type="string") + */ + private $title; + + /** + * @var string + * @ORM\Column(type="string") + */ + private $slug; + + /** + * @var int + * @ORM\Column(type="integer") + */ + private $rank; + + /** + * @var Category + * @ORM\ManyToOne(targetEntity="Category") + */ + private $parentCategory; + + /** + * @var Category + * @ORM\ManyToOne(targetEntity="Category") + */ + private $topCategory; + + /** + * @var int + * @ORM\Column(type="integer") + */ + private $left; + + /** + * @var int + * @ORM\Column(type="integer") + */ + private $right; + + /** + * @var int + * @ORM\Column(type="integer") + */ + private $level; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * @return self + */ + public function setTitle($title) + { + $this->title = $title; + return $this; + } + + /** + * @return string + */ + public function getSlug() + { + return $this->slug; + } + + /** + * @param string $slug + * @return self + */ + public function setSlug($slug) + { + $this->slug = $slug; + return $this; + } + + /** + * @return int + */ + public function getRank() + { + return $this->rank; + } + + /** + * @param int $rank + * @return self + */ + public function setRank($rank) + { + $this->rank = $rank; + return $this; + } + + /** + * @return Category + */ + public function getParentCategory() + { + return $this->parentCategory; + } + + /** + * @param Category $parentCategory + * @return self + */ + public function setParentCategory(Category $parentCategory) + { + $this->parentCategory = $parentCategory; + return $this; + } + + /** + * @return Category + */ + public function getTopCategory() + { + return $this->topCategory; + } + + /** + * @param Category $topCategory + * @return self + */ + public function setTopCategory(Category $topCategory) + { + $this->topCategory = $topCategory; + return $this; + } + + /** + * @return int + */ + public function getLeft() + { + return $this->left; + } + + /** + * @param int $left + * @return self + */ + public function setLeft($left) + { + $this->left = $left; + return $this; + } + + /** + * @return int + */ + public function getRight() + { + return $this->right; + } + + /** + * @param int $right + * @return self + */ + public function setRight($right) + { + $this->right = $right; + return $this; + } + + /** + * @return int + */ + public function getLevel() + { + return $this->level; + } + + /** + * @param int $level + * @return self + */ + public function setLevel($level) + { + $this->level = $level; + return $this; + } + + /** + * @return string + */ + public function getMenuTitle() + { + return str_repeat("-", $this->getLevel()) . " " . $this->getTitle(); + } + + /** + * @return bool + */ + public function isLowestLevel() + { + return ($this->getRight() - $this->getLeft()) === 1; + } + +} \ No newline at end of file diff --git a/src/AppBundle/Entity/Product.php b/src/AppBundle/Entity/Product.php index 155d28f..1337a0f 100644 --- a/src/AppBundle/Entity/Product.php +++ b/src/AppBundle/Entity/Product.php @@ -172,4 +172,4 @@ public function setRank($rank) $this->rank = $rank; return $this; } -} \ No newline at end of file +} diff --git a/src/AppBundle/Entity/Product.php~ b/src/AppBundle/Entity/Product.php~ new file mode 100644 index 0000000..155d28f --- /dev/null +++ b/src/AppBundle/Entity/Product.php~ @@ -0,0 +1,175 @@ + + * @author Jan Klat + * + * @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository") + */ +class Product +{ + + /** + * @var int + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + private $id; + + /** + * @var string + * @ORM\Column(type="string") + */ + private $title; + + /** + * @var string + * @ORM\Column(type="string") + */ + private $image; + + /** + * @var string + * @ORM\Column(type="string") + */ + private $slug; + + /** + * @var string + * @ORM\Column(type="string") + */ + private $description; + + /** + * @var float + * @ORM\Column(type="float") + */ + private $price; + + /** + * var int + * @ORM\Column(type="integer") + */ + private $rank; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * @return self + */ + public function setTitle($title) + { + $this->title = $title; + return $this; + } + + /** + * @return string + */ + public function getImage() + { + return $this->image; + } + + /** + * @param string $image + * @return self + */ + public function setImage($image) + { + $this->image = $image; + return $this; + } + + /** + * @return string + */ + public function getSlug() + { + return $this->slug; + } + + /** + * @param string $slug + * @return self + */ + public function setSlug($slug) + { + $this->slug = $slug; + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + * @return self + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * @return float + */ + public function getPrice() + { + return $this->price; + } + + /** + * @param float $price + * @return self + */ + public function setPrice($price) + { + $this->price = $price; + return $this; + } + + /** + * @return mixed + */ + public function getRank() + { + return $this->rank; + } + + /** + * @param mixed $rank + * @return self + */ + public function setRank($rank) + { + $this->rank = $rank; + return $this; + } +} \ No newline at end of file diff --git a/src/AppBundle/Entity/ProductCategory.php b/src/AppBundle/Entity/ProductCategory.php index c292120..0de2e0a 100644 --- a/src/AppBundle/Entity/ProductCategory.php +++ b/src/AppBundle/Entity/ProductCategory.php @@ -69,4 +69,4 @@ public function setCategory(Category $category) { $this->category = $category; } -} \ No newline at end of file +} diff --git a/src/AppBundle/Entity/ProductCategory.php~ b/src/AppBundle/Entity/ProductCategory.php~ new file mode 100644 index 0000000..c292120 --- /dev/null +++ b/src/AppBundle/Entity/ProductCategory.php~ @@ -0,0 +1,72 @@ + + * @author Jan Klat + * + * @ORM\Entity(repositoryClass="AppBundle\Repository\ProductCategoryRepository") + * @ORM\Table(name="product_category") + */ +class ProductCategory +{ + + /** + * @var int + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + private $id; + + /** + * @var Product + * @ORM\ManyToOne(targetEntity="Product") + */ + private $product; + + /** + * @var Category + * @ORM\ManyToOne(targetEntity="Category") + */ + private $category; + + /** + * @return int + */ + public function getId() { + return $this->id; + } + + /** + * @return Product + */ + public function getProduct() { + return $this->product; + } + + /** + * @param Product $product + */ + public function setProduct(Product $product) { + $this->product = $product; + } + + /** + * @return Category + */ + public function getCategory() { + return $this->category; + } + + /** + * @param Category $category + */ + public function setCategory(Category $category) { + $this->category = $category; + } + +} \ No newline at end of file diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php index 5dd2213..0a2a8b0 100644 --- a/src/AppBundle/Entity/User.php +++ b/src/AppBundle/Entity/User.php @@ -41,7 +41,27 @@ class User implements UserInterface */ private $plainPassword; - /** + /** + * @ORM\Column(type="string", length=50) + */ + private $name; + + /** + * @ORM\Column(type="string", length=15) + */ + private $phone; + + /** + * @ORM\OneToMany(targetEntity="Adress", mappedBy="user") + */ + private $adresses; + + public function __construct() + { + $this->adresses = new ArrayCollection(); + } + + /** * @return int */ public function getId() @@ -129,4 +149,86 @@ public function eraseCredentials() return; } + + /** + * Set name + * + * @param string $name + * + * @return User + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set phone + * + * @param string $phone + * + * @return User + */ + public function setPhone($phone) + { + $this->phone = $phone; + + return $this; + } + + /** + * Get phone + * + * @return string + */ + public function getPhone() + { + return $this->phone; + } + + /** + * Add adress + * + * @param \AppBundle\Entity\Adress $adress + * + * @return User + */ + public function addAdress(\AppBundle\Entity\Adress $adress) + { + $this->adresses[] = $adress; + + return $this; + } + + /** + * Remove adress + * + * @param \AppBundle\Entity\Adress $adress + */ + public function removeAdress(\AppBundle\Entity\Adress $adress) + { + $this->adresses->removeElement($adress); + } + + /** + * Get adresses + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getAdresses() + { + return $this->adresses; + } } diff --git a/src/AppBundle/Entity/User.php~ b/src/AppBundle/Entity/User.php~ new file mode 100644 index 0000000..eb2dc88 --- /dev/null +++ b/src/AppBundle/Entity/User.php~ @@ -0,0 +1,200 @@ + + * @author Jan Klat + * @ORM\Entity + * @UniqueEntity(fields="username", message="Tento e-mail je již registrován") + */ +class User implements UserInterface +{ + + /** + * @var int + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + private $id; + + /** + * @ORM\Column(type="string", length=255, unique=true, name="email") + * @Assert\NotBlank() + * @Assert\Email() + */ + private $username; + + /** + * @ORM\Column(type="string", length=64) + */ + private $password; + + /** + * @Assert\NotBlank() + * @Assert\Length(max=4096) + */ + private $plainPassword; + + /** + * @ORM\Column(type="string", length=50) + */ + private $name; + + /** + * @ORM\Column(type="string", length=15) + */ + private $phone; + + /** + * @ORM\OneToMany(targetEntity="Adress", mappedBy="user") + */ + private $adresses; + + public function __construct() + { + $this->adresses = new ArrayCollection(); + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + * @return self + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return mixed + */ + public function getUsername() + { + return $this->username; + } + + /** + * @param mixed $username + * @return self + */ + public function setUsername($username) + { + $this->username = $username; + return $this; + } + + /** + * @return mixed + */ + public function getPassword() + { + return $this->password; + } + + /** + * @param mixed $password + * @return self + */ + public function setPassword($password) + { + $this->password = $password; + return $this; + } + + /** + * @return mixed + */ + public function getPlainPassword() + { + return $this->plainPassword; + } + + /** + * @param mixed $plainPassword + * @return self + */ + public function setPlainPassword($plainPassword) + { + $this->plainPassword = $plainPassword; + return $this; + } + + public function getRoles() + { + return []; + } + + public function getSalt() + { + return null; + } + + public function eraseCredentials() + { + //nothing to do + return; + } + + + /** + * Set name + * + * @param string $name + * + * @return User + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set phone + * + * @param string $phone + * + * @return User + */ + public function setPhone($phone) + { + $this->phone = $phone; + + return $this; + } + + /** + * Get phone + * + * @return string + */ + public function getPhone() + { + return $this->phone; + } +} diff --git a/src/AppBundle/Repository/AdressRepository.php b/src/AppBundle/Repository/AdressRepository.php new file mode 100644 index 0000000..94925cc --- /dev/null +++ b/src/AppBundle/Repository/AdressRepository.php @@ -0,0 +1,13 @@ + Date: Sun, 23 Oct 2016 01:22:58 +0200 Subject: [PATCH 4/5] Editing user profile, managing addresses also refactoring entity typo mistake (adress -> address) --- app/Resources/views/base.html.twig | 2 +- app/Resources/views/user/addaddress.html.twig | 18 ++++++ app/Resources/views/user/profile.html.twig | 25 ++++++++ app/config/services.yml | 13 ++++ src/AppBundle/Controller/UserController.php | 60 +++++++++++++++++++ .../Entity/{Adress.php => Address.php} | 20 +++---- src/AppBundle/Entity/User.php | 29 ++++----- src/AppBundle/FormType/AddressFormType.php | 47 +++++++++++++++ src/AppBundle/FormType/ProfileFormType.php | 42 +++++++++++++ ...ssRepository.php => AddressRepository.php} | 6 +- 10 files changed, 235 insertions(+), 27 deletions(-) create mode 100644 app/Resources/views/user/addaddress.html.twig create mode 100644 app/Resources/views/user/profile.html.twig rename src/AppBundle/Entity/{Adress.php => Address.php} (89%) create mode 100644 src/AppBundle/FormType/AddressFormType.php create mode 100644 src/AppBundle/FormType/ProfileFormType.php rename src/AppBundle/Repository/{AdressRepository.php => AddressRepository.php} (59%) diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index 7e93622..bc0982d 100644 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -49,7 +49,7 @@
    +
    + {{ form_start(form) }} + {{ form_row(form.street) }} + {{ form_row(form.city) }} + {{ form_row(form.postcode) }} + {{ form_row(form.country) }} +
    + + {{ form_end(form) }} +
    +
    + +{% endblock %} \ No newline at end of file diff --git a/app/Resources/views/user/profile.html.twig b/app/Resources/views/user/profile.html.twig new file mode 100644 index 0000000..262a636 --- /dev/null +++ b/app/Resources/views/user/profile.html.twig @@ -0,0 +1,25 @@ +{% extends 'base.html.twig' %} + +{% block body %} +
    +
    +

    Osobní údaje

    + {{ form_start(form) }} + {{ form_row(form.username) }} + {{ form_row(form.name) }} + {{ form_row(form.phone) }} +
    + + {{ form_end(form) }} +
    +
    +

    Adresy

    + {% for address in addresses %} +
    +

    {{ address.street }}, {{ address.postcode }} {{ address.city }}, {{ address.country }}

    +
    + {% endfor %} +

    Správa adres

    +
    +
    +{% endblock %} \ No newline at end of file diff --git a/app/config/services.yml b/app/config/services.yml index 59f9fb4..c7306b4 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -20,6 +20,14 @@ services: class: AppBundle\Controller\UserController autowire: true + app.controller.adress_controller: + class: AppBundle\Controller\AdressController + autowire: true + + app.facade.adress_facade: + class: AppBundle\Facade\AdressFacade + autowire: true + app.facade.category_facade: class: AppBundle\Facade\CategoryFacade autowire: true @@ -42,6 +50,11 @@ services: factory: ['@doctrine.orm.default_entity_manager', getRepository] arguments: ['AppBundle\Entity\Product'] + app.repository.adress_repository: + class: AppBundle\Repository\AdressRepository + factory: ['@doctrine.orm.default_entity_manager', getRepository] + arguments: ['AppBundle\Entity\Adress'] + encoder: class: Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder arguments: diff --git a/src/AppBundle/Controller/UserController.php b/src/AppBundle/Controller/UserController.php index d0958e3..8bb0c35 100644 --- a/src/AppBundle/Controller/UserController.php +++ b/src/AppBundle/Controller/UserController.php @@ -1,8 +1,11 @@ userFacade->getUser(); + $form = $this->formFactory->create(ProfileFormType::class, $user); + $addresses = $user->getAddresses(); + + $form->handleRequest($request); + if ($form->isSubmitted()) { + + $this->entityManager->persist($user); + $this->entityManager->flush(); + + return RedirectResponse::create($this->router->generate("user_profile")); + } + + return [ + "form" => $form->createView(), + "user" => $this->userFacade->getUser(), + "addresses" => $addresses, + ]; + } + + /** + * @Route("/pridat-adresu", name="add_address") + * @Template("user/addaddress.html.twig") + * + * @param Request $request + * @return RedirectResponse|array + */ + public function addAddressAction(Request $request) + { + $user = $this->userFacade->getUser(); + $address = new Address(); + $form = $this->formFactory->create(AddressFormType::class, $address); + + $form->handleRequest($request); + if ($form->isSubmitted()) { + + $address->setUser($user); + + $this->entityManager->persist($address); + $this->entityManager->flush(); + + return RedirectResponse::create($this->router->generate("user_profile")); + } + + return [ + "form" => $form->createView(), + ]; + } } \ No newline at end of file diff --git a/src/AppBundle/Entity/Adress.php b/src/AppBundle/Entity/Address.php similarity index 89% rename from src/AppBundle/Entity/Adress.php rename to src/AppBundle/Entity/Address.php index 61bdb82..1a9450b 100644 --- a/src/AppBundle/Entity/Adress.php +++ b/src/AppBundle/Entity/Address.php @@ -5,12 +5,12 @@ use Doctrine\ORM\Mapping as ORM; /** - * Adress + * Address * - * @ORM\Table(name="adress") - * @ORM\Entity(repositoryClass="AppBundle\Repository\AdressRepository") + * @ORM\Table(name="address") + * @ORM\Entity(repositoryClass="AppBundle\Repository\AddressRepository") */ -class Adress +class Address { /** * @var int @@ -50,7 +50,7 @@ class Adress private $country; /** - * @ORM\ManyToOne(targetEntity="User", inversedBy="adresses") + * @ORM\ManyToOne(targetEntity="User", inversedBy="addresses") * @ORM\JoinColumn(name="user_id", referencedColumnName="id") */ private $user; @@ -70,7 +70,7 @@ public function getId() * * @param string $street * - * @return Adress + * @return Address */ public function setStreet($street) { @@ -94,7 +94,7 @@ public function getStreet() * * @param string $city * - * @return Adress + * @return Address */ public function setCity($city) { @@ -118,7 +118,7 @@ public function getCity() * * @param string $postcode * - * @return Adress + * @return Address */ public function setPostcode($postcode) { @@ -142,7 +142,7 @@ public function getPostcode() * * @param string $country * - * @return Adress + * @return Address */ public function setCountry($country) { @@ -166,7 +166,7 @@ public function getCountry() * * @param \AppBundle\Entity\User $user * - * @return Adress + * @return Address */ public function setUser(\AppBundle\Entity\User $user = null) { diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php index 0a2a8b0..1b1409e 100644 --- a/src/AppBundle/Entity/User.php +++ b/src/AppBundle/Entity/User.php @@ -5,6 +5,7 @@ use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; +use Doctrine\Common\Collections\ArrayCollection; /** * @author Vašek Boch @@ -52,13 +53,13 @@ class User implements UserInterface private $phone; /** - * @ORM\OneToMany(targetEntity="Adress", mappedBy="user") + * @ORM\OneToMany(targetEntity="Address", mappedBy="user") */ - private $adresses; + private $addresses; public function __construct() { - $this->adresses = new ArrayCollection(); + $this->addresses = new ArrayCollection(); } /** @@ -199,36 +200,36 @@ public function getPhone() } /** - * Add adress + * Add address * - * @param \AppBundle\Entity\Adress $adress + * @param \AppBundle\Entity\Address $address * * @return User */ - public function addAdress(\AppBundle\Entity\Adress $adress) + public function addAddress(\AppBundle\Entity\Address $address) { - $this->adresses[] = $adress; + $this->addresses[] = $address; return $this; } /** - * Remove adress + * Remove address * - * @param \AppBundle\Entity\Adress $adress + * @param \AppBundle\Entity\Address $address */ - public function removeAdress(\AppBundle\Entity\Adress $adress) + public function removeAddress(\AppBundle\Entity\Address $address) { - $this->adresses->removeElement($adress); + $this->addresses->removeElement($address); } /** - * Get adresses + * Get addresses * * @return \Doctrine\Common\Collections\Collection */ - public function getAdresses() + public function getAddresses() { - return $this->adresses; + return $this->addresses; } } diff --git a/src/AppBundle/FormType/AddressFormType.php b/src/AppBundle/FormType/AddressFormType.php new file mode 100644 index 0000000..4ea45e4 --- /dev/null +++ b/src/AppBundle/FormType/AddressFormType.php @@ -0,0 +1,47 @@ +add("street", TextType::class, [ + "label" => "Ulice", + "attr" => [ + "class" => "form-control", + ], + ]) + ->add("city", TextType::class, [ + "label" => "Město", + "attr" => [ + "class" => "form-control", + ], + ]) + ->add("postcode", TextType::class, [ + "label" => "PSČ", + "attr" => [ + "class" => "form-control", + ], + ]) + ->add("country", TextType::class, [ + "label" => "Země", + "attr" => [ + "class" => "form-control", + ], + ]); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + "data_class" => Address::class, + )); + } +} \ No newline at end of file diff --git a/src/AppBundle/FormType/ProfileFormType.php b/src/AppBundle/FormType/ProfileFormType.php new file mode 100644 index 0000000..7c6ab08 --- /dev/null +++ b/src/AppBundle/FormType/ProfileFormType.php @@ -0,0 +1,42 @@ +add("username", EmailType::class, [ + "label" => "E-mail", + "attr" => [ + "class" => "form-control", + ], + ]) + ->add("name", TextType::class, [ + "label" => "Jméno a příjmení", + "attr" => [ + "class" => "form-control", + ], + ]) + ->add("phone", TextType::class, [ + "label" => "Telefon", + "attr" => [ + "class" => "form-control", + ], + ]); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + "data_class" => User::class, + )); + } +} \ No newline at end of file diff --git a/src/AppBundle/Repository/AdressRepository.php b/src/AppBundle/Repository/AddressRepository.php similarity index 59% rename from src/AppBundle/Repository/AdressRepository.php rename to src/AppBundle/Repository/AddressRepository.php index 94925cc..407c58f 100644 --- a/src/AppBundle/Repository/AdressRepository.php +++ b/src/AppBundle/Repository/AddressRepository.php @@ -2,12 +2,14 @@ namespace AppBundle\Repository; +use Doctrine\ORM\EntityRepository; + /** - * AdressRepository + * AddressRepository * * This class was generated by the Doctrine ORM. Add your own custom * repository methods below. */ -class AdressRepository extends \Doctrine\ORM\EntityRepository +class AddressRepository extends EntityRepository { } From dbfdfea47cdb01d1328236ce1e1bfdf98be5614f Mon Sep 17 00:00:00 2001 From: spitd1 Date: Sun, 23 Oct 2016 02:16:58 +0200 Subject: [PATCH 5/5] Change password & firewall setup --- .../views/user/changepassword.html.twig | 10 ++ app/Resources/views/user/profile.html.twig | 1 + app/config/security.yml | 6 +- app/config/services.yml | 13 --- src/AppBundle/Controller/UserController.php | 106 ++++++++++++------ src/AppBundle/FormType/ChangePasswordFormType | 43 +++++++ 6 files changed, 128 insertions(+), 51 deletions(-) create mode 100644 app/Resources/views/user/changepassword.html.twig create mode 100644 src/AppBundle/FormType/ChangePasswordFormType diff --git a/app/Resources/views/user/changepassword.html.twig b/app/Resources/views/user/changepassword.html.twig new file mode 100644 index 0000000..ab1c8d8 --- /dev/null +++ b/app/Resources/views/user/changepassword.html.twig @@ -0,0 +1,10 @@ +{% extends 'base.html.twig' %} + +{% block body %} + {{ form_start(form) }} + {{ form_row(form.plainPassword.first) }} + {{ form_row(form.plainPassword.second) }} +
    + + {{ form_end(form) }} +{% endblock %} \ No newline at end of file diff --git a/app/Resources/views/user/profile.html.twig b/app/Resources/views/user/profile.html.twig index 262a636..499dca6 100644 --- a/app/Resources/views/user/profile.html.twig +++ b/app/Resources/views/user/profile.html.twig @@ -4,6 +4,7 @@

    Osobní údaje

    +

    Změnit heslo

    {{ form_start(form) }} {{ form_row(form.username) }} {{ form_row(form.name) }} diff --git a/app/config/security.yml b/app/config/security.yml index 82c6691..d50f979 100644 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -24,4 +24,8 @@ security: # The route name the user can go to in order to logout path: user_logout # The name of the route to redirect to after logging out - target: homepage \ No newline at end of file + target: homepage + + access_control: + - { path: /prihlasit, roles: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: /uzivatel/*, roles: IS_AUTHENTICATED_FULLY } diff --git a/app/config/services.yml b/app/config/services.yml index c7306b4..59f9fb4 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -20,14 +20,6 @@ services: class: AppBundle\Controller\UserController autowire: true - app.controller.adress_controller: - class: AppBundle\Controller\AdressController - autowire: true - - app.facade.adress_facade: - class: AppBundle\Facade\AdressFacade - autowire: true - app.facade.category_facade: class: AppBundle\Facade\CategoryFacade autowire: true @@ -50,11 +42,6 @@ services: factory: ['@doctrine.orm.default_entity_manager', getRepository] arguments: ['AppBundle\Entity\Product'] - app.repository.adress_repository: - class: AppBundle\Repository\AdressRepository - factory: ['@doctrine.orm.default_entity_manager', getRepository] - arguments: ['AppBundle\Entity\Adress'] - encoder: class: Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder arguments: diff --git a/src/AppBundle/Controller/UserController.php b/src/AppBundle/Controller/UserController.php index 8bb0c35..6314cd5 100644 --- a/src/AppBundle/Controller/UserController.php +++ b/src/AppBundle/Controller/UserController.php @@ -6,6 +6,7 @@ use AppBundle\FormType\RegistrationFormType; use AppBundle\FormType\ProfileFormType; use AppBundle\FormType\AddressFormType; +use AppBundle\FormType\ChangePasswordFormType; use Doctrine\ORM\EntityManager; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; @@ -44,43 +45,74 @@ public function __construct( $this->router = $router; } - /** - * @Route("/registrovat", name="user_registration") - * @Template("user/registration.html.twig") - * - * @param Request $request - * @return RedirectResponse|array - */ - public function registrationAction(Request $request) - { - // 1) build the form - $user = new User(); - $form = $this->formFactory->create(RegistrationFormType::class, $user); - - // 2) handle the submit (will only happen on POST) - $form->handleRequest($request); - if ($form->isSubmitted() && $form->isValid()) { - - // 3) Encode the password (you could also do this via Doctrine listener) - $user->setPassword( - $this->passwordEncoder->encodePassword($user->getPlainPassword(), null) - ); - - // 4) save the User! - $this->entityManager->persist($user); - $this->entityManager->flush(); - - // ... do any other work - like sending them an email, etc - // maybe set a "flash" success message for the user - return RedirectResponse::create($this->router->generate("homepage")); - } + /** + * @Route("/registrovat", name="user_registration") + * @Template("user/registration.html.twig") + * + * @param Request $request + * @return RedirectResponse|array + */ + public function registrationAction(Request $request) + { + // 1) build the form + $user = new User(); + $form = $this->formFactory->create(RegistrationFormType::class, $user); - return [ - "form" => $form->createView(), - ]; - } + // 2) handle the submit (will only happen on POST) + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { - /** + // 3) Encode the password (you could also do this via Doctrine listener) + $user->setPassword( + $this->passwordEncoder->encodePassword($user->getPlainPassword(), null) + ); + + // 4) save the User! + $this->entityManager->persist($user); + $this->entityManager->flush(); + + // ... do any other work - like sending them an email, etc + // maybe set a "flash" success message for the user + return RedirectResponse::create($this->router->generate("homepage")); + } + + return [ + "form" => $form->createView(), + ]; + } + + /** + * @Route("/uzivatel/zmenit-heslo", name="user_changepassword") + * @Template("user/changepassword.html.twig") + * + * @param Request $request + * @return RedirectResponse|array + */ + public function changepasswordAction(Request $request) + { + $user = $this->userFacade->getUser(); + $form = $this->formFactory->create(ChangePasswordFormType::class, $user); + + $form->handleRequest($request); + if ($form->isSubmitted()) { + + $user->setPassword( + $this->passwordEncoder->encodePassword($user->getPlainPassword(), null) + ); + + $this->entityManager->persist($user); + $this->entityManager->flush(); + + return RedirectResponse::create($this->router->generate("user_profile")); + } + + return [ + "form" => $form->createView(), + "user" => $this->userFacade->getUser(), + ]; + } + + /** * @Route("/prihlasit", name="user_login") * @Template("user/login.html.twig") * @@ -117,7 +149,7 @@ public function superSecretAction() } /** - * @Route("/profil", name="user_profile") + * @Route("/uzivatel/profil", name="user_profile") * @Template("user/profile.html.twig") * * @param Request $request @@ -146,7 +178,7 @@ public function profileAction(Request $request) } /** - * @Route("/pridat-adresu", name="add_address") + * @Route("/uzivatel/pridat-adresu", name="add_address") * @Template("user/addaddress.html.twig") * * @param Request $request diff --git a/src/AppBundle/FormType/ChangePasswordFormType b/src/AppBundle/FormType/ChangePasswordFormType new file mode 100644 index 0000000..192f5db --- /dev/null +++ b/src/AppBundle/FormType/ChangePasswordFormType @@ -0,0 +1,43 @@ + + * @author Jan Klat + */ +class ChangePasswordFormType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add("plainPassword", RepeatedType::class, [ + "type" => PasswordType::class, + "first_options" => [ + "label" => "Heslo", + "attr" => [ + "class" => "form-control", + ], + ], + "second_options" => [ + "label" => "Heslo znova", + "attr" => [ + "class" => "form-control", + ], + ], + ]); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + "data_class" => User::class, + )); + } +} \ No newline at end of file