From 7e081d99e497eb03ddd34f280072a8d0401c52d8 Mon Sep 17 00:00:00 2001 From: mespeche Date: Fri, 20 Sep 2013 16:10:53 +0200 Subject: [PATCH 01/94] Creation of mailing system configuration variables management view --- .../Thelia/Config/Resources/routing/admin.xml | 7 ++ .../Admin/MailingSystemController.php | 39 +++++++ templates/admin/default/mailing-system.html | 102 ++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 core/lib/Thelia/Controller/Admin/MailingSystemController.php create mode 100644 templates/admin/default/mailing-system.html diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 4d176d2fc..6d3d80942 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -529,6 +529,13 @@ + + + + Thelia\Controller\Admin\MailingSystemController::defaultAction + + + diff --git a/core/lib/Thelia/Controller/Admin/MailingSystemController.php b/core/lib/Thelia/Controller/Admin/MailingSystemController.php new file mode 100644 index 000000000..89defe01d --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/MailingSystemController.php @@ -0,0 +1,39 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Admin; + +/** + * Class MailingSystemController + * @package Thelia\Controller\Admin + * @author Manuel Raynaud + */ +class MailingSystemController extends BaseAdminController +{ + public function defaultAction() + { + if (null !== $response = $this->checkAuth("admin.configuration.mailing-system.view")) return $response; + return $this->render("mailing-system"); + } + +} \ No newline at end of file diff --git a/templates/admin/default/mailing-system.html b/templates/admin/default/mailing-system.html new file mode 100644 index 000000000..a3be96084 --- /dev/null +++ b/templates/admin/default/mailing-system.html @@ -0,0 +1,102 @@ +{extends file="admin-layout.tpl"} + +{block name="page-title"}{intl l='Thelia Mailing System'}{/block} + +{block name="check-permissions"}admin.configuration.mailing-system.view{/block} + +{block name="main-content"} +
+ +
+ + + + {module_include location='mailing_system_top'} + +
+
+
+ +
{intl l="Configuration variables"}
+ +
+ +
+ +
+ + + + +
+
+ +
+ +
+ + + + +
+
+ +
+ +
+ + + + +
+
+ +
+ +
+ + + + +
+
+ +
+ +
+ + + + +
+
+ +
+ + +
+ +
+
+ +
+ +
+
+
+ + {module_include location='mailing_system_bottom'} + +
+
+{/block} + +{block name="javascript-initialization"} + {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} + + {/javascripts} +{/block} \ No newline at end of file From eab7cd9fa8ef6fda240452b6dde450226d990e6b Mon Sep 17 00:00:00 2001 From: mespeche Date: Fri, 20 Sep 2013 16:12:49 +0200 Subject: [PATCH 02/94] Password type on password field --- templates/admin/default/mailing-system.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/admin/default/mailing-system.html b/templates/admin/default/mailing-system.html index a3be96084..4f826e954 100644 --- a/templates/admin/default/mailing-system.html +++ b/templates/admin/default/mailing-system.html @@ -58,7 +58,7 @@
- + From 0eabcb4f28b3296bf5a5f43576055574883341d0 Mon Sep 17 00:00:00 2001 From: mespeche Date: Mon, 23 Sep 2013 09:55:54 +0200 Subject: [PATCH 03/94] Setting languages view and route --- .../Thelia/Config/Resources/routing/admin.xml | 8 + .../Controller/Admin/LanguageController.php | 39 +++ templates/admin/default/languages.html | 224 ++++++++++++++++++ 3 files changed, 271 insertions(+) create mode 100644 core/lib/Thelia/Controller/Admin/LanguageController.php create mode 100644 templates/admin/default/languages.html diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 6d3d80942..180077a4c 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -535,6 +535,14 @@ Thelia\Controller\Admin\MailingSystemController::defaultAction + + + + + + Thelia\Controller\Admin\LanguageController::defaultAction + + diff --git a/core/lib/Thelia/Controller/Admin/LanguageController.php b/core/lib/Thelia/Controller/Admin/LanguageController.php new file mode 100644 index 000000000..aa818daad --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/LanguageController.php @@ -0,0 +1,39 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Admin; + +/** + * Class LanguageController + * @package Thelia\Controller\Admin + * @author Manuel Raynaud + */ +class LanguageController extends BaseAdminController +{ + public function defaultAction() + { + if (null !== $response = $this->checkAuth("admin.configuration.languages.view")) return $response; + return $this->render("languages"); + } + +} \ No newline at end of file diff --git a/templates/admin/default/languages.html b/templates/admin/default/languages.html new file mode 100644 index 000000000..1a11b9537 --- /dev/null +++ b/templates/admin/default/languages.html @@ -0,0 +1,224 @@ +{extends file="admin-layout.tpl"} + +{block name="page-title"}{intl l='Thelia Languages'}{/block} + +{block name="check-permissions"}admin.configuration.languages.view{/block} + +{block name="main-content"} +
+ +
+ + + + {module_include location='languages_top'} + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {intl l="Languages management"} + {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.configuration.languages.create"} + + + + {/loop} + +
{intl l="Language name"}{intl l="ISO 639 Code"}{intl l="Default"}{intl l="Actions"}
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
{intl l="Parameters"}
+ +
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+
+
+ +
{intl l="Association language/URL"}
+ +
+
+
+ + +
+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
{intl l="France"}
{intl l="English"}
{intl l="Spanish"}
+ +
+
+
+ +
+
+
+ + {module_include location='languages_bottom'} + +
+
+ +{* Delete confirmation dialog *} + +{capture "delete_dialog"} + + + {module_include location='languages_delete_form'} + +{/capture} + +{include + file = "includes/generic-confirm-dialog.html" + + dialog_id = "delete_dialog" + dialog_title = {intl l="Delete language"} + dialog_message = {intl l="Do you really want to delete this language ?"} + + form_action = {url path='/admin/configuration/languages/delete'} + form_content = {$smarty.capture.delete_dialog nofilter} +} + +{/block} + +{block name="javascript-initialization"} + {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} + + + + {/javascripts} + + {javascripts file='assets/js/main.js'} + + {/javascripts} + + {javascripts file='assets/js/bootstrap-select/bootstrap-select.js'} + + {/javascripts} +{/block} \ No newline at end of file From 44dc4dbcc853b2085ef11c5195d48015d3e77e69 Mon Sep 17 00:00:00 2001 From: mespeche Date: Mon, 23 Sep 2013 10:22:14 +0200 Subject: [PATCH 04/94] Setting creation form language --- core/lib/Thelia/Config/Resources/config.xml | 2 + core/lib/Thelia/Form/LanguageCreationForm.php | 58 +++++++++++++++++++ templates/admin/default/languages.html | 50 +++++++++++++++- 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 core/lib/Thelia/Form/LanguageCreationForm.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 876814d5d..3857b0a4b 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -103,6 +103,8 @@
+ + diff --git a/core/lib/Thelia/Form/LanguageCreationForm.php b/core/lib/Thelia/Form/LanguageCreationForm.php new file mode 100644 index 000000000..713cafcd9 --- /dev/null +++ b/core/lib/Thelia/Form/LanguageCreationForm.php @@ -0,0 +1,58 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Translation\Translator; + +class LanguageCreationForm extends BaseForm +{ + protected function buildForm() + { + $this->formBuilder + ->add("title", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => Translator::getInstance()->trans("Language title *"), + "label_attr" => array( + "for" => "title" + ) + )) + ->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"; + } +} diff --git a/templates/admin/default/languages.html b/templates/admin/default/languages.html index 1a11b9537..499e903d7 100644 --- a/templates/admin/default/languages.html +++ b/templates/admin/default/languages.html @@ -180,10 +180,58 @@
+{form name="thelia.admin.language.creation"} + + {* Capture the dialog body, to pass it to the generic dialog *} + {capture "creation_dialog"} + + {form_hidden_fields form=$form} + + {* Be sure to get the language_id, even if the form could not be validated *} + + + {form_field form=$form field='success_url'} + {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} + + {/form_field} + + {form_field form=$form field='title'} +
+ + +
+ {/form_field} + + {form_field form=$form field='isocode'} +
+ + +
+ {/form_field} + + {module_include location='language_create_form'} + + {/capture} + + {include + file = "includes/generic-create-dialog.html" + + dialog_id = "creation_dialog" + dialog_title = {intl l="Create a new language"} + dialog_body = {$smarty.capture.creation_dialog nofilter} + + dialog_ok_label = {intl l="Create this language"} + + form_action = {url path='/admin/configuration/languages/create'} + form_enctype = {form_enctype form=$form} + form_error_message = $form_error_message + } +{/form} + {* Delete confirmation dialog *} {capture "delete_dialog"} - + {module_include location='languages_delete_form'} From 1f54a288fce6c9994417eb93495dd9ae2eeb9f71 Mon Sep 17 00:00:00 2001 From: mespeche Date: Tue, 24 Sep 2013 09:36:48 +0200 Subject: [PATCH 05/94] Setting admin profile creation (route, view, form) --- core/lib/Thelia/Config/Resources/config.xml | 2 + .../Thelia/Config/Resources/routing/admin.xml | 9 + .../Admin/AdminProfileController.php | 39 ++++ .../Thelia/Form/AdminProfileCreationForm.php | 65 ++++++ templates/admin/default/admin-profiles.html | 219 ++++++++++++++++++ 5 files changed, 334 insertions(+) create mode 100644 core/lib/Thelia/Controller/Admin/AdminProfileController.php create mode 100644 core/lib/Thelia/Form/AdminProfileCreationForm.php create mode 100644 templates/admin/default/admin-profiles.html diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 3857b0a4b..6731152c4 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -106,6 +106,8 @@ + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 180077a4c..e6a545297 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -545,6 +545,15 @@ + + + + Thelia\Controller\Admin\AdminProfileController::defaultAction + + + + + diff --git a/core/lib/Thelia/Controller/Admin/AdminProfileController.php b/core/lib/Thelia/Controller/Admin/AdminProfileController.php new file mode 100644 index 000000000..91f3f2031 --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/AdminProfileController.php @@ -0,0 +1,39 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Admin; + +/** + * Class AdminProfileController + * @package Thelia\Controller\Admin + * @author Manuel Raynaud + */ +class AdminProfileController extends BaseAdminController +{ + public function defaultAction() + { + if (null !== $response = $this->checkAuth("admin.admin-profile.view")) return $response; + return $this->render("admin-profiles", array("display_admin_profile" => 20)); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Form/AdminProfileCreationForm.php b/core/lib/Thelia/Form/AdminProfileCreationForm.php new file mode 100644 index 000000000..34ce7556b --- /dev/null +++ b/core/lib/Thelia/Form/AdminProfileCreationForm.php @@ -0,0 +1,65 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Translation\Translator; + +class AdminProfileCreationForm extends BaseForm +{ + protected function buildForm() + { + $this->formBuilder + ->add("wording" , "text" , array( + "constraints" => array( + new NotBlank() + ), + "label" => Translator::getInstance()->trans("Wording *"), + "label_attr" => array( + "for" => "wording" + )) + ) + ->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" + )) + ) + ; + } + + public function getName() + { + return "thelia_admin_profile_creation"; + } +} \ No newline at end of file diff --git a/templates/admin/default/admin-profiles.html b/templates/admin/default/admin-profiles.html new file mode 100644 index 000000000..b0d84b04a --- /dev/null +++ b/templates/admin/default/admin-profiles.html @@ -0,0 +1,219 @@ +{extends file="admin-layout.tpl"} + +{block name="page-title"}{intl l='Admin profiles'}{/block} + +{block name="check-permissions"}admin.admin-profiles.view{/block} + +{block name="main-content"} +
+ +
+ +
+ + {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.admin-profiles.create"} + + + + {/loop} +
+ + {module_include location='admin_profiles_top'} + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {intl l="Profile"} +
+ +
+
+ + +
+
+ +
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {intl l="General rights"} +
{intl l="Authorization"}{intl l="Description"}{intl l="Access"}
Access to customers + Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur, saepe, libero, veniam ab quod. + +
+ +
+
Access to orders + Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur, saepe, libero, veniam ab quod. + +
+ +
+
Access to catalog + Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur, saepe, libero, veniam ab quod. + +
+ +
+
+ +
+
+
+
+
+
+ + {module_include location='admin_profiles_bottom'} + +
+
+ +{* Creation dialog *} + +{form name="thelia.admin.admin-profile.creation"} + + {* Capture the dialog body, to pass it to the generic dialog *} + {capture "creation_dialog"} + + {form_hidden_fields form=$form} + + {* Be sure to get the language_id, even if the form could not be validated *} + + + {form_field form=$form field='success_url'} + {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} + + {/form_field} + + {form_field form=$form field='wording'} +
+ + +
+ {/form_field} + + {form_field form=$form field='name'} +
+ + +
+ {/form_field} + + {form_field form=$form field='description'} +
+ + +
+ {/form_field} + + {module_include location='admin_profile_create_form'} + + {/capture} + + {include + file = "includes/generic-create-dialog.html" + + dialog_id = "creation_dialog" + dialog_title = {intl l="Create a new admin profile"} + dialog_body = {$smarty.capture.creation_dialog nofilter} + + dialog_ok_label = {intl l="Create this admin profile"} + + form_action = {url path='/admin/configuration/admin_profile/create'} + form_enctype = {form_enctype form=$form} + form_error_message = $form_error_message + } +{/form} + +{/block} + +{block name="javascript-initialization"} + + {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} + + {/javascripts} + + {javascripts file='assets/js/bootstrap-select/bootstrap-select.js'} + + {/javascripts} + + {javascripts file='assets/js/main.js'} + + {/javascripts} +{/block} \ No newline at end of file From cf8af9c1bba05bc3578e1ffbe6822859286501f3 Mon Sep 17 00:00:00 2001 From: mespeche Date: Tue, 24 Sep 2013 09:41:15 +0200 Subject: [PATCH 06/94] Setting dropdown menu on orders item --- templates/admin/default/admin-layout.tpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/admin/default/admin-layout.tpl b/templates/admin/default/admin-layout.tpl index 553466def..bf2e1c1ee 100644 --- a/templates/admin/default/admin-layout.tpl +++ b/templates/admin/default/admin-layout.tpl @@ -111,21 +111,21 @@ {/loop} {loop name="menu-auth-order" type="auth" roles="ADMIN" permissions="admin.orders.view"} - + {for $foo=1 to $previousLevel-$LEVEL} + + {/for} {if $CHILD_COUNT > 0 } -
  • {$TITLE} ({$CHILD_COUNT}) - +
  • + {$TITLE} ({$CHILD_COUNT})
      - {else} - -
    • {$TITLE} (0)
    • - {/if} - {assign "previousLevel" $LEVEL} - {/loop} + {else} +
    • {$TITLE} (0)
    • + {/if} + {assign "previousLevel" $LEVEL} + {/loop} + {for $i=$previousLevel to 1 step -1}
    +
  • + {/for} + - \ No newline at end of file + From 9365e9ee3888ca86195378fcee8f6dab506e12ec Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 16 Oct 2013 11:46:30 +0200 Subject: [PATCH 54/94] tax management --- core/lib/Thelia/Core/Form/Type/TheliaType.php | 45 ++++++ .../Thelia/Core/Template/Element/BaseLoop.php | 2 +- .../Core/Template/Smarty/Plugins/Form.php | 135 ++++++++++++++++-- .../Template/Smarty/Plugins/TheliaLoop.php | 2 +- core/lib/Thelia/Form/TaxCreationForm.php | 23 +++ .../TaxType/FeatureSlicePercentTaxType.php | 2 +- .../Thelia/Type/AlphaNumStringListType.php | 10 ++ core/lib/Thelia/Type/AlphaNumStringType.php | 10 ++ core/lib/Thelia/Type/AnyType.php | 10 ++ core/lib/Thelia/Type/BooleanOrBothType.php | 10 ++ core/lib/Thelia/Type/BooleanType.php | 10 ++ core/lib/Thelia/Type/EnumListType.php | 10 ++ core/lib/Thelia/Type/EnumType.php | 10 ++ .../lib/Thelia/Type/FloatToFloatArrayType.php | 10 ++ core/lib/Thelia/Type/FloatType.php | 10 ++ core/lib/Thelia/Type/IntListType.php | 10 ++ .../Thelia/Type/IntToCombinedIntsListType.php | 10 ++ .../Type/IntToCombinedStringsListType.php | 10 ++ core/lib/Thelia/Type/IntType.php | 10 ++ core/lib/Thelia/Type/JsonType.php | 10 ++ core/lib/Thelia/Type/ModelType.php | 10 ++ core/lib/Thelia/Type/ModelValidIdType.php | 19 +++ core/lib/Thelia/Type/TypeInterface.php | 3 + templates/admin/default/tax-edit.html | 24 +++- 24 files changed, 393 insertions(+), 12 deletions(-) create mode 100644 core/lib/Thelia/Core/Form/Type/TheliaType.php diff --git a/core/lib/Thelia/Core/Form/Type/TheliaType.php b/core/lib/Thelia/Core/Form/Type/TheliaType.php new file mode 100644 index 000000000..4820f9b3b --- /dev/null +++ b/core/lib/Thelia/Core/Form/Type/TheliaType.php @@ -0,0 +1,45 @@ +setDefaults(array( + 'instance' => false, + 'type' => false, + 'options' => false, + )); + + $resolver->setAllowedTypes(array( + 'instance' => array('Thelia\Type\TypeInterface'), + )); + } + + /** + * {@inheritdoc} + */ + public function buildView(FormView $view, FormInterface $form, array $options) + { + $view->vars = array_replace($view->vars, array( + 'instance' => $options['instance'], + 'type' => $options['type'], + 'options' => $options['options'], + )); + } + + public function getParent() + { + return 'form'; + } + + public function getName() + { + return 'thelia_type'; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index 5ac23142d..7e803c43a 100755 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -254,7 +254,7 @@ abstract class BaseLoop * * @param $pagination * - * @return mixed + * @return LoopResult */ abstract public function exec(&$pagination); diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 37be09824..7897b74a0 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -22,7 +22,11 @@ /*************************************************************************************/ namespace Thelia\Core\Template\Smarty\Plugins; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; +use Symfony\Component\Form\Extension\Core\View\ChoiceView; use Symfony\Component\Form\FormView; +use Thelia\Core\Form\Type\TheliaType; use Thelia\Form\BaseForm; use Thelia\Core\Template\Element\Exception\ElementNotFoundException; use Symfony\Component\HttpFoundation\Request; @@ -56,6 +60,8 @@ use Thelia\Core\Template\ParserContext; */ class Form extends AbstractSmartyPlugin { + static private $taggedFieldsStack = null; + static private $taggedFieldsStackPosition = null; protected $request; protected $parserContext; @@ -118,11 +124,16 @@ class Form extends AbstractSmartyPlugin $template->assign("value", $fieldValue); + $template->assign("options", $formFieldView->vars); + // If Checkbox input type if ($fieldVars['checked'] !== null) { $this->renderFormFieldCheckBox($template, $formFieldView['checked']); } + //data + $template->assign("data", $fieldVars['data']); + $template->assign("label", $fieldVars["label"]); $template->assign("label_attr", $fieldVars["label_attr"]); @@ -143,18 +154,51 @@ class Form extends AbstractSmartyPlugin $template->assign("attr", implode(" ", $attr)); } + protected function assignFormTypeValues($template, $formFieldConfig, $formFieldView) + { + $formFieldType = $formFieldConfig->getType()->getInnerType(); + + /* access to choices */ + if($formFieldType instanceof ChoiceType) { + $template->assign("choices", $formFieldView->vars['choices']); + } + + /* access to collections */ + if($formFieldType instanceof CollectionType) { + if( true === $formFieldConfig->getOption('prototype') ) { + + } else { + + } + } + + /* access to thelia type */ + if($formFieldType instanceof TheliaType) { + $template->assign("formType", $formFieldView->vars['type']); + + switch($formFieldView->vars['type']) { + case "choice": + if(!isset($formFieldView->vars['options']['choices']) || !is_array($formFieldView->vars['options']['choices'])) { + //throw new + } + $choices = array(); + foreach($formFieldView->vars['options']['choices'] as $value => $choice) { + $choices[] = new ChoiceView($value, $value, $choice); + } + $template->assign("choices", $choices); + break; + } + } + } + public function renderFormField($params, $content, \Smarty_Internal_Template $template, &$repeat) { - if ($repeat) { + if ($repeat) { - $formFieldView = $this->getFormFieldView($params); + $formFieldView = $this->getFormFieldView($params); + $formFieldConfig = $this->getFormFieldConfig($params); - $template->assign("options", $formFieldView->vars); - - /* access to choices */ - if(isset($formFieldView->vars['choices'])) { - $template->assign("choices", $formFieldView->vars['choices']); - } + $this->assignFormTypeValues($template, $formFieldConfig, $formFieldView); $value = $formFieldView->vars["value"]; /* FIXME: doesnt work. We got "This form should not contain extra fields." error. @@ -185,6 +229,38 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar } } + public function renderTaggedFormFields($params, $content, \Smarty_Internal_Template $template, &$repeat) + { + if(null === $content) { + self::$taggedFieldsStack = $this->getFormFieldsFromTag($params); + self::$taggedFieldsStackPosition = 0; + } else { + self::$taggedFieldsStackPosition++; + } + + if(isset(self::$taggedFieldsStack[self::$taggedFieldsStackPosition])) { + $this->assignFieldValues( + $template, + self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars["full_name"], + self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars["value"], + self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars + ); + + $this->assignFormTypeValues($template, self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['config'], self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']); + + self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->setRendered(); + + $repeat = true; + } + + if (! $repeat) { + self::$taggedFieldsStack = null; + self::$taggedFieldsStackPosition = null; + } + + return $content; + } + public function renderHiddenFormField($params, \Smarty_Internal_Template $template) { $attrFormat = '%s="%s"'; @@ -266,6 +342,48 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar return $instance->getView()[$fieldName]; } + protected function getFormFieldsFromTag($params) + { + $instance = $this->getInstanceFromParams($params); + + $tag = $this->getParam($params, 'tag'); + + if (null == $tag) + throw new \InvalidArgumentException("'tag' parameter is missing"); + + $viewList = array(); + foreach($instance->getView() as $view) { + if(isset($view->vars['attr']['tag']) && $tag == $view->vars['attr']['tag']) { + $fieldData = $instance->getForm()->all()[$view->vars['name']]; + $viewList[] = array( + 'view' => $view, + 'config' => $fieldData->getConfig(), + ); + } + } + + return $viewList; + } + + protected function getFormFieldConfig($params) + { + $instance = $this->getInstanceFromParams($params); + + $fieldName = $this->getParam($params, 'field'); + + if (null == $fieldName) { + throw new \InvalidArgumentException("'field' parameter is missing"); + } + + $fieldData = $instance->getForm()->all()[$fieldName]; + + if (empty( $fieldData )) { + throw new \InvalidArgumentException(sprintf("Field name '%s' not found in form %s children", $fieldName, $instance->getName())); + } + + return $fieldData->getConfig(); + } + protected function getInstanceFromParams($params) { $instance = $this->getParam($params, 'form'); @@ -304,6 +422,7 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar return array( new SmartyPluginDescriptor("block", "form", $this, "generateForm"), new SmartyPluginDescriptor("block", "form_field", $this, "renderFormField"), + new SmartyPluginDescriptor("block", "form_tagged_fields", $this, "renderTaggedFormFields"), new SmartyPluginDescriptor("function", "form_hidden_fields", $this, "renderHiddenFormField"), new SmartyPluginDescriptor("function", "form_enctype", $this, "formEnctype"), new SmartyPluginDescriptor("block", "form_error", $this, "formError") diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php index a076c808a..f7b6fc559 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php @@ -300,7 +300,7 @@ class TheliaLoop extends AbstractSmartyPlugin /** * @param $smartyParams * - * @return object + * @return BaseLoop * @throws \Thelia\Core\Template\Element\Exception\InvalidElementException * @throws \Thelia\Core\Template\Element\Exception\ElementNotFoundException */ diff --git a/core/lib/Thelia/Form/TaxCreationForm.php b/core/lib/Thelia/Form/TaxCreationForm.php index 31b0834d4..302e55890 100644 --- a/core/lib/Thelia/Form/TaxCreationForm.php +++ b/core/lib/Thelia/Form/TaxCreationForm.php @@ -24,6 +24,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Form\Type\TheliaType; use Thelia\Core\Translation\Translator; use Thelia\TaxEngine\TaxEngine; use Thelia\TaxEngine\TaxType; @@ -36,10 +37,12 @@ class TaxCreationForm extends BaseForm { $types = TaxEngine::getInstance()->getTaxTypeList(); $typeList = array(); + $requirementList = array(); foreach($types as $type) { $classPath = "\\Thelia\\TaxEngine\\TaxType\\$type"; $instance = new $classPath(); $typeList[$type] = $instance->getTitle(); + $requirementList[$type] = $instance->getRequirementsList(); } $this->formBuilder @@ -57,6 +60,26 @@ class TaxCreationForm extends BaseForm )) ; + foreach($requirementList as $type => $requirements) { + foreach($requirements as $name => $requirementType) { + $this->formBuilder + ->add($type . '_' . $name, new TheliaType(), array( + "instance" => $requirementType, + "constraints" => array(new NotBlank()), + "attr" => array( + "tag" => "requirements", + ), + "data" => array( + "tax_type" => $type, + ), + "label" => Translator::getInstance()->trans($name), + "type" => $requirementType->getFormType(), + "options" => $requirementType->getFormOptions(), + )) + ; + } + } + $this->addStandardDescFields(array('postscriptum', 'chapo', 'locale')); } diff --git a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php index f1e95c5c7..8ec254843 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php @@ -45,7 +45,7 @@ class featureSlicePercentTaxType extends BaseTaxType public function getRequirementsList() { return array( - 'featureId' => new ModelValidIdType('Currency'), + 'featureId' => new ModelValidIdType('Feature'), 'slices' => new FloatToFloatArrayType(), ); } diff --git a/core/lib/Thelia/Type/AlphaNumStringListType.php b/core/lib/Thelia/Type/AlphaNumStringListType.php index d8e53cd95..9205373ca 100755 --- a/core/lib/Thelia/Type/AlphaNumStringListType.php +++ b/core/lib/Thelia/Type/AlphaNumStringListType.php @@ -50,4 +50,14 @@ class AlphaNumStringListType implements TypeInterface { return $this->isValid($values) ? explode(',', $values) : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/AlphaNumStringType.php b/core/lib/Thelia/Type/AlphaNumStringType.php index 726e6eb67..f574300cb 100755 --- a/core/lib/Thelia/Type/AlphaNumStringType.php +++ b/core/lib/Thelia/Type/AlphaNumStringType.php @@ -44,4 +44,14 @@ class AlphaNumStringType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/AnyType.php b/core/lib/Thelia/Type/AnyType.php index 5cdbb1272..bf5349546 100755 --- a/core/lib/Thelia/Type/AnyType.php +++ b/core/lib/Thelia/Type/AnyType.php @@ -44,4 +44,14 @@ class AnyType implements TypeInterface { return $value; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/BooleanOrBothType.php b/core/lib/Thelia/Type/BooleanOrBothType.php index 210201e26..eacd89ffc 100755 --- a/core/lib/Thelia/Type/BooleanOrBothType.php +++ b/core/lib/Thelia/Type/BooleanOrBothType.php @@ -49,4 +49,14 @@ class BooleanOrBothType implements TypeInterface if ($value === self::ANY) return $value; return $value === null ? null : filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/BooleanType.php b/core/lib/Thelia/Type/BooleanType.php index 69cba66ac..e231ce26a 100755 --- a/core/lib/Thelia/Type/BooleanType.php +++ b/core/lib/Thelia/Type/BooleanType.php @@ -44,4 +44,14 @@ class BooleanType implements TypeInterface { return $value === null ? null : filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/EnumListType.php b/core/lib/Thelia/Type/EnumListType.php index 2c37929a8..0d82e3a3e 100755 --- a/core/lib/Thelia/Type/EnumListType.php +++ b/core/lib/Thelia/Type/EnumListType.php @@ -69,4 +69,14 @@ class EnumListType implements TypeInterface { return in_array($value, $this->values); } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/EnumType.php b/core/lib/Thelia/Type/EnumType.php index 416f9714a..91f45a308 100755 --- a/core/lib/Thelia/Type/EnumType.php +++ b/core/lib/Thelia/Type/EnumType.php @@ -52,4 +52,14 @@ class EnumType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/FloatToFloatArrayType.php b/core/lib/Thelia/Type/FloatToFloatArrayType.php index 682ddebdd..404b7e4e4 100755 --- a/core/lib/Thelia/Type/FloatToFloatArrayType.php +++ b/core/lib/Thelia/Type/FloatToFloatArrayType.php @@ -54,4 +54,14 @@ class FloatToFloatArrayType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/FloatType.php b/core/lib/Thelia/Type/FloatType.php index f82f34b58..74d71adfb 100755 --- a/core/lib/Thelia/Type/FloatType.php +++ b/core/lib/Thelia/Type/FloatType.php @@ -44,4 +44,14 @@ class FloatType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/IntListType.php b/core/lib/Thelia/Type/IntListType.php index 28590472e..ff87bbd4e 100755 --- a/core/lib/Thelia/Type/IntListType.php +++ b/core/lib/Thelia/Type/IntListType.php @@ -50,4 +50,14 @@ class IntListType implements TypeInterface { return $this->isValid($values) ? explode(',', $values) : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/IntToCombinedIntsListType.php b/core/lib/Thelia/Type/IntToCombinedIntsListType.php index b2dc6b068..dfa21310d 100755 --- a/core/lib/Thelia/Type/IntToCombinedIntsListType.php +++ b/core/lib/Thelia/Type/IntToCombinedIntsListType.php @@ -124,4 +124,14 @@ class IntToCombinedIntsListType implements TypeInterface return true; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/IntToCombinedStringsListType.php b/core/lib/Thelia/Type/IntToCombinedStringsListType.php index 5863feb97..38152fdaa 100755 --- a/core/lib/Thelia/Type/IntToCombinedStringsListType.php +++ b/core/lib/Thelia/Type/IntToCombinedStringsListType.php @@ -124,4 +124,14 @@ class IntToCombinedStringsListType implements TypeInterface return true; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/IntType.php b/core/lib/Thelia/Type/IntType.php index 8e2ec4fd8..7a06a50fb 100755 --- a/core/lib/Thelia/Type/IntType.php +++ b/core/lib/Thelia/Type/IntType.php @@ -44,4 +44,14 @@ class IntType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/JsonType.php b/core/lib/Thelia/Type/JsonType.php index 5c92182a8..a1a1f5af6 100755 --- a/core/lib/Thelia/Type/JsonType.php +++ b/core/lib/Thelia/Type/JsonType.php @@ -46,4 +46,14 @@ class JsonType implements TypeInterface { return $this->isValid($value) ? json_decode($value, true) : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/ModelType.php b/core/lib/Thelia/Type/ModelType.php index 9eacef094..dadd47308 100755 --- a/core/lib/Thelia/Type/ModelType.php +++ b/core/lib/Thelia/Type/ModelType.php @@ -63,4 +63,14 @@ class ModelType implements TypeInterface { return $this->isValid($value) ? $value : null; } + + public function getFormType() + { + return 'text'; + } + + public function getFormOptions() + { + return array(); + } } diff --git a/core/lib/Thelia/Type/ModelValidIdType.php b/core/lib/Thelia/Type/ModelValidIdType.php index 9ae94e497..16a39359e 100755 --- a/core/lib/Thelia/Type/ModelValidIdType.php +++ b/core/lib/Thelia/Type/ModelValidIdType.php @@ -67,4 +67,23 @@ class ModelValidIdType implements TypeInterface return $this->isValid($value) ? $queryClass::create()->findPk($value) : null; } + + public function getFormType() + { + return 'choice'; + } + + public function getFormOptions() + { + $queryClass = $this->expectedModelActiveRecordQuery; + + $choices = array(); + foreach($queryClass::create()->find() as $item) { + $choices[$item->getId()] = method_exists($item, "getTitle") ? $item->getTitle() : $item->getId(); + } + + return array( + "choices" => $choices, + ); + } } diff --git a/core/lib/Thelia/Type/TypeInterface.php b/core/lib/Thelia/Type/TypeInterface.php index b293b1783..642c6d935 100755 --- a/core/lib/Thelia/Type/TypeInterface.php +++ b/core/lib/Thelia/Type/TypeInterface.php @@ -35,4 +35,7 @@ interface TypeInterface public function isValid($value); public function getFormattedValue($value); + + public function getFormType(); + public function getFormOptions(); } diff --git a/templates/admin/default/tax-edit.html b/templates/admin/default/tax-edit.html index 435ace42b..173246d76 100644 --- a/templates/admin/default/tax-edit.html +++ b/templates/admin/default/tax-edit.html @@ -76,7 +76,7 @@
    - {foreach $choices as $choice} {/foreach} @@ -85,6 +85,24 @@
    {/form_field} + {form_tagged_fields form=$form tag='requirements'} +
    + + {if $formType == 'choice'} + + {/if} + {if $formType == 'text'} + + {/if} +
    + {/form_tagged_fields} +
    @@ -123,6 +141,10 @@ From c6dbb76ebbfc0a59b0383d696488b302d4ff4044 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 16 Oct 2013 12:02:59 +0200 Subject: [PATCH 55/94] thelia type constraints --- core/lib/Thelia/Form/TaxCreationForm.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Form/TaxCreationForm.php b/core/lib/Thelia/Form/TaxCreationForm.php index 302e55890..5448d3367 100644 --- a/core/lib/Thelia/Form/TaxCreationForm.php +++ b/core/lib/Thelia/Form/TaxCreationForm.php @@ -65,7 +65,11 @@ class TaxCreationForm extends BaseForm $this->formBuilder ->add($type . '_' . $name, new TheliaType(), array( "instance" => $requirementType, - "constraints" => array(new NotBlank()), + "constraints" => array( + "methods" => array( + array($this, "verifyTaxId"), + ), + ), "attr" => array( "tag" => "requirements", ), From 9469c1a0ecaecef108136bfcec81f82e48ab7187 Mon Sep 17 00:00:00 2001 From: touffies Date: Wed, 16 Oct 2013 12:36:17 +0200 Subject: [PATCH 56/94] - Redirect to /customer/account on success - Agreements are mandatory --- templates/default/register.html | 93 ++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 36 deletions(-) diff --git a/templates/default/register.html b/templates/default/register.html index 018a4a8d6..266bc623b 100644 --- a/templates/default/register.html +++ b/templates/default/register.html @@ -5,7 +5,7 @@ {* Breadcrumb *} {block name='no-return-functions' append} - {$breadcrumbs = [['title' => {intl l="Register"}, 'url'=>{url path="/register?toto=tutu&tutu=titi"}]]} + {$breadcrumbs = [['title' => {intl l="Register"}, 'url'=>{url path="/register"}]]} {/block} {block name="main-content"} @@ -15,13 +15,13 @@

    {intl l="Create New Account"}

    {form name="thelia.customer.creation"} - + {form_field form=$form field='success_url'} - {* the url the user is redirected to on login success *} + {* the url the user is redirected to on registration success *} {/form_field} {form_field form=$form field='error_message'} - {* the url the user is redirected to on login success *} + {/form_field} {form_hidden_fields form=$form} {if $form_error}
    {$form_error_message}
    {/if} @@ -33,9 +33,9 @@
    {form_field form=$form field="title"}
    - +
    - {loop type="title" name="country.list"} @@ -43,6 +43,9 @@ {if $error } {$message} + {assign var="error_focus" value="true"} + {elseif !$value} + {assign var="error_focus" value="true"} {elseif $value != "" && !$error} {/if} @@ -51,11 +54,12 @@ {/form_field} {form_field form=$form field="firstname"}
    - +
    - + {if $error } {$message} + {assign var="error_focus" value="true"} {elseif $value != "" && !$error} {/if} @@ -64,11 +68,12 @@ {/form_field} {form_field form=$form field="lastname"}
    - +
    - + {if $error } {$message} + {assign var="error_focus" value="true"} {elseif $value != "" && !$error} {/if} @@ -77,12 +82,13 @@ {/form_field} {form_field form=$form field="email"}
    - +
    - + {if $error } {$message} + {assign var="error_focus" value="true"} {elseif $value != "" && !$error} {/if} @@ -91,11 +97,12 @@ {/form_field} {form_field form=$form field="phone"}
    - +
    - + {if $error } {$message} + {assign var="error_focus" value="true"} {elseif $value != "" && !$error} {/if} @@ -104,11 +111,12 @@ {/form_field} {form_field form=$form field="cellphone"}
    - +
    - + {if $error } {$message} + {assign var="error_focus" value="true"} {elseif $value != "" && !$error} {/if} @@ -126,11 +134,12 @@
    {form_field form=$form field="company"}
    - +
    - + {if $error } {$message} + {assign var="error_focus" value="true"} {elseif $value != "" && !$error} {/if} @@ -140,11 +149,12 @@ {form_field form=$form field="address1"}
    - +
    - + {if $error } {$message} + {assign var="error_focus" value="true"} {elseif $value != "" && !$error} {/if} @@ -154,11 +164,12 @@ {form_field form=$form field="address2"}
    - +
    - + {if $error } {$message} + {assign var="error_focus" value="true"} {elseif $value != "" && !$error} {/if} @@ -168,11 +179,12 @@ {form_field form=$form field="city"}
    - +
    - + {if $error } {$message} + {assign var="error_focus" value="true"} {elseif $value != "" && !$error} {/if} @@ -182,11 +194,12 @@ {form_field form=$form field="zipcode"}
    - +
    - + {if $error } {$message} + {assign var="error_focus" value="true"} {elseif $value != "" && !$error} {/if} @@ -196,9 +209,9 @@ {form_field form=$form field="country"}
    - +
    - {loop type="country" name="country.list"}