Merge with master

This commit is contained in:
touffies
2013-10-24 16:52:03 +02:00
741 changed files with 169402 additions and 4971 deletions

View File

@@ -0,0 +1,138 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Translation\Translator;
use Thelia\Model\AdminQuery;
use Thelia\Model\ProfileQuery;
use Thelia\Model\ConfigQuery;
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" => Translator::getInstance()->trans("Login"),
"label_attr" => array(
"for" => "login"
),
))
->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("password", "password", array(
"constraints" => array(),
"label" => Translator::getInstance()->trans("Password"),
"label_attr" => array(
"for" => "password"
),
))
->add("password_confirm", "password", array(
"constraints" => array(
new Constraints\Callback(array("methods" => array(
array($this, "verifyPasswordField")
)))
),
"label" => "Password confirmation",
"label_attr" => array(
"for" => "password_confirmation"
),
))
->add(
'profile',
"choice",
array(
"choices" => ProfileQuery::getProfileList(),
"constraints" => array(
new Constraints\NotBlank(),
),
"label" => "Profile",
"label_attr" => array(
"for" => "profile"
),
)
)
;
}
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");
}
if(strlen($data["password"]) < 4) {
$context->addViolation("password must be composed of at least 4 characters");
}
}
public function verifyExistingLogin($value, ExecutionContextInterface $context)
{
$administrator = AdminQuery::create()->findOneByLogin($value);
if ($administrator !== null) {
$context->addViolation("This login already exists");
}
}
public function getName()
{
return "thelia_admin_administrator_creation";
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\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",
),
))
;
}
/**
* @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("Administrator ID not found");
}
}
public function verifyExistingLogin($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
$administrator = AdminQuery::create()->findOneByLogin($value);
if ($administrator !== null && $administrator->getId() != $data['id']) {
$context->addViolation("This login already exists");
}
}
public function verifyPasswordField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["password"] != $data["password_confirm"]) {
$context->addViolation("password confirmation is not the same as password field");
}
if($data["password"] !== '' && strlen($data["password"]) < 4) {
$context->addViolation("password must be composed of at least 4 characters");
}
}
}

View File

@@ -1,7 +1,7 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
@@ -17,49 +17,47 @@
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ModuleQuery;
use Thelia\Module\BaseModule;
class AdminProfileCreationForm extends BaseForm
/**
* 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("wording" , "text" , array(
->add("coupon-code", "text", array(
"required" => true,
"constraints" => array(
new NotBlank()
),
"label" => Translator::getInstance()->trans("Wording *"),
"label_attr" => array(
"for" => "wording"
))
new Constraints\NotBlank(),
)
)
->add("name" , "text" , array(
"constraints" => array(
new NotBlank()
),
"label" => Translator::getInstance()->trans("Name *"),
"label_attr" => array(
"for" => "name"
))
)
->add("description" , "text" , array(
"label" => Translator::getInstance()->trans("Description"),
"label_attr" => array(
"for" => "description"
))
)
;
);
}
/**
* Form name
*
* @return string
*/
public function getName()
{
return "thelia_admin_profile_creation";
return "thelia_coupon_code";
}
}
}

View File

@@ -27,6 +27,7 @@ use Symfony\Component\Validator\Constraints\Date;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotEqualTo;
use Symfony\Component\Validator\Constraints\Range;
/**
* Created by JetBrains PhpStorm.
@@ -109,7 +110,7 @@ class CouponCreationForm extends BaseForm
)
->add(
'isEnabled',
'checkbox',
'text',
array()
)
->add(
@@ -124,17 +125,17 @@ class CouponCreationForm extends BaseForm
)
->add(
'isCumulative',
'checkbox',
'text',
array()
)
->add(
'isRemovingPostage',
'checkbox',
'text',
array()
)
->add(
'isAvailableOnSpecialOffers',
'checkbox',
'text',
array()
)
->add(

View File

@@ -0,0 +1,116 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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 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_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'
)
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'thelia_language_create';
}
}

View File

@@ -0,0 +1,85 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form\Lang;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Range;
use Thelia\Form\BaseForm;
use Thelia\Core\Translation\Translator;
/**
* Class LangDefaultBehaviorForm
* @package Thelia\Form\Lang
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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

@@ -20,39 +20,35 @@
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
namespace Thelia\Form\Lang;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class LanguageCreationForm extends BaseForm
/**
* Class LangUpdateForm
* @package Thelia\Form\Lang
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class LangUpdateForm extends LangCreateForm
{
protected function buildForm()
public function buildForm()
{
parent::buildForm();
$this->formBuilder
->add("title", "text", array(
"constraints" => array(
new NotBlank()
),
"label" => Translator::getInstance()->trans("Language title *"),
"label_attr" => array(
"for" => "title"
->add('id', 'hidden', array(
'constraints' => array(
new NotBlank(),
new GreaterThan(array('value' => 0))
)
))
->add("isocode", "text", array(
"constraints" => array(
new NotBlank()
),
"label" => Translator::getInstance()->trans("ISO Code *"),
"label_attr" => array(
"for" => "isocode"
)
))
;
));
}
public function getName()
{
return "thelia_language_creation";
return 'thelia_lang_update';
}
}
}

View File

@@ -0,0 +1,46 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form\Lang;
use Thelia\Core\Event\ActionEvent;
/**
* Class LangUrlEvent
* @package Thelia\Form\Lang
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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,87 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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,31 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
class ProductDefaultSaleElementUpdateForm extends ProductSaleElementUpdateForm
{
public function getName()
{
return "thelia_product_default_sale_element_update_form";
}
}

View File

@@ -25,28 +25,33 @@ namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Thelia\Core\Translation\Translator;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Model\Currency;
class ProductDetailsModificationForm extends BaseForm
class ProductSaleElementUpdateForm extends BaseForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
$this->formBuilder
->add("id", "integer", array(
"label" => Translator::getInstance()->trans("Prodcut ID *"),
"label_attr" => array("for" => "product_id_field"),
"constraints" => array(new GreaterThan(array('value' => 0)))
->add("product_id", "integer", array(
"label" => Translator::getInstance()->trans("Product ID *"),
"label_attr" => array("for" => "product_id_field"),
"constraints" => array(new GreaterThan(array('value' => 0)))
))
->add("product_sale_element_id", "integer", array(
"label" => Translator::getInstance()->trans("Product sale element ID *"),
"label_attr" => array("for" => "product_sale_element_id_field")
))
->add("reference", "text", array(
"label" => Translator::getInstance()->trans("Reference *"),
"label_attr" => array("for" => "reference_field")
))
->add("price", "number", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Product base price excluding taxes *"),
"label" => Translator::getInstance()->trans("Product price excluding taxes *"),
"label_attr" => array("for" => "price_field")
))
->add("price_with_tax", "number", array(
"label" => Translator::getInstance()->trans("Product base price including taxes *"),
"label_attr" => array("for" => "price_with_tax_field")
))
->add("currency", "integer", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Price currency *"),
@@ -64,11 +69,11 @@ class ProductDetailsModificationForm extends BaseForm
))
->add("quantity", "number", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Current quantity *"),
"label" => Translator::getInstance()->trans("Available quantity *"),
"label_attr" => array("for" => "quantity_field")
))
->add("sale_price", "number", array(
"label" => Translator::getInstance()->trans("Sale price *"),
"label" => Translator::getInstance()->trans("Sale price without taxes *"),
"label_attr" => array("for" => "price_with_tax_field")
))
->add("onsale", "integer", array(
@@ -79,12 +84,23 @@ class ProductDetailsModificationForm extends BaseForm
"label" => Translator::getInstance()->trans("Advertise this product as new"),
"label_attr" => array("for" => "isnew_field")
))
->add("isdefault", "integer", array(
"label" => Translator::getInstance()->trans("Is it the default product sale element ?"),
"label_attr" => array("for" => "isdefault_field")
))
->add("ean_code", "integer", array(
"label" => Translator::getInstance()->trans("EAN Code"),
"label_attr" => array("for" => "ean_code_field")
))
->add("use_exchange_rate", "integer", array(
"label" => Translator::getInstance()->trans("Apply exchange rates on price in %sym", array("%sym" => Currency::getDefaultCurrency()->getSymbol())),
"label_attr" => array("for" => "use_exchange_rate_field")
))
;
}
public function getName()
{
return "thelia_product_details_modification";
return "thelia_product_sale_element_update_form";
}
}

View File

@@ -0,0 +1,98 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ProfileQuery;
use Thelia\Model\ModuleQuery;
/**
* Class ProfileUpdateModuleAccessForm
* @package Thelia\Form
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class ProfileUpdateModuleAccessForm extends BaseForm
{
const MODULE_ACCESS_FIELD_PREFIX = "module";
protected function buildForm($change_mode = false)
{
$this->formBuilder
->add("id", "hidden", array(
"required" => true,
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(
array(
"methods" => array(
array($this, "verifyProfileId"),
),
)
),
)
))
;
foreach(ModuleQuery::create()->find() as $module) {
$this->formBuilder->add(
self::MODULE_ACCESS_FIELD_PREFIX . ':' . str_replace(".", ":", $module->getCode()),
"choice",
array(
"choices" => array(
AccessManager::VIEW => AccessManager::VIEW,
AccessManager::CREATE => AccessManager::CREATE,
AccessManager::UPDATE => AccessManager::UPDATE,
AccessManager::DELETE => AccessManager::DELETE,
),
"attr" => array(
"tag" => "modules",
"module_code" => $module->getCode(),
),
"multiple" => true,
"constraints" => array(
)
)
);
}
}
public function getName()
{
return "thelia_profile_module_access_modification";
}
public function verifyProfileId($value, ExecutionContextInterface $context)
{
$profile = ProfileQuery::create()
->findPk($value);
if (null === $profile) {
$context->addViolation("Profile ID not found");
}
}
}

View File

@@ -0,0 +1,98 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ProfileQuery;
use Thelia\Model\ResourceQuery;
/**
* Class ProfileUpdateResourceAccessForm
* @package Thelia\Form
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class ProfileUpdateResourceAccessForm extends BaseForm
{
const RESOURCE_ACCESS_FIELD_PREFIX = "resource";
protected function buildForm($change_mode = false)
{
$this->formBuilder
->add("id", "hidden", array(
"required" => true,
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(
array(
"methods" => array(
array($this, "verifyProfileId"),
),
)
),
)
))
;
foreach(ResourceQuery::create()->find() as $resource) {
$this->formBuilder->add(
self::RESOURCE_ACCESS_FIELD_PREFIX . ':' . str_replace(".", ":", $resource->getCode()),
"choice",
array(
"choices" => array(
AccessManager::VIEW => AccessManager::VIEW,
AccessManager::CREATE => AccessManager::CREATE,
AccessManager::UPDATE => AccessManager::UPDATE,
AccessManager::DELETE => AccessManager::DELETE,
),
"attr" => array(
"tag" => "resources",
"resource_code" => $resource->getCode(),
),
"multiple" => true,
"constraints" => array(
)
)
);
}
}
public function getName()
{
return "thelia_profile_resource_access_modification";
}
public function verifyProfileId($value, ExecutionContextInterface $context)
{
$profile = ProfileQuery::create()
->findPk($value);
if (null === $profile) {
$context->addViolation("Profile ID not found");
}
}
}