本文整理汇总了PHP中Thelia\Model\ModuleQuery类的典型用法代码示例。如果您正苦于以下问题:PHP ModuleQuery类的具体用法?PHP ModuleQuery怎么用?PHP ModuleQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModuleQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container
*
* @api
*/
public function process(ContainerBuilder $container)
{
try {
$chainRouter = $container->getDefinition("router.chainRequest");
} catch (InvalidArgumentException $e) {
return;
}
foreach ($container->findTaggedServiceIds("router.register") as $id => $attributes) {
$priority = isset($attributes[0]["priority"]) ? $attributes[0]["priority"] : 0;
$router = $container->getDefinition($id);
$router->addMethodCall("setOption", array("matcher_cache_class", $container::camelize("ProjectUrlMatcher" . $id)));
$router->addMethodCall("setOption", array("generator_cache_class", $container::camelize("ProjectUrlGenerator" . $id)));
$chainRouter->addMethodCall("add", array(new Reference($id), $priority));
}
if (defined("THELIA_INSTALL_MODE") === false) {
$modules = \Thelia\Model\ModuleQuery::getActivated();
foreach ($modules as $module) {
$moduleBaseDir = $module->getBaseDir();
$routingConfigFilePath = $module->getAbsoluteBaseDir() . DS . "Config" . DS . "routing.xml";
if (file_exists($routingConfigFilePath)) {
$definition = new Definition($container->getParameter("router.class"), array(new Reference("router.module.xmlLoader"), $routingConfigFilePath, array("cache_dir" => $container->getParameter("kernel.cache_dir"), "debug" => $container->getParameter("kernel.debug"), "matcher_cache_class" => $container::camelize("ProjectUrlMatcher" . $moduleBaseDir), "generator_cache_class" => $container::camelize("ProjectUrlGenerator" . $moduleBaseDir)), new Reference("request.context")));
$container->setDefinition("router." . $moduleBaseDir, $definition);
$chainRouter->addMethodCall("add", array(new Reference("router." . $moduleBaseDir), 150));
}
}
}
}
示例2: processHook
protected function processHook(ContainerBuilder $container, $definition)
{
foreach ($container->findTaggedServiceIds('hook.event_listener') as $id => $events) {
$class = $container->getDefinition($id)->getClass();
// the class must extends BaseHook
$implementClass = HookDefinition::BASE_CLASS;
if (!is_subclass_of($class, $implementClass)) {
throw new \InvalidArgumentException(sprintf('Hook class "%s" must extends class "%s".', $class, $implementClass));
}
// retrieve the module id
$properties = $container->getDefinition($id)->getProperties();
$module = null;
if (array_key_exists('module', $properties)) {
$moduleCode = explode(".", $properties['module'])[1];
if (null !== ($module = ModuleQuery::create()->findOneByCode($moduleCode))) {
$module = $module->getId();
}
}
foreach ($events as $event) {
$this->registerHook($class, $module, $id, $event);
}
}
// now we can add listeners for active hooks and active module
$this->addHooksMethodCall($definition);
}
示例3: checkValidInvoice
protected function checkValidInvoice()
{
$order = $this->getSession()->getOrder();
if (null === $order || null === $order->getChoosenInvoiceAddress() || null === $order->getPaymentModuleId() || null === AddressQuery::create()->findPk($order->getChoosenInvoiceAddress()) || null === ModuleQuery::create()->findPk($order->getPaymentModuleId())) {
throw new RedirectException($this->retrieveUrlFromRouteId('order.invoice'));
}
}
示例4: processHookFunction
/**
* Generates the content of the hook
*
* {hook name="hook_code" var1="value1" var2="value2" ... }
*
* This function create an event, feed it with the custom variables passed to the function (var1, var2, ...) and
* dispatch it to the hooks that respond to it.
*
* The name of the event is `hook.{context}.{hook_code}` where :
* * context : the id of the context of the smarty render : 1: frontoffice, 2: backoffice, 3: email, 4: pdf
* * hook_code : the code of the hook
*
* The event collects all the fragments of text rendered in each modules functions that listen to this event.
* Finally, this fragments are concatenated and injected in the template
*
* @param array $params the params passed in the smarty function
* @param \TheliaSmarty\Template\SmartyParser $smarty the smarty parser
*
* @return string the contents generated by modules
*/
public function processHookFunction($params, &$smarty)
{
$hookName = $this->getParam($params, 'name');
$module = intval($this->getParam($params, 'module', 0));
$moduleCode = $this->getParam($params, 'modulecode', "");
$type = $smarty->getTemplateDefinition()->getType();
$event = new HookRenderEvent($hookName, $params);
$event->setArguments($this->getArgumentsFromParams($params));
$eventName = sprintf('hook.%s.%s', $type, $hookName);
// this is a hook specific to a module
if (0 === $module && "" !== $moduleCode) {
if (null !== ($mod = ModuleQuery::create()->findOneByCode($moduleCode))) {
$module = $mod->getId();
}
}
if (0 !== $module) {
$eventName .= '.' . $module;
}
$this->getDispatcher()->dispatch($eventName, $event);
$content = trim($event->dump());
if ($this->debug && $smarty->getRequest()->get('SHOW_HOOK')) {
$content = sprintf('<div style="background-color: #C82D26; color: #fff; border-color: #000000; border: solid;">%s</div>%s', $hookName, $content);
}
$this->hookResults[$hookName] = $content;
// support for compatibility with module_include
if ($type === TemplateDefinition::BACK_OFFICE) {
$content .= $this->moduleIncludeCompat($params, $smarty);
}
return $content;
}
示例5: testModuleRefreshCommand
/**
* Test ModuleRefreshCommand
*/
public function testModuleRefreshCommand()
{
$moduleManagement = new ModuleManagement();
$moduleManagement->updateModules();
$module = ModuleQuery::create()->filterByType(1)->orderByPosition(Criteria::DESC)->findOne();
if ($module !== null) {
$module->delete();
$application = new Application($this->getKernel());
$moduleRefresh = new ModuleRefreshCommand();
$moduleRefresh->setContainer($this->getContainer());
$application->add($moduleRefresh);
$command = $application->find('module:refresh');
$commandTester = new CommandTester($command);
$commandTester->execute(['command' => $command->getName()]);
$expected = $module;
$actual = ModuleQuery::create()->filterByType(1)->orderByPosition(Criteria::DESC)->findOne();
$this->assertEquals($expected->getCode(), $actual->getCode(), 'Last standard module code must be same after deleting this one and calling module:refresh');
$this->assertEquals($expected->getType(), $actual->getType(), 'Last standard module type must be same after deleting this one and calling module:refresh');
$this->assertEquals($expected->getFullNamespace(), $actual->getFullNamespace(), 'Last standard module namespace must be same after deleting this one and calling module:refresh');
// Restore activation status
$actual->setActivate($expected->getActivate())->save();
} else {
$this->markTestIncomplete('This test cannot be complete without at least one standard module.');
}
}
示例6: verifyModuleId
public function verifyModuleId($value, ExecutionContextInterface $context)
{
$module = ModuleQuery::create()->findPk($value);
if (null === $module) {
$context->addViolation(Translator::getInstance()->trans("Module ID not found"));
}
}
示例7: buildForm
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()));
}
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$moduleCode = $this->formatModuleName($input->getArgument("module"));
$module = ModuleQuery::create()->findOneByCode($moduleCode);
if (null === $module) {
throw new \RuntimeException(sprintf("module %s not found", $moduleCode));
}
if ($module->getActivate() == BaseModule::IS_NOT_ACTIVATED) {
throw new \RuntimeException(sprintf("module %s is already deactivated", $moduleCode));
}
try {
$event = new ModuleToggleActivationEvent($module->getId());
$module = ModuleQuery::create()->findPk($module->getId());
if ($module->getMandatory() == BaseModule::IS_MANDATORY) {
if (!$this->askConfirmation($input, $output)) {
return;
}
$event->setAssumeDeactivate(true);
}
if ($input->getOption("with-dependencies")) {
$event->setRecursive(true);
}
$this->getDispatcher()->dispatch(TheliaEvents::MODULE_TOGGLE_ACTIVATION, $event);
} catch (\Exception $e) {
throw new \RuntimeException(sprintf("Deactivation fail with Exception : [%d] %s", $e->getCode(), $e->getMessage()));
}
//impossible to change output class in CommandTester...
if (method_exists($output, "renderBlock")) {
$output->renderBlock(array('', sprintf("Deactivation succeed for module %s", $moduleCode), ''), "bg=green;fg=black");
}
}
示例9: theliaModule
/**
* Process theliaModule template inclusion function
*
* This function accepts two parameters:
*
* - location : this is the location in the admin template. Example: folder-edit'. The function will search for
* AdminIncludes/<location>.html file, and fetch it as a Smarty template.
* - countvar : this is the name of a template variable where the number of found modules includes will be assigned.
*
* @param array $params
* @param \Smarty_Internal_Template $template
* @internal param \Thelia\Core\Template\Smarty\Plugins\unknown $smarty
*
* @return string
*/
public function theliaModule($params, \Smarty_Internal_Template $template)
{
$content = null;
$count = 0;
if (false !== ($location = $this->getParam($params, 'location', false))) {
if ($this->debug === true && $this->request->get('SHOW_INCLUDE')) {
echo sprintf('<div style="background-color: #C82D26; color: #fff; border-color: #000000; border: solid;">%s</div>', $location);
}
$moduleLimit = $this->getParam($params, 'module', null);
$modules = ModuleQuery::getActivated();
/** @var \Thelia\Model\Module $module */
foreach ($modules as $module) {
if (null !== $moduleLimit && $moduleLimit != $module->getCode()) {
continue;
}
$file = $module->getAbsoluteAdminIncludesPath() . DS . $location . '.html';
if (file_exists($file)) {
$output = trim(file_get_contents($file));
if (!empty($output)) {
$content .= $output;
$count++;
}
}
}
}
if (false !== ($countvarname = $this->getParam($params, 'countvar', false))) {
$template->assign($countvarname, $count);
}
if (!empty($content)) {
return $template->fetch(sprintf("string:%s", $content));
}
return "";
}
示例10: setUp
public function setUp()
{
$stubContainer = $this->getMockBuilder('\\Symfony\\Component\\DependencyInjection\\ContainerInterface')->disableOriginalConstructor()->getMock();
$this->action = new ModuleHook($stubContainer, $this->getMockEventDispatcher());
$this->module = ModuleQuery::create()->findOneByActivate(1);
$this->hook = HookQuery::create()->findOneByActivate(true);
}
示例11: getModule
/**
* @param string $itemName the modume code
* @return Module the module object
* @throws \InvalidArgumentException if module was not found
*/
protected function getModule($itemName)
{
if (null !== ($module = ModuleQuery::create()->findPk($itemName))) {
return $module;
}
throw new \InvalidArgumentException($this->getTranslator()->trans("No module found for code '%item'", ['%item' => $itemName]));
}
示例12: isModuleActive
protected function isModuleActive($module_id)
{
if (null !== ($module = ModuleQuery::create()->findPk($module_id))) {
return $module->getActivate();
}
return false;
}
示例13: updateModules
public function updateModules()
{
$finder = new Finder();
$finder->name('module.xml')->in($this->baseModuleDir . '/*/Config');
$descriptorValidator = new ModuleDescriptorValidator();
foreach ($finder as $file) {
$content = $descriptorValidator->getDescriptor($file->getRealPath());
$reflected = new \ReflectionClass((string) $content->fullnamespace);
$code = basename(dirname($reflected->getFileName()));
$con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$module = ModuleQuery::create()->filterByCode($code)->findOne();
if (null === $module) {
$module = new Module();
$module->setCode($code)->setFullNamespace((string) $content->fullnamespace)->setType($this->getModuleType($reflected))->setActivate(0)->save($con);
}
$this->saveDescription($module, $content, $con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
}
示例14: process
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('event_dispatcher')) {
return;
}
$definition = $container->getDefinition('event_dispatcher');
foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) {
foreach ($events as $event) {
$priority = isset($event['priority']) ? $event['priority'] : 0;
if (!isset($event['event'])) {
throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "kernel.event_listener" tags.', $id));
}
if (!isset($event['method'])) {
$event['method'] = 'on' . preg_replace_callback(array('/(?<=\\b)[a-z]/i', '/[^a-z0-9]/i'), function ($matches) {
return strtoupper($matches[0]);
}, $event['event']);
$event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
}
$definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority));
}
}
foreach ($container->findTaggedServiceIds('kernel.event_subscriber') as $id => $attributes) {
// We must assume that the class value has been correctly filled, even if the service is created by a factory
$class = $container->getDefinition($id)->getClass();
$refClass = new \ReflectionClass($class);
$interface = 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface';
if (!$refClass->implementsInterface($interface)) {
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
}
$definition->addMethodCall('addSubscriberService', array($id, $class));
}
// We have to check if Propel is initialized before registering hooks
$managers = Propel::getServiceContainer()->getConnectionManagers();
if (!array_key_exists('thelia', $managers)) {
return;
}
foreach ($container->findTaggedServiceIds('hook.event_listener') as $id => $events) {
$class = $container->getDefinition($id)->getClass();
// the class must extends BaseHook
$implementClass = HookDefinition::BASE_CLASS;
if (!is_subclass_of($class, $implementClass)) {
throw new \InvalidArgumentException(sprintf('Hook class "%s" must extends class "%s".', $class, $implementClass));
}
// retrieve the module id
$properties = $container->getDefinition($id)->getProperties();
$module = null;
if (array_key_exists('module', $properties)) {
$moduleCode = explode(".", $properties['module'])[1];
if (null !== ($module = ModuleQuery::create()->findOneByCode($moduleCode))) {
$module = $module->getId();
}
}
foreach ($events as $event) {
$this->registerHook($class, $module, $id, $event);
}
}
// now we can add listeners for active hooks and active module
$this->addHooksMethodCall($definition);
}
示例15: preActivation
/**
*
* return false if CreditAccount module is not present
*
* @param ConnectionInterface $con
* @return bool|void
*/
public function preActivation(ConnectionInterface $con = null)
{
$module = ModuleQuery::create()->filterByCode('CreditAccount')->filterByActivate(self::IS_ACTIVATED)->findOne();
if (null === $module) {
throw new \RuntimeException(Translator::getInstance()->trans('CreditAccount must be installed and activated', [], 'loyalty'));
}
return true;
}