Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Catalog completeness #25

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
45 changes: 45 additions & 0 deletions Command/FillCompletenessCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

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;
use Symfony\Component\Console\Helper\ProgressBar;
use Isics\Bundle\OpenMiamMiamBundle\Entity\Product;
use Isics\Bundle\OpenMiamMiamBundle\Entity\ProductInsight;

class FillCompletenessCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('openmiammiam:fill-completeness')
->setDescription('Fill completeness fields for products in database');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('<comment>Computing products insights...</comment>');
$output->writeln('');

$productInsightManager = $this->getContainer()->get('open_miam_miam.product_insight_manager');

$progressBar = new ProgressBar($output, $productInsightManager->count());
$progressBar->setBarCharacter('<fg=green>•</>');
$progressBar->setEmptyBarCharacter('<fg=red>•</>');
$progressBar->setProgressCharacter('<fg=green>➤</>');
$progressBar->setFormat(
"%memory% %current%/%max% [%bar%] %percent:3s%%\n Elapsed : %elapsed% Remaining : %remaining:-6s%"
);

$callback = function() use ($progressBar) {
$progressBar->advance(1);
};

$productInsightManager->updateProductInsights($callback);
}

}
77 changes: 77 additions & 0 deletions Command/SendMailCompletenessCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/*
* This file is part of the OpenMiamMiam project.
*
* (c) Isics <[email protected]>
*
* 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('<info>- %s</info>', $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)));
}
}
}

}
6 changes: 6 additions & 0 deletions Controller/Admin/Producer/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be smarter to use Doctrine Events to add this behavior.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look at it

$productManager->save($product, $this->get('security.token_storage')->getToken()->getUser());

$this->get('session')->getFlashBag()->add('notice', 'admin.producer.products.message.created');
Expand Down Expand Up @@ -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');
Expand All @@ -126,6 +130,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)
));
}
Expand Down
56 changes: 56 additions & 0 deletions Entity/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ class Product
*/
private $branches;

/**
* @var integer $completeness
*
* @ORM\Column(name="completeness", type="integer", nullable=true)
*/
private $completeness;

/**
* @var Doctrine\Common\Collections\Collection $insights
*
* @ORM\OneToMany(targetEntity="ProductInsight", mappedBy="product", cascade={"persist", "remove"})
*/
private $insights;

/**
* Constructor
Expand All @@ -201,6 +214,8 @@ public function __construct()
$this->availability = self::AVAILABILITY_AVAILABLE;
$this->hasNoPrice = (null === $this->id) ? false : (null === $this->price);
$this->branches = new ArrayCollection();
$this->completeness = 7;
$this->insights = new ArrayCollection();
}

/**
Expand Down Expand Up @@ -738,4 +753,45 @@ 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;
}

public function addProductInsight(ProductInsight $insight)
{
$this->insights[] = $insight;

return $this;
}

/**
* Get insights
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProductInsights()
{
return $this->insights;
}
}
142 changes: 142 additions & 0 deletions Entity/ProductInsight.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

/*
* This file is part of the OpenMiamMiam project.
*
* (c) Isics <[email protected]>
*
* 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;
use Isics\Bundle\OpenMiamMiamBundle\Entity\Product;

/**
* ProductInsight
*
* @ORM\Table(name="product_insight")
* @ORM\Entity(repositoryClass="Isics\Bundle\OpenMiamMiamBundle\Repository\ProductInsightRepository")
*/
class ProductInsight
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @var Product
*
* @ORM\ManyToOne(targetEntity="Product", inversedBy="insights")
*
*/
private $product;

/**
* @var string
*
* @ORM\Column(name="type", type="string", length=255)
*/
private $type;

/**
* @var string
*
* @ORM\Column(name="code", type="integer")
*/
private $code;

public function __construct($type, $code, Product $product)
{
$this->product = $product;
$this->code = $code;
$this->type = $type;
$product->addProductInsight($this);
}

/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set product
*
* @param integer $product
* @return ProductInsight
*/
public function setProduct($productId)
{
$this->productId = $productId;

return $this;
}

/**
* Get product
*
* @return integer
*/
public function getProduct()
{
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;
}
}
Loading