This commit is contained in:
Manuel Raynaud
2014-04-22 12:41:22 +02:00
parent 05bb8ecb80
commit 0435478ae8
17 changed files with 1654 additions and 1654 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -27,11 +27,12 @@ use Thelia\Tools\URL;
class TranslationsController extends BaseAdminController class TranslationsController extends BaseAdminController
{ {
/** /**
* @param string $item_name the modume code * @param string $item_name the modume code
* @return Module the module object * @return Module the module object
* @throws \InvalidArgumentException if module was not found * @throws \InvalidArgumentException if module was not found
*/ */
protected function getModule($item_name) { protected function getModule($item_name)
{
if (null !== $module = ModuleQuery::create()->findPk($item_name)) if (null !== $module = ModuleQuery::create()->findPk($item_name))
return $module; return $module;
@@ -40,8 +41,8 @@ class TranslationsController extends BaseAdminController
); );
} }
protected function getModuleTemplateNames(Module $module, $template_type)
protected function getModuleTemplateNames(Module $module, $template_type) { {
$templates = $templates =
TemplateHelper::getInstance()->getList( TemplateHelper::getInstance()->getList(
$template_type, $template_type,
@@ -96,14 +97,12 @@ class TranslationsController extends BaseAdminController
$domain = $module->getTranslationDomain(); $domain = $module->getTranslationDomain();
$i18n_directory = $module->getAbsoluteI18nPath(); $i18n_directory = $module->getAbsoluteI18nPath();
$walkMode = TemplateHelper::WALK_MODE_PHP; $walkMode = TemplateHelper::WALK_MODE_PHP;
} } elseif ($module_part == 'admin-includes') {
else if ($module_part == 'admin-includes') {
$directory = $module->getAbsoluteAdminIncludesPath(); $directory = $module->getAbsoluteAdminIncludesPath();
$domain = $module->getAdminIncludesTranslationDomain(); $domain = $module->getAdminIncludesTranslationDomain();
$i18n_directory = $module->getAbsoluteAdminIncludesI18nPath(); $i18n_directory = $module->getAbsoluteAdminIncludesI18nPath();
$walkMode = TemplateHelper::WALK_MODE_TEMPLATE; $walkMode = TemplateHelper::WALK_MODE_TEMPLATE;
} } elseif (! empty($module_part)) {
else if (! empty($module_part)) {
// Front or back office template, form of $module_part is [bo|fo].subdir-name // Front or back office template, form of $module_part is [bo|fo].subdir-name
list($type, $subdir) = explode('.', $module_part); list($type, $subdir) = explode('.', $module_part);
@@ -111,13 +110,11 @@ class TranslationsController extends BaseAdminController
$directory = $module->getAbsoluteBackOfficeTemplatePath($subdir); $directory = $module->getAbsoluteBackOfficeTemplatePath($subdir);
$domain = $module->getBackOfficeTemplateTranslationDomain($subdir); $domain = $module->getBackOfficeTemplateTranslationDomain($subdir);
$i18n_directory = $module->getAbsoluteBackOfficeI18nTemplatePath($subdir); $i18n_directory = $module->getAbsoluteBackOfficeI18nTemplatePath($subdir);
} } elseif ($type == 'fo') {
else if ($type == 'fo') {
$directory = $module->getAbsoluteFrontOfficeTemplatePath($subdir); $directory = $module->getAbsoluteFrontOfficeTemplatePath($subdir);
$domain = $module->getFrontOfficeTemplateTranslationDomain($subdir); $domain = $module->getFrontOfficeTemplateTranslationDomain($subdir);
$i18n_directory = $module->getAbsoluteFrontOfficeI18nTemplatePath($subdir); $i18n_directory = $module->getAbsoluteFrontOfficeI18nTemplatePath($subdir);
} } else {
else {
throw new \InvalidArgumentException("Undefined module template type: '$type'."); throw new \InvalidArgumentException("Undefined module template type: '$type'.");
} }
@@ -171,7 +168,7 @@ class TranslationsController extends BaseAdminController
if ($template) { if ($template) {
$directory = $template->getAbsolutePath(); $directory = $template->getAbsolutePath();
$i18n_directory = $template->getAbsoluteI18nPath(); $i18n_directory = $template->getAbsoluteI18nPath();
$domain = $template->getTranslationDomain(); $domain = $template->getTranslationDomain();

View File

@@ -132,10 +132,10 @@ abstract class BaseLoop
/** /**
* Provides a getter to loop parameter values * Provides a getter to loop parameter values
* *
* @param string $name the method name (only getArgname is supported) * @param string $name the method name (only getArgname is supported)
* @param mixed $arguments this parameter is ignored * @param mixed $arguments this parameter is ignored
* *
* @return mixed the argument value * @return mixed the argument value
* @throws \InvalidArgumentException if the parameter is unknown or the method name is not supported. * @throws \InvalidArgumentException if the parameter is unknown or the method name is not supported.
*/ */
public function __call($name, $arguments) public function __call($name, $arguments)
@@ -230,7 +230,7 @@ abstract class BaseLoop
* *
* @param string $argumentName the argument name * @param string $argumentName the argument name
* *
* @return Argument the loop argument. * @return Argument the loop argument.
* @throws \InvalidArgumentException if argument is not found in loop argument list * @throws \InvalidArgumentException if argument is not found in loop argument list
*/ */
protected function getArg($argumentName) protected function getArg($argumentName)
@@ -251,7 +251,7 @@ abstract class BaseLoop
* @param string $argumentName the argument name * @param string $argumentName the argument name
* *
* @throws \InvalidArgumentException if argument is not found in loop argument list * @throws \InvalidArgumentException if argument is not found in loop argument list
* @return mixed the loop argument value * @return mixed the loop argument value
*/ */
protected function getArgValue($argumentName) protected function getArgValue($argumentName)
{ {
@@ -263,7 +263,7 @@ abstract class BaseLoop
* @param PropelModelPager $pagination the pagination part * @param PropelModelPager $pagination the pagination part
* *
* @return array|PropelModelPager|ObjectCollection * @return array|PropelModelPager|ObjectCollection
* @throws \InvalidArgumentException if the search mode is undefined. * @throws \InvalidArgumentException if the search mode is undefined.
*/ */
protected function search(ModelCriteria $search, &$pagination = null) protected function search(ModelCriteria $search, &$pagination = null)
{ {
@@ -356,7 +356,7 @@ abstract class BaseLoop
} }
/** /**
* @param ModelCriteria $search * @param ModelCriteria $search
* @param PropelModelPager $pagination * @param PropelModelPager $pagination
* *
* @return array|PropelModelPager * @return array|PropelModelPager
@@ -536,4 +536,4 @@ abstract class BaseLoop
*/ */
abstract protected function getArgDefinitions(); abstract protected function getArgDefinitions();
} }

View File

@@ -94,4 +94,4 @@ class Delivery extends BaseSpecificModule
{ {
return BaseModule::DELIVERY_MODULE_TYPE; return BaseModule::DELIVERY_MODULE_TYPE;
} }
} }

View File

@@ -59,7 +59,7 @@ class TheliaLoop extends AbstractSmartyPlugin
} }
/** /**
* @param string $loopName * @param string $loopName
* @return PropelModelPager * @return PropelModelPager
* @throws \InvalidArgumentException if no pagination was found for loop * @throws \InvalidArgumentException if no pagination was found for loop
*/ */
@@ -77,10 +77,10 @@ class TheliaLoop extends AbstractSmartyPlugin
/** /**
* Process the count function: executes a loop and return the number of items found * Process the count function: executes a loop and return the number of items found
* *
* @param array $params parameters array * @param array $params parameters array
* @param \Smarty_Internal_Template $template * @param \Smarty_Internal_Template $template
* *
* @return int the item count * @return int the item count
* @throws \InvalidArgumentException if a parameter is missing * @throws \InvalidArgumentException if a parameter is missing
* *
*/ */
@@ -104,10 +104,10 @@ class TheliaLoop extends AbstractSmartyPlugin
/** /**
* Process {loop name="loop name" type="loop type" ... } ... {/loop} block * Process {loop name="loop name" type="loop type" ... } ... {/loop} block
* *
* @param array $params * @param array $params
* @param string $content * @param string $content
* @param \Smarty_Internal_Template $template * @param \Smarty_Internal_Template $template
* @param boolean $repeat * @param boolean $repeat
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* *
@@ -209,11 +209,11 @@ class TheliaLoop extends AbstractSmartyPlugin
/** /**
* Process {elseloop rel="loopname"} ... {/elseloop} block * Process {elseloop rel="loopname"} ... {/elseloop} block
* *
* @param array $params loop parameters * @param array $params loop parameters
* @param string $content loop text content * @param string $content loop text content
* @param \Smarty_Internal_Template $template the Smarty object * @param \Smarty_Internal_Template $template the Smarty object
* @param boolean $repeat repeat indicator (see Smarty doc.) * @param boolean $repeat repeat indicator (see Smarty doc.)
* @return string the loop output * @return string the loop output
*/ */
public function theliaElseloop($params, $content, /** @noinspection PhpUnusedParameterInspection */ $template, &$repeat) public function theliaElseloop($params, $content, /** @noinspection PhpUnusedParameterInspection */ $template, &$repeat)
{ {
@@ -228,11 +228,11 @@ class TheliaLoop extends AbstractSmartyPlugin
/** /**
* Process {ifloop rel="loopname"} ... {/ifloop} block * Process {ifloop rel="loopname"} ... {/ifloop} block
* *
* @param array $params loop parameters * @param array $params loop parameters
* @param string $content loop text content * @param string $content loop text content
* @param \Smarty_Internal_Template $template the Smarty object * @param \Smarty_Internal_Template $template the Smarty object
* @param boolean $repeat repeat indicator (see Smarty doc.) * @param boolean $repeat repeat indicator (see Smarty doc.)
* @return string the loop output * @return string the loop output
*/ */
public function theliaIfLoop($params, $content, /** @noinspection PhpUnusedParameterInspection */ $template, &$repeat) public function theliaIfLoop($params, $content, /** @noinspection PhpUnusedParameterInspection */ $template, &$repeat)
{ {
@@ -247,11 +247,11 @@ class TheliaLoop extends AbstractSmartyPlugin
/** /**
* Process {pageloop rel="loopname"} ... {/pageloop} block * Process {pageloop rel="loopname"} ... {/pageloop} block
* *
* @param array $params loop parameters * @param array $params loop parameters
* @param string $content loop text content * @param string $content loop text content
* @param \Smarty_Internal_Template $template the Smarty object * @param \Smarty_Internal_Template $template the Smarty object
* @param boolean $repeat repeat indicator (see Smarty doc.) * @param boolean $repeat repeat indicator (see Smarty doc.)
* @return string the loop output * @return string the loop output
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function theliaPageLoop($params, $content, $template, &$repeat) public function theliaPageLoop($params, $content, $template, &$repeat)
@@ -337,9 +337,9 @@ class TheliaLoop extends AbstractSmartyPlugin
* Check if a loop has returned results. The loop shoud have been executed before, or an * Check if a loop has returned results. The loop shoud have been executed before, or an
* InvalidArgumentException is thrown * InvalidArgumentException is thrown
* *
* @param array $params * @param array $params
* *
* @return boolean true if the loop is empty * @return boolean true if the loop is empty
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
protected function checkEmptyLoop($params) protected function checkEmptyLoop($params)

View File

@@ -29,7 +29,7 @@ class Translation extends AbstractSmartyPlugin
/** /**
* Set the default translation domain * Set the default translation domain
* *
* @param array $params * @param array $params
* @param \Smarty_Internal_Template $smarty * @param \Smarty_Internal_Template $smarty
* @return string * @return string
*/ */
@@ -41,7 +41,7 @@ class Translation extends AbstractSmartyPlugin
/** /**
* Process translate function * Process translate function
* *
* @param array $params * @param array $params
* @param \Smarty_Internal_Template $smarty * @param \Smarty_Internal_Template $smarty
* @return string * @return string
*/ */

View File

@@ -242,6 +242,7 @@ class SmartyParser extends Smarty implements ParserInterface
if (false === $this->templateExists($realTemplateName) || false === $this->checkTemplate($realTemplateName)) { if (false === $this->templateExists($realTemplateName) || false === $this->checkTemplate($realTemplateName)) {
throw new ResourceNotFoundException(Translator::getInstance()->trans("Template file %file cannot be found.", array('%file' => $realTemplateName))); throw new ResourceNotFoundException(Translator::getInstance()->trans("Template file %file cannot be found.", array('%file' => $realTemplateName)));
} }
return $this->internalRenderer('file', $realTemplateName, $parameters); return $this->internalRenderer('file', $realTemplateName, $parameters);
} }

View File

@@ -77,7 +77,8 @@ class TemplateDefinition
} }
} }
public function getTranslationDomain() { public function getTranslationDomain()
{
return $this->translationDomainPrefix . strtolower($this->getName()); return $this->translationDomainPrefix . strtolower($this->getName());
} }

View File

@@ -96,7 +96,7 @@ class TemplateHelper
/** /**
* Return a list of existing templates for a given template type * Return a list of existing templates for a given template type
* *
* @param int $templateType the template type * @param int $templateType the template type
* @param string the template base (module or core, default to core). * @param string the template base (module or core, default to core).
* @return TemplateDefinition[] of \Thelia\Core\Template\TemplateDefinition * @return TemplateDefinition[] of \Thelia\Core\Template\TemplateDefinition
*/ */
@@ -126,8 +126,7 @@ class TemplateHelper
$list[] = new TemplateDefinition($file->getFilename(), $templateType); $list[] = new TemplateDefinition($file->getFilename(), $templateType);
} }
} } catch (\UnexpectedValueException $ex) {
catch (\UnexpectedValueException $ex) {
// Ignore the exception and continue // Ignore the exception and continue
} }
} }

View File

@@ -217,7 +217,7 @@ class Thelia extends Kernel
$module->getAbsoluteTemplateBasePath() $module->getAbsoluteTemplateBasePath()
); );
foreach($templates as $template) { foreach ($templates as $template) {
$translationDirs[$module->getBackOfficeTemplateTranslationDomain($template->getName())] = $translationDirs[$module->getBackOfficeTemplateTranslationDomain($template->getName())] =
$module->getAbsoluteBackOfficeI18nTemplatePath($template->getName()); $module->getAbsoluteBackOfficeI18nTemplatePath($template->getName());
} }
@@ -229,7 +229,7 @@ class Thelia extends Kernel
$module->getAbsoluteTemplateBasePath() $module->getAbsoluteTemplateBasePath()
); );
foreach($templates as $template) { foreach ($templates as $template) {
$translationDirs[$module->getFrontOfficeTemplateTranslationDomain($template->getName())] = $translationDirs[$module->getFrontOfficeTemplateTranslationDomain($template->getName())] =
$module->getAbsoluteFrontOfficeI18nTemplatePath($template->getName()); $module->getAbsoluteFrontOfficeI18nTemplatePath($template->getName());
} }
@@ -279,8 +279,7 @@ class Thelia extends Kernel
$translator->addMethodCall('addResource', array($format, (string) $file, $locale, $domain)); $translator->addMethodCall('addResource', array($format, (string) $file, $locale, $domain));
} }
} } catch (\InvalidArgumentException $ex) {
catch (\InvalidArgumentException $ex) {
// Ignore missing I18n directories // Ignore missing I18n directories
Tlog::getInstance()->addWarning("loadTranslation: missing $dir directory"); Tlog::getInstance()->addWarning("loadTranslation: missing $dir directory");
} }

View File

@@ -13,224 +13,224 @@
namespace Thelia\Form; namespace Thelia\Form;
use Symfony\Component\Form\Extension\Validator\ValidatorExtension; use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
use Symfony\Component\Form\Forms; use Symfony\Component\Form\Forms;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension; use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
use Symfony\Component\Form\Extension\Csrf\CsrfExtension; use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
use Symfony\Component\Validator\Validation; use Symfony\Component\Validator\Validation;
use Thelia\Core\Translation\Translator; use Thelia\Core\Translation\Translator;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Tools\URL; use Thelia\Tools\URL;
/** /**
* Base form class for creating form objects * Base form class for creating form objects
* *
* Class BaseForm * Class BaseForm
* @package Thelia\Form * @package Thelia\Form
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
abstract class BaseForm abstract class BaseForm
{ {
/** /**
* @var \Symfony\Component\Form\FormFactoryInterface * @var \Symfony\Component\Form\FormFactoryInterface
*/ */
protected $formBuilder; protected $formBuilder;
/** /**
* @var \Symfony\Component\Form\Form * @var \Symfony\Component\Form\Form
*/ */
protected $form; protected $form;
protected $request; protected $request;
private $view = null; private $view = null;
/** /**
* true if the form has an error, false otherwise. * true if the form has an error, false otherwise.
* @var boolean * @var boolean
*/ */
private $has_error = false; private $has_error = false;
/** /**
* The form error message. * The form error message.
* @var string * @var string
*/ */
private $error_message = ''; private $error_message = '';
public function __construct(Request $request, $type= "form", $data = array(), $options = array()) public function __construct(Request $request, $type= "form", $data = array(), $options = array())
{ {
$this->request = $request; $this->request = $request;
$validator = Validation::createValidatorBuilder(); $validator = Validation::createValidatorBuilder();
if (!isset($options["attr"]["name"])) { if (!isset($options["attr"]["name"])) {
$options["attr"]["thelia_name"] = $this->getName(); $options["attr"]["thelia_name"] = $this->getName();
} }
$builder = Forms::createFormFactoryBuilder() $builder = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension()); ->addExtension(new HttpFoundationExtension());
if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) { if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
$builder->addExtension( $builder->addExtension(
new CsrfExtension( new CsrfExtension(
new SessionCsrfProvider( new SessionCsrfProvider(
$request->getSession(), $request->getSession(),
isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__)) isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__))
) )
) )
); );
} }
$translator = Translator::getInstance(); $translator = Translator::getInstance();
$validator $validator
->setTranslationDomain('validators') ->setTranslationDomain('validators')
->setTranslator($translator); ->setTranslator($translator);
$this->formBuilder = $builder $this->formBuilder = $builder
->addExtension(new ValidatorExtension($validator->getValidator())) ->addExtension(new ValidatorExtension($validator->getValidator()))
->getFormFactory() ->getFormFactory()
->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options)); ->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
; ;
$this->buildForm(); $this->buildForm();
// If not already set, define the success_url field // If not already set, define the success_url field
if (! $this->formBuilder->has('success_url')) { if (! $this->formBuilder->has('success_url')) {
$this->formBuilder->add("success_url", "text"); $this->formBuilder->add("success_url", "text");
} }
if (! $this->formBuilder->has('error_message')) { if (! $this->formBuilder->has('error_message')) {
$this->formBuilder->add("error_message", "text"); $this->formBuilder->add("error_message", "text");
} }
$this->form = $this->formBuilder->getForm(); $this->form = $this->formBuilder->getForm();
} }
public function getRequest() public function getRequest()
{ {
return $this->request; return $this->request;
} }
protected function cleanOptions($options) protected function cleanOptions($options)
{ {
unset($options["csrf_protection"]); unset($options["csrf_protection"]);
return $options; return $options;
} }
/** /**
* Returns the absolute URL to redirect the user to if the form is successfully processed. * Returns the absolute URL to redirect the user to if the form is successfully processed.
* *
* @param string $default the default URL. If not given, the configured base URL is used. * @param string $default the default URL. If not given, the configured base URL is used.
* *
* @return string an absolute URL * @return string an absolute URL
*/ */
public function getSuccessUrl($default = null) public function getSuccessUrl($default = null)
{ {
$successUrl = $this->form->get('success_url')->getData(); $successUrl = $this->form->get('success_url')->getData();
if (empty($successUrl)) { if (empty($successUrl)) {
if ($default === null) $default = ConfigQuery::read('base_url', '/'); if ($default === null) $default = ConfigQuery::read('base_url', '/');
$successUrl = $default; $successUrl = $default;
} }
return URL::getInstance()->absoluteUrl($successUrl); return URL::getInstance()->absoluteUrl($successUrl);
} }
public function createView() public function createView()
{ {
$this->view = $this->form->createView(); $this->view = $this->form->createView();
return $this; return $this;
} }
public function getView() public function getView()
{ {
if ($this->view === null) throw new \LogicException("View was not created. Please call BaseForm::createView() first."); if ($this->view === null) throw new \LogicException("View was not created. Please call BaseForm::createView() first.");
return $this->view; return $this->view;
} }
// -- Error and errro message ---------------------------------------------- // -- Error and errro message ----------------------------------------------
/** /**
* Set the error status of the form. * Set the error status of the form.
* *
* @param boolean $has_error * @param boolean $has_error
*/ */
public function setError($has_error = true) public function setError($has_error = true)
{ {
$this->has_error = $has_error; $this->has_error = $has_error;
return $this; return $this;
} }
/** /**
* Get the cuirrent error status of the form. * Get the cuirrent error status of the form.
* *
* @return boolean * @return boolean
*/ */
public function hasError() public function hasError()
{ {
return $this->has_error; return $this->has_error;
} }
/** /**
* Set the error message related to global form error * Set the error message related to global form error
* *
* @param string $message * @param string $message
*/ */
public function setErrorMessage($message) public function setErrorMessage($message)
{ {
$this->setError(true); $this->setError(true);
$this->error_message = $message; $this->error_message = $message;
return $this; return $this;
} }
/** /**
* Get the form error message. * Get the form error message.
* *
* @return string * @return string
*/ */
public function getErrorMessage() public function getErrorMessage()
{ {
return $this->error_message; return $this->error_message;
} }
/** /**
* @return \Symfony\Component\Form\Form * @return \Symfony\Component\Form\Form
*/ */
public function getForm() public function getForm()
{ {
return $this->form; return $this->form;
} }
/** /**
* *
* in this function you add all the fields you need for your Form. * 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 : * Form this you have to call add method on $this->formBuilder attribute :
* *
* $this->formBuilder->add("name", "text") * $this->formBuilder->add("name", "text")
* ->add("email", "email", array( * ->add("email", "email", array(
* "attr" => array( * "attr" => array(
* "class" => "field" * "class" => "field"
* ), * ),
* "label" => "email", * "label" => "email",
* "constraints" => array( * "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank() * new \Symfony\Component\Validator\Constraints\NotBlank()
* ) * )
* ) * )
* ) * )
* ->add('age', 'integer'); * ->add('age', 'integer');
* *
* @return null * @return null
*/ */
abstract protected function buildForm(); abstract protected function buildForm();
/** /**
* @return string the name of you form. This name must be unique * @return string the name of you form. This name must be unique
*/ */
abstract public function getName(); abstract public function getName();
} }

View File

@@ -1,179 +1,182 @@
<?php <?php
namespace Thelia\Model; namespace Thelia\Model;
use Propel\Runtime\Connection\ConnectionInterface; use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Core\Template\TemplateDefinition; use Thelia\Core\Template\TemplateDefinition;
use Thelia\Model\Base\Module as BaseModule; use Thelia\Model\Base\Module as BaseModule;
use Thelia\Model\Tools\ModelEventDispatcherTrait; use Thelia\Model\Tools\ModelEventDispatcherTrait;
use Thelia\Model\Tools\PositionManagementTrait; use Thelia\Model\Tools\PositionManagementTrait;
class Module extends BaseModule class Module extends BaseModule
{ {
use ModelEventDispatcherTrait; use ModelEventDispatcherTrait;
use PositionManagementTrait; use PositionManagementTrait;
const ADMIN_INCLUDES_DIRECTORY_NAME = "AdminIncludes"; const ADMIN_INCLUDES_DIRECTORY_NAME = "AdminIncludes";
public function postSave(ConnectionInterface $con = null)
public function postSave(ConnectionInterface $con = null) {
{ ModuleQuery::resetActivated();
ModuleQuery::resetActivated(); }
}
public function getTranslationDomain()
public function getTranslationDomain() { {
return strtolower($this->getCode()); return strtolower($this->getCode());
} }
public function getAdminIncludesTranslationDomain() { public function getAdminIncludesTranslationDomain()
return $this->getTranslationDomain().'.ai'; {
} return $this->getTranslationDomain().'.ai';
}
public function getAbsoluteBackOfficeTemplatePath($subdir)
{ public function getAbsoluteBackOfficeTemplatePath($subdir)
return sprintf("%s".DS."%s".DS."%s", {
$this->getAbsoluteTemplateBasePath(), return sprintf("%s".DS."%s".DS."%s",
TemplateDefinition::BACK_OFFICE_SUBDIR, $this->getAbsoluteTemplateBasePath(),
$subdir TemplateDefinition::BACK_OFFICE_SUBDIR,
); $subdir
} );
}
public function getAbsoluteBackOfficeI18nTemplatePath($subdir)
{ public function getAbsoluteBackOfficeI18nTemplatePath($subdir)
return sprintf("%s".DS."%s".DS."%s", {
$this->getAbsoluteI18nPath(), return sprintf("%s".DS."%s".DS."%s",
TemplateDefinition::BACK_OFFICE_SUBDIR, $this->getAbsoluteI18nPath(),
$subdir TemplateDefinition::BACK_OFFICE_SUBDIR,
); $subdir
} );
}
public function getBackOfficeTemplateTranslationDomain($templateName) {
return $this->getTranslationDomain(). '.bo.' . $templateName; public function getBackOfficeTemplateTranslationDomain($templateName)
} {
return $this->getTranslationDomain(). '.bo.' . $templateName;
public function getAbsoluteFrontOfficeTemplatePath($subdir) }
{
return sprintf("%s".DS."%s".DS."%s", public function getAbsoluteFrontOfficeTemplatePath($subdir)
$this->getAbsoluteTemplateBasePath(), {
TemplateDefinition::FRONT_OFFICE_SUBDIR, return sprintf("%s".DS."%s".DS."%s",
$subdir $this->getAbsoluteTemplateBasePath(),
); TemplateDefinition::FRONT_OFFICE_SUBDIR,
} $subdir
);
public function getAbsoluteFrontOfficeI18nTemplatePath($subdir) }
{
return sprintf("%s".DS."%s".DS."%s", public function getAbsoluteFrontOfficeI18nTemplatePath($subdir)
$this->getAbsoluteI18nPath(), {
TemplateDefinition::FRONT_OFFICE_SUBDIR, return sprintf("%s".DS."%s".DS."%s",
$subdir $this->getAbsoluteI18nPath(),
); TemplateDefinition::FRONT_OFFICE_SUBDIR,
} $subdir
);
public function getFrontOfficeTemplateTranslationDomain($templateName) { }
return $this->getTranslationDomain(). '.fo.' . $templateName;
} public function getFrontOfficeTemplateTranslationDomain($templateName)
{
/** return $this->getTranslationDomain(). '.fo.' . $templateName;
* @return the module's base directory path, relative to THELIA_MODULE_DIR }
*/
public function getBaseDir() /**
{ * @return the module's base directory path, relative to THELIA_MODULE_DIR
return ucfirst($this->getCode()); */
} public function getBaseDir()
{
/** return ucfirst($this->getCode());
* @return the module's base directory path, relative to THELIA_MODULE_DIR }
*/
public function getAbsoluteBaseDir() /**
{ * @return the module's base directory path, relative to THELIA_MODULE_DIR
return THELIA_MODULE_DIR . $this->getBaseDir(); */
} public function getAbsoluteBaseDir()
{
/** return THELIA_MODULE_DIR . $this->getBaseDir();
* @return the module's config directory path, relative to THELIA_MODULE_DIR }
*/
public function getConfigPath() /**
{ * @return the module's config directory path, relative to THELIA_MODULE_DIR
return $this->getBaseDir() . DS . "Config"; */
} public function getConfigPath()
{
/** return $this->getBaseDir() . DS . "Config";
* @return the module's config absolute directory path }
*/
public function getAbsoluteConfigPath() /**
{ * @return the module's config absolute directory path
return THELIA_MODULE_DIR . $this->getConfigPath(); */
} public function getAbsoluteConfigPath()
{
/** return THELIA_MODULE_DIR . $this->getConfigPath();
* @return the module's i18N directory path, relative to THELIA_MODULE_DIR }
*/
public function getI18nPath() /**
{ * @return the module's i18N directory path, relative to THELIA_MODULE_DIR
return $this->getBaseDir() . DS . "I18n"; */
} public function getI18nPath()
{
/** return $this->getBaseDir() . DS . "I18n";
* @return the module's i18N absolute directory path }
*/
public function getAbsoluteI18nPath() /**
{ * @return the module's i18N absolute directory path
return THELIA_MODULE_DIR . $this->getI18nPath(); */
} public function getAbsoluteI18nPath()
{
/** return THELIA_MODULE_DIR . $this->getI18nPath();
* @return the module's AdminIncludes absolute directory path }
*/
public function getAbsoluteAdminIncludesPath() /**
{ * @return the module's AdminIncludes absolute directory path
return $this->getAbsoluteBaseDir() . DS . self::ADMIN_INCLUDES_DIRECTORY_NAME; */
} public function getAbsoluteAdminIncludesPath()
{
/** return $this->getAbsoluteBaseDir() . DS . self::ADMIN_INCLUDES_DIRECTORY_NAME;
* @return the module's AdminIncludes i18N absolute directory path }
*/
public function getAbsoluteAdminIncludesI18nPath() /**
{ * @return the module's AdminIncludes i18N absolute directory path
return THELIA_MODULE_DIR . $this->getI18nPath() . DS . self::ADMIN_INCLUDES_DIRECTORY_NAME; */
} public function getAbsoluteAdminIncludesI18nPath()
{
/** return THELIA_MODULE_DIR . $this->getI18nPath() . DS . self::ADMIN_INCLUDES_DIRECTORY_NAME;
* Return the absolute path to the module's template directory }
*
* @return string a path /**
*/ * Return the absolute path to the module's template directory
public function getAbsoluteTemplateBasePath() *
{ * @return string a path
return $this->getAbsoluteBaseDir() . DS . 'templates'; */
} public function getAbsoluteTemplateBasePath()
{
/** return $this->getAbsoluteBaseDir() . DS . 'templates';
* Return the absolute path to one of the module's template directories }
*
* @param int $templateSubdirName the name of the, probably one of TemplateDefinition::xxx_SUBDIR constants /**
* @return string a path * Return the absolute path to one of the module's template directories
*/ *
public function getAbsoluteTemplateDirectoryPath($templateSubdirName) * @param int $templateSubdirName the name of the, probably one of TemplateDefinition::xxx_SUBDIR constants
{ * @return string a path
return $this->getAbsoluteTemplateBasePath() .DS. $templateSubdirName; */
} public function getAbsoluteTemplateDirectoryPath($templateSubdirName)
{
/** return $this->getAbsoluteTemplateBasePath() .DS. $templateSubdirName;
* Calculate next position relative to module type }
*/
protected function addCriteriaToPositionQuery($query) /**
{ * Calculate next position relative to module type
$query->filterByType($this->getType()); */
} protected function addCriteriaToPositionQuery($query)
{
/** $query->filterByType($this->getType());
* {@inheritDoc} }
*/
public function preInsert(ConnectionInterface $con = null) /**
{ * {@inheritDoc}
$this->setPosition($this->getNextPosition()); */
public function preInsert(ConnectionInterface $con = null)
return true; {
} $this->setPosition($this->getNextPosition());
}
return true;
}
}

View File

@@ -1,19 +1,19 @@
<?php <?php
/*************************************************************************************/ /*************************************************************************************/
/* This file is part of the Thelia package. */ /* This file is part of the Thelia package. */
/* */ /* */
/* Copyright (c) OpenStudio */ /* Copyright (c) OpenStudio */
/* email : dev@thelia.net */ /* email : dev@thelia.net */
/* web : http://www.thelia.net */ /* web : http://www.thelia.net */
/* */ /* */
/* For the full copyright and license information, please view the LICENSE.txt */ /* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */ /* file that was distributed with this source code. */
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Module; namespace Thelia\Module;
abstract class AbstractDeliveryModule extends BaseModule implements DeliveryModuleInterface abstract class AbstractDeliveryModule extends BaseModule implements DeliveryModuleInterface
{ {
// This class is the base class for delivery modules // This class is the base class for delivery modules
// It may contains common methods in the future. // It may contains common methods in the future.
} }

View File

@@ -92,4 +92,4 @@ abstract class AbstractPaymentModule extends BaseModule implements PaymentModule
) )
); );
} }
} }

View File

@@ -159,7 +159,7 @@ class BaseModule extends ContainerAware implements BaseModuleInterface
* Sets a module titles for various languages * Sets a module titles for various languages
* *
* @param Module $module the module. * @param Module $module the module.
* @param array $titles an associative array of locale => title_string * @param array $titles an associative array of locale => title_string
*/ */
public function setTitle(Module $module, $titles) public function setTitle(Module $module, $titles)
{ {
@@ -451,4 +451,4 @@ class BaseModule extends ContainerAware implements BaseModuleInterface
{ {
// Override this method to do something useful. // Override this method to do something useful.
} }
} }

View File

@@ -35,7 +35,7 @@ interface DeliveryModuleInterface extends BaseModuleInterface
* *
* @param Country $country the country to deliver to. * @param Country $country the country to deliver to.
* *
* @return float the delivery price * @return float the delivery price
* @throws DeliveryException if the postage price cannot be calculated. * @throws DeliveryException if the postage price cannot be calculated.
*/ */
public function getPostage(Country $country); public function getPostage(Country $country);

View File

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