public function onModuleConfigure(HookRenderEvent $event) { $vars = []; if (null !== ($params = ModuleConfigQuery::create()->findByModuleId(ForcePhone::getModuleId()))) { /** @var ModuleConfig $param */ foreach ($params as $param) { $vars[$param->getName()] = $param->getValue(); } } $event->add($this->render('force-phone/module-configuration.html', $vars)); }
/** * @param LoopResult $loopResult * * @return LoopResult */ public function parseResults(LoopResult $loopResult) { $moduleCode = $this->getModule(); if (null === ($module = ModuleQuery::create()->filterByCode($moduleCode, Criteria::LIKE)->findOne())) { throw new \InvalidArgumentException("Module with code '{$moduleCode}' does not exists."); } $configValue = ModuleConfigQuery::create()->getConfigValue($module->getId(), $this->getVariable(), $this->getDefaultValue(), $this->getLocale()); $loopResultRow = new LoopResultRow(); $loopResultRow->set("VARIABLE", $this->getVariable())->set("VALUE", $configValue); $loopResult->addRow($loopResultRow); return $loopResult; }
public function onModuleConfigure(HookRenderEvent $event) { $logFilePath = sprintf(THELIA_ROOT . "log" . DS . "%s.log", Atos::MODULE_DOMAIN); $traces = @file_get_contents($logFilePath); if (false === $traces) { $traces = $this->translator->trans("The log file '%log' does not exists yet.", ['%log' => $logFilePath], Atos::MODULE_DOMAIN); } elseif (empty($traces)) { $traces = $this->translator->trans("The log file is currently empty.", [], Atos::MODULE_DOMAIN); } $vars = ['trace_content' => nl2br($traces)]; if (null !== ($params = ModuleConfigQuery::create()->findByModuleId(Atos::getModuleId()))) { /** @var ModuleConfig $param */ foreach ($params as $param) { $vars[$param->getName()] = $param->getValue(); } } $event->add($this->render('atos/module-configuration.html', $vars)); }
/** * Provides access to a module configuration value * * @param array $params * @param \Smarty $smarty * @return string the value of the configuration value */ public function moduleConfigDataAccess($params, $smarty) { $key = $this->getParam($params, 'key', false); $moduleCode = $this->getParam($params, 'module', false); $locale = $this->getParam($params, 'locale'); if (null === $locale) { $locale = $this->getSession()->getLang()->getLocale(); } if ($key === false || $moduleCode === false) { return null; } $default = $this->getParam($params, 'default', ''); if (null !== ($module = ModuleQuery::create()->findOneByCode($moduleCode))) { return ModuleConfigQuery::create()->getConfigValue($module->getId(), $key, $default, $locale); } else { Tlog::getInstance()->addWarning(sprintf("Module code '%s' not found in module-config Smarty function", $moduleCode)); $value = $default; } return $value; }
/** * Performs an INSERT on the database, given a ModuleConfig or Criteria object. * * @param mixed $criteria Criteria or ModuleConfig object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(ModuleConfigTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from ModuleConfig object } if ($criteria->containsKey(ModuleConfigTableMap::ID) && $criteria->keyContainsValue(ModuleConfigTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . ModuleConfigTableMap::ID . ')'); } // Set the correct dbName $query = ModuleConfigQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = $query->doInsert($con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }
/** * @inheritdoc */ public static function setConfigValue($variableName, $variableValue, $valueLocale = null, $createIfNotExists = true) { ModuleConfigQuery::create()->setConfigValue(self::getModuleId(), $variableName, $variableValue, $valueLocale, $createIfNotExists); }
/** * Returns the number of related ModuleConfig objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con * @return int Count of related ModuleConfig objects. * @throws PropelException */ public function countModuleConfigs(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collModuleConfigsPartial && !$this->isNew(); if (null === $this->collModuleConfigs || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collModuleConfigs) { return 0; } if ($partial && !$criteria) { return count($this->getModuleConfigs()); } $query = ChildModuleConfigQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByModule($this)->count($con); } return count($this->collModuleConfigs); }
/** * @expectedException \LogicException */ public function testSetNotExists() { $moduleModel = ModuleQuery::create()->findOne(); $moduleConfig = ModuleConfigQuery::create()->setConfigValue($moduleModel->getId(), 'test-name-4', 'test-value', null, false); }
/** * Returns a new ChildModuleConfigQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return ChildModuleConfigQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof \Thelia\Model\ModuleConfigQuery) { return $criteria; } $query = new \Thelia\Model\ModuleConfigQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see ModuleConfig::setDeleted() * @see ModuleConfig::isDeleted() */ public function delete(ConnectionInterface $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getServiceContainer()->getWriteConnection(ModuleConfigTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildModuleConfigQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Get the associated ChildModuleConfig object * * @param ConnectionInterface $con Optional Connection object. * @return ChildModuleConfig The associated ChildModuleConfig object. * @throws PropelException */ public function getModuleConfig(ConnectionInterface $con = null) { if ($this->aModuleConfig === null && $this->id !== null) { $this->aModuleConfig = ChildModuleConfigQuery::create()->findPk($this->id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aModuleConfig->addModuleConfigI18ns($this); */ } return $this->aModuleConfig; }