Initial commit

This commit is contained in:
2021-03-23 13:54:38 +01:00
commit 82b142ff95
16941 changed files with 2617212 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\CountryQuery;
use Thelia\Model\StateQuery;
/**
* Class AddressCountryValidationTrait
* @package Thelia\Form
* @author Julien Chanséaume <julien@thelia.net>
*/
trait AddressCountryValidationTrait
{
public function verifyZipCode($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if (null !== $country = CountryQuery::create()->findPk($data['country'])) {
if ($country->getNeedZipCode()) {
$zipCodeRegExp = $country->getZipCodeRE();
if (null !== $zipCodeRegExp) {
if (!preg_match($zipCodeRegExp, $data['zipcode'])) {
$context->addViolation(
Translator::getInstance()->trans(
"This zip code should respect the following format : %format.",
['%format' => $country->getZipCodeFormat()]
)
);
}
}
}
}
}
public function verifyState($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if (null !== $country = CountryQuery::create()->findPk($data['country'])) {
if ($country->getHasStates()) {
if (null !== $state = StateQuery::create()->findPk($data['state'])) {
if ($state->getCountryId() !== $country->getId()) {
$context->addViolation(
Translator::getInstance()->trans(
"This state doesn't belong to this country."
)
);
}
} else {
$context->addViolation(
Translator::getInstance()->trans(
"You should select a state for this country."
)
);
}
}
}
}
}

View File

@@ -0,0 +1,197 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
/**
* Class AddressCreateForm
* @package Thelia\Form
* @author Manuel Raynaud <manu@raynaud.io>
*/
class AddressCreateForm extends FirewallForm
{
use AddressCountryValidationTrait;
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add("label", "text", array(
"constraints" => array(
new NotBlank(),
),
"label" => Translator::getInstance()->trans("Address label"),
"label_attr" => array(
"for" => "address_label",
),
))
->add("title", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans("Title"),
"label_attr" => array(
"for" => "title",
),
))
->add("firstname", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans("First Name"),
"label_attr" => array(
"for" => "firstname",
),
))
->add("lastname", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans("Last Name"),
"label_attr" => array(
"for" => "lastname",
),
))
->add("company", "text", array(
"label" => Translator::getInstance()->trans("Company Name"),
"label_attr" => array(
"for" => "company",
),
"required" => false,
))
->add("address1", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans("Street Address"),
"label_attr" => array(
"for" => "address1",
),
))
->add("address2", "text", array(
"label" => Translator::getInstance()->trans("Address Line 2"),
"label_attr" => array(
"for" => "address2",
),
"required" => false,
))
->add("address3", "text", array(
"label" => Translator::getInstance()->trans("Address Line 3"),
"label_attr" => array(
"for" => "address3",
),
"required" => false,
))
->add("city", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans("City"),
"label_attr" => array(
"for" => "city",
),
))
->add("zipcode", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyZipCode")
),
)),
),
"label" => Translator::getInstance()->trans("Zip code"),
"label_attr" => array(
"for" => "zipcode",
),
))
->add("country", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans("Country"),
"label_attr" => array(
"for" => "country",
),
))
->add("state", "text", array(
"constraints" => array(
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyState")
),
)),
),
"label" => Translator::getInstance()->trans("State"),
"label_attr" => array(
"for" => "state",
),
))
// Phone
->add("phone", "text", array(
"label" => Translator::getInstance()->trans("Phone"),
"label_attr" => array(
"for" => "phone",
),
"required" => false,
))
->add("cellphone", "text", array(
"label" => Translator::getInstance()->trans("Cellphone"),
"label_attr" => array(
"for" => "cellphone",
),
"required" => false,
))
// Default address
->add("is_default", "checkbox", array(
"label" => Translator::getInstance()->trans("Make this address as my primary address"),
"label_attr" => array(
"for" => "default_address",
),
"required" => false,
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_address_creation";
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
/**
* Class AddressUpdateForm
* @package Thelia\Form
* @author Manuel Raynaud <manu@raynaud.io>
*/
class AddressUpdateForm extends AddressCreateForm
{
protected function buildForm()
{
parent::buildForm();
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_address_update";
}
}

View File

@@ -0,0 +1,70 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ConfigQuery;
class AdminCreatePassword extends BruteforceForm
{
protected function buildForm()
{
$this->formBuilder
->add("password", "password", array(
"constraints" => array(),
"label" => $this->translator->trans("Password"),
"label_attr" => array(
"for" => "password",
),
"attr" => [
'placeholder' => Translator::getInstance()->trans('Enter the new password')
]
))
->add("password_confirm", "password", array(
"constraints" => array(
new Callback(array("methods" => array(
array($this, "verifyPasswordField"),
))),
),
"label" => $this->translator->trans('Password confirmation'),
"label_attr" => array(
"for" => "password_confirmation",
),
"attr" => [
'placeholder' => Translator::getInstance()->trans('Enter the new password again')
]
))
;
}
public function verifyPasswordField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["password"] === '' && $data["password_confirm"] === '') {
$context->addViolation("password can't be empty");
}
if ($data["password"] != $data["password_confirm"]) {
$context->addViolation("password confirmation is not the same as password field");
}
$minLength = ConfigQuery::getMinimuAdminPasswordLength();
if (strlen($data["password"]) < $minLength) {
$context->addViolation("password must be composed of at least $minLength characters");
}
}
}

View File

@@ -0,0 +1,57 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class AdminLogin extends BruteforceForm
{
protected function buildForm()
{
$this->formBuilder
->add("username", "text", array(
"constraints" => array(
new NotBlank(),
new Length(array("min" => 3)),
),
"label" => Translator::getInstance()->trans("Username or e-mail address *"),
"label_attr" => array(
"for" => "username",
),
))
->add("password", "password", array(
"constraints" => array(
new NotBlank(),
),
"label" => Translator::getInstance()->trans("Password *"),
"label_attr" => array(
"for" => "password",
),
))
->add("remember_me", "checkbox", array(
'value' => 'yes',
"label" => Translator::getInstance()->trans("Remember me ?"),
"label_attr" => array(
"for" => "remember_me",
),
))
;
}
public function getName()
{
return "thelia_admin_login";
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class AdminLostPassword extends BruteforceForm
{
protected function buildForm()
{
$this->formBuilder
->add("username_or_email", "text", array(
"constraints" => array(
new NotBlank(),
new Length(array("min" => 3)),
),
"label" => Translator::getInstance()->trans("Username or e-mail address *"),
"label_attr" => array(
"for" => "username",
),
))
;
}
}

View File

@@ -0,0 +1,181 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\AdminQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\LangQuery;
use Thelia\Model\ProfileQuery;
class AdministratorCreationForm extends BaseForm
{
const PROFILE_FIELD_PREFIX = "profile";
protected function buildForm()
{
$this->formBuilder
->add("login", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyExistingLogin"),
),
)),
),
"label" => $this->translator->trans("Login name"),
"label_attr" => array(
"for" => "login",
'help' => $this->translator->trans("This is the name used on the login screen")
),
))
->add("email", "email", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Email(),
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyExistingEmail"),
),
)),
),
"label" => $this->translator->trans("Email address"),
"label_attr" => array(
"for" => "email",
'help' => $this->translator->trans("Please enter a valid email address")
),
'attr' => [
'placeholder' => $this->translator->trans('Administrator email address'),
]
))
->add("firstname", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => $this->translator->trans("First Name"),
"label_attr" => array(
"for" => "firstname",
),
))
->add("lastname", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => $this->translator->trans("Last Name"),
"label_attr" => array(
"for" => "lastname",
),
))
->add("password", "password", array(
"constraints" => array(),
"label" => $this->translator->trans("Password"),
"label_attr" => array(
"for" => "password",
),
))
->add("password_confirm", "password", array(
"constraints" => array(
new Constraints\Callback(array("methods" => array(
array($this, "verifyPasswordField"),
))),
),
"label" => $this->translator->trans('Password confirmation'),
"label_attr" => array(
"for" => "password_confirmation",
),
))
->add(
'profile',
"choice",
array(
"choices" => ProfileQuery::getProfileList(),
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => $this->translator->trans('Profile'),
"label_attr" => array(
"for" => "profile",
),
)
)
->add(
'locale',
"choice",
array(
"choices" => $this->getLocaleList(),
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => $this->translator->trans('Preferred locale'),
"label_attr" => array(
"for" => "locale",
),
)
)
;
}
protected function getLocaleList()
{
$locales = array();
$list = LangQuery::create()->find();
foreach ($list as $item) {
$locales[$item->getLocale()] = $item->getLocale();
}
return $locales;
}
public function verifyPasswordField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["password"] === '' && $data["password_confirm"] === '') {
$context->addViolation("password can't be empty");
}
if ($data["password"] != $data["password_confirm"]) {
$context->addViolation("password confirmation is not the same as password field");
}
$minLength = ConfigQuery::getMinimuAdminPasswordLength();
if (strlen($data["password"]) < $minLength) {
$context->addViolation("password must be composed of at least $minLength characters");
}
}
public function verifyExistingLogin($value, ExecutionContextInterface $context)
{
if (null !== $administrator = AdminQuery::create()->findOneByLogin($value)) {
$context->addViolation($this->translator->trans("This administrator login already exists"));
}
}
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
if (null !== $administrator = AdminQuery::create()->findOneByEmail($value)) {
$context->addViolation($this->translator->trans("An administrator with thie email address already exists"));
}
}
public function getName()
{
return "thelia_admin_administrator_creation";
}
}

View File

@@ -0,0 +1,103 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\AdminQuery;
class AdministratorModificationForm extends AdministratorCreationForm
{
protected function buildForm()
{
parent::buildForm();
$this->formBuilder
->add("id", "hidden", array(
"required" => true,
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(
array(
"methods" => array(
array($this, "verifyAdministratorId"),
),
)
),
),
"attr" => array(
"id" => "administrator_update_id",
),
))
;
$this->formBuilder->get('password')->setRequired(false);
$this->formBuilder->get('password_confirm')->setRequired(false);
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_admin_administrator_modification";
}
public function verifyAdministratorId($value, ExecutionContextInterface $context)
{
$administrator = AdminQuery::create()
->findPk($value);
if (null === $administrator) {
$context->addViolation(Translator::getInstance()->trans("Administrator ID not found"));
}
}
public function verifyExistingLogin($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
$administrator = AdminQuery::create()->findOneByLogin($value);
if (null !== $administrator && $administrator->getId() != $data['id']) {
$context->addViolation($this->translator->trans("This administrator login already exists"));
}
}
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
$administrator = AdminQuery::create()->findOneByEmail($value);
if (null !== $administrator && $administrator->getId() != $data['id']) {
$context->addViolation($this->translator->trans("An administrator with this email address already exists"));
}
}
public function verifyPasswordField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if (!empty($data["password"])) {
if ($data["password"] != $data["password_confirm"]) {
$context->addViolation(Translator::getInstance()->trans("password confirmation is not the same as password field"));
}
if ($data["password"] !== '' && strlen($data["password"]) < 4) {
$context->addViolation(Translator::getInstance()->trans("password must be composed of at least 4 characters"));
}
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Api;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
use Thelia\Model\ProfileQuery;
/**
* Class ApiCreateForm
* @package Thelia\Form\Api
* @author Manuel Raynaud <manu@raynaud.io>
*/
class ApiCreateForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add('label', 'text', [
'constraints' => [
new NotBlank(),
],
'label' => Translator::getInstance()->trans('label'),
'label_attr' => ['for' => 'api_label']
])
->add(
'profile',
"choice",
array(
"choices" => ProfileQuery::getProfileList(),
"constraints" => array(
new NotBlank(),
),
"label" => Translator::getInstance()->trans('Profile'),
"label_attr" => array(
"for" => "profile",
),
)
)
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_api_create';
}
}

View File

@@ -0,0 +1,28 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Api;
use Thelia\Form\EmptyForm;
/**
* Class ApiEmptyForm
* @package Thelia\Form\Api
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ApiEmptyForm extends EmptyForm
{
public function getName()
{
return '';
}
}

View File

@@ -0,0 +1,73 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Api;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
use Thelia\Model\ProfileQuery;
/**
* Class ApiUpdateForm
* @package Thelia\Form\Api
* @author Manuel Raynaud <manu@raynaud.io>
*/
class ApiUpdateForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add(
'profile',
"choice",
array(
"choices" => ProfileQuery::getProfileList(),
"constraints" => array(
new NotBlank(),
),
"label" => Translator::getInstance()->trans('Profile'),
"label_attr" => array(
"for" => "profile",
),
)
);
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_api_create';
}
}

View File

@@ -0,0 +1,28 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Api\Category;
use Thelia\Form\CategoryCreationForm as BaseCategoryCreationForm;
/**
* Class CategoryCreationForm
* @package Thelia\Form\Api\Category
* @author manuel raynaud <manu@raynaud.io>
*/
class CategoryCreationForm extends BaseCategoryCreationForm
{
public function getName()
{
return '';
}
}

View File

@@ -0,0 +1,28 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Api\Category;
use Thelia\Form\CategoryModificationForm as BaseCategoryModificationForm;
/**
* Class CategoryModificationForm
* @package Thelia\Form\Api\Category
* @author manuel raynaud <manu@raynaud.io>
*/
class CategoryModificationForm extends BaseCategoryModificationForm
{
public function getName()
{
return '';
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Api\Customer;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\CustomerCreateForm as BaseCustomerCreateForm;
/**
* Class CustomerCreateForm
* @package Thelia\Form\Api\Customer
* @author manuel raynaud <manu@raynaud.io>
*/
class CustomerCreateForm extends BaseCustomerCreateForm
{
public function buildForm()
{
parent::buildForm();
$this->formBuilder
->remove('email_confirm')
->remove('password_confirm')
->remove('agreed')
->add('lang_id', 'integer', [
'constraints' => [
new NotBlank(),
]
]);
}
public function getName()
{
return '';
}
}

View File

@@ -0,0 +1,39 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Api\Customer;
use Thelia\Form\CustomerLogin as BaseCustomerLogin;
/**
* Customer login form for the API.
*
* Class CustomerLogin
* @package Thelia\Form\Api\Customer
* @author Baptiste Cabarrou <bcabarrou@openstudio.fr>
*/
class CustomerLogin extends BaseCustomerLogin
{
public function buildForm()
{
parent::buildForm();
$this->formBuilder->remove('remember_me');
// "I am an existing customer"
$this->formBuilder->get('account')->setEmptyData(1)->setDataLocked(true);
}
public function getName()
{
return '';
}
}

View File

@@ -0,0 +1,38 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Api\Customer;
use Thelia\Form\CustomerUpdateForm as BaseCustomerUpdateForm;
/**
* Class CustomerUpdateForm
* @package Thelia\Form\Api\Customer
* @author Manuel Raynaud <manu@raynaud.io>
*/
class CustomerUpdateForm extends BaseCustomerUpdateForm
{
public function buildForm()
{
parent::buildForm();
$this->formBuilder
->add('lang_id', 'lang_id')
->add('id', 'customer_id')
;
}
public function getName()
{
return '';
}
}

View File

@@ -0,0 +1,57 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Api\Product;
use Thelia\Core\Translation\Translator;
use Thelia\Form\ProductCreationForm as BaseProductCreationForm;
use Thelia\Form\StandardDescriptionFieldsTrait;
/**
* Class ProductCreateForm
* @package Thelia\Form\Api\Product
* @author manuel raynaud <manu@raynaud.io>
*/
class ProductCreationForm extends BaseProductCreationForm
{
use StandardDescriptionFieldsTrait;
/**
* @inherited
*/
protected function buildForm()
{
$translator = Translator::getInstance();
BaseProductCreationForm::buildForm();
$this
->formBuilder
->add("brand_id", "integer", [
'required' => true,
'label' => $translator->trans('Brand / Supplier'),
'label_attr' => [
'for' => 'mode',
'help' => $translator->trans("Select the product brand, or supplier."),
],
]);
$this->addStandardDescFields(array('title', 'locale'));
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return '';
}
}

View File

@@ -0,0 +1,28 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Api\Product;
use Thelia\Form\ProductModificationForm as BaseProductModificationForm;
/**
* Class ProductModificationForm
* @package Thelia\Form\Api\Product
* @author manuel raynaud <manu@raynaud.io>
*/
class ProductModificationForm extends BaseProductModificationForm
{
public function getName()
{
return '';
}
}

View File

@@ -0,0 +1,61 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Api\ProductSaleElements;
use Thelia\Form\BaseForm;
/**
* Class ProductSaleElementsForm
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ProductSaleElementsForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add("pse", "collection", array(
"type" => "product_sale_elements",
"allow_add" => true,
"required" => true,
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return '';
}
}

View File

@@ -0,0 +1,80 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Area;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
/**
* Class AreaCountryForm
* @package Thelia\Form\Area
* @author Manuel Raynaud <manu@raynaud.io>
*/
class AreaCountryForm extends BaseForm
{
use CountryListValidationTrait;
/**
* @inheritdoc
*/
protected function buildForm()
{
$this->formBuilder
->add(
'area_id',
'hidden',
[
'constraints' => [
new GreaterThan(array('value' => 0)),
new NotBlank(),
]
]
)
->add(
'country_id',
'collection',
[
'type' => 'text',
'required' => true,
'constraints' => [
new NotBlank(),
new Callback(["methods" => [[$this, "verifyCountryList"]]])
],
'allow_add' => true,
'allow_delete' => true,
'label' => Translator::getInstance()->trans('Countries'),
'label_attr' => [
'for' => 'countries-add',
'help' => Translator::getInstance()
->trans('Select the countries to include in this shipping zone'),
],
'attr' => [
'size' => 10,
'multiple' => true,
]
]
)
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_area_country';
}
}

View File

@@ -0,0 +1,55 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Area;
use Thelia\Core\Translation\Translator;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
/**
* Class AreaCreateForm
* @package Thelia\Form\Shipping
* @author Manuel Raynaud <manu@raynaud.io>
*/
class AreaCreateForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add(
'name',
'text',
[
'constraints' => [
new NotBlank(),
],
'label' => Translator::getInstance()->trans('Shipping zone name'),
'label_attr' => [
'for' => 'shipping_name'
],
'attr' => [
'placeholder' => Translator::getInstance()->trans("A name such as Europe or Overseas"),
],
]
)
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_area_creation';
}
}

View File

@@ -0,0 +1,79 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Area;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
/**
* Class AreaDeleteCountryForm
* @package Thelia\Form\Area
* @author Franck Allimant <franck@cqfdev.fr>
*/
class AreaDeleteCountryForm extends BaseForm
{
use CountryListValidationTrait;
/**
* @inheritdoc
*/
protected function buildForm()
{
$this->formBuilder
->add(
'area_id',
'hidden',
[
'required' => true,
'constraints' => [
new GreaterThan(array('value' => 0)),
new NotBlank(),
]
]
)
->add(
'country_id',
'collection',
[
'type' => 'text',
'constraints' => [
new NotBlank(),
new Callback(["methods" => [[$this, "verifyCountryList"]]])
],
'allow_add' => true,
'allow_delete' => true,
'label' => Translator::getInstance()->trans('Countries'),
'label_attr' => [
'for' => 'country_delete_id',
'help' => Translator::getInstance()->trans(
'Select the countries to delete from this shipping zone'
),
]
]
)
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_area_delete_country';
}
}

View File

@@ -0,0 +1,45 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Area;
use Symfony\Component\Validator\Constraints\GreaterThan;
/**
* Class AreaModificationForm
* @package Thelia\Form\Shipping
* @author Manuel Raynaud <manu@raynaud.io>
*/
class AreaModificationForm extends AreaCreateForm
{
public function buildForm()
{
parent::buildForm();
$this->formBuilder
->add(
"area_id",
"hidden",
[
"constraints" => [
new GreaterThan([ 'value' => 0 ])
]
]
)
;
}
public function getName()
{
return 'thelia_area_modification';
}
}

View File

@@ -0,0 +1,75 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Area;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
use Thelia\Core\Translation\Translator;
/**
* Class AreaPostageForm
* @package Thelia\Form\Area
* @author Manuel Raynaud <manu@raynaud.io>
*/
class AreaPostageForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add('area_id', 'integer', array(
'constraints' => array(
new GreaterThan(array('value' => 0)),
new NotBlank(),
),
))
->add('postage', 'number', array(
'constraints' => array(
new GreaterThanOrEqual(array('value' => 0)),
new NotBlank(),
),
'label_attr' => array('for' => 'area_postage'),
'label' => Translator::getInstance()->trans('Postage'),
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_area_postage';
}
}

View File

@@ -0,0 +1,64 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Area;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\CountryQuery;
use Thelia\Model\StateQuery;
/**
* Class CountryListValidationTrait
* @package Thelia\Form\Area
* @author Julien Chanséaume <julien@thelia.net>
*/
trait CountryListValidationTrait
{
public function verifyCountryList($value, ExecutionContextInterface $context)
{
$countryList = is_array($value) ? $value : [$value];
foreach ($countryList as $countryItem) {
$item = explode('-', $countryItem);
if (count($item) == 2) {
$country = CountryQuery::create()->findPk($item[0]);
if (null === $country) {
$context->addViolation(
Translator::getInstance()->trans(
"Country ID %id not found",
['%id' => $item[0]]
)
);
}
if ($item[1] == "0") {
continue;
}
$state = StateQuery::create()->findPk($item[1]);
if (null === $state) {
$context->addViolation(
Translator::getInstance()->trans(
"State ID %id not found",
['%id' => $item[1]]
)
);
}
} else {
$context->addViolation(Translator::getInstance()->trans("Wrong country definition"));
}
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class AttributeAvCreationForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add("title", "text", [
"constraints" => [
new NotBlank(),
],
"label" => Translator::getInstance()->trans("Title *"),
"label_attr" => [
"for" => "title",
]
])
->add("locale", "text", [
"constraints" => [
new NotBlank(),
]
])
->add("attribute_id", "hidden", [
"constraints" => [
new NotBlank(),
]
]);
}
public function getName()
{
return "thelia_attributeav_creation";
}
}

View File

@@ -0,0 +1,50 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class AttributeCreationForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add("title", "text", [
"constraints" => [
new NotBlank(),
],
"label" => Translator::getInstance()->trans("Title *"),
"label_attr" => [
"for" => "title",
]
])
->add("locale", "text", [
"constraints" => [
new NotBlank(),
]
])
->add("add_to_all", "checkbox", [
"label" => Translator::getInstance()->trans("Add to all product templates"),
"label_attr" => [
"for" => "add_to_all",
]
]);
}
public function getName()
{
return "thelia_attribute_creation";
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\GreaterThan;
class AttributeModificationForm extends AttributeCreationForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
$this->formBuilder
->add("id", "hidden", array(
"constraints" => array(
new GreaterThan(
array('value' => 0)
),
),
))
;
// Add standard description fields
$this->addStandardDescFields();
}
public function getName()
{
return "thelia_attribute_modification";
}
}

View File

@@ -0,0 +1,468 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Config\Definition\Builder\ValidationBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
use Symfony\Component\Form\FormFactoryBuilderInterface;
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Csrf\CsrfTokenManager;
use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;
use Symfony\Component\Validator\Validation;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\TheliaFormEvent;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ConfigQuery;
use Thelia\Tools\URL;
/**
* Base form class for creating form objects
*
* Class BaseForm
* @package Thelia\Form
* @author Manuel Raynaud <manu@raynaud.io>
*/
abstract class BaseForm
{
/**
* @var \Symfony\Component\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* @var \Symfony\Component\Form\FormFactoryBuilderInterface
*/
protected $formFactoryBuilder;
/**
* @var \Symfony\Component\Form\Form
*/
protected $form;
/**
* @var ContainerInterface
*/
protected $container;
/**
* @var Request
*/
protected $request;
/**
* @var \Symfony\Component\Validator\ValidatorBuilderInterface
*/
protected $validatorBuilder;
/**
* @var \Symfony\Component\Translation\TranslatorInterface
*/
protected $translator;
private $view = null;
/**
* true if the form has an error, false otherwise.
* @var boolean
*/
private $has_error = false;
/**
* The form error message.
* @var string
*/
private $error_message = '';
/**
* @var \Symfony\Component\EventDispatcher\EventDispatcher
*/
protected $dispatcher;
/**
* @var string
*/
private $type;
/**
* @var string The form name
*/
private $formUniqueIdentifier;
/**
* @param Request $request
* @param string $type
* @param array $data
* @param array $options
* @param ContainerInterface $container
* @deprecated Thelia forms should not be instantiated directly. Please use BaseController::createForm() instead
* @see BaseController::createForm()
*/
public function __construct(
Request $request,
$type = "form",
$data = array(),
$options = array(),
ContainerInterface $container = null
) {
// Generate the form name from the complete class name
$this->formUniqueIdentifier = strtolower(str_replace('\\', '_', get_class($this)));
$this->request = $request;
$this->type = $type;
if (null !== $container) {
$this->container = $container;
$this->dispatcher = $container->get("event_dispatcher");
$this->initFormWithContainer($type, $data, $options);
} else {
$this->initFormWithRequest($type, $data, $options);
}
if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
$this->formFactoryBuilder
->addExtension(
new CsrfExtension(
new CsrfTokenManager(null, new SessionTokenStorage(
$this->getRequest()->getSession()
))
)
)
;
}
$this->formBuilder = $this->formFactoryBuilder
->addExtension(new ValidatorExtension($this->validatorBuilder->getValidator()))
->getFormFactory()
->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options))
;
/**
* Build the form
*/
$name = $this->getName();
$event = null;
$dispatchEvents = $this->hasContainer() && $name !== null && $name !== '';
// We need to wrap the dispatch with a condition for backward compatibility
if ($dispatchEvents) {
$event = new TheliaFormEvent($this);
/**
* If the form has the container, disptach the events
*/
$this->dispatcher->dispatch(
TheliaEvents::FORM_BEFORE_BUILD.".".$name,
$event
);
}
$this->buildForm();
if ($dispatchEvents) {
/**
* If the form has the container, disptach the events
*/
$this->dispatcher->dispatch(
TheliaEvents::FORM_AFTER_BUILD.".".$name,
$event
);
}
// If not already set, define the success_url field
// This field is not included in the standard form hidden fields
// This field is not included in the hidden fields generated by form_hidden_fields Smarty function
if (! $this->formBuilder->has('success_url')) {
$this->formBuilder->add("success_url", "hidden");
}
// If not already set, define the error_url field
// This field is not included in the standard form hidden fields
// This field is not included in the hidden fields generated by form_hidden_fields Smarty function
if (! $this->formBuilder->has('error_url')) {
$this->formBuilder->add("error_url", "hidden");
}
// The "error_message" field defines the error message displayed if
// the form could not be validated. If it is empty, a standard error message is displayed instead.
// This field is not included in the hidden fields generated by form_hidden_fields Smarty function
if (! $this->formBuilder->has('error_message')) {
$this->formBuilder->add("error_message", "hidden");
}
$this->form = $this->formBuilder->getForm();
}
public function initFormWithContainer($type, $data, $options)
{
/** @var Translator translator */
$this->translator = $this->container->get("thelia.translator");
/** @var FormFactoryBuilderInterface formFactoryBuilder */
$this->formFactoryBuilder = $this->container->get("thelia.form_factory_builder");
/** @var ValidationBuilder validatorBuilder */
$this->validatorBuilder = $this->container->get("thelia.forms.validator_builder");
}
protected function initFormWithRequest($type, $data, $options)
{
$this->validatorBuilder = Validation::createValidatorBuilder();
$this->formFactoryBuilder = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension())
;
$this->translator = Translator::getInstance();
$this->validatorBuilder
->setTranslationDomain('validators')
->setTranslator($this->translator);
}
/**
* @return \Symfony\Component\Form\FormBuilderInterface
*/
public function getFormBuilder()
{
return $this->formBuilder;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Return true if the given field value is defined only in the HTML template, and its value is defined
* in the template file, not the form builder.
* Thus, it should not be included in the form hidden fields generated by form_hidden_fields
* Smarty function, to prevent it from existing twice in the form.
*
* @param FormView $fieldView
* @return bool
*/
public function isTemplateDefinedHiddenField(FormView $fieldView)
{
return $this->isTemplateDefinedHiddenFieldName($fieldView->vars['name']);
}
public function isTemplateDefinedHiddenFieldName($fieldName)
{
return $fieldName == 'success_url' || $fieldName == 'error_url' || $fieldName == 'error_message';
}
/**
* @return \Thelia\Core\HttpFoundation\Request
*/
public function getRequest()
{
return $this->request;
}
protected function cleanOptions($options)
{
unset($options["csrf_protection"]);
return $options;
}
/**
* Returns the absolute URL to redirect the user to if the form is not successfully processed,
* using the 'error_url' form parameter value
*
* @param string $default the default URL. If not given, the configured base URL is used.
* @return string an absolute URL
*/
public function getErrorUrl($default = null)
{
return $this->getFormDefinedUrl('error_url', $default);
}
/**
* @return bool true if an error URL is defined in the 'error_url' form parameter, false otherwise
*/
public function hasErrorUrl()
{
return null !== $this->form->get('error_url')->getData();
}
/**
* Returns the absolute URL to redirect the user to if the form is successfully processed.
* using the 'success_url' form parameter value
*
* @param string $default the default URL. If not given, the configured base URL is used.
* @return string an absolute URL
*/
public function getSuccessUrl($default = null)
{
return $this->getFormDefinedUrl('success_url', $default);
}
/**
* @return bool true if a success URL is defined in the form, false otherwise
*/
public function hasSuccessUrl()
{
return null !== $this->form->get('success_url')->getData();
}
/**
* Build an absolute URL using the value of a form parameter.
*
* @param string $parameterName the form parameter name
* @param string $default a default value for the form parameter. If not defined, the configured base URL is used.
* @return string an absolute URL
*/
public function getFormDefinedUrl($parameterName, $default = null)
{
$formDefinedUrl = $this->form->get($parameterName)->getData();
if (empty($formDefinedUrl)) {
if ($default === null) {
$default = ConfigQuery::read('base_url', '/');
}
$formDefinedUrl = $default;
}
return URL::getInstance()->absoluteUrl($formDefinedUrl);
}
public function createView()
{
$this->view = $this->form->createView();
return $this;
}
/**
* @return FormView
* @throws \LogicException
*/
public function getView()
{
if ($this->view === null) {
throw new \LogicException("View was not created. Please call BaseForm::createView() first.");
}
return $this->view;
}
// -- Error and errro message ----------------------------------------------
/**
* Set the error status of the form.
*
* @param boolean $has_error
* @return $this
*/
public function setError($has_error = true)
{
$this->has_error = $has_error;
return $this;
}
/**
* Get the cuirrent error status of the form.
*
* @return boolean
*/
public function hasError()
{
return $this->has_error;
}
/**
* Set the error message related to global form error
*
* @param string $message
* @return $this
*/
public function setErrorMessage($message)
{
$this->setError(true);
$this->error_message = $message;
return $this;
}
/**
* Get the form error message.
*
* @return string
*/
public function getErrorMessage()
{
return $this->error_message;
}
/**
* @return \Symfony\Component\Form\Form
*/
public function getForm()
{
return $this->form;
}
/**
* @return bool
*/
public function hasContainer()
{
return $this->container !== null;
}
/**
* Override this method if you don't want to use the standard name, which is created from the full class name.
*
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return $this->formUniqueIdentifier;
}
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
abstract protected function buildForm();
}

View File

@@ -0,0 +1,84 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Brand;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
use Thelia\Model\Lang;
/**
* Class BrandCreationForm
* @package Thelia\Form\Brand
* @author Franck Allimant <franck@cqfdev.fr>
*/
class BrandCreationForm extends BaseForm
{
protected function doBuilForm($titleFieldHelpLabel)
{
$this->formBuilder->add(
'title',
'text',
[
'constraints' => [ new NotBlank() ],
'required' => true,
'label' => Translator::getInstance()->trans('Brand name'),
'label_attr' => [
'for' => 'title',
'help' => $titleFieldHelpLabel,
],
'attr' => [
'placeholder' => Translator::getInstance()->trans('The brand name or title'),
]
]
)
->add(
'locale',
'hidden',
[
'constraints' => [ new NotBlank() ],
'required' => true,
]
)
// Is this brand online ?
->add(
'visible',
'checkbox',
[
'required' => false,
'label' => Translator::getInstance()->trans('This brand is online'),
'label_attr' => [
'for' => 'visible_create',
],
'attr' => [
'checked' => 'checked'
]
]
);
}
protected function buildForm()
{
$this->doBuilForm(
Translator::getInstance()->trans(
'Enter here the brand name in the default language (%title%)',
[ '%title%' => Lang::getDefaultLanguage()->getTitle()]
)
);
}
public function getName()
{
return 'thelia_brand_creation';
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Brand;
use Thelia\Form\Image\DocumentModification;
/**
* @author Franck Allimant <franck@cqfdev.fr>
*/
class BrandDocumentModification extends DocumentModification
{
/**
* @inheritdoc
*/
public function getName()
{
return 'thelia_brand_document_modification';
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Brand;
use Thelia\Form\Image\ImageModification;
/**
* @author Franck Allimant <franck@cqfdev.fr>
*/
class BrandImageModification extends ImageModification
{
/**
* @inheritdoc
*/
public function getName()
{
return 'thelia_brand_image_modification';
}
}

View File

@@ -0,0 +1,61 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Brand;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Thelia\Core\Translation\Translator;
use Thelia\Form\StandardDescriptionFieldsTrait;
/**
* Class BrandModificationForm
* @package Thelia\Form\Brand
* @author Franck Allimant <franck@cqfdev.fr>
*/
class BrandModificationForm extends BrandCreationForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
$this->doBuilForm(
Translator::getInstance()->trans('The brand name or title')
);
$this->formBuilder->add(
'id',
'hidden',
[
'constraints' => [ new GreaterThan(['value' => 0]) ],
'required' => true,
]
)
->add("logo_image_id", "integer", [
'constraints' => [ ],
'required' => false,
'label' => Translator::getInstance()->trans('Select the brand logo'),
'label_attr' => [
'for' => 'logo_image_id',
'help' => Translator::getInstance()->trans("Select the brand logo amongst the brand images"),
]
])
;
// Add standard description fields, excluding title and locale, which are already defined
$this->addStandardDescFields(array('title', 'locale'));
}
public function getName()
{
return "thelia_brand_modification";
}
}

View File

@@ -0,0 +1,37 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Thelia\Model\ConfigQuery;
/**
* Class BruteforceForm
* @package Thelia\Form
* @author Benjamin Perche <bperche@openstudio.fr>
*/
abstract class BruteforceForm extends FirewallForm
{
const DEFAULT_TIME_TO_WAIT = 10; // 10 minutes
const DEFAULT_ATTEMPTS = 10;
public function getConfigTime()
{
return ConfigQuery::read("form_firewall_bruteforce_time_to_wait", static::DEFAULT_TIME_TO_WAIT);
}
public function getConfigAttempts()
{
return ConfigQuery::read("form_firewall_bruteforce_attempts", static::DEFAULT_ATTEMPTS);
}
}

View File

@@ -0,0 +1,39 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Cache;
use Thelia\Form\BaseForm;
/**
* Class CacheFlushForm
* @package Thelia\Form\Cache
* @author Manuel Raynaud <manu@raynaud.io>
*/
class AssetsFlushForm extends BaseForm
{
/**
* @inheritdoc
*/
protected function buildForm()
{
//Nothing, we just want CSRF protection
}
/**
* @inheritdoc
*/
public function getName()
{
return "assets_flush";
}
}

View File

@@ -0,0 +1,39 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Cache;
use Thelia\Form\BaseForm;
/**
* Class CacheFlushForm
* @package Thelia\Form\Cache
* @author Manuel Raynaud <manu@raynaud.io>
*/
class CacheFlushForm extends BaseForm
{
/**
* @inheritdoc
*/
protected function buildForm()
{
//Nothing, we just want CSRF protection
}
/**
* @inheritdoc
*/
public function getName()
{
return "cache_flush";
}
}

View File

@@ -0,0 +1,39 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Cache;
use Thelia\Form\BaseForm;
/**
* Class CacheFlushForm
* @package Thelia\Form\Cache
* @author Manuel Raynaud <manu@raynaud.io>
*/
class ImagesAndDocumentsCacheFlushForm extends BaseForm
{
/**
* @inheritdoc
*/
protected function buildForm()
{
//Nothing, we just want CSRF protection
}
/**
* @inheritdoc
*/
public function getName()
{
return "images_and_documents_cache_flush";
}
}

View File

@@ -0,0 +1,148 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Form\Exception\StockNotFoundException;
use Thelia\Form\Exception\ProductNotFoundException;
use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\ProductQuery;
use Thelia\Core\Translation\Translator;
/**
* Class CartAdd
* @package Thelia\Form
* @author Manuel Raynaud <manu@raynaud.io>
*/
class CartAdd extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add("product", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array("methods" => array(
array($this, "checkProduct"),
))),
),
"label" => "product",
"label_attr" => array(
"for" => "cart_product",
),
))
->add("product_sale_elements_id", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array("methods" => array(
array($this, "checkStockAvailability"),
))),
),
"required" => true,
))
->add("quantity", "number", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array("methods" => array(
array($this, "checkStock"),
))),
new Constraints\GreaterThanOrEqual(array(
"value" => 0,
)),
),
"label" => Translator::getInstance()->trans("Quantity"),
"label_attr" => array(
"for" => "quantity",
),
))
->add("append", "integer")
->add("newness", "integer")
;
}
public function checkProduct($value, ExecutionContextInterface $context)
{
$product = ProductQuery::create()->findPk($value);
if (is_null($product) || $product->getVisible() == 0) {
throw new ProductNotFoundException(sprintf(Translator::getInstance()->trans("this product id does not exists : %d"), $value));
}
}
public function checkStockAvailability($value, ExecutionContextInterface $context)
{
if ($value) {
$data = $context->getRoot()->getData();
$productSaleElements = ProductSaleElementsQuery::create()
->filterById($value)
->filterByProductId($data["product"])
->count();
if ($productSaleElements == 0) {
throw new StockNotFoundException(sprintf(Translator::getInstance()->trans("This product_sale_elements_id does not exists for this product : %d"), $value));
}
}
}
public function checkStock($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if (null === $data["product_sale_elements_id"]) {
$context->buildViolation(Translator::getInstance()->trans("Invalid product_sale_elements"));
} else {
$productSaleElements = ProductSaleElementsQuery::create()
->filterById($data["product_sale_elements_id"])
->filterByProductId($data["product"])
->findOne();
$product = $productSaleElements->getProduct();
if ($productSaleElements->getQuantity() < $value && $product->getVirtual() === 0 && ConfigQuery::checkAvailableStock()) {
$context->addViolation(Translator::getInstance()->trans("quantity value is not valid"));
}
}
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_cart_add";
}
}

View File

@@ -0,0 +1,77 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Model\Lang;
class CategoryCreationForm extends BaseForm
{
protected function doBuilForm($titleHelpText)
{
$this->formBuilder
->add(
'title',
'text',
[
'constraints' => [ new NotBlank() ],
'label' => $this->translator->trans('Category title'),
'label_attr' => [
'help' => $titleHelpText
]
]
)
->add(
'parent',
'integer',
[
'label' => $this->translator->trans('Parent category'),
'constraints' => [ new NotBlank() ],
'label_attr' => [
'help' => $this->translator->trans('Select the parent category of this category.'),
]
]
)
->add(
'locale',
'hidden',
[
'constraints' => [ new NotBlank() ],
]
)
->add(
'visible',
'integer', // Should be checkbox, but this is not API compatible, see #1199
[
'required' => false,
'label' => $this->translator->trans('This category is online')
]
)
;
}
protected function buildForm()
{
$this->doBuilForm(
$this->translator->trans(
'Enter here the category title in the default language (%title%)',
[ '%title%' => Lang::getDefaultLanguage()->getTitle()]
)
);
}
public function getName()
{
return "thelia_category_creation";
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Thelia\Form\Image\DocumentModification;
/**
* Created by JetBrains PhpStorm.
* Date: 9/18/13
* Time: 3:56 PM
*
* Form allowing to process an document collection
*
* @package Image
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class CategoryDocumentModification extends DocumentModification
{
/**
* Get form name
* This name must be unique
*
* @return string
*/
public function getName()
{
return 'thelia_category_document_modification';
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Thelia\Form\Image\ImageModification;
/**
* Created by JetBrains PhpStorm.
* Date: 9/18/13
* Time: 3:56 PM
*
* Form allowing to process an image collection
*
* @package Image
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class CategoryImageModification extends ImageModification
{
/**
* Get form name
* This name must be unique
*
* @return string
*/
public function getName()
{
return 'thelia_category_image_modification';
}
}

View File

@@ -0,0 +1,79 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Thelia\Model\TemplateQuery;
class CategoryModificationForm extends CategoryCreationForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
$this->doBuilForm(
$this->translator->trans('The category title')
);
// Create countries and shipping modules list
$templateList = [0 => ' '];
$list = TemplateQuery::create()->find();
// Get the current edition locale
$locale = $this->getRequest()->getSession()->getAdminEditionLang()->getLocale();
/** @var \Thelia\Model\Template $item */
foreach ($list as $item) {
$templateList[$item->getId()] = $item->setLocale($locale)->getName();
}
asort($templateList);
$templateList[0] = $this->translator->trans("None");
$this->formBuilder
->add(
'id',
'hidden',
[
'constraints' => [ new GreaterThan(array('value' => 0)) ]
]
)
->add(
'default_template_id',
'choice',
[
'choices' => $templateList,
'label' => $this->translator->trans('Default product template'),
'label_attr' => [
'for' => 'price_offset_type',
'help' => $this->translator->trans(
'Select a default template for new products created in this category'
)
],
'attr' => [
]
]
)
;
// Add standard description fields, excluding title which is defined in parent class
$this->addStandardDescFields([ 'title' ]);
}
public function getName()
{
return "thelia_category_modification";
}
}

View File

@@ -0,0 +1,80 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Thelia\Model\ConfigQuery;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
class ConfigCreationForm extends BaseForm
{
protected function buildForm($change_mode = false)
{
$name_constraints = array(new Constraints\NotBlank());
if (!$change_mode) {
$name_constraints[] = new Constraints\Callback(array(
"methods" => array(array($this, "checkDuplicateName")),
));
}
$this->formBuilder
->add("name", "text", array(
"constraints" => $name_constraints,
"label" => Translator::getInstance()->trans('Name *'),
"label_attr" => array(
"for" => "name",
),
))
->add("title", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans('Purpose *'),
"label_attr" => array(
"for" => "purpose",
),
))
->add("locale", "hidden", array(
"constraints" => array(
new Constraints\NotBlank(),
),
))
->add("value", "text", array(
"label" => Translator::getInstance()->trans('Value *'),
"label_attr" => array(
"for" => "value",
),
))
->add("hidden", "hidden", array())
->add("secured", "hidden", array(
"label" => Translator::getInstance()->trans('Prevent variable modification or deletion, except for super-admin'),
))
;
}
public function getName()
{
return "thelia_config_creation";
}
public function checkDuplicateName($value, ExecutionContextInterface $context)
{
$config = ConfigQuery::create()->findOneByName($value);
if ($config) {
$context->addViolation(Translator::getInstance()->trans('A variable with name "%name" already exists.', array('%name' => $value)));
}
}
}

View File

@@ -0,0 +1,62 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Thelia\Core\Translation\Translator;
class ConfigModificationForm extends BaseForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
$this->formBuilder
->add("id", "hidden", array(
"constraints" => array(
new GreaterThan(
array('value' => 0)
),
),
))
->add("name", "text", array(
"constraints" => array(
new NotBlank(),
),
"label" => Translator::getInstance()->trans('Name'),
"label_attr" => array(
"for" => "name",
),
))
->add("value", "text", array(
"label" => Translator::getInstance()->trans('Value'),
"label_attr" => array(
"for" => "value",
),
))
->add("hidden", "hidden", array())
->add("secured", "hidden", array(
"label" => Translator::getInstance()->trans('Prevent variable modification or deletion, except for super-admin'),
))
;
// Add standard description fields
$this->addStandardDescFields();
}
public function getName()
{
return "thelia_config_modification";
}
}

View File

@@ -0,0 +1,270 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ConfigQuery;
class ConfigStoreForm extends BaseForm
{
protected function buildForm()
{
$tr = Translator::getInstance();
$this->formBuilder
->add(
'store_name',
'text',
[
'data' => ConfigQuery::getStoreName(),
'constraints' => [new Constraints\NotBlank()],
'label' => $tr->trans('Store name'),
'attr' => [
'placeholder' => $tr->trans('Used in your store front'),
]
]
)
->add(
'store_description',
'text',
[
'data' => ConfigQuery::getStoreDescription(),
'required' => false,
'label' => $tr->trans('Store description'),
'attr' => [
'placeholder' => $tr->trans('Used in your store front'),
]
]
)
->add(
'store_email',
'text',
[
'data' => ConfigQuery::getStoreEmail(),
'constraints' => [
new Constraints\NotBlank(),
new Constraints\Email(),
],
'label' => $tr->trans('Store email address'),
'attr' => [
'placeholder' => $tr->trans('Contact and sender email address'),
],
'label_attr' => [
'help' => $tr->trans('This is the contact email address, and the sender email of all e-mails sent by your store.'),
]
]
)
->add(
'store_notification_emails',
'text',
[
'data' => ConfigQuery::read('store_notification_emails'),
'constraints' => [
new Constraints\NotBlank(),
new Constraints\Callback([
'methods' => [
[$this, 'checkEmailList'],
],
]),
],
'label' => $tr->trans('Email addresses of notification recipients'),
'attr' => [
'placeholder' => $tr->trans('A comma separated list of email addresses'),
],
'label_attr' => [
'help' => $tr->trans('This is a comma separated list of email addresses where store notifications (such as order placed) are sent.'),
]
]
)
->add(
'store_business_id',
'text',
[
'data' => ConfigQuery::read('store_business_id'),
'label' => $tr->trans('Business ID'),
'required' => false,
'attr' => [
'placeholder' => $tr->trans('Store Business Identification Number (SIRET, etc).'),
]
]
)
->add(
'store_phone',
'text',
[
'data' => ConfigQuery::read('store_phone'),
'label' => $tr->trans('Phone'),
'required' => false,
'attr' => [
'placeholder' => $tr->trans('The store phone number.'),
]
]
)
->add(
'store_fax',
'text',
[
'data' => ConfigQuery::read('store_fax'),
'label' => $tr->trans('Fax'),
'required' => false,
'attr' => [
'placeholder' => $tr->trans('The store fax number.'),
]
]
)
->add(
'store_address1',
'text',
[
'data' => ConfigQuery::read('store_address1'),
'constraints' => [
new Constraints\NotBlank(),
],
'label' => $tr->trans('Street Address'),
'attr' => [
'placeholder' => $tr->trans('Address.'),
]
]
)
->add(
'store_address2',
'text',
[
'data' => ConfigQuery::read('store_address2'),
'required' => false,
'attr' => [
'placeholder' => $tr->trans('Additional address information'),
]
]
)
->add(
'store_address3',
'text',
[
'data' => ConfigQuery::read('store_address3'),
'required' => false,
'attr' => [
'placeholder' => $tr->trans('Additional address information'),
]
]
)
->add(
'store_zipcode',
'text',
[
'data' => ConfigQuery::read('store_zipcode'),
'constraints' => [
new Constraints\NotBlank(),
],
'label' => $tr->trans('Zip code'),
'attr' => [
'placeholder' => $tr->trans('Zip code'),
]
]
)
->add(
'store_city',
'text',
[
'data' => ConfigQuery::read('store_city'),
'constraints' => [
new Constraints\NotBlank(),
],
'label' => $tr->trans('City'),
'attr' => [
'placeholder' => $tr->trans('City'),
]
]
)
->add(
'store_country',
'integer',
[
'data' => ConfigQuery::read('store_country'),
'constraints' => [
new Constraints\NotBlank(),
],
'label' => $tr->trans('Country'),
'attr' => [
'placeholder' => $tr->trans('Country'),
]
]
)
->add(
'favicon_file',
'file',
[
'required' => false,
'constraints' => [
new Constraints\Image(array(
'mimeTypes' => ['image/png', 'image/x-icon']
))
],
'label' => $tr->trans('Favicon image'),
'label_attr' => [
'for' => 'favicon_file',
'help' => $tr->trans('Icon of the website. Only PNG and ICO files are allowed.'),
]
]
)
->add(
'logo_file',
'file',
[
'required' => false,
'constraints' => [
new Constraints\Image()
],
'label' => $tr->trans('Store logo'),
'label_attr' => [
'for' => 'logo_file'
]
]
)
->add(
'banner_file',
'file',
[
'required' => false,
'constraints' => [
new Constraints\Image()
],
'label' => $tr->trans('Banner'),
'label_attr' => [
'for' => 'banner_file',
'help' => $tr->trans('Banner of the website. Used in the e-mails send to the customers.'),
]
]
);
}
public function checkEmailList($value, ExecutionContextInterface $context)
{
$list = preg_split('/[,;]/', $value);
$emailValidator = new Constraints\Email();
foreach ($list as $email) {
$email = trim($email);
$context->getValidator()->validate($email, $emailValidator);
}
}
public function getName()
{
return 'thelia_configuration_store';
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
/**
* Class ContactForm
* @package Thelia\Form
* @author Manuel Raynaud <manu@raynaud.io>
*/
class ContactForm extends FirewallForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add('name', 'text', array(
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans('Full Name'),
'label_attr' => array(
'for' => 'name_contact',
),
))
->add('email', 'email', array(
'constraints' => array(
new NotBlank(),
new Email(),
),
'label' => Translator::getInstance()->trans('Your Email Address'),
'label_attr' => array(
'for' => 'email_contact',
),
))
->add('subject', 'text', array(
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans('Subject'),
'label_attr' => array(
'for' => 'subject_contact',
),
))
->add('message', 'text', array(
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans('Your Message'),
'label_attr' => array(
'for' => 'message_contact',
),
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_contact';
}
}

View File

@@ -0,0 +1,55 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class ContentCreationForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add("title", "text", array(
"constraints" => array(
new NotBlank(),
),
"label" => Translator::getInstance()->trans('Content title *'),
"label_attr" => array(
"for" => "title",
),
))
->add("default_folder", "integer", array(
"label" => Translator::getInstance()->trans("Default folder *"),
"constraints" => array(
new NotBlank(),
),
"label_attr" => array("for" => "default_folder"),
))
->add("locale", "text", array(
"constraints" => array(
new NotBlank(),
),
))
->add("visible", "integer", array(
"label" => Translator::getInstance()->trans("This content is online."),
"label_attr" => array("for" => "visible_create"),
))
;
}
public function getName()
{
return "thelia_content_creation";
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Thelia\Form\Image\DocumentModification;
/**
* Created by JetBrains PhpStorm.
* Date: 9/18/13
* Time: 3:56 PM
*
* Form allowing to process a file
*
* @package File
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ContentDocumentModification extends DocumentModification
{
/**
* Get form name
* This name must be unique
*
* @return string
*/
public function getName()
{
return 'thelia_content_document_modification';
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Thelia\Form\Image\ImageModification;
/**
* Created by JetBrains PhpStorm.
* Date: 9/18/13
* Time: 3:56 PM
*
* Form allowing to process an image collection
*
* @package Image
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ContentImageModification extends ImageModification
{
/**
* Get form name
* This name must be unique
*
* @return string
*/
public function getName()
{
return 'thelia_content_image_modification';
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
/**
* Class ContentModificationForm
* @package Thelia\Form
* @author manuel raynaud <manu@raynaud.io>
*/
class ContentModificationForm extends ContentCreationForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
parent::buildForm();
$this->formBuilder
->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))
;
// Add standard description fields, excluding title and locale, which a re defined in parent class
$this->addStandardDescFields(array('title', 'locale'));
}
public function getName()
{
return "thelia_content_modification";
}
}

View File

@@ -0,0 +1,109 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
class CountryCreationForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add(
'title',
'text',
[
'constraints' => [
new NotBlank(),
],
'label' => $this->translator->trans('Country title')
]
)
->add(
'locale',
'hidden',
[
'constraints' => [
new NotBlank(),
],
]
)
->add(
'visible',
'checkbox',
[
'required' => false,
'label' => $this->translator->trans('This country is online'),
'label_attr' => [
'for' => 'visible_create',
]
]
)
->add(
'isocode',
'text',
[
'constraints' => [
new NotBlank(),
],
'label' => $this->translator->trans('Numerical ISO Code'),
'label_attr' => [
'help' => $this->translator->trans('Check country iso codes <a href="http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes" target="_blank">here</a>.')
],
]
)
->add(
'isoalpha2',
'text',
[
'constraints' => [
new NotBlank(),
],
'label' => $this->translator->trans('ISO Alpha-2 code'),
'label_attr' => [
'help' => $this->translator->trans('Check country iso codes <a href="http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes" target="_blank">here</a>.')
],
]
)
->add(
'isoalpha3',
'text',
[
'constraints' => [
new NotBlank(),
],
'label' => $this->translator->trans('ISO Alpha-3 code'),
'label_attr' => [
'help' => $this->translator->trans('Check country iso codes <a href="http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes" target="_blank">here</a>.')
],
]
)
->add(
'has_states',
'checkbox',
[
'required' => false,
'label' => $this->translator->trans('This country has states / provinces'),
'label_attr' => [
'for' => 'has_states_create',
]
]
)
;
}
public function getName()
{
return "thelia_country_creation";
}
}

View File

@@ -0,0 +1,62 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
class CountryModificationForm extends CountryCreationForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
parent::buildForm(true);
$this->formBuilder
->add('id', 'hidden', ['constraints' => [new GreaterThan(['value' => 0])]])
->add(
'need_zip_code',
'checkbox',
[
'required' => false,
'label' => $this->translator->trans('Addresses for this country need a zip code'),
'label_attr' => [
'for' => 'need_zip_code',
],
]
)
->add(
'zip_code_format',
'text',
[
'required' => false,
'constraints' => [],
'label' => $this->translator->trans('The zip code format'),
'label_attr' => [
'help' => $this->translator->trans(
'Use a N for a number, L for Letter, C for an iso code for the state.'
)
],
]
)
;
// Add standard description fields, excluding title and locale, which a re defined in parent class
$this->addStandardDescFields(['title', 'locale']);
}
public function getName()
{
return "thelia_country_modification";
}
}

View File

@@ -0,0 +1,75 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\CouponQuery;
/**
* Class CouponCode
*
* Manage how a coupon is entered by a customer
*
* @package Thelia\Form
* @author Guillaume MOREL <gmorel@openstudio.fr>
*/
class CouponCode extends BaseForm
{
/**
* Build form
*/
protected function buildForm()
{
$this->formBuilder
->add(
"coupon-code",
"text",
[
"required" => true,
"constraints" => [
new Constraints\NotBlank(),
new Constraints\Callback([
"methods" => [
[$this, "verifyExistingCode"],
],
]),
]
]
)
;
}
public function verifyExistingCode($value, ExecutionContextInterface $context)
{
$coupon = CouponQuery::create()
->filterByCode($value, Criteria::EQUAL)
->findOne();
if (null === $coupon) {
$context->addViolation(Translator::getInstance()->trans("This coupon does not exists"));
}
}
/**
* Form name
*
* @return string
*/
public function getName()
{
return "thelia_coupon_code";
}
}

View File

@@ -0,0 +1,346 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotEqualTo;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\CountryQuery;
use Thelia\Model\CouponQuery;
use Thelia\Model\LangQuery;
use Thelia\Model\Module;
use Thelia\Model\ModuleQuery;
use Thelia\Module\BaseModule;
/**
* Allow to build a form Coupon
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class CouponCreationForm extends BaseForm
{
const COUPON_CREATION_FORM_NAME = 'thelia_coupon_creation';
public function __construct(
Request $request,
$type = "form",
$data = array(),
$options = array(),
ContainerInterface $container = null
) {
$this->data = $data;
parent::__construct($request, $type, $data, $options, $container); // TODO: Change the autogenerated stub
}
/**
* Build Coupon form
*
* @return void
*/
protected function buildForm()
{
// Create countries and shipping modules list
$countries = [0 => ' '];
$list = CountryQuery::create()->find();
/** @var \Thelia\Model\Country $item */
foreach ($list as $item) {
$countries[$item->getId()] = $item->getTitle();
}
asort($countries);
$countries[0] = Translator::getInstance()->trans("All countries");
$modules = [0 => ' '];
$list = ModuleQuery::create()->filterByActivate(BaseModule::IS_ACTIVATED)->filterByType(BaseModule::DELIVERY_MODULE_TYPE)->find();
/** @var Module $item */
foreach ($list as $item) {
$modules[$item->getId()] = $item->getTitle();
}
asort($modules);
$modules[0] = Translator::getInstance()->trans("All shipping methods");
$this->formBuilder
->add(
'code',
'text',
[
'constraints' => [
new NotBlank(),
new Callback(
[
"methods" => [
[$this, "checkDuplicateCouponCode"],
],
"groups" => "creation",
]
),
new Callback(
[
"methods" => [
[$this, "checkCouponCodeChangedAndDoesntExists"],
],
"groups" => "update",
]
),
]
]
)
->add(
'title',
'text',
[
'constraints' => [
new NotBlank(),
]
]
)
->add(
'shortDescription',
'text'
)
->add(
'description',
'textarea'
)
->add(
'type',
'text',
[
'constraints' => [
new NotBlank(),
new NotEqualTo(
[
'value' => -1,
]
),
]
]
)
->add(
'isEnabled',
'text',
[]
)
->add(
'startDate',
'text',
[
'constraints' => [
new Callback(
[
"methods" => [
[$this, "checkLocalizedDate"],
],
]
),
]
]
)
->add(
'expirationDate',
'text',
[
'constraints' => [
new NotBlank(),
new Callback(
[
"methods" => [
[$this, "checkLocalizedDate"],
[$this, "checkConsistencyDates"],
],
]
),
]
]
)
->add(
'isCumulative',
'text',
[]
)
->add(
'isRemovingPostage',
'text',
[]
)
->add(
'freeShippingForCountries',
'choice',
[
'multiple' => true,
'choices' => $countries
]
)
->add(
'freeShippingForModules',
'choice',
[
'multiple' => true,
'choices' => $modules
]
)
->add(
'isAvailableOnSpecialOffers',
'text',
[]
)
->add(
'maxUsage',
'text',
[
'constraints' => [
new NotBlank(),
new GreaterThanOrEqual(['value' => -1]),
]
]
)
->add(
'perCustomerUsageCount',
'choice',
[
'multiple' => false,
'required' => true,
'choices' => [
1 => Translator::getInstance()->trans('Per customer'),
0 => Translator::getInstance()->trans('Overall'),
]
]
)
->add(
'locale',
'hidden',
[
'constraints' => [
new NotBlank(),
]
]
)
->add(
'coupon_specific',
'collection',
[
'allow_add' => true,
'allow_delete' => true,
]
)
;
}
/**
* Check coupon code unicity
*
* @param string $value
* @param ExecutionContextInterface $context
*/
public function checkDuplicateCouponCode($value, ExecutionContextInterface $context)
{
$exists = CouponQuery::create()->filterByCode($value)->count() > 0;
if ($exists) {
$context->addViolation(
Translator::getInstance()->trans(
"The coupon code '%code' already exists. Please choose another coupon code",
['%code' => $value]
)
);
}
}
public function checkCouponCodeChangedAndDoesntExists($value, ExecutionContextInterface $context)
{
$changed = isset($this->data["code"]) && $this->data["code"] !== $value;
$exists = CouponQuery::create()->filterByCode($value)->count() > 0;
if ($changed && $exists) {
$context->addViolation(
Translator::getInstance()->trans(
"The coupon code '%code' already exist. Please choose another coupon code",
['%code' => $value]
)
);
}
}
/**
* Validate a date entered with the default Language date format.
*
* @param string $value
* @param ExecutionContextInterface $context
*/
public function checkLocalizedDate($value, ExecutionContextInterface $context)
{
$format = LangQuery::create()->findOneByByDefault(true)->getDatetimeFormat();
if (false === \DateTime::createFromFormat($format, $value)) {
$context->addViolation(
Translator::getInstance()->trans(
"Date '%date' is invalid, please enter a valid date using %fmt format",
[
'%fmt' => $format,
'%date' => $value
]
)
);
}
}
/**
* @param $value
* @param ExecutionContextInterface $context
*/
public function checkConsistencyDates($value, ExecutionContextInterface $context)
{
if (null === $startDate = $this->getForm()->get('startDate')->getData()) {
return;
}
$format = LangQuery::create()->findOneByByDefault(true)->getDatetimeFormat();
$startDate = \DateTime::createFromFormat($format, $startDate);
$expirationDate = \DateTime::createFromFormat($format, $value);
if ($startDate <= $expirationDate) {
return;
}
$context->addViolation(
Translator::getInstance()->trans("Start date and expiration date are inconsistent")
);
}
/**
* Get form name
*
* @return string
*/
public function getName()
{
return self::COUPON_CREATION_FORM_NAME;
}
}

View File

@@ -0,0 +1,131 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\CurrencyQuery;
class CurrencyCreationForm extends BaseForm
{
protected function buildForm($change_mode = false)
{
$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(true);
$this->formBuilder
->add("name", "text", [
"required" => true,
"constraints" => [
new NotBlank(),
],
"label" => $this->translator->trans('Name'),
"label_attr" => [
"for" => "name",
"help" => "&nbsp;"
],
"attr" => [
"placeholder" => $this->translator->trans('Currency name')
]
])
->add("locale", "text", [
"required" => true,
"constraints" => [
new NotBlank(),
]
])
->add("symbol", "text", [
"required" => true,
"constraints" => [
new NotBlank(),
],
"label" => $this->translator->trans('Symbol'),
"label_attr" => [
"for" => "symbol",
"help" => $this->translator->trans('The symbol, such as &#36;, £, &euro;...'),
],
"attr" => [
"placeholder" => $this->translator->trans('Symbol'),
]
])
->add("format", "text", [
"required" => true,
"constraints" => [
new NotBlank(),
],
"label" => $this->translator->trans('Format'),
"label_attr" => [
"for" => "format",
"help" => $this->translator->trans("%n for number, %c for the currency code, %s for the currency symbol")
],
"attr" => [
"placeholder" => "%n"
]
])
->add("rate", "text", [
"required" => true,
"constraints" => [
new NotBlank(),
],
"label" => $this->translator->trans(
'Rate from %currencyCode',
['%currencyCode' => $defaultCurrency->getCode()]
),
"label_attr" => [
"for" => "rate",
"help" => $this->translator->trans(
"The rate from %currencyCode: Price in %currencyCode x rate = Price in this currency",
["%currencyCode" => $defaultCurrency->getCode()]
),
],
"attr" => [
"placeholder" => $this->translator->trans('Rate'),
]
])
->add("code", "text", [
"required" => true,
"constraints" => [
new NotBlank(),
],
"label" => $this->translator->trans('ISO 4217 code'),
"label_attr" => [
"for" => "iso_4217_code",
"help" => $this->translator->trans('More information about ISO 4217'),
],
"attr" => [
"placeholder" => $this->translator->trans('Code')
]
])
;
}
public function getName()
{
return "thelia_currency_creation";
}
public function checkDuplicateCode($value, ExecutionContextInterface $context)
{
$currency = CurrencyQuery::create()->findOneByCode($value);
if ($currency) {
$context->addViolation(
Translator::getInstance()->trans(
'A currency with code "%name" already exists.',
['%name' => $value]
)
);
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
class CurrencyModificationForm extends CurrencyCreationForm
{
protected function buildForm()
{
parent::buildForm(true);
$this->formBuilder
->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))
;
}
public function getName()
{
return "thelia_currency_modification";
}
}

View File

@@ -0,0 +1,137 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CustomerQuery;
use Thelia\Core\Translation\Translator;
/**
* Class CustomerCreateForm
* @package Thelia\Form
* @author Manuel Raynaud <manu@raynaud.io>
*/
class CustomerCreateForm extends AddressCreateForm
{
protected function buildForm()
{
parent::buildForm();
$this->formBuilder
// Remove From Address create form
->remove("label")
->remove("is_default")
// Add
->add("auto_login", "integer")
// Add Email address
->add("email", "email", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Email(),
new Constraints\Callback(array(
"methods" => array(
array($this,
"verifyExistingEmail", ),
),
)),
),
"label" => Translator::getInstance()->trans("Email Address"),
"label_attr" => array(
"for" => "email",
),
))
// Add Login Information
->add("password", "password", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Length(array("min" => ConfigQuery::read("password.length", 4))),
),
"label" => Translator::getInstance()->trans("Password"),
"label_attr" => array(
"for" => "password",
),
))
->add("password_confirm", "password", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Length(array("min" => ConfigQuery::read("password.length", 4))),
new Constraints\Callback(array("methods" => array(
array($this, "verifyPasswordField"),
))),
),
"label" => Translator::getInstance()->trans("Password confirmation"),
"label_attr" => array(
"for" => "password_confirmation",
),
))
// Add Newsletter
->add("newsletter", "checkbox", array(
"label" => Translator::getInstance()->trans('I would like to receive the newsletter or the latest news.'),
"label_attr" => array(
"for" => "newsletter",
),
"required" => false,
));
//confirm email
if (intval(ConfigQuery::read("customer_confirm_email", 0))) {
$this->formBuilder->add("email_confirm", "email", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Email(),
new Constraints\Callback(array("methods" => array(
array($this, "verifyEmailField"),
))),
),
"label" => Translator::getInstance()->trans("Confirm Email Address"),
"label_attr" => array(
"for" => "email_confirm",
),
));
}
}
public function verifyPasswordField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["password"] != $data["password_confirm"]) {
$context->addViolation(Translator::getInstance()->trans("password confirmation is not the same as password field"));
}
}
public function verifyEmailField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["email"] != $data["email_confirm"]) {
$context->addViolation(Translator::getInstance()->trans("email confirmation is not the same as email field"));
}
}
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$customer = CustomerQuery::getCustomerByEmail($value);
if ($customer) {
$context->addViolation(Translator::getInstance()->trans("This email already exists."));
}
}
public function getName()
{
return "thelia_customer_create";
}
}

View File

@@ -0,0 +1,123 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\CustomerQuery;
/**
* Class CustomerLogin
* @package Thelia\Form
* @author Manuel Raynaud <manu@raynaud.io>
*/
class CustomerLogin extends BruteforceForm
{
protected function buildForm()
{
$this->formBuilder
->add("email", "email", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Email(),
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyExistingEmail"),
),
)),
),
"label" => Translator::getInstance()->trans("Please enter your email address"),
"label_attr" => array(
"for" => "email",
),
))
->add("account", "choice", array(
"constraints" => array(
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyAccount"),
),
)),
),
"choices" => array(
0 => Translator::getInstance()->trans("No, I am a new customer."),
1 => Translator::getInstance()->trans("Yes, I have a password :"),
),
"label_attr" => array(
"for" => "account",
),
"data" => 0,
))
->add("password", "password", array(
"constraints" => array(
new Constraints\NotBlank(array(
'groups' => array('existing_customer'),
)),
),
"label" => Translator::getInstance()->trans("Please enter your password"),
"label_attr" => array(
"for" => "password",
),
"required" => false,
))
->add("remember_me", "checkbox", array(
'value' => 'yes',
"label" => Translator::getInstance()->trans("Remember me ?"),
"label_attr" => array(
"for" => "remember_me",
),
))
;
}
/**
* If the user select "Yes, I have a password", we check the password.
*/
public function verifyAccount($value, ExecutionContextInterface $context)
{
if ($value == 1) {
$data = $context->getRoot()->getData();
if (false === $data['password'] || (empty($data['password']) && '0' != $data['password'])) {
$context->getViolations()->add(new ConstraintViolation(
Translator::getInstance()->trans('This value should not be blank.'),
'account_password',
array(),
$context->getRoot(),
'children[password].data',
'propertyPath'
));
}
}
}
/**
* If the user select "I'am a new customer", we make sure is email address does not exit in the database.
*/
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["account"] == 0) {
$customer = CustomerQuery::create()->findOneByEmail($value);
if ($customer) {
$context->addViolation(Translator::getInstance()->trans("A user already exists with this email address. Please login or if you've forgotten your password, go to Reset Your Password."));
}
}
}
public function getName()
{
return "thelia_customer_login";
}
}

View File

@@ -0,0 +1,85 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\CustomerQuery;
/**
* Class CustomerLostPasswordForm
* @package Thelia\Form
* @author Manuel Raynaud <manu@raynaud.io>
*/
class CustomerLostPasswordForm extends FirewallForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add("email", "email", array(
"constraints" => array(
new NotBlank(),
new Email(),
new Callback(array(
"methods" => array(
array($this,
"verifyExistingEmail", ),
),
)),
),
"label" => Translator::getInstance()->trans("Please enter your email address"),
"label_attr" => array(
"for" => "forgot-email",
),
));
}
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$customer = CustomerQuery::create()->findOneByEmail($value);
if (null === $customer) {
$context->addViolation(Translator::getInstance()->trans("This email does not exists"));
}
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_customer_lost_password";
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Translation\Translator;
use Thelia\Model\CustomerQuery;
/**
* Class CustomerPasswordUpdateForm
* @package Thelia\Form
* @author Christophe Laffont <claffont@openstudio.fr>
*/
class CustomerPasswordUpdateForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
// Login Information
->add("password_old", "password", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array("methods" => array(
array($this, "verifyCurrentPasswordField"),
))),
),
"label" => Translator::getInstance()->trans("Current Password"),
"label_attr" => array(
"for" => "password_old",
),
))
->add("password", "password", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Length(array("min" => ConfigQuery::read("password.length", 4))),
),
"label" => Translator::getInstance()->trans("New Password"),
"label_attr" => array(
"for" => "password",
),
))
->add("password_confirm", "password", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Length(array("min" => ConfigQuery::read("password.length", 4))),
new Constraints\Callback(array("methods" => array(
array($this, "verifyPasswordField"),
))),
),
"label" => Translator::getInstance()->trans('Password confirmation'),
"label_attr" => array(
"for" => "password_confirmation",
),
));
}
public function verifyCurrentPasswordField($value, ExecutionContextInterface $context)
{
/**
* Retrieve the user recording, because after the login action, the password is deleted in the session
*/
$userId = $this->getRequest()->getSession()->getCustomerUser()->getId();
$user = CustomerQuery::create()->findPk($userId);
// Check if value of the old password match the password of the current user
if (!password_verify($value, $user->getPassword())) {
$context->addViolation(Translator::getInstance()->trans("Your current password does not match."));
}
}
public function verifyPasswordField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["password"] != $data["password_confirm"]) {
$context->addViolation(Translator::getInstance()->trans("password confirmation is not the same as password field"));
}
}
public function getName()
{
return "thelia_customer_password_update";
}
}

View File

@@ -0,0 +1,83 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CustomerQuery;
/**
* Class CustomerProfileUpdateForm
* @package Thelia\Form
* @author Christophe Laffont <claffont@openstudio.fr>
*/
class CustomerProfileUpdateForm extends CustomerCreateForm
{
protected function buildForm()
{
parent::buildForm();
$this->formBuilder
->remove("auto_login")
// Remove From Personal Informations
->remove("phone")
->remove("cellphone")
// Remove Delivery Informations
->remove("company")
->remove("address1")
->remove("address2")
->remove("address3")
->remove("city")
->remove("zipcode")
->remove("country")
->remove("state")
// Remove Login Information
->remove("password")
->remove("password_confirm")
;
$customerCanChangeEmail = ConfigQuery::read("customer_change_email");
$emailConfirmation = ConfigQuery::read("customer_confirm_email");
if (! $customerCanChangeEmail) {
$currentOptions = $this->formBuilder->get("email")->getOptions();
$currentOptions["constraints"] = [];
$currentOptions["required"] = false;
$this->formBuilder->remove("email")->add("email", "text", $currentOptions);
}
if ($this->formBuilder->has("email_confirm") && ! ($customerCanChangeEmail && $emailConfirmation)) {
$this->formBuilder->remove("email_confirm");
}
}
/**
* @param $value
* @param ExecutionContextInterface $context
*/
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$customer = CustomerQuery::getCustomerByEmail($value);
// If there is already a customer for this email address and if the customer is different from the current user, do a violation
if ($customer && $customer->getId() != $this->getRequest()->getSession()->getCustomerUser()->getId()) {
$context->addViolation(Translator::getInstance()->trans("This email already exists."));
}
}
public function getName()
{
return "thelia_customer_profile_update";
}
}

View File

@@ -0,0 +1,230 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
/**
* Class CustomerUpdateForm
* @package Thelia\Form
* @author Manuel Raynaud <manu@raynaud.io>
*/
class CustomerUpdateForm extends BaseForm
{
use AddressCountryValidationTrait;
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->form attribute :
*
* $this->form->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add('update_logged_in_user',
'integer')// In a front office context, update the in-memory logged-in user data
->add("company", "text", array(
"label" => Translator::getInstance()->trans("Company"),
"label_attr" => array(
"for" => "company",
),
"required" => false,
))
->add("firstname", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans("First Name"),
"label_attr" => array(
"for" => "firstname",
),
))
->add("lastname", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans("Last Name"),
"label_attr" => array(
"for" => "lastname",
),
))
->add("email", "email", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Email(),
),
"label" => Translator::getInstance()->trans("Email address"),
"label_attr" => array(
"for" => "email",
),
))
->add("email_confirm", "email", array(
"constraints" => array(
new Constraints\Email(),
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyEmailField"),
)
)),
),
"label" => Translator::getInstance()->trans("Confirm Email address"),
"label_attr" => array(
"for" => "email_confirm",
),
))
->add("password", "text", array(
"label" => Translator::getInstance()->trans("Password"),
"label_attr" => array(
"for" => "password",
),
))
->add("address1", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label_attr" => array(
"for" => "address",
),
"label" => Translator::getInstance()->trans("Street Address "),
))
->add("address2", "text", array(
"label" => Translator::getInstance()->trans("Address Line 2"),
"label_attr" => array(
"for" => "address2",
),
))
->add("address3", "text", array(
"label" => Translator::getInstance()->trans("Address Line 3"),
"label_attr" => array(
"for" => "address3",
),
))
->add("phone", "text", array(
"label" => Translator::getInstance()->trans("Phone"),
"label_attr" => array(
"for" => "phone",
),
"required" => false,
))
->add("cellphone", "text", array(
"label" => Translator::getInstance()->trans("Cellphone"),
"label_attr" => array(
"for" => "cellphone",
),
"required" => false,
))
->add("zipcode", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyZipCode")
),
)),
),
"label" => Translator::getInstance()->trans("Zip code"),
"label_attr" => array(
"for" => "zipcode",
),
))
->add("city", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans("City"),
"label_attr" => array(
"for" => "city",
),
))
->add("country", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans("Country"),
"label_attr" => array(
"for" => "country",
),
))
->add("state", "text", array(
"constraints" => array(
new Constraints\Callback(array(
"methods" => array(
array($this, "verifyState")
),
)),
),
"label" => Translator::getInstance()->trans("State"),
"label_attr" => array(
"for" => "state",
),
))
->add("title", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans("Title"),
"label_attr" => array(
"for" => "title",
),
))
->add('discount', 'text', array(
'label' => Translator::getInstance()->trans('permanent discount (in percent)'),
'label_attr' => array(
'for' => 'discount',
),
))
->add('reseller', 'integer', array(
'label' => Translator::getInstance()->trans('Reseller'),
'label_attr' => array(
'for' => 'reseller',
),
))
;
}
public function verifyEmailField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if (isset($data["email_confirm"]) && $data["email"] != $data["email_confirm"]) {
$context->addViolation(
Translator::getInstance()->trans("email confirmation is not the same as email field")
);
}
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_customer_update";
}
}

View File

@@ -0,0 +1,168 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Definition;
/**
* Class AdminForm
*
* @author Franck Allimant <franck@cqfdev.fr>
* @package Thelia\Form\Definition
*/
final class AdminForm
{
const ADMIN_LOGIN = 'thelia.admin.login';
const ADMIN_LOST_PASSWORD = 'thelia.admin.lostpassword';
const ADMIN_CREATE_PASSWORD = 'thelia.admin.createpassword';
const SEO = 'thelia.admin.seo';
const CUSTOMER_CREATE = 'thelia.admin.customer.create';
const CUSTOMER_UPDATE = 'thelia.admin.customer.update';
const ADDRESS_CREATE = 'thelia.admin.address.create';
const ADDRESS_UPDATE = 'thelia.admin.address.update';
const CATEGORY_CREATION = 'thelia.admin.category.creation';
const CATEGORY_MODIFICATION = 'thelia.admin.category.modification';
const CATEGORY_IMAGE_MODIFICATION = 'thelia.admin.category.image.modification';
const CATEGORY_DOCUMENT_MODIFICATION = 'thelia.admin.category.document.modification';
const PRODUCT_CREATION = 'thelia.admin.product.creation';
const PRODUCT_CLONE = 'thelia.admin.product.clone';
const PRODUCT_MODIFICATION = 'thelia.admin.product.modification';
const PRODUCT_DETAILS_MODIFICATION = 'thelia.admin.product.details.modification';
const PRODUCT_IMAGE_MODIFICATION = 'thelia.admin.product.image.modification';
const PRODUCT_DOCUMENT_MODIFICATION = 'thelia.admin.product.document.modification';
const PRODUCT_SALE_ELEMENT_UPDATE = 'thelia.admin.product_sale_element.update';
const PRODUCT_DEFAULT_SALE_ELEMENT_UPDATE = 'thelia.admin.product_default_sale_element.update';
const PRODUCT_COMBINATION_GENERATION = 'thelia.admin.product_combination.build';
const PRODUCT_DELETE = 'thelia.admin.product.deletion';
const FOLDER_CREATION = 'thelia.admin.folder.creation';
const FOLDER_MODIFICATION = 'thelia.admin.folder.modification';
const FOLDER_IMAGE_MODIFICATION = 'thelia.admin.folder.image.modification';
const FOLDER_DOCUMENT_MODIFICATION = 'thelia.admin.folder.document.modification';
const CONTENT_CREATION = 'thelia.admin.content.creation';
const CONTENT_MODIFICATION = 'thelia.admin.content.modification';
const CONTENT_IMAGE_MODIFICATION = 'thelia.admin.content.image.modification';
const CONTENT_DOCUMENT_MODIFICATION = 'thelia.admin.content.document.modification';
const BRAND_CREATION = 'thelia.admin.brand.creation';
const BRAND_MODIFICATION = 'thelia.admin.brand.modification';
const BRAND_IMAGE_MODIFICATION = 'thelia.admin.brand.image.modification';
const BRAND_DOCUMENT_MODIFICATION = 'thelia.admin.brand.document.modification';
const CART_ADD = 'thelia.cart.add';
const ORDER_DELIVERY = 'thelia.order.delivery';
const ORDER_PAYMENT = 'thelia.order.payment';
const ORDER_UPDATE_ADDRESS = 'thelia.order.update.address';
const ORDER_STATUS_CREATION = 'thelia.admin.order-status.creation';
const ORDER_STATUS_MODIFICATION = 'thelia.admin.order-status.modification';
const COUPON_CODE = 'thelia.order.coupon';
const CONFIG_CREATION = 'thelia.admin.config.creation';
const CONFIG_MODIFICATION = 'thelia.admin.config.modification';
const MESSAGE_CREATION = 'thelia.admin.message.creation';
const MESSAGE_MODIFICATION = 'thelia.admin.message.modification';
const MESSAGE_SEND_SAMPLE = 'thelia.admin.message.send-sample';
const CURRENCY_CREATION = 'thelia.admin.currency.creation';
const CURRENCY_MODIFICATION = 'thelia.admin.currency.modification';
const COUPON_CREATION = 'thelia.admin.coupon.creation';
const ATTRIBUTE_CREATION = 'thelia.admin.attribute.creation';
const ATTRIBUTE_MODIFICATION = 'thelia.admin.attribute.modification';
const FEATURE_CREATION = 'thelia.admin.feature.creation';
const FEATURE_MODIFICATION = 'thelia.admin.feature.modification';
const ATTRIBUTE_AV_CREATION = 'thelia.admin.attributeav.creation';
const FEATURE_AV_CREATION = 'thelia.admin.featureav.creation';
const TAX_RULE_MODIFICATION = 'thelia.admin.taxrule.modification';
const TAX_RULE_TAX_LIST_UPDATE = 'thelia.admin.taxrule.taxlistupdate';
const TAX_RULE_CREATION = 'thelia.admin.taxrule.add';
const TAX_MODIFICATION = 'thelia.admin.tax.modification';
const TAX_TAX_LIST_UPDATE = 'thelia.admin.tax.taxlistupdate';
const TAX_CREATION = 'thelia.admin.tax.add';
const PROFILE_CREATION = 'thelia.admin.profile.add';
const PROFILE_MODIFICATION = 'thelia.admin.profile.modification';
const PROFILE_UPDATE_RESOURCE_ACCESS = 'thelia.admin.profile.resource-access.modification';
const PROFILE_UPDATE_MODULE_ACCESS = 'thelia.admin.profile.module-access.modification';
const ADMINISTRATOR_CREATION = 'thelia.admin.administrator.add';
const ADMINISTRATOR_MODIFICATION = 'thelia.admin.administrator.update';
const MAILING_SYSTEM_MODIFICATION = 'thelia.admin.mailing-system.update';
const TEMPLATE_CREATION = 'thelia.admin.template.creation';
const TEMPLATE_MODIFICATION = 'thelia.admin.template.modification';
const COUNTRY_CREATION = 'thelia.admin.country.creation';
const COUNTRY_MODIFICATION = 'thelia.admin.country.modification';
const STATE_CREATION = 'thelia.admin.state.creation';
const STATE_MODIFICATION = 'thelia.admin.state.modification';
const AREA_CREATE = 'thelia.admin.area.create';
const AREA_MODIFICATION = 'thelia.admin.area.modification';
const AREA_COUNTRY = 'thelia.admin.area.country';
const AREA_DELETE_COUNTRY = 'thelia.admin.area.delete.country';
const AREA_POSTAGE = 'thelia.admin.area.postage';
const SHIPPING_ZONE_ADD_AREA = 'thelia.shopping_zone_area';
const SHIPPING_ZONE_REMOVE_AREA = 'thelia.shopping_zone_remove_area';
const LANG_UPDATE = 'thelia.lang.update';
const LANG_CREATE = 'thelia.lang.create';
const LANG_DEFAULT_BEHAVIOR = 'thelia.lang.defaultBehavior';
const LANG_URL = 'thelia.lang.url';
const CONFIG_STORE = 'thelia.configuration.store';
const SYSTEM_LOG_CONFIGURATION = 'thelia.system-logs.configuration';
const MODULE_MODIFICATION = 'thelia.admin.module.modification';
const MODULE_INSTALL = 'thelia.admin.module.install';
const HOOK_CREATION = 'thelia.admin.hook.creation';
const HOOK_MODIFICATION = 'thelia.admin.hook.modification';
const MODULE_HOOK_CREATION = 'thelia.admin.module-hook.creation';
const MODULE_HOOK_MODIFICATION = 'thelia.admin.module-hook.modification';
const CACHE_FLUSH = 'thelia.cache.flush';
const ASSETS_FLUSH = 'thelia.assets.flush';
const IMAGES_AND_DOCUMENTS_CACHE_FLUSH = 'thelia.images-and-documents-cache.flush';
const EXPORT = 'thelia.export';
const IMPORT = 'thelia.import';
const SALE_CREATION = 'thelia.admin.sale.creation';
const SALE_MODIFICATION = 'thelia.admin.sale.modification';
const EMPTY_FORM = 'thelia.empty';
const API_CREATE = 'thelia_api_create';
const API_UPDATE = 'thelia_api_update';
}

View File

@@ -0,0 +1,36 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Definition;
/**
* Class ApiForm
*
* @author Franck Allimant <franck@cqfdev.fr>
* @package TheliaFormDefinition
*/
final class ApiForm
{
const EMPTY_FORM = 'thelia.api.empty';
const CUSTOMER_CREATE = 'thelia.api.customer.create';
const CUSTOMER_UPDATE = 'thelia.api.customer.update';
const CUSTOMER_LOGIN = 'thelia.api.customer.login';
const CATEGORY_CREATION = 'thelia.api.category.create';
const CATEGORY_MODIFICATION = 'thelia.api.category.update';
const PRODUCT_SALE_ELEMENTS = 'thelia.api.product_sale_elements';
const PRODUCT_CREATION = 'thelia.api.product.creation';
const PRODUCT_MODIFICATION = 'thelia.api.product.modification';
}

View File

@@ -0,0 +1,37 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Definition;
/**
* Class FrontForm
*
* @author Franck Allimant <franck@cqfdev.fr>
* @package Thelia\Form\Definition
*/
final class FrontForm
{
const ADDRESS_CREATE = 'thelia.front.address.create';
const ADDRESS_UPDATE = 'thelia.front.address.update';
const CART_ADD = 'thelia.cart.add';
const CONTACT = 'thelia.front.contact';
const COUPON_CONSUME = 'thelia.order.coupon';
const CUSTOMER_LOGIN = 'thelia.front.customer.login';
const CUSTOMER_LOST_PASSWORD = 'thelia.front.customer.lostpassword';
const CUSTOMER_CREATE = 'thelia.front.customer.create';
const CUSTOMER_PROFILE_UPDATE = 'thelia.front.customer.profile.update';
const CUSTOMER_PASSWORD_UPDATE = 'thelia.front.customer.password.update';
const NEWSLETTER = 'thelia.front.newsletter';
const NEWSLETTER_UNSUBSCRIBE = 'thelia.front.newsletter.unsubscribe';
const ORDER_DELIVER = 'thelia.order.delivery';
const ORDER_PAYMENT = 'thelia.order.payment';
}

View File

@@ -0,0 +1,53 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
/**
* Class EmptyForm
* @package Thelia\Form
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class EmptyForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "empty";
}
}

View File

@@ -0,0 +1,17 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Exception;
class FormValidationException extends \RuntimeException
{
}

View File

@@ -0,0 +1,17 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Exception;
class ProductNotFoundException extends FormValidationException
{
}

View File

@@ -0,0 +1,17 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Exception;
class StockNotFoundException extends FormValidationException
{
}

View File

@@ -0,0 +1,126 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Model\LangQuery;
/**
* Class ExportForm
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ExportForm extends BaseForm
{
public function getName()
{
return 'thelia_export';
}
protected function buildForm()
{
$this->formBuilder
// Todo: use list
->add(
'serializer',
'text',
[
'required' => true,
'label' => $this->translator->trans('File format'),
'label_attr' => [
'for' => 'serializer'
],
]
)
// Todo: use list
->add(
'language',
'integer',
[
'required' => true,
'label' => $this->translator->trans('Language'),
'label_attr' => [
'for' => 'language'
],
'constraints' => [
new Callback([
'methods' => [
[$this, 'checkLanguage'],
],
]),
],
]
)
->add("do_compress", "checkbox", array(
"label" => $this->translator->trans("Do compress"),
"label_attr" => ["for" => "do_compress"],
"required" => false,
))
// Todo: use list
->add(
'archiver',
'text',
[
'required' => false,
'label' => $this->translator->trans('Archive Format'),
'label_attr' => [
'for' => 'archiver'
],
]
)
->add("images", "checkbox", array(
"label" => $this->translator->trans("Include images"),
"label_attr" => ["for" => "with_images"],
"required" => false,
))
->add("documents", "checkbox", array(
"label" => $this->translator->trans("Include documents"),
"label_attr" => ["for" => "with_documents"],
"required" => false,
))
->add("range_date_start", "date", array(
"label" => $this->translator->trans("Range date Start"),
"label_attr" => ["for" => "for_range_date_start"],
"required" => false,
'years' => range(date('Y'), date('Y') - 5),
'input' => 'array',
'widget' => 'choice',
'empty_value' => array('year' => 'Year', 'month' => 'Month', 'day' => 'Day'),
'format' => 'yyyy-MM-d',
))
->add("range_date_end", "date", array(
"label" => $this->translator->trans("Range date End"),
"label_attr" => ["for" => "for_range_date_end"],
"required" => false,
'years' => range(date('Y'), date('Y') - 5),
'input' => 'array',
'widget' => 'choice',
'empty_value' => array('year' => 'Year', 'month' => 'Month', 'day' => 'Day'),
'format' => 'yyyy-MM-d',
));
}
public function checkLanguage($value, ExecutionContextInterface $context)
{
if (null === LangQuery::create()->findPk($value)) {
$context->addViolation(
$this->translator->trans(
"The language \"%id\" doesn't exist",
[
"%id" => $value
]
)
);
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class FeatureAvCreationForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add("title", "text", array(
"constraints" => array(
new NotBlank(),
),
"label" => Translator::getInstance()->trans("Title *"),
"label_attr" => array(
"for" => "title",
),
))
->add("locale", "text", array(
"constraints" => array(
new NotBlank(),
),
))
->add("feature_id", "hidden", array(
"constraints" => array(
new NotBlank(),
),
))
;
}
public function getName()
{
return "thelia_featureav_creation";
}
}

View File

@@ -0,0 +1,60 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class FeatureCreationForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add(
"title",
"text",
array(
"constraints" => array(
new NotBlank(),
),
"label" => Translator::getInstance()->trans("Title *"),
"label_attr" => array(
"for" => "title",
), )
)
->add(
"locale",
"text",
array(
"constraints" => array(
new NotBlank(),
), )
)
->add(
"add_to_all",
"checkbox",
array(
"label" => Translator::getInstance()->trans("Add to all product templates"),
"label_attr" => array(
"for" => "add_to_all",
), )
)
;
}
public function getName()
{
return "thelia_feature_creation";
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\GreaterThan;
class FeatureModificationForm extends FeatureCreationForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
$this->formBuilder
->add("id", "hidden", array(
"constraints" => array(
new GreaterThan(
array('value' => 0)
),
),
))
;
// Add standard description fields
$this->addStandardDescFields();
}
public function getName()
{
return "thelia_feature_modification";
}
}

View File

@@ -0,0 +1,122 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ConfigQuery;
use Thelia\Model\FormFirewall;
use Thelia\Model\FormFirewallQuery;
/**
* Class FirewallForm
* @package Thelia\Form
* @author Benjamin Perche <bperche@openstudio.fr>
*/
abstract class FirewallForm extends BaseForm
{
/**
* Those values are for a "normal" security policy
*
* Time is in minutes
*/
const DEFAULT_TIME_TO_WAIT = 60; // 1 hour
const DEFAULT_ATTEMPTS = 6;
public function isFirewallOk($env)
{
if ($env === "prod" && $this->isFirewallActive()) {
/**
* Empty the firewall
*/
$deleteTime = date("Y-m-d G:i:s", time() - $this->getConfigTime() * 60);
$collection = FormFirewallQuery::create()
->filterByFormName($this->getName())
->filterByUpdatedAt($deleteTime, Criteria::LESS_THAN)
->find();
$collection->delete();
$firewallInstance = FormFirewallQuery::create()
->filterByFormName($this->getName())
->filterByIpAddress($this->request->getClientIp())
->findOne()
;
if (null !== $firewallInstance) {
if ($firewallInstance->getAttempts() < $this->getConfigAttempts()) {
$firewallInstance->incrementAttempts();
} else {
/** Set updated_at at NOW() */
$firewallInstance->save();
return false;
}
} else {
$firewallInstance = (new FormFirewall())
->setIpAddress($this->request->getClientIp())
->setFormName($this->getName())
;
$firewallInstance->save();
}
}
return true;
}
/**
* @return int
*
* The time (in hours) to wait if the attempts have been exceeded
*/
public function getConfigTime()
{
return ConfigQuery::read("form_firewall_time_to_wait", static::DEFAULT_TIME_TO_WAIT);
}
/**
* @return int
*
* The number of allowed attempts
*/
public function getConfigAttempts()
{
return ConfigQuery::read("form_firewall_attempts", static::DEFAULT_ATTEMPTS);
}
public function isFirewallActive()
{
return ConfigQuery::read("form_firewall_active", true);
}
public function getWaitingTime()
{
$translator = Translator::getInstance();
$minutes = $this->getConfigTime();
$minutesName = $translator->trans("minute(s)");
$text = "";
if ($minutes >= 60) {
$hour = floor($minutes / 60);
$minutes %= 60;
$text = $hour." ".$translator->trans("hour(s)")." ";
}
if ($minutes !== 0) {
$text .= $minutes." ".$minutesName;
} else {
$text = rtrim($text);
}
return $text;
}
}

View File

@@ -0,0 +1,56 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class FolderCreationForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add("title", "text", array(
"constraints" => array(
new NotBlank(),
),
"label" => Translator::getInstance()->trans("Folder title *"),
"label_attr" => array(
"for" => "title",
),
))
->add("parent", "text", array(
"label" => Translator::getInstance()->trans("Parent folder *"),
"constraints" => array(
new NotBlank(),
),
"label_attr" => array("for" => "parent_create"),
))
->add("locale", "text", array(
"constraints" => array(
new NotBlank(),
),
"label_attr" => array("for" => "locale_create"),
))
->add("visible", "integer", array(
"label" => Translator::getInstance()->trans("This folder is online."),
"label_attr" => array("for" => "visible_create"),
))
;
}
public function getName()
{
return "thelia_folder_creation";
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Thelia\Form\Image\DocumentModification;
/**
* Created by JetBrains PhpStorm.
* Date: 9/18/13
* Time: 3:56 PM
*
* Form allowing to process a file
*
* @package Image
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class FolderDocumentModification extends DocumentModification
{
/**
* Get form name
* This name must be unique
*
* @return string
*/
public function getName()
{
return 'thelia_folder_document_modification';
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Thelia\Form\Image\ImageModification;
/**
* Created by JetBrains PhpStorm.
* Date: 9/18/13
* Time: 3:56 PM
*
* Form allowing to process an image collection
*
* @package Image
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class FolderImageModification extends ImageModification
{
/**
* Get form name
* This name must be unique
*
* @return string
*/
public function getName()
{
return 'thelia_folder_image_modification';
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
class FolderModificationForm extends FolderCreationForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
parent::buildForm();
$this->formBuilder
->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))
;
// Add standard description fields, excluding title and locale, which a re defined in parent class
$this->addStandardDescFields(array('title', 'locale'));
}
public function getName()
{
return "thelia_folder_modification";
}
}

View File

@@ -0,0 +1,115 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Template\TemplateDefinition;
use Thelia\Core\Translation\Translator;
use Thelia\Model\HookQuery;
/**
* Class HookCreationForm
* @package Thelia\Form
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
class HookCreationForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add("code", "text", array(
"constraints" => array(
new NotBlank(),
new Callback(array(
"methods" => array(array($this, "checkCodeUnicity"))
)),
),
"label" => Translator::getInstance()->trans("Hook code"),
"label_attr" => array(
"for" => "code",
),
))
->add("locale", "hidden", array(
"constraints" => array(
new NotBlank(),
),
))
->add("type", "choice", array(
"choices" => array(
TemplateDefinition::FRONT_OFFICE => Translator::getInstance()->trans("Front Office"),
TemplateDefinition::BACK_OFFICE => Translator::getInstance()->trans("Back Office"),
TemplateDefinition::EMAIL => Translator::getInstance()->trans("email"),
TemplateDefinition::PDF => Translator::getInstance()->trans("pdf"),
),
"constraints" => array(
new NotBlank(),
),
"label" => Translator::getInstance()->trans("Type"),
"label_attr" => array(
"for" => "type",
),
))
->add("native", "hidden", array(
"label" => Translator::getInstance()->trans("Native"),
"label_attr" => array(
"for" => "native",
"help" => Translator::getInstance()->trans("Core hook of Thelia."),
),
))
->add("active", "checkbox", array(
"label" => Translator::getInstance()->trans("Active"),
"required" => false,
"label_attr" => array(
"for" => "active",
),
))
->add("title", "text", array(
"constraints" => array(
new NotBlank(),
),
"label" => Translator::getInstance()->trans("Hook title"),
"label_attr" => array(
"for" => "title",
),
))
;
}
public function checkCodeUnicity($code, ExecutionContextInterface $context)
{
$type = $context->getRoot()->getData()['type'];
$query = HookQuery::create()->filterByCode($code)->filterByType($type);
if ($this->form->has('id')) {
$query->filterById($this->form->getRoot()->getData()['id'], Criteria::NOT_EQUAL);
}
if ($query->count() > 0) {
$context->addViolation(
Translator::getInstance()->trans(
"A Hook with code %name already exists. Please choose another code.",
array('%name' => $code)
)
);
}
}
public function getName()
{
return "thelia_hook_creation";
}
}

View File

@@ -0,0 +1,63 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Thelia\Core\Translation\Translator;
/**
* Class HookModificationForm
* @package Thelia\Form
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
class HookModificationForm extends HookCreationForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
parent::buildForm(true);
$this->formBuilder
->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))
->add("by_module", "checkbox", array(
"label" => Translator::getInstance()->trans("By Module"),
"required" => false,
"label_attr" => array(
"for" => "by_module",
"help" => Translator::getInstance()->trans(
"This hook is specific to a module (delivery/payment modules)."
),
),
))
->add("block", "checkbox", array(
"label" => Translator::getInstance()->trans("Hook block"),
"required" => false,
"label_attr" => array(
"for" => "block",
"help" => Translator::getInstance()->trans(
"If checked, this hook will be used by a hook block. If not, by hook function."
),
),
))
;
// Add standard description fields, excluding title and locale, which a re defined in parent class
$this->addStandardDescFields(array('title', 'postscriptum', 'locale'));
}
public function getName()
{
return "thelia_hook_modification";
}
}

View File

@@ -0,0 +1,71 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Image;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
use Thelia\Form\StandardDescriptionFieldsTrait;
/**
* Created by JetBrains PhpStorm.
* Date: 9/18/13
* Time: 3:56 PM
*
* Form allowing to process a file
*
* @package File
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
abstract class DocumentModification extends BaseForm
{
use StandardDescriptionFieldsTrait;
/**
* @inheritdoc
*/
protected function buildForm()
{
$translator = Translator::getInstance();
$this->formBuilder
->add(
'file',
'file',
[
'required' => false,
'constraints' => [ ],
'label' => $translator->trans('Replace current document by this file'),
'label_attr' => [
'for' => 'file',
]
]
)
// Is this document online ?
->add(
'visible',
'checkbox',
[
'constraints' => [ ],
'required' => false,
'label' => $translator->trans('This document is online'),
'label_attr' => [
'for' => 'visible_create',
]
]
);
// Add standard description fields
$this->addStandardDescFields();
}
}

View File

@@ -0,0 +1,78 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Image;
use Symfony\Component\Validator\Constraints\Image;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
use Thelia\Form\StandardDescriptionFieldsTrait;
/**
* Created by JetBrains PhpStorm.
* Date: 9/18/13
* Time: 3:56 PM
*
* Form allowing to process an image
*
* @package Image
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
abstract class ImageModification extends BaseForm
{
use StandardDescriptionFieldsTrait;
/**
* @inheritdoc
*/
protected function buildForm()
{
$translator = Translator::getInstance();
$this->formBuilder
->add(
'file',
'file',
[
'required' => false,
'constraints' => [
new Image([
//'minWidth' => 200,
//'minHeight' => 200
]),
],
'label' => $translator->trans('Replace current image by this file'),
'label_attr' => [
'for' => 'file',
]
]
)
// Is this image online ?
->add(
'visible',
'checkbox',
[
'constraints' => [ ],
'required' => false,
'label' => $translator->trans('This image is online'),
'label_attr' => [
'for' => 'visible_create',
]
]
)
;
// Add standard description fields
$this->addStandardDescFields();
}
}

View File

@@ -0,0 +1,73 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Model\LangQuery;
/**
* Class ImportForm
* @package Thelia\Form
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ImportForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add("file_upload", "file", array(
"label" => $this->translator->trans("File to upload"),
"label_attr" => ["for" => "file_to_upload"],
"required" => true,
"constraints" => [
new Assert\NotNull
]
))
->add("language", "integer", array(
"label" => $this->translator->trans("Language"),
"label_attr" => ["for" => "language"],
"required" => true,
"constraints" => [
new Assert\Callback([
"methods" => [
[$this, "checkLanguage"],
],
]),
],
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_import";
}
public function checkLanguage($value, ExecutionContextInterface $context)
{
if (null === LangQuery::create()->findPk($value)) {
$context->addViolation(
$this->translator->trans(
"The language \"%id\" doesn't exist",
[
"%id" => $value
]
)
);
}
}
}

View File

@@ -0,0 +1,100 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* Created by JetBrains PhpStorm.
* Date: 8/29/13
* Time: 3:45 PM
*
* Allow to build a form Install Step 3 Database connection
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class InstallStep3Form extends BaseForm
{
/**
* Build Coupon form
*
* @return void
*/
protected function buildForm()
{
$this->formBuilder
->add(
'host',
'text',
array(
'constraints' => array(
new NotBlank(),
),
)
)
->add(
'user',
'text',
array(
'constraints' => array(
new NotBlank(),
),
)
)
->add(
'password',
'text',
array(
'constraints' => array(
new NotBlank(),
),
)
)
->add(
'port',
'text',
array(
'constraints' => array(
new NotBlank(),
new GreaterThan(
array(
'value' => 0,
)
),
),
)
)
->add(
'locale',
'hidden',
array(
'constraints' => array(
new NotBlank(),
),
)
);
}
/**
* Get form name
*
* @return string
*/
public function getName()
{
return 'thelia_install_step3';
}
}

View File

@@ -0,0 +1,138 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Lang;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
use Thelia\Core\Translation\Translator;
/**
* Class LangCreateForm
* @package Thelia\Form\Lang
* @author Manuel Raynaud <manu@raynaud.io>
*/
class LangCreateForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add('title', 'text', array(
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans('Language name'),
'label_attr' => array(
'for' => 'title_lang',
),
))
->add('code', 'text', array(
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans('ISO 639-1 Code'),
'label_attr' => array(
'for' => 'code_lang',
),
))
->add('locale', 'text', array(
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans('language locale'),
'label_attr' => array(
'for' => 'locale_lang',
),
))
->add('date_time_format', 'text', array(
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans('date/time format'),
'label_attr' => array(
'for' => 'date_time_format',
),
))
->add('date_format', 'text', array(
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans('date format'),
'label_attr' => array(
'for' => 'date_lang',
),
))
->add('time_format', 'text', array(
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans('time format'),
'label_attr' => array(
'for' => 'time_lang',
),
))
->add('decimal_separator', 'text', array(
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans('decimal separator'),
'label_attr' => array(
'for' => 'decimal_separator',
),
))
->add('thousands_separator', 'text', array(
'trim' => false,
'label' => Translator::getInstance()->trans('thousands separator'),
'label_attr' => array(
'for' => 'thousands_separator',
),
))
->add('decimals', 'text', array(
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans('Decimal places'),
'label_attr' => array(
'for' => 'decimals',
),
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_language_create';
}
}

View File

@@ -0,0 +1,71 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Lang;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
use Thelia\Core\Translation\Translator;
/**
* Class LangDefaultBehaviorForm
* @package Thelia\Form\Lang
* @author Manuel Raynaud <manu@raynaud.io>
*/
class LangDefaultBehaviorForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add('behavior', 'choice', array(
'choices' => array(
0 => Translator::getInstance()->trans("Strictly use the requested language"),
1 => Translator::getInstance()->trans("Replace by the default language"),
),
'constraints' => array(
new NotBlank(),
),
'label' => Translator::getInstance()->trans("If a translation is missing or incomplete :"),
'label_attr' => array(
'for' => 'defaultBehavior-form',
),
));
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_lang_defaultBehavior';
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Lang;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* Class LangUpdateForm
* @package Thelia\Form\Lang
* @author Manuel Raynaud <manu@raynaud.io>
*/
class LangUpdateForm extends LangCreateForm
{
public function buildForm()
{
parent::buildForm();
$this->formBuilder
->add('id', 'hidden', array(
'constraints' => array(
new NotBlank(),
new GreaterThan(array('value' => 0)),
),
));
}
public function getName()
{
return 'thelia_lang_update';
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Lang;
use Thelia\Core\Event\ActionEvent;
/**
* Class LangUrlEvent
* @package Thelia\Form\Lang
* @author Manuel Raynaud <manu@raynaud.io>
*/
class LangUrlEvent extends ActionEvent
{
protected $url = array();
public function addUrl($id, $url)
{
$this->url[$id] = $url;
}
public function getUrl()
{
return $this->url;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Lang;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
use Thelia\Model\LangQuery;
/**
* Class LangUrlForm
* @package Thelia\Form\Lang
* @author Manuel Raynaud <manu@raynaud.io>
*/
class LangUrlForm extends BaseForm
{
const LANG_PREFIX = 'url_';
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
foreach (LangQuery::create()->find() as $lang) {
$this->formBuilder->add(
self::LANG_PREFIX.$lang->getId(),
'text',
array(
'constraints' => array(
new NotBlank(),
),
"attr" => array(
"tag" => "url",
"url_id" => $lang->getId(),
"url_title" => $lang->getTitle(),
),
)
);
}
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_language_url';
}
}

View File

@@ -0,0 +1,87 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Thelia\Core\Translation\Translator;
/**
* Class MailingSystemModificationForm
* @package Thelia\Form
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class MailingSystemModificationForm extends BaseForm
{
protected function buildForm($change_mode = false)
{
$this->formBuilder
->add("enabled", "choice", array(
"choices" => array(1 => "Yes", 0 => "No"),
"label" => Translator::getInstance()->trans("Enable remote SMTP use"),
"label_attr" => array("for" => "enabled_field"),
))
->add("host", "text", array(
"label" => Translator::getInstance()->trans("Host"),
"label_attr" => array("for" => "host_field"),
))
->add("port", "text", array(
"label" => Translator::getInstance()->trans("Port"),
"label_attr" => array("for" => "port_field"),
))
->add("encryption", "text", array(
"label" => Translator::getInstance()->trans("Encryption"),
"label_attr" => array(
"for" => "encryption_field",
"help" => Translator::getInstance()->trans("ssl, tls or empty"),
),
))
->add("username", "text", array(
"label" => Translator::getInstance()->trans("Username"),
"label_attr" => array("for" => "username_field"),
))
->add("password", "text", array(
"label" => Translator::getInstance()->trans("Password"),
"label_attr" => array("for" => "password_field"),
))
->add("authmode", "text", array(
"label" => Translator::getInstance()->trans("Auth mode"),
"label_attr" => array(
"for" => "authmode_field",
"help" => Translator::getInstance()->trans("plain, login, cram-md5 or empty"),
),
))
->add("timeout", "text", array(
"label" => Translator::getInstance()->trans("Timeout"),
"label_attr" => array("for" => "timeout_field"),
))
->add("sourceip", "text", array(
"label" => Translator::getInstance()->trans("Source IP"),
"label_attr" => array("for" => "sourceip_field"),
))
;
}
public function getName()
{
return "thelia_mailing_system_modification";
}
/*public function verifyCode($value, ExecutionContextInterface $context)
{
$profile = ProfileQuery::create()
->findOneByCode($value);
if (null !== $profile) {
$context->addViolation("Profile `code` already exists");
}
}*/
}

View File

@@ -0,0 +1,83 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Thelia\Model\Lang;
use Thelia\Model\MessageQuery;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
class MessageCreationForm extends BaseForm
{
protected function buildForm($change_mode = false)
{
$name_constraints = array(new Constraints\NotBlank());
if (!$change_mode) {
$name_constraints[] = new Constraints\Callback(array(
"methods" => array(array($this, "checkDuplicateName")),
));
}
$this->formBuilder
->add("name", "text", array(
"constraints" => $name_constraints,
"label" => Translator::getInstance()->trans('Name'),
"label_attr" => array(
"for" => "name",
'help' => Translator::getInstance()->trans("This is an identifier that will be used in the code to get this message"),
),
'attr' => [
'placeholder' => Translator::getInstance()->trans("Mail template name"),
],
))
->add("title", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => Translator::getInstance()->trans('Purpose'),
"label_attr" => array(
"for" => "purpose",
'help' => Translator::getInstance()->trans(
"Enter here the mail template purpose in the default language (%title%)",
[ '%title%' => Lang::getDefaultLanguage()->getTitle() ]
),
),
'attr' => [
'placeholder' => Translator::getInstance()->trans("Mail template purpose"),
],
))
->add("locale", "hidden", array(
"constraints" => array(
new Constraints\NotBlank(),
),
))
->add("secured", "hidden", array())
;
}
public function getName()
{
return "thelia_message_creation";
}
public function checkDuplicateName($value, ExecutionContextInterface $context)
{
$message = MessageQuery::create()->findOneByName($value);
if ($message) {
$context->addViolation(Translator::getInstance()->trans('A message with name "%name" already exists.', array('%name' => $value)));
}
}
}

View File

@@ -0,0 +1,138 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\Type;
use Thelia\Core\Translation\Translator;
class MessageModificationForm extends BaseForm
{
public function getName()
{
return "thelia_message_modification";
}
protected function buildForm()
{
$this->formBuilder
->add("id", "hidden", array(
"constraints" => array(
new GreaterThan(array('value' => 0))
)
))
->add("name", "text", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans('Name'),
"label_attr" => array(
"for" => "name",
"help" => Translator::getInstance()->trans('This the unique name of this message. Do not change this value unless you understand what you do.'),
),
'attr' => [
"placeholder" => Translator::getInstance()->trans('Message name'),
],
))
/*->add("secured" , "checkbox" , array(
"constraints" => array(new Type([ 'type' => 'bool'])),
'required' => false,
"label" => Translator::getInstance()->trans('Prevent mailing template modification or deletion, except for super-admin')
))*/
// The "secured" function is useless, as all mails are required for the system to work.
// Define all messages as not secured.
->add("secured", "hidden", array(
"constraints" => array(new Type([ 'type' => 'bool'])),
'required' => false,
'data' => false,
))
->add("locale", "hidden", array())
->add("title", "text", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans('Title'),
"label_attr" => array(
"for" => "title",
"help" => Translator::getInstance()->trans("This is the message purpose, such as 'Order confirmation'."),
),
'attr' => [
"placeholder" => Translator::getInstance()->trans('Title'),
],
))
->add("subject", "text", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans('Message subject'),
"label_attr" => array(
"for" => "subject",
"help" => Translator::getInstance()->trans("This is the subject of the e-mail, such as 'Your order is confirmed'."),
),
'attr' => [
"placeholder" => Translator::getInstance()->trans('Message subject'),
],
))
->add("html_message", "text", array(
"label" => Translator::getInstance()->trans('HTML Message'),
"label_attr" => array(
"for" => "html_message",
"help" => Translator::getInstance()->trans("The mailing template in HTML format."),
),
"required" => false,
))
->add("text_message", "textarea", array(
"label" => Translator::getInstance()->trans('Text Message'),
"label_attr" => array(
"for" => "text_message",
"help" => Translator::getInstance()->trans("The mailing template in text-only format."),
),
'required' => false,
))
->add("html_layout_file_name", "text", array(
"label" => Translator::getInstance()->trans('Name of the HTML layout file'),
"label_attr" => array(
"for" => "html_layout_file_name",
),
"required" => false,
))
->add("html_template_file_name", "text", array(
"label" => Translator::getInstance()->trans('Name of the HTML template file'),
"label_attr" => array(
"for" => "html_template_file_name",
),
"required" => false,
))
->add("text_layout_file_name", "text", array(
"label" => Translator::getInstance()->trans('Name of the text layout file'),
"label_attr" => array(
"for" => "text_layout_file_name",
),
"required" => false,
))
->add("text_template_file_name", "text", array(
"label" => Translator::getInstance()->trans('Name of the text template file'),
"label_attr" => array(
"for" => "text_template_file_name",
),
"required" => false,
))
;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class MessageSendSampleForm extends BaseForm
{
public function getName()
{
return "thelia_message_send_sample";
}
protected function buildForm()
{
$this->formBuilder
->add(
"recipient_email",
"email",
[
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans('Send test e-mail to:'),
"attr" => [
'placeholder' => Translator::getInstance()->trans('Recipient e-mail address')
]
]
);
;
}
}

View File

@@ -0,0 +1,245 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Hook\BaseHook;
use Thelia\Core\Translation\Translator;
use Thelia\Model\Base\ModuleHookQuery;
use Thelia\Model\Hook;
use Thelia\Model\HookQuery;
use Thelia\Model\IgnoredModuleHookQuery;
use Thelia\Model\Module;
use Thelia\Model\ModuleQuery;
/**
* Class HookCreationForm
* @package Thelia\Form
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
class ModuleHookCreationForm extends BaseForm
{
/** @var Translator */
protected $translator;
protected function buildForm()
{
$this->formBuilder
->add(
"module_id",
"choice",
array(
"choices" => $this->getModuleChoices(),
"constraints" => array(
new NotBlank(),
),
"label" => $this->trans("Module"),
"label_attr" => array(
"for" => "module_id",
"help" => $this->trans(
"Only hookable modules are displayed in this menu."
),
),
)
)
->add(
"hook_id",
"choice",
array(
"choices" => $this->getHookChoices(),
"constraints" => array(
new NotBlank(),
),
"label" => $this->trans("Hook"),
"label_attr" => array("for" => "hook_id"),
)
)
->add(
"classname",
"text",
array(
"constraints" => array(
new NotBlank(),
),
"label" => $this->trans("Service ID"),
"label_attr" => array(
"for" => "classname",
"help" => $this->trans(
"The service id that will handle the hook (defined in the config.xml file of the module)."
),
),
)
)
->add(
"method",
"text",
array(
"label" => $this->trans("Method Name"),
"constraints" => array(
new NotBlank(),
new Callback(
array(
"methods" => array(
array($this, "verifyMethod"),
),
)
),
),
"label_attr" => array(
"for" => "method",
"help" => $this->trans(
"The method name that will handle the hook event."
),
),
)
)
->add(
"templates",
"text",
array(
"label" => $this->trans("Automatic rendered templates"),
"constraints" => array(
new Callback(
array(
"methods" => array(
array($this, "verifyTemplates"),
),
)
),
),
"label_attr" => array(
"for" => "templates",
"help" => $this->trans(
"When using the %method% method you can automatically render or dump templates or add CSS and JS files (e.g.: render:mytemplate.html;js:assets/js/myjs.js)",
["%method%" => BaseHook::INJECT_TEMPLATE_METHOD_NAME]
),
),
"required" => false
)
)
;
}
protected function trans($id, $parameters = [])
{
if (null === $this->translator) {
$this->translator = Translator::getInstance();
}
return $this->translator->trans($id, $parameters);
}
protected function getModuleChoices()
{
$choices = array();
$modules = ModuleQuery::getActivated();
/** @var Module $module */
foreach ($modules as $module) {
// Check if module defines a hook ID
if (ModuleHookQuery::create()->filterByModuleId($module->getId())->count() > 0
||
IgnoredModuleHookQuery::create()->filterByModuleId($module->getId())->count() > 0
) {
$choices[$module->getId()] = $module->getTitle();
}
}
asort($choices);
return $choices;
}
protected function getHookChoices()
{
$choices = array();
$hooks = HookQuery::create()
->filterByActivate(true, Criteria::EQUAL)
->joinWithI18n($this->translator->getLocale())
->orderBy('HookI18n.title', Criteria::ASC)
->find();
/** @var Hook $hook */
foreach ($hooks as $hook) {
$choices[$hook->getId()] = $hook->getTitle().' (code '.$hook->getCode().')';
}
return $choices;
}
/**
*
* Check if method has a valid signature.
* See RegisterListenersPass::isValidHookMethod for implementing this verification
*
* @param $value
* @param ExecutionContextInterface $context
* @return bool
*/
public function verifyMethod($value, ExecutionContextInterface $context)
{
if (! $this->hasContainer()) {
return true;
}
$data = $context->getRoot()->getData();
if (null === $service = $this->container->get($data["classname"])) {
return true;
}
if (!method_exists($service, $data['method'])) {
$context->addViolation(
$this->trans(
"The method %method% doesn't exist in classname %classname%",
[
'%method%' => $data['method'],
'%classname%' => $data['classname']
]
)
);
}
}
/**
* Check if method is the right one if we want to use automatic inserted templates .
*
* @param $value
* @param ExecutionContextInterface $context
*
* @return bool
*/
public function verifyTemplates($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if (!empty($data['templates']) && $data['method'] !== BaseHook::INJECT_TEMPLATE_METHOD_NAME) {
$context->addViolation(
$this->trans(
"If you use automatic insert templates, you should use the method %method%",
[
'%method%' => BaseHook::INJECT_TEMPLATE_METHOD_NAME
]
)
);
}
}
public function getName()
{
return "thelia_module_hook_creation";
}
}

View File

@@ -0,0 +1,45 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Thelia\Core\Translation\Translator;
/**
* Class HookModificationForm
* @package Thelia\Form
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
class ModuleHookModificationForm extends ModuleHookCreationForm
{
protected function buildForm()
{
parent::buildForm();
$this->formBuilder
->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))
->add("active", "checkbox", array(
"label" => Translator::getInstance()->trans("Active"),
"required" => false,
"label_attr" => array(
"for" => "active",
),
))
;
}
public function getName()
{
return "thelia_module_hook_modification";
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Thelia\Form\Image\ImageModification;
class ModuleImageModification extends ImageModification
{
/**
* Get form name
* This name must be unique
*
* @return string
*/
public function getName()
{
return 'thelia_module_image_modification';
}
}

View File

@@ -0,0 +1,193 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Exception;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Archiver\Archiver\ZipArchiver;
use Thelia\Core\Translation\Translator;
use Thelia\Module\Validator\ModuleDefinition;
use Thelia\Module\Validator\ModuleValidator;
/**
* Class ProductCreationForm
* @package Thelia\Form
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
class ModuleInstallForm extends BaseForm
{
/** @var ModuleDefinition */
protected $moduleDefinition = null;
protected $modulePath = null;
protected function buildForm($change_mode = false)
{
$this->formBuilder
->add(
'module',
'file',
[
'required' => true,
'constraints' => [
new Constraints\File(
[
'mimeTypes' => [
'application/zip',
],
'mimeTypesMessage' => Translator::getInstance()->trans('Please upload a valid Zip file'),
]
),
new Constraints\Callback([
"methods" => [
[$this, "checkModuleValidity"],
],
]),
],
'label' => Translator::getInstance()->trans('The module zip file'),
'label_attr' => [
'for' => 'module',
]
]
);
}
/**
* Check module validity
*
* @param UploadedFile $file
* @param ExecutionContextInterface $context
*/
public function checkModuleValidity(UploadedFile $file, ExecutionContextInterface $context)
{
$modulePath = $this->unzipModule($file);
if ($modulePath !== false) {
try {
// get the first directory
$moduleFiles = $this->getDirContents($modulePath);
if (count($moduleFiles['directories']) !== 1) {
throw new Exception(
Translator::getInstance()->trans(
"Your zip must contain 1 root directory which is the root folder directory of your module"
)
);
}
$moduleDirectory = $moduleFiles['directories'][0];
$this->modulePath = sprintf('%s/%s', $modulePath, $moduleDirectory);
$moduleValidator = new ModuleValidator($this->modulePath);
$moduleValidator->validate();
$this->moduleDefinition = $moduleValidator->getModuleDefinition();
} catch (Exception $ex) {
$context->addViolation(
Translator::getInstance()->trans(
"The module is not valid : %message",
['%message' => $ex->getMessage()]
)
);
}
}
}
public function getModuleDefinition()
{
return $this->moduleDefinition;
}
/**
* @return string|null
*/
public function getModulePath()
{
return $this->modulePath;
}
/**
* Unzip a module file.
*
* @param UploadedFile $file
*
* @return string|bool the path where the module has been extracted or false if an error has occured
*/
protected function unzipModule(UploadedFile $file)
{
$extractPath = false;
$zip = new ZipArchiver(true);
if (!$zip->open($file->getRealPath())) {
throw new \Exception("unable to open zipfile");
}
$extractPath = $this->tempdir();
if ($extractPath !== false) {
if ($zip->extract($extractPath) === false) {
$extractPath = false;
}
}
$zip->close();
return $extractPath;
}
/**
* create a unique directory.
*
* @return bool|string the directory path or false if it fails
*/
protected function tempdir()
{
$tempfile = tempnam(sys_get_temp_dir(), '');
if (file_exists($tempfile)) {
unlink($tempfile);
}
mkdir($tempfile);
if (is_dir($tempfile)) {
return $tempfile;
}
return false;
}
protected function getDirContents($dir)
{
$paths = array_diff(scandir($dir), ['..', '.']);
$out = [
'directories' => [],
'files' => [],
];
foreach ($paths as $path) {
if (is_dir($dir.DS.$path)) {
$out['directories'][] = $path;
} else {
$out['files'][] = $path;
}
}
return $out;
}
public function getName()
{
return "module_install";
}
}

View File

@@ -0,0 +1,65 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ModuleQuery;
class ModuleModificationForm extends BaseForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
$this->addStandardDescFields();
$this->formBuilder
->add("id", "hidden", array(
"required" => true,
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(
array(
"methods" => array(
array($this, "verifyModuleId"),
),
)
),
),
"attr" => array(
"id" => "module_update_id",
),
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_admin_module_modification";
}
public function verifyModuleId($value, ExecutionContextInterface $context)
{
$module = ModuleQuery::create()
->findPk($value);
if (null === $module) {
$context->addViolation(Translator::getInstance()->trans("Module ID not found"));
}
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\NewsletterQuery;
/**
* Class NewsletterForm
* @package Thelia\Form
* @author Manuel Raynaud <manu@raynaud.io>
*/
class NewsletterForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add('email', 'email', array(
'constraints' => array(
new NotBlank(),
new Email(),
new Callback(array(
"methods" => array(
array($this,
"verifyExistingEmail", ),
),
)),
),
'label' => Translator::getInstance()->trans('Email address'),
'label_attr' => array(
'for' => 'email_newsletter',
),
))
->add('firstname', 'text', array(
'label' => Translator::getInstance()->trans('Firstname'),
'label_attr' => array(
'for' => 'firstname_newsletter',
),
))
->add('lastname', 'text', array(
'label' => Translator::getInstance()->trans('Lastname'),
'label_attr' => array(
'for' => 'lastname_newsletter',
),
));
}
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$customer = NewsletterQuery::create()->filterByUnsubscribed(false)->findOneByEmail($value);
if ($customer) {
$context->addViolation(Translator::getInstance()->trans("You are already registered!"));
}
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_newsletter';
}
}

View File

@@ -0,0 +1,62 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\NewsletterQuery;
/**
* Class NewsletterForm
* @package Thelia\Form
* @author Manuel Raynaud <manu@raynaud.io>
*/
class NewsletterUnsubscribeForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add('email', 'email', array(
'constraints' => array(
new NotBlank(),
new Email(),
new Callback(array(
"methods" => array(
array($this,
"verifyExistingEmail", ),
),
)),
),
'label' => Translator::getInstance()->trans('Email address'),
'label_attr' => array(
'for' => 'email_newsletter',
),
))
;
}
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
if (null === NewsletterQuery::create()->filterByUnsubscribed(false)->findOneByEmail($value)) {
$context->addViolation(
Translator::getInstance()->trans(
"The email address \"%mail\" was not found.",
[ '%mail' => $value ]
)
);
}
}
}

Some files were not shown because too many files have changed in this diff Show More