From c74422f5dc446c7097a9828181dcd0eef5b4f076 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 29 Oct 2013 15:56:03 +0100 Subject: [PATCH] implement module inclusion --- .../lib/Thelia/Command/BaseModuleGenerate.php | 9 ++++---- .../Core/Template/Smarty/Plugins/Module.php | 23 +++++++++++++++---- core/lib/Thelia/Model/Module.php | 5 ++++ core/lib/Thelia/Model/ModuleQuery.php | 19 ++++++++++++--- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/core/lib/Thelia/Command/BaseModuleGenerate.php b/core/lib/Thelia/Command/BaseModuleGenerate.php index b26db435b..1a27d9e4c 100755 --- a/core/lib/Thelia/Command/BaseModuleGenerate.php +++ b/core/lib/Thelia/Command/BaseModuleGenerate.php @@ -35,13 +35,14 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand protected $moduleDirectory; protected $reservedKeyWords = array( - "thelia" + 'thelia' ); protected $neededDirectories = array( - "Config", - "Model", - "Loop" + 'Config', + 'Model', + 'Loop', + 'AdminModule' ); protected function verifyExistingModule() diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php index 52feae096..1c6ab4fd1 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php @@ -25,6 +25,7 @@ namespace Thelia\Core\Template\Smarty\Plugins; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; +use Thelia\Model\ModuleQuery; class Module extends AbstractSmartyPlugin { @@ -32,13 +33,27 @@ class Module extends AbstractSmartyPlugin * Process theliaModule template inclusion function * * @param unknown $params - * @param unknown $smarty + * @param \Smarty_Internal_Template $template + * @internal param \Thelia\Core\Template\Smarty\Plugins\unknown $smarty + * * @return string */ - public function theliaModule($params, &$smarty) + public function theliaModule($params, \Smarty_Internal_Template $template) { - // TODO - return ""; + $content = null; + if (array_key_exists('location', $params)) { + $location = $params['location']; + $modules = ModuleQuery::getActivated(); + + foreach ($modules as $module) { + + $file = THELIA_MODULE_DIR . "/". ucfirst($module->getCode()) . "/ModuleAdmin/".$location.".html"; + if(file_exists($file)) { + $content .= file_get_contents($file); + } + } + } + return $template->fetch(sprintf("string:%s", $content)); } /** diff --git a/core/lib/Thelia/Model/Module.php b/core/lib/Thelia/Model/Module.php index b7fb2a443..c9ccd5f8d 100755 --- a/core/lib/Thelia/Model/Module.php +++ b/core/lib/Thelia/Model/Module.php @@ -2,8 +2,13 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\Module as BaseModule; class Module extends BaseModule { + public function postSave(ConnectionInterface $con = null) + { + ModuleQuery::resetActivated(); + } } diff --git a/core/lib/Thelia/Model/ModuleQuery.php b/core/lib/Thelia/Model/ModuleQuery.php index fdfe502a4..aaf2092e6 100755 --- a/core/lib/Thelia/Model/ModuleQuery.php +++ b/core/lib/Thelia/Model/ModuleQuery.php @@ -16,13 +16,26 @@ use Thelia\Model\Base\ModuleQuery as BaseModuleQuery; * */ class ModuleQuery extends BaseModuleQuery { + + protected static $activated = null; /** * @return array|mixed|\PropelObjectCollection */ public static function getActivated() { - return self::create() - ->filterByActivate(1) - ->find(); + if(null === self::$activated) { + self::$activated = self::create() + ->filterByActivate(1) + ->find(); + } + + return self::$activated; } + + public static function resetActivated() + { + self::$activated = null; + } + + } // ModuleQuery