From 5e822266a7222ec6f7142471d83944b0c6696996 Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Mon, 22 Oct 2018 20:37:43 +0200 Subject: [PATCH 01/17] Add design * Add Bootstrap Progress Bar Import * Add Progress Bar and Quality Icon --- Resources/assets/less/admin.less | 16 +++++++++++++++- Resources/assets/less/bootstrap.less | 2 +- .../views/Admin/Producer/Product/list.html.twig | 10 ++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Resources/assets/less/admin.less b/Resources/assets/less/admin.less index f4577a1..ce09a27 100644 --- a/Resources/assets/less/admin.less +++ b/Resources/assets/less/admin.less @@ -783,6 +783,20 @@ form.filter { } } +.progress-stuff { + display: flex; + align-items: center; +} + +.table-glyph { + margin-left: 1rem; +} + +.progress { + flex: 1; + margin-top: 2rem; +} + // // Producer / Product form // @@ -1067,4 +1081,4 @@ div.user_payment_allocation { .table-striped > tbody > tr.deleted:nth-child(odd) > th { background-color: darken(#f2dede, 5%); border-color: darken(#ebccd1, 5%); -} \ No newline at end of file +} diff --git a/Resources/assets/less/bootstrap.less b/Resources/assets/less/bootstrap.less index cea72a1..bed2d31 100644 --- a/Resources/assets/less/bootstrap.less +++ b/Resources/assets/less/bootstrap.less @@ -41,7 +41,7 @@ // @import "../../../../../../web/bootstrap/less/jumbotron.less"; // @import "../../../../../../web/bootstrap/less/thumbnails.less"; @import "../../../../../../web/bootstrap/less/alerts.less"; -// @import "../../../../../../web/bootstrap/less/progress-bars.less"; +@import "../../../../../../web/bootstrap/less/progress-bars.less"; // @import "../../../../../../web/bootstrap/less/media.less"; @import "../../../../../../web/bootstrap/less/list-group.less"; @import "../../../../../../web/bootstrap/less/panels.less"; diff --git a/Resources/views/Admin/Producer/Product/list.html.twig b/Resources/views/Admin/Producer/Product/list.html.twig index cc2e4ec..a6b3589 100644 --- a/Resources/views/Admin/Producer/Product/list.html.twig +++ b/Resources/views/Admin/Producer/Product/list.html.twig @@ -34,6 +34,7 @@ {{ branch.name|truncate(8) }} {% endfor %} {{ 'admin.producer.products.list.availability'|trans }} + Complétion du formulaire   @@ -62,6 +63,15 @@ {% endif %} {% endif %} + +
+
+
100%
+
+ +
+ + From 8d42e7b29edf0c06736eb0d5f6d099a89b7cdb05 Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Mon, 22 Oct 2018 21:54:15 +0200 Subject: [PATCH 02/17] Add Translation * Add french translation * Add english translation --- Resources/translations/messages.en.yml | 3 +++ Resources/translations/messages.fr.yml | 3 +++ Resources/views/Admin/Producer/Product/list.html.twig | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Resources/translations/messages.en.yml b/Resources/translations/messages.en.yml index a2cf946..a9c61d3 100644 --- a/Resources/translations/messages.en.yml +++ b/Resources/translations/messages.en.yml @@ -807,6 +807,9 @@ admin.producer.products.list.is_bio: "Organic" admin.producer.products.list.is_of_the_moment: "Featured" admin.producer.products.list.price: "Price" admin.producer.products.list.availability: "Availability" +admin.producer.products.list.completeness: "Form Completion" +admin.producer.products.list.completeness_quality_0: "Either the picture is missing or the description is incomplete" +admin.producer.products.list.completeness_quality_1: "The form is well completed" admin.producer.products.form.new_title: "New product" admin.producer.products.form.edit_title: "Product %name% (%ref%)" admin.producer.products.form.fieldset.main: "Main" diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 61a61ae..dd3a1be 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -854,6 +854,9 @@ admin.producer.products.list.is_bio: "Bio" admin.producer.products.list.is_of_the_moment: "Produit du moment" admin.producer.products.list.price: "Prix" admin.producer.products.list.availability: "Dispo" +admin.producer.products.list.completeness: "Complétion du formulaire" +admin.producer.products.list.completeness_quality_0: "La description est incomplète et/ou l'image est manquante" +admin.producer.products.list.completeness_quality_1: "Le formulaire a bien était complété" admin.producer.products.form.new_title: "Nouveau produit" admin.producer.products.form.edit_title: "Produit %name% (%ref%)" admin.producer.products.form.fieldset.main: "Principal" diff --git a/Resources/views/Admin/Producer/Product/list.html.twig b/Resources/views/Admin/Producer/Product/list.html.twig index a6b3589..b51b088 100644 --- a/Resources/views/Admin/Producer/Product/list.html.twig +++ b/Resources/views/Admin/Producer/Product/list.html.twig @@ -34,7 +34,7 @@ {{ branch.name|truncate(8) }} {% endfor %} {{ 'admin.producer.products.list.availability'|trans }} - Complétion du formulaire + {{ 'admin.producer.products.list.completeness' |trans}}   @@ -68,7 +68,7 @@
100%
- + From c1cc2532449c50fd9e4c5a99f657d8125f18708c Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Tue, 23 Oct 2018 09:52:46 +0200 Subject: [PATCH 03/17] Add completeness to Product * Add $completeness to Product Entity * Add $completeness_quality to Product Entity --- Entity/Product.php | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Entity/Product.php b/Entity/Product.php index 74496d6..914b80e 100644 --- a/Entity/Product.php +++ b/Entity/Product.php @@ -188,6 +188,19 @@ class Product */ private $branches; + /** + * @var integer $completeness + * + * @ORM\Column(name="completeness", type="integer", nullable=true) + */ + private $completeness; + + /** + * @var integer $completeness_quality + * + * @ORM\Column(name="completeness_quality", type="integer", nullable=true) + */ + private $completeness_quality; /** * Constructor @@ -201,6 +214,7 @@ public function __construct() $this->availability = self::AVAILABILITY_AVAILABLE; $this->hasNoPrice = (null === $this->id) ? false : (null === $this->price); $this->branches = new ArrayCollection(); + $this->completeness = 4; } /** @@ -738,4 +752,53 @@ public function hasBranch(Branch $branch) return false; } + + /** + * Set completeness + * + * @param integer $completeness + * + * @return Product + */ + public function setCompleteness($completeness) + { + $this->completeness = $completeness; + + return $this; + } + + /** + * Get completeness + * + * @return integer + */ + public function getCompleteness() + { + return $this->completeness; + } + + /** + * Set completeness quality + * + * @param integer $completeness + * + * @return Product + */ + public function setCompletenessQuality($completeness_quality) + { + $this->completeness_quality = $completeness_quality; + + return $this; + } + + /** + * Get completeness quality + * + * @return integer + */ + public function getCompletenessQuality() + { + return $this->completeness_quality; + } + } From 27aa93cad31de56316f3f4740baf71539cc89fe4 Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Tue, 23 Oct 2018 10:11:55 +0200 Subject: [PATCH 04/17] Remove completeness_quality --- Entity/Product.php | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/Entity/Product.php b/Entity/Product.php index 914b80e..9c9e2f1 100644 --- a/Entity/Product.php +++ b/Entity/Product.php @@ -195,13 +195,6 @@ class Product */ private $completeness; - /** - * @var integer $completeness_quality - * - * @ORM\Column(name="completeness_quality", type="integer", nullable=true) - */ - private $completeness_quality; - /** * Constructor */ @@ -776,29 +769,4 @@ public function getCompleteness() { return $this->completeness; } - - /** - * Set completeness quality - * - * @param integer $completeness - * - * @return Product - */ - public function setCompletenessQuality($completeness_quality) - { - $this->completeness_quality = $completeness_quality; - - return $this; - } - - /** - * Get completeness quality - * - * @return integer - */ - public function getCompletenessQuality() - { - return $this->completeness_quality; - } - } From 1c2da006aaaab9a4ba74a777982dba19b8c70857 Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Tue, 23 Oct 2018 11:14:14 +0200 Subject: [PATCH 05/17] Add Product Insight * Create product insight entity * Create insights field in Product Entity --- Entity/Product.php | 15 +++++ Entity/ProductInsight.php | 124 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 Entity/ProductInsight.php diff --git a/Entity/Product.php b/Entity/Product.php index 9c9e2f1..c23731d 100644 --- a/Entity/Product.php +++ b/Entity/Product.php @@ -195,6 +195,11 @@ class Product */ private $completeness; + /** + * @ORM\ManyToOne(targetEntity="ProductInsight") + */ + private $insights; + /** * Constructor */ @@ -769,4 +774,14 @@ public function getCompleteness() { return $this->completeness; } + + /** + * Get insights + * + * @return ProductInsight[] + */ + public function getProductInsights() + { + return $this->insights; + } } diff --git a/Entity/ProductInsight.php b/Entity/ProductInsight.php new file mode 100644 index 0000000..09e94cb --- /dev/null +++ b/Entity/ProductInsight.php @@ -0,0 +1,124 @@ +id; + } + + /** + * Set productId + * + * @param integer $productId + * @return ProductInsight + */ + public function setProductId($productId) + { + $this->productId = $productId; + + return $this; + } + + /** + * Get productId + * + * @return integer + */ + public function getProductId() + { + return $this->productId; + } + + /** + * Set type + * + * @param string $type + * @return ProductInsight + */ + public function setType($type) + { + $this->type = $type; + + return $this; + } + + /** + * Get type + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Set code + * + * @param integer $code + * @return ProductInsight + */ + public function setCode($code) + { + $this->code = $code; + + return $this; + } + + /** + * Get code + * + * @return integer + */ + public function getCode() + { + return $this->code; + } +} From efcdc42d49ef68c09d0b7a0e7874a41042114a77 Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Tue, 23 Oct 2018 16:36:39 +0200 Subject: [PATCH 06/17] Add FillCompletenessCommand This command updates all the actual Products and create the insights when completeness is not full. This also add completeness bar. --- Command/FillCompletenessCommand.php | 87 +++++++++++++++++++++++++++++ Entity/Product.php | 10 +++- Entity/ProductInsight.php | 2 +- 3 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 Command/FillCompletenessCommand.php diff --git a/Command/FillCompletenessCommand.php b/Command/FillCompletenessCommand.php new file mode 100644 index 0000000..7001557 --- /dev/null +++ b/Command/FillCompletenessCommand.php @@ -0,0 +1,87 @@ +setName('openmiammiam:fill-completeness') + ->setDescription('Fill completeness fields for products in database'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $productManager = $this->getContainer()->get('doctrine')->getRepository('IsicsOpenMiamMiamBundle:Product'); + $products = $productManager->findAll(); + $completeness = 7; + foreach ($products as $db_product) + { + $product = $productManager->find($db_product->getId()); + if ($product->getDescription()) + { + $completeness++; + + if ($product->getImage()) + { + $completeness++; + + if ($product->getPriceInfo()) + { + $completeness++; + + } else + { + $output->writeln('No price info provided'); + } + + } else + { + $insight = new ProductInsight(); + $insight->setType("COMPLETENESS"); + $insight->setCode(2); + $insight->setProductId($product->getId()); + $product->addProductInsight($insight); + } + } else + { + $insight = new ProductInsight(); + $insight->setType("COMPLETENESS"); + $insight->setCode(1); + $insight->setProductId($product->getId()); + $product->addProductInsight($insight); + + if (!$product->getImage()) + { + $insight = new ProductInsight(); + $insight->setType("COMPLETENESS"); + $insight->setCode(2); + $insight->setProductId($product->getId()); + $product->addProductInsight($insight); + } + + if (!$product->getPriceInfo()) + { + $insight = new ProductInsight(); + $insight->setType("COMPLETENESS"); + $insight->setCode(3); + $insight->setProductId($product->getId()); + $product->addProductInsight($insight); + } + } + $product->setCompleteness($completeness); + $this->getContainer()->get('doctrine')->getManager()->flush(); + $completeness = 7; + } + } + +} diff --git a/Entity/Product.php b/Entity/Product.php index c23731d..b61154d 100644 --- a/Entity/Product.php +++ b/Entity/Product.php @@ -196,7 +196,7 @@ class Product private $completeness; /** - * @ORM\ManyToOne(targetEntity="ProductInsight") + * @ORM\OneToMany(targetEntity="ProductInsight", mappedBy="product", cascade={"persist"}) */ private $insights; @@ -212,7 +212,8 @@ public function __construct() $this->availability = self::AVAILABILITY_AVAILABLE; $this->hasNoPrice = (null === $this->id) ? false : (null === $this->price); $this->branches = new ArrayCollection(); - $this->completeness = 4; + $this->completeness = 7; + $this->insights = new ArrayCollection(); } /** @@ -775,6 +776,11 @@ public function getCompleteness() return $this->completeness; } + public function addProductInsight(ProductInsight $insight) + { + $this->insights->add($insight); + } + /** * Get insights * diff --git a/Entity/ProductInsight.php b/Entity/ProductInsight.php index 09e94cb..bed05c0 100644 --- a/Entity/ProductInsight.php +++ b/Entity/ProductInsight.php @@ -115,7 +115,7 @@ public function setCode($code) /** * Get code * - * @return integer + * @return integer */ public function getCode() { From 6faa3d20e24695f3dbf321d7e20d5df2f48041b6 Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Tue, 23 Oct 2018 16:53:39 +0200 Subject: [PATCH 07/17] Update FillCompletenessCommand Add quality check for description --- Command/FillCompletenessCommand.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Command/FillCompletenessCommand.php b/Command/FillCompletenessCommand.php index 7001557..4ebb07a 100644 --- a/Command/FillCompletenessCommand.php +++ b/Command/FillCompletenessCommand.php @@ -31,10 +31,21 @@ protected function execute(InputInterface $input, OutputInterface $output) { $completeness++; + if (strlen($product->getDescription()) < 10) + { + $insight = new ProductInsight(); + $insight->setType("QUALITY"); + $insight->setCode(4); + $insight->setProductId($product->getId()); + $product->addProductInsight($insight); + } + if ($product->getImage()) { $completeness++; + // Image quality detection here + if ($product->getPriceInfo()) { $completeness++; @@ -71,17 +82,19 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$product->getPriceInfo()) { - $insight = new ProductInsight(); - $insight->setType("COMPLETENESS"); - $insight->setCode(3); - $insight->setProductId($product->getId()); - $product->addProductInsight($insight); + $insight = new ProductInsight(); + $insight->setType("COMPLETENESS"); + $insight->setCode(3); + $insight->setProductId($product->getId()); + $product->addProductInsight($insight); } } $product->setCompleteness($completeness); $this->getContainer()->get('doctrine')->getManager()->flush(); $completeness = 7; } + + $output->writeln(" - Finished"); } } From df268884b7427fa4102b8bc9d2d6c650c4304096 Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Wed, 24 Oct 2018 09:26:32 +0200 Subject: [PATCH 08/17] Update EntityProduct * Add hasProductInsights --- Entity/Product.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Entity/Product.php b/Entity/Product.php index b61154d..d68573c 100644 --- a/Entity/Product.php +++ b/Entity/Product.php @@ -790,4 +790,14 @@ public function getProductInsights() { return $this->insights; } + + /** + * Has Insights + * + * @return string + */ + public function hasProductInsights() + { + return "Hello"; + } } From a293ed4c24f6bc4ed3819f5720322fddaadf973a Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Wed, 24 Oct 2018 09:26:58 +0200 Subject: [PATCH 09/17] Add edit page design --- .../Admin/Producer/Product/edit.html.twig | 19 +++++++++++++++++++ .../Admin/Producer/Product/list.html.twig | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Resources/views/Admin/Producer/Product/edit.html.twig b/Resources/views/Admin/Producer/Product/edit.html.twig index 2147443..13f47ea 100644 --- a/Resources/views/Admin/Producer/Product/edit.html.twig +++ b/Resources/views/Admin/Producer/Product/edit.html.twig @@ -11,6 +11,25 @@ {% set product = form.vars.data %}

{{ 'admin.producer.products.form.edit_title'|trans({'%name%': product.name, '%ref%': product.ref}) }}

+ {% include 'IsicsOpenMiamMiamBundle:Admin:Producer\\Product\\form.html.twig' with {'form': form} %} {% include 'IsicsOpenMiamMiamBundle:Admin:Producer\\Product\\deleteDialog.html.twig' %} diff --git a/Resources/views/Admin/Producer/Product/list.html.twig b/Resources/views/Admin/Producer/Product/list.html.twig index b51b088..c383173 100644 --- a/Resources/views/Admin/Producer/Product/list.html.twig +++ b/Resources/views/Admin/Producer/Product/list.html.twig @@ -66,9 +66,10 @@
-
100%
+
{{ product.completeness * 10 }}%
- + {{ product.hasProductInsights() }} +
From 3f9a314cc40e6bed30daadb560d8262a20902283 Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Wed, 24 Oct 2018 10:17:11 +0200 Subject: [PATCH 10/17] Update FillCompletenessCommand * Create ProductInsightManager * Add progress bar --- Command/FillCompletenessCommand.php | 85 ++++---------------- Manager/ProductInsightManager.php | 115 ++++++++++++++++++++++++++++ Resources/config/services.yml | 5 ++ 3 files changed, 135 insertions(+), 70 deletions(-) create mode 100644 Manager/ProductInsightManager.php diff --git a/Command/FillCompletenessCommand.php b/Command/FillCompletenessCommand.php index 4ebb07a..c58fac5 100644 --- a/Command/FillCompletenessCommand.php +++ b/Command/FillCompletenessCommand.php @@ -7,6 +7,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Helper\ProgressBar; use Isics\Bundle\OpenMiamMiamBundle\Entity\Product; use Isics\Bundle\OpenMiamMiamBundle\Entity\ProductInsight; @@ -21,80 +22,24 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $productManager = $this->getContainer()->get('doctrine')->getRepository('IsicsOpenMiamMiamBundle:Product'); - $products = $productManager->findAll(); - $completeness = 7; - foreach ($products as $db_product) - { - $product = $productManager->find($db_product->getId()); - if ($product->getDescription()) - { - $completeness++; + $output->writeln('Computing products insights...'); + $output->writeln(''); - if (strlen($product->getDescription()) < 10) - { - $insight = new ProductInsight(); - $insight->setType("QUALITY"); - $insight->setCode(4); - $insight->setProductId($product->getId()); - $product->addProductInsight($insight); - } + $productInsightManager = $this->getContainer()->get('open_miam_miam.product_insight_manager'); - if ($product->getImage()) - { - $completeness++; + $progressBar = new ProgressBar($output, $productInsightManager->count()); + $progressBar->setBarCharacter('•'); + $progressBar->setEmptyBarCharacter('•'); + $progressBar->setProgressCharacter('➤'); + $progressBar->setFormat( + "%memory% %current%/%max% [%bar%] %percent:3s%%\n Elapsed : %elapsed% Remaining : %remaining:-6s%" + ); - // Image quality detection here + $callback = function() use ($progressBar) { + $progressBar->advance(1); + }; - if ($product->getPriceInfo()) - { - $completeness++; - - } else - { - $output->writeln('No price info provided'); - } - - } else - { - $insight = new ProductInsight(); - $insight->setType("COMPLETENESS"); - $insight->setCode(2); - $insight->setProductId($product->getId()); - $product->addProductInsight($insight); - } - } else - { - $insight = new ProductInsight(); - $insight->setType("COMPLETENESS"); - $insight->setCode(1); - $insight->setProductId($product->getId()); - $product->addProductInsight($insight); - - if (!$product->getImage()) - { - $insight = new ProductInsight(); - $insight->setType("COMPLETENESS"); - $insight->setCode(2); - $insight->setProductId($product->getId()); - $product->addProductInsight($insight); - } - - if (!$product->getPriceInfo()) - { - $insight = new ProductInsight(); - $insight->setType("COMPLETENESS"); - $insight->setCode(3); - $insight->setProductId($product->getId()); - $product->addProductInsight($insight); - } - } - $product->setCompleteness($completeness); - $this->getContainer()->get('doctrine')->getManager()->flush(); - $completeness = 7; - } - - $output->writeln(" - Finished"); + $productInsightManager->updateProductInsights($callback); } } diff --git a/Manager/ProductInsightManager.php b/Manager/ProductInsightManager.php new file mode 100644 index 0000000..646a36d --- /dev/null +++ b/Manager/ProductInsightManager.php @@ -0,0 +1,115 @@ + + * + * This source file is subject to the AGPL v3 license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Isics\Bundle\OpenMiamMiamBundle\Manager; + +use Isics\Bundle\OpenMiamMiamBundle\Entity\ProductInsight; +use Doctrine\ORM\EntityManager; + +/** + * Class ProductInsightRepository + * + * @package Isics\Bundle\OpenMiamMiamBundle\Manager + */ +class ProductInsightManager +{ + /** + * @var EntityManager $entityManager + */ + protected $entityManager; + + /** + * Constructs object + * + * @param EntityManager $entityManager + */ + public function __construct(EntityManager $entityManager) + { + $this->entityManager = $entityManager; + } + + /** + * Update Products Insights + * @param \Closure $callback + */ + public function updateProductInsights(\Closure $callback = null) + { + $productManager = $this->entityManager->getRepository('IsicsOpenMiamMiamBundle:Product'); + $products = $productManager->findAll(); + $completeness = 7; + foreach ($products as $db_product) { + $product = $productManager->find($db_product->getId()); + if ($product->getDescription()) { + $completeness++; + + if (strlen($product->getDescription()) < 10) { + $insight = new ProductInsight(); + $insight->setType("QUALITY"); + $insight->setCode(4); + $insight->setProductId($product->getId()); + $product->addProductInsight($insight); + } + + if ($product->getImage()) { + $completeness++; + + // Image quality detection here + + if ($product->getPriceInfo()) { + $completeness++; + } + } else { + $insight = new ProductInsight(); + $insight->setType("COMPLETENESS"); + $insight->setCode(2); + $insight->setProductId($product->getId()); + $product->addProductInsight($insight); + } + } else { + $insight = new ProductInsight(); + $insight->setType("COMPLETENESS"); + $insight->setCode(1); + $insight->setProductId($product->getId()); + $product->addProductInsight($insight); + + if (!$product->getImage()) { + $insight = new ProductInsight(); + $insight->setType("COMPLETENESS"); + $insight->setCode(2); + $insight->setProductId($product->getId()); + $product->addProductInsight($insight); + } + + if (!$product->getPriceInfo()) { + $insight = new ProductInsight(); + $insight->setType("COMPLETENESS"); + $insight->setCode(3); + $insight->setProductId($product->getId()); + $product->addProductInsight($insight); + } + } + $product->setCompleteness($completeness); + $this->entityManager->flush(); + $completeness = 7; + $callback(); + } + } + + /** + * Return the count of products + * + * @return int + */ + public function count() + { + $productManager = $this->entityManager->getRepository('IsicsOpenMiamMiamBundle:Product'); + return $productManager->count(); + } +} diff --git a/Resources/config/services.yml b/Resources/config/services.yml index cd13727..f3b8281 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -28,6 +28,7 @@ parameters: open_miam_miam.article_manager.class: 'Isics\Bundle\OpenMiamMiamBundle\Manager\ArticleManager' open_miam_miam.product_manager.class: 'Isics\Bundle\OpenMiamMiamBundle\Manager\ProductManager' open_miam_miam.product_matching_manager.class: 'Isics\Bundle\OpenMiamMiamBundle\Manager\ProductMatchingManager' + open_miam_miam.product_insight_manager.class: 'Isics\Bundle\OpenMiamMiamBundle\Manager\ProductInsightManager' open_miam_miam.association_manager.class: 'Isics\Bundle\OpenMiamMiamBundle\Manager\AssociationManager' open_miam_miam.association_has_producer_manager.class: 'Isics\Bundle\OpenMiamMiamBundle\Manager\AssociationHasProducerManager' open_miam_miam.producer_manager.class: 'Isics\Bundle\OpenMiamMiamBundle\Manager\ProducerManager' @@ -306,6 +307,10 @@ services: class: %open_miam_miam.product_matching_manager.class% arguments: ['@doctrine.orm.entity_manager'] + open_miam_miam.product_insight_manager: + class: %open_miam_miam.product_insight_manager.class% + arguments: ['@doctrine.orm.entity_manager'] + open_miam_miam.association_manager: class: %open_miam_miam.association_manager.class% arguments: ['@doctrine.orm.entity_manager', %open_miam_miam.artificial_product_ref%, '@open_miam_miam_user.manager.user', '@open_miam_miam.activity_manager'] From 88833c305b36dade1f420841503b50d31f003898 Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Wed, 24 Oct 2018 17:19:12 +0200 Subject: [PATCH 11/17] Update Completeness * Update FillCompletenessCommand * Update Relatoins between Product & Insights * Add Design to the edit page --- .../Admin/Producer/ProductController.php | 2 + Entity/Product.php | 14 +++--- Entity/ProductInsight.php | 25 +++++++---- Manager/ProductInsightManager.php | 45 ++++--------------- .../Admin/Producer/Product/edit.html.twig | 31 ++++++++++--- .../Admin/Producer/Product/list.html.twig | 8 +++- 6 files changed, 67 insertions(+), 58 deletions(-) diff --git a/Controller/Admin/Producer/ProductController.php b/Controller/Admin/Producer/ProductController.php index 200eed9..db3b6b1 100644 --- a/Controller/Admin/Producer/ProductController.php +++ b/Controller/Admin/Producer/ProductController.php @@ -126,6 +126,8 @@ public function editAction(Request $request, Producer $producer, Product $produc return $this->render('IsicsOpenMiamMiamBundle:Admin\Producer\Product:edit.html.twig', array( 'producer' => $producer, 'form' => $form->createView(), + 'completeness' => $product->getCompleteness(), + 'insights' => $product->getProductInsights(), 'activities' => $productManager->getActivities($product) )); } diff --git a/Entity/Product.php b/Entity/Product.php index d68573c..564e123 100644 --- a/Entity/Product.php +++ b/Entity/Product.php @@ -196,7 +196,9 @@ class Product private $completeness; /** - * @ORM\OneToMany(targetEntity="ProductInsight", mappedBy="product", cascade={"persist"}) + * @var Doctrine\Common\Collections\Collection $insights + * + * @ORM\OneToMany(targetEntity="ProductInsight", mappedBy="product", cascade={"persist", "remove"}) */ private $insights; @@ -778,13 +780,15 @@ public function getCompleteness() public function addProductInsight(ProductInsight $insight) { - $this->insights->add($insight); + $this->insights[] = $insight; + + return $this; } /** * Get insights * - * @return ProductInsight[] + * @return \Doctrine\Common\Collections\Collection */ public function getProductInsights() { @@ -794,10 +798,10 @@ public function getProductInsights() /** * Has Insights * - * @return string + * @return integer */ public function hasProductInsights() { - return "Hello"; + return 0; } } diff --git a/Entity/ProductInsight.php b/Entity/ProductInsight.php index bed05c0..692f8d9 100644 --- a/Entity/ProductInsight.php +++ b/Entity/ProductInsight.php @@ -3,6 +3,7 @@ namespace Isics\Bundle\OpenMiamMiamBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Isics\Bundle\OpenMiamMiamBundle\Entity\Product; /** * ProductInsight @@ -22,11 +23,12 @@ class ProductInsight private $id; /** - * @var int + * @var Product + * + * @ORM\ManyToOne(targetEntity="Product", inversedBy="insights") * - * @ORM\Column(name="product_id", type="integer") */ - private $productId; + private $product; /** * @var string @@ -42,6 +44,13 @@ class ProductInsight */ private $code; + public function __construct($type, $code, Product $product) + { + $this->product = $product; + $this->code = $code; + $this->type = $type; + $product->addProductInsight($this); + } /** * Get id @@ -54,12 +63,12 @@ public function getId() } /** - * Set productId + * Set product * - * @param integer $productId + * @param integer $product * @return ProductInsight */ - public function setProductId($productId) + public function setProduct($productId) { $this->productId = $productId; @@ -67,11 +76,11 @@ public function setProductId($productId) } /** - * Get productId + * Get product * * @return integer */ - public function getProductId() + public function getProduct() { return $this->productId; } diff --git a/Manager/ProductInsightManager.php b/Manager/ProductInsightManager.php index 646a36d..4da603c 100644 --- a/Manager/ProductInsightManager.php +++ b/Manager/ProductInsightManager.php @@ -42,62 +42,35 @@ public function __construct(EntityManager $entityManager) public function updateProductInsights(\Closure $callback = null) { $productManager = $this->entityManager->getRepository('IsicsOpenMiamMiamBundle:Product'); - $products = $productManager->findAll(); + $ids = $productManager->findAllId(); $completeness = 7; - foreach ($products as $db_product) { - $product = $productManager->find($db_product->getId()); + foreach ($ids as $id) { + $product = $productManager->findOneBy(["id" => $id[0]['id']]); if ($product->getDescription()) { $completeness++; if (strlen($product->getDescription()) < 10) { - $insight = new ProductInsight(); - $insight->setType("QUALITY"); - $insight->setCode(4); - $insight->setProductId($product->getId()); - $product->addProductInsight($insight); + $insight = new ProductInsight("QUALITY", 4, $product); } if ($product->getImage()) { $completeness++; // Image quality detection here - - if ($product->getPriceInfo()) { - $completeness++; - } } else { - $insight = new ProductInsight(); - $insight->setType("COMPLETENESS"); - $insight->setCode(2); - $insight->setProductId($product->getId()); - $product->addProductInsight($insight); + $insight = new ProductInsight("COMPLETENESS", 2, $product); } } else { - $insight = new ProductInsight(); - $insight->setType("COMPLETENESS"); - $insight->setCode(1); - $insight->setProductId($product->getId()); - $product->addProductInsight($insight); + $insight = new ProductInsight("COMPLETENESS", 1, $product); if (!$product->getImage()) { - $insight = new ProductInsight(); - $insight->setType("COMPLETENESS"); - $insight->setCode(2); - $insight->setProductId($product->getId()); - $product->addProductInsight($insight); - } - - if (!$product->getPriceInfo()) { - $insight = new ProductInsight(); - $insight->setType("COMPLETENESS"); - $insight->setCode(3); - $insight->setProductId($product->getId()); - $product->addProductInsight($insight); + $insight = new ProductInsight("COMPLETENESS", 2, $product); } } $product->setCompleteness($completeness); + $this->entityManager->persist($product); $this->entityManager->flush(); - $completeness = 7; + $completeness = 8; $callback(); } } diff --git a/Resources/views/Admin/Producer/Product/edit.html.twig b/Resources/views/Admin/Producer/Product/edit.html.twig index 13f47ea..104d7ed 100644 --- a/Resources/views/Admin/Producer/Product/edit.html.twig +++ b/Resources/views/Admin/Producer/Product/edit.html.twig @@ -11,25 +11,42 @@ {% set product = form.vars.data %}

{{ 'admin.producer.products.form.edit_title'|trans({'%name%': product.name, '%ref%': product.ref}) }}

+ {% if insights |length >= 1 %} + {% endif %} {% include 'IsicsOpenMiamMiamBundle:Admin:Producer\\Product\\form.html.twig' with {'form': form} %} {% include 'IsicsOpenMiamMiamBundle:Admin:Producer\\Product\\deleteDialog.html.twig' %} diff --git a/Resources/views/Admin/Producer/Product/list.html.twig b/Resources/views/Admin/Producer/Product/list.html.twig index c383173..ccdccad 100644 --- a/Resources/views/Admin/Producer/Product/list.html.twig +++ b/Resources/views/Admin/Producer/Product/list.html.twig @@ -7,6 +7,7 @@ #} {% extends 'IsicsOpenMiamMiamBundle:Admin:admin.html.twig' %} + {% block content %}
@@ -66,10 +67,13 @@
-
{{ product.completeness * 10 }}%
+
{{ product.completeness * 10 }}%
- {{ product.hasProductInsights() }} + {% if product.getProductInsights() |length >= 1 %} + + {% else %} + {% endif %}
From f1e8f1cba09502114e91093fcae51d78eb8491ec Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Wed, 24 Oct 2018 17:30:43 +0200 Subject: [PATCH 12/17] Add edit form translation --- Resources/translations/messages.en.yml | 5 +++++ Resources/translations/messages.fr.yml | 5 +++++ Resources/views/Admin/Producer/Product/edit.html.twig | 10 +++++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Resources/translations/messages.en.yml b/Resources/translations/messages.en.yml index a9c61d3..e4c7bea 100644 --- a/Resources/translations/messages.en.yml +++ b/Resources/translations/messages.en.yml @@ -839,6 +839,11 @@ admin.producer.products.message.created: "Product has been created admin.producer.products.message.updated: "Product has been modified" admin.producer.products.message.deleted: "Product has been deleted" admin.producer.products.delete_dialog.content: "Are you sure you want to delete product?" +admin.producer.products.edit.bad_description: "Tip: The product description quality is bad, you can change it in the part 'Image and description'" +admin.producer.products.edit.bad_image: "Tip: The product image quality is bad, you can change it in the part 'Image and description'" +admin.producer.products.empty_elements: "Many elements are empty" +admin.producer.products.empty_description: "The description is empty" +admin.producer.products.empty_image: "The image is empty" # Admin / Producer / Calendar admin.producer.calendar.title: "Calendar" diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index dd3a1be..8ee7b4a 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -886,6 +886,11 @@ admin.producer.products.message.created: "Le produit a bien été admin.producer.products.message.updated: "Le produit a bien été mis à jour." admin.producer.products.message.deleted: "Le produit a bien été supprimé." admin.producer.products.delete_dialog.content: "Êtes-vous vraiment certain de vouloir supprimer ce produit ?" +admin.producer.products.edit.bad_description: "Conseil: La description du produit est de mauvaise qualité, vous pouvez la modifier dans la partie 'Image et description'" +admin.producer.products.edit.bad_image: "Conseil: La photo du produit est de mauvaise qualité, vous pouvez la modifier dans la partie 'Image et description'" +admin.producer.products.edit.empty_elements: "Certains éléments sont manquants" +admin.producer.products.empty_description: "La description est manquante" +admin.producer.products.empty_image: "L'image est manquante" # Admin / Producer / Calendar admin.producer.calendar.title: "Calendrier de présence" diff --git a/Resources/views/Admin/Producer/Product/edit.html.twig b/Resources/views/Admin/Producer/Product/edit.html.twig index 104d7ed..7698dee 100644 --- a/Resources/views/Admin/Producer/Product/edit.html.twig +++ b/Resources/views/Admin/Producer/Product/edit.html.twig @@ -16,20 +16,20 @@
{% for insight in insights %} {% if insight.getCode() == 4 %} - Conseil: La description du produit est de mauvaise qualité, vous pouvez la modifier dans la partie 'Image et description'

+ {{ 'admin.producer.products.edit.bad_description' |trans }}

{% elseif insight.getCode() == 3 %} - Conseil: La photo du produit est de mauvaise qualité, vous pouvez la modifier dans la partie 'Image et description'

+ {{ 'admin.producer.products.edit.bad_image' |trans }}

{% endif %} {% endfor %} {% if completeness < 10 %} -

+

    {% for insight in insights %} {% if insight.code == 1 %} -
  • La description est manquante
  • +
  • {{ 'admin.producer.products.edit.empty_description' |trans }}
  • {% elseif insight.code == 2 %} -
  • L'image est manquante
  • +
  • {{ 'admin.producer.products.edit.empty_image' |trans }}
  • {% endif %} {% endfor %}
From 54547c6922b1b724135393439a05ce3b891d68f0 Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Wed, 24 Oct 2018 17:48:08 +0200 Subject: [PATCH 13/17] Fix translation --- Resources/translations/messages.en.yml | 6 +++--- Resources/translations/messages.fr.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Resources/translations/messages.en.yml b/Resources/translations/messages.en.yml index e4c7bea..dabbd4b 100644 --- a/Resources/translations/messages.en.yml +++ b/Resources/translations/messages.en.yml @@ -841,9 +841,9 @@ admin.producer.products.message.deleted: "Product has been deleted admin.producer.products.delete_dialog.content: "Are you sure you want to delete product?" admin.producer.products.edit.bad_description: "Tip: The product description quality is bad, you can change it in the part 'Image and description'" admin.producer.products.edit.bad_image: "Tip: The product image quality is bad, you can change it in the part 'Image and description'" -admin.producer.products.empty_elements: "Many elements are empty" -admin.producer.products.empty_description: "The description is empty" -admin.producer.products.empty_image: "The image is empty" +admin.producer.products.edit.empty_elements: "Many elements are empty" +admin.producer.products.edit.empty_description: "The description is empty" +admin.producer.products.edit.empty_image: "The image is empty" # Admin / Producer / Calendar admin.producer.calendar.title: "Calendar" diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 8ee7b4a..e0a414f 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -889,8 +889,8 @@ admin.producer.products.delete_dialog.content: "Êtes-vous vraiment cert admin.producer.products.edit.bad_description: "Conseil: La description du produit est de mauvaise qualité, vous pouvez la modifier dans la partie 'Image et description'" admin.producer.products.edit.bad_image: "Conseil: La photo du produit est de mauvaise qualité, vous pouvez la modifier dans la partie 'Image et description'" admin.producer.products.edit.empty_elements: "Certains éléments sont manquants" -admin.producer.products.empty_description: "La description est manquante" -admin.producer.products.empty_image: "L'image est manquante" +admin.producer.products.edit.empty_description: "La description est manquante" +admin.producer.products.edit.empty_image: "L'image est manquante" # Admin / Producer / Calendar admin.producer.calendar.title: "Calendrier de présence" From 51b020ba4b1016b0f14dd868dfa86af176d87a3a Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Thu, 25 Oct 2018 11:55:26 +0200 Subject: [PATCH 14/17] Add Completeness estimation on edit & create --- .../Admin/Producer/ProductController.php | 4 ++ Entity/Product.php | 12 +----- Manager/ProductInsightManager.php | 38 ++++++++++++++++++- Resources/translations/messages.en.yml | 8 ++-- Resources/translations/messages.fr.yml | 6 +-- .../Admin/Producer/Product/edit.html.twig | 2 +- 6 files changed, 50 insertions(+), 20 deletions(-) diff --git a/Controller/Admin/Producer/ProductController.php b/Controller/Admin/Producer/ProductController.php index db3b6b1..896b816 100644 --- a/Controller/Admin/Producer/ProductController.php +++ b/Controller/Admin/Producer/ProductController.php @@ -67,12 +67,14 @@ public function createAction(Request $request, Producer $producer) $this->secure($producer); $productManager = $this->get('open_miam_miam.product_manager'); + $productInsightsManager = $this->get('open_miam_miam.product_insight_manager'); $product = $productManager->createForProducer($producer); $form = $this->getForm($product); if ($request->isMethod('POST')) { $form->handleRequest($request); if ($form->isValid()) { + $productInsightsManager->createProductInsight($product); $productManager->save($product, $this->get('security.token_storage')->getToken()->getUser()); $this->get('session')->getFlashBag()->add('notice', 'admin.producer.products.message.created'); @@ -107,11 +109,13 @@ public function editAction(Request $request, Producer $producer, Product $produc $this->secureProduct($producer, $product); $productManager = $this->get('open_miam_miam.product_manager'); + $productInsightsManager = $this->get('open_miam_miam.product_insight_manager'); $form = $this->getForm($product); if ($request->isMethod('POST')) { $form->handleRequest($request); if ($form->isValid()) { + $productInsightsManager->createProductInsight($product); $productManager->save($product, $this->get('security.token_storage')->getToken()->getUser()); $this->get('session')->getFlashBag()->add('notice', 'admin.producer.products.message.updated'); diff --git a/Entity/Product.php b/Entity/Product.php index 564e123..25a9eb4 100644 --- a/Entity/Product.php +++ b/Entity/Product.php @@ -792,16 +792,6 @@ public function addProductInsight(ProductInsight $insight) */ public function getProductInsights() { - return $this->insights; - } - - /** - * Has Insights - * - * @return integer - */ - public function hasProductInsights() - { - return 0; + return $this->insights; } } diff --git a/Manager/ProductInsightManager.php b/Manager/ProductInsightManager.php index 4da603c..dfb45ed 100644 --- a/Manager/ProductInsightManager.php +++ b/Manager/ProductInsightManager.php @@ -43,7 +43,7 @@ public function updateProductInsights(\Closure $callback = null) { $productManager = $this->entityManager->getRepository('IsicsOpenMiamMiamBundle:Product'); $ids = $productManager->findAllId(); - $completeness = 7; + $completeness = 8; foreach ($ids as $id) { $product = $productManager->findOneBy(["id" => $id[0]['id']]); if ($product->getDescription()) { @@ -75,6 +75,42 @@ public function updateProductInsights(\Closure $callback = null) } } + /** + * Create the product insights + * @param \Isics\Bundle\OpenMiamMiamBundle\Entity\Product $product + */ + public function createProductInsight(\Isics\Bundle\OpenMiamMiamBundle\Entity\Product $product) + { + $completeness = 8; + $insights = $product->getProductInsights(); + + foreach ($insights as $insight) + { + $this->entityManager->remove($insight); + } + + if (!$product->getDescription()) + { + $insight = new ProductInsight("COMPLETENESS", 1, $product); + } else { + $completeness ++; + + if(strlen($product->getDescription()) < 10) + { + $insight = new ProductInsight("QUALITY", 4, $product); + } + } + + if(!$product->getImage()) + { + $insight = new ProductInsight("COMPLETENESS", 2, $product); + } else { + $completeness++; + } + + $product->setCompleteness($completeness); + $completeness = 8; + } /** * Return the count of products * diff --git a/Resources/translations/messages.en.yml b/Resources/translations/messages.en.yml index dabbd4b..54c2bc6 100644 --- a/Resources/translations/messages.en.yml +++ b/Resources/translations/messages.en.yml @@ -807,7 +807,7 @@ admin.producer.products.list.is_bio: "Organic" admin.producer.products.list.is_of_the_moment: "Featured" admin.producer.products.list.price: "Price" admin.producer.products.list.availability: "Availability" -admin.producer.products.list.completeness: "Form Completion" +admin.producer.products.list.completeness: "Completeness" admin.producer.products.list.completeness_quality_0: "Either the picture is missing or the description is incomplete" admin.producer.products.list.completeness_quality_1: "The form is well completed" admin.producer.products.form.new_title: "New product" @@ -841,9 +841,9 @@ admin.producer.products.message.deleted: "Product has been deleted admin.producer.products.delete_dialog.content: "Are you sure you want to delete product?" admin.producer.products.edit.bad_description: "Tip: The product description quality is bad, you can change it in the part 'Image and description'" admin.producer.products.edit.bad_image: "Tip: The product image quality is bad, you can change it in the part 'Image and description'" -admin.producer.products.edit.empty_elements: "Many elements are empty" -admin.producer.products.edit.empty_description: "The description is empty" -admin.producer.products.edit.empty_image: "The image is empty" +admin.producer.products.edit.empty_elements: "Many elements are empty" +admin.producer.products.edit.empty_description: "The description is empty" +admin.producer.products.edit.empty_image: "The image is empty (if you already uploaded an image reclick on 'Register')" # Admin / Producer / Calendar admin.producer.calendar.title: "Calendar" diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index e0a414f..0c43307 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -854,7 +854,7 @@ admin.producer.products.list.is_bio: "Bio" admin.producer.products.list.is_of_the_moment: "Produit du moment" admin.producer.products.list.price: "Prix" admin.producer.products.list.availability: "Dispo" -admin.producer.products.list.completeness: "Complétion du formulaire" +admin.producer.products.list.completeness: "Complétion" admin.producer.products.list.completeness_quality_0: "La description est incomplète et/ou l'image est manquante" admin.producer.products.list.completeness_quality_1: "Le formulaire a bien était complété" admin.producer.products.form.new_title: "Nouveau produit" @@ -889,8 +889,8 @@ admin.producer.products.delete_dialog.content: "Êtes-vous vraiment cert admin.producer.products.edit.bad_description: "Conseil: La description du produit est de mauvaise qualité, vous pouvez la modifier dans la partie 'Image et description'" admin.producer.products.edit.bad_image: "Conseil: La photo du produit est de mauvaise qualité, vous pouvez la modifier dans la partie 'Image et description'" admin.producer.products.edit.empty_elements: "Certains éléments sont manquants" -admin.producer.products.edit.empty_description: "La description est manquante" -admin.producer.products.edit.empty_image: "L'image est manquante" +admin.producer.products.edit.empty_description: "La description est manquante" +admin.producer.products.edit.empty_image: "L'image est manquante (si vous avez déjà importé une image, recliquez sur 'Enregistrer')" # Admin / Producer / Calendar admin.producer.calendar.title: "Calendrier de présence" diff --git a/Resources/views/Admin/Producer/Product/edit.html.twig b/Resources/views/Admin/Producer/Product/edit.html.twig index 7698dee..ca455d4 100644 --- a/Resources/views/Admin/Producer/Product/edit.html.twig +++ b/Resources/views/Admin/Producer/Product/edit.html.twig @@ -22,7 +22,7 @@ {% endif %} {% endfor %} {% if completeness < 10 %} -

+

    {% for insight in insights %} From f2d7133e939e4b8a20a2571d405e06eb70e30a3c Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Fri, 26 Oct 2018 11:20:03 +0200 Subject: [PATCH 15/17] Add SendMail command --- Command/SendMailCompletenessCommand.php | 77 +++++++++++++++++++++++++ Entity/ProductInsight.php | 9 +++ 2 files changed, 86 insertions(+) create mode 100644 Command/SendMailCompletenessCommand.php diff --git a/Command/SendMailCompletenessCommand.php b/Command/SendMailCompletenessCommand.php new file mode 100644 index 0000000..327f2d9 --- /dev/null +++ b/Command/SendMailCompletenessCommand.php @@ -0,0 +1,77 @@ + + * + * This source file is subject to the AGPL v3 license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Isics\Bundle\OpenMiamMiamBundle\Command; + +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class SendMailCompletenessCommand extends ContainerAwareCommand +{ + protected function configure() + { + $this + ->setName('openmiammiam:send-mail-completeness') + ->setDescription('Send Mail with completeness quality info'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $mailer = $this->getContainer()->get('open_miam_miam.mailer'); + $translator = $mailer->getTranslator(); + $translator->setLocale($this->getContainer()->getParameter('locale')); + + $associations = $this->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('IsicsOpenMiamMiamBundle:Association') + ->findAll(); + + foreach($associations as $association) + { + $producers = $association->getProducers(); + + foreach ($producers as $producer) { + /**$message = $mailer->getNewMessage(); + $message + ->setFrom(array($association->getEmail() => $association->getName())) + ->setTo($this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('IsicsOpenMiamMiamUserBundle:User')->findManager($producer)[0]->getEmail()) + ->setSubject( + $mailer->translate( + 'mail.completeness' + ) + ) + ->setBody( + $mailer->render($this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('IsicsOpenMiamMiamUserBundle:User')->findManager($producer) + 'IsicsOpenMiamMiamBundle:Mail:ordersClosed.html.twig', + array( + 'salesOrder' => $salesOrder, + 'branchOccurrence' => $nextBranchOccurrence + ) + ), + 'text/html' + ); + + $mailer->send($message); + + ++$mailNumber; + + $output->writeln(sprintf('- %s', $this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('IsicsOpenMiamMiamUserBundle:User')->findManager($producer)->getEmail()));**/ + $output->writeln(var_dump($producer->getName())); + $managers = $this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('IsicsOpenMiamMiamUserBundle:User')->findManager($producer); + $output->writeln(var_dump(count($managers))); + } + } + } + +} diff --git a/Entity/ProductInsight.php b/Entity/ProductInsight.php index 692f8d9..b87e5d3 100644 --- a/Entity/ProductInsight.php +++ b/Entity/ProductInsight.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the AGPL v3 license that is bundled + * with this source code in the file LICENSE. + */ + namespace Isics\Bundle\OpenMiamMiamBundle\Entity; use Doctrine\ORM\Mapping as ORM; From d30772ae6a1bea1d6245eaa2a9d7ba4e2a1daf26 Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Tue, 8 Oct 2019 20:52:55 +0200 Subject: [PATCH 16/17] Update ProductInsightManager.php Use PSR-2 condition style --- Manager/ProductInsightManager.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Manager/ProductInsightManager.php b/Manager/ProductInsightManager.php index dfb45ed..4132ca3 100644 --- a/Manager/ProductInsightManager.php +++ b/Manager/ProductInsightManager.php @@ -84,25 +84,21 @@ public function createProductInsight(\Isics\Bundle\OpenMiamMiamBundle\Entity\Pro $completeness = 8; $insights = $product->getProductInsights(); - foreach ($insights as $insight) - { + foreach ($insights as $insight) { $this->entityManager->remove($insight); } - if (!$product->getDescription()) - { + if (!$product->getDescription()) { $insight = new ProductInsight("COMPLETENESS", 1, $product); } else { $completeness ++; - if(strlen($product->getDescription()) < 10) - { + if(strlen($product->getDescription()) < 10) { $insight = new ProductInsight("QUALITY", 4, $product); } } - if(!$product->getImage()) - { + if(!$product->getImage()) { $insight = new ProductInsight("COMPLETENESS", 2, $product); } else { $completeness++; From d0f20f83d41366055081d67d4c174dd1ce03423d Mon Sep 17 00:00:00 2001 From: Erwan ROUSSEL Date: Tue, 8 Oct 2019 21:02:45 +0200 Subject: [PATCH 17/17] Update edit.html.twig Fix two space indentation by replacing with a four space indentation --- .../Admin/Producer/Product/edit.html.twig | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Resources/views/Admin/Producer/Product/edit.html.twig b/Resources/views/Admin/Producer/Product/edit.html.twig index ca455d4..f453c2f 100644 --- a/Resources/views/Admin/Producer/Product/edit.html.twig +++ b/Resources/views/Admin/Producer/Product/edit.html.twig @@ -15,22 +15,22 @@