Initial Commit

This commit is contained in:
2019-11-21 12:25:31 +01:00
commit f4aabcb9b1
13959 changed files with 787761 additions and 0 deletions

View File

@@ -0,0 +1,187 @@
<?php
namespace DigressivePrice\Form;
use DigressivePrice\DigressivePrice;
use DigressivePrice\Model\DigressivePriceQuery;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Form\BaseForm;
/**
* Class CreateDigressivePriceForm
* Build form to create a new digressive price
*
* @package DigressivePrice\Form
* @author Etienne PERRIERE <eperriere@openstudio.fr> - Nexxpix - OpenStudio
*/
class CreateDigressivePriceForm extends BaseForm
{
public function getName()
{
return "digressiveprice_create";
}
protected function buildForm()
{
$this->formBuilder
->add(
"productId",
"number",
array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => $this->translator->trans('product ID', [], DigressivePrice::DOMAIN)
)
)
->add(
"quantityFrom",
"number",
array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(
array(
"methods" => array(
array(
$this,
"fromNotInRange"
)
)
)
)
),
"label" => $this->translator->trans('FROM {quantity}', [], DigressivePrice::DOMAIN)
)
)
->add(
"quantityTo",
"number",
array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(
array(
"methods" => array(
array($this,
"toIsGreaterThanFrom"
),
array($this,
"toNotInRange"
),
array($this,
"notSurround"
)
)
)
)
),
"label" => $this->translator->trans('TO {quantity}', [], DigressivePrice::DOMAIN)
)
)
->add(
"discount",
"number",
array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\GreaterThanOrEqual(['value' => 0]),
new Constraints\LessThanOrEqual(['value' => 100])
),
"label" => $this->translator->trans('Remise (%)', [], DigressivePrice::DOMAIN)
)
);
}
/**
* @param $value
* @param ExecutionContextInterface $context
*/
public function toIsGreaterThanFrom($value, ExecutionContextInterface $context)
{
$quantityFrom = $this->getForm()->getData()['quantityFrom'];
if ($quantityFrom >= $value) {
$context->addViolation($this->translator->trans('The end of range must be greater than the beginning', [], DigressivePrice::DOMAIN));
}
}
/**
* @param $value
* @param ExecutionContextInterface $context
* @param bool $isUpdating
*/
public function fromNotInRange($value, ExecutionContextInterface $context, $isUpdating = false)
{
$digressivePrices = $this->inRangeQuery($value, $isUpdating);
if (count($digressivePrices) !== 0) {
$context->addViolation($this->translator->trans('Your new range begins in another one', [], DigressivePrice::DOMAIN));
}
}
/**
* @param $value
* @param ExecutionContextInterface $context
* @param bool $isUpdating
*/
public function toNotInRange($value, ExecutionContextInterface $context, $isUpdating = false)
{
$digressivePrices = $this->inRangeQuery($value, $isUpdating);
if (count($digressivePrices) !== 0) {
$context->addViolation($this->translator->trans('Your new range ends in another one', [], DigressivePrice::DOMAIN));
}
}
/**
* @param $value
* @param ExecutionContextInterface $context
* @param bool $isUpdating
*/
public function notSurround($value, ExecutionContextInterface $context, $isUpdating = false)
{
// Check if the values are around FROM and TO quantities of an existing digressive price of the current product
$digressivePricesQuery = DigressivePriceQuery::create()
->filterByProductId($this->getForm()->getData()['productId'])
->filterByQuantityFrom($this->getForm()->getData()['quantityFrom'], Criteria::GREATER_EQUAL)
->filterByQuantityTo($value, Criteria::LESS_EQUAL);
// If it's an update, don't check itself
if ($isUpdating) {
$digressivePricesQuery->filterById($this->getForm()->getData()['id'], Criteria::NOT_IN);
} else {
// Else it's a new one, so we only check for the current product
$digressivePricesQuery->filterByProductId($this->getForm()->getData()['productId']);
}
$digressivePrices = $digressivePricesQuery->find();
if (count($digressivePrices) !== 0) {
$context->addViolation($this->translator->trans('Your new range surrounds an existing one', [], DigressivePrice::DOMAIN));
}
}
/**
* @param $value
* @param $isUpdating
* @return array|mixed|\Propel\Runtime\Collection\ObjectCollection
*/
public function inRangeQuery($value, $isUpdating)
{
// Check if the value is between FROM and TO quantities of an existing digressive price of the current product
$digressivePricesQuery = DigressivePriceQuery::create()
->filterByProductId($this->getForm()->getData()['productId'])
->filterByQuantityFrom($value, Criteria::LESS_EQUAL)
->filterByQuantityTo($value, Criteria::GREATER_EQUAL);
// If it's an update, don't check itself
if ($isUpdating) {
$digressivePricesQuery->filterById($this->getForm()->getData()['id'], Criteria::NOT_IN);
}
return $digressivePricesQuery->find();
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace DigressivePrice\Form;
use DigressivePrice\DigressivePrice;
use Symfony\Component\Validator\Constraints;
use Thelia\Form\BaseForm;
/**
* Class DeleteDigressivePriceForm
* Build form to delete a digressive price
*
* @package DigressivePrice\Form
* @author Etienne PERRIERE <eperriere@openstudio.fr> - Nexxpix - OpenStudio
*/
class DeleteDigressivePriceForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add(
"productId",
"number",
array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => $this->translator->trans('product ID', [], DigressivePrice::DOMAIN)
)
)
->add(
"id",
"number",
array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => 'ID'
)
);
}
public function getName()
{
return "digressiveprice_delete";
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace DigressivePrice\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
/**
* Class UpdateDigressivePriceForm
* Build form to update a digressive price
*
* @package DigressivePrice\Form
* @author Etienne PERRIERE <eperriere@openstudio.fr> - Nexxpix - OpenStudio
*/
class UpdateDigressivePriceForm extends CreateDigressivePriceForm
{
public function getName()
{
return "digressiveprice_update";
}
protected function buildForm()
{
parent::buildForm();
$this->formBuilder
->add(
"id",
"number",
array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => 'ID'
)
);
}
public function fromNotInRange($value, ExecutionContextInterface $context, $isUpdating = true)
{
parent::fromNotInRange($value, $context, $isUpdating);
}
public function toNotInRange($value, ExecutionContextInterface $context, $isUpdating = true)
{
parent::toNotInRange($value, $context, $isUpdating);
}
public function notSurround($value, ExecutionContextInterface $context, $isUpdating = true)
{
parent::notSurround($value, $context, $isUpdating);
}
}