Exemplo n.º 1
0
 /**
  * Set module configuration variable, creating it if required
  *
  * @param  int             $moduleId          the module id
  * @param  string          $variableName      the variable name
  * @param  string          $variableValue     the variable value
  * @param  null            $valueLocale       the locale, or null if not required
  * @param  bool            $createIfNotExists if true, the variable will be created if not already defined
  * @throws \LogicException if variable does not exists and $createIfNotExists is false
  * @return $this;
  */
 public function setConfigValue($moduleId, $variableName, $variableValue, $valueLocale = null, $createIfNotExists = true)
 {
     $configValue = self::create()->filterByModuleId($moduleId)->filterByName($variableName)->findOne();
     if (null === $configValue) {
         if (true === $createIfNotExists) {
             $configValue = new ModuleConfig();
             $configValue->setModuleId($moduleId)->setName($variableName);
         } else {
             throw new \LogicException("Module configuration variable {$variableName} does not exists. Create it first.");
         }
     }
     if (null !== $valueLocale) {
         $configValue->setLocale($valueLocale);
     }
     $configValue->setValue($variableValue)->save();
     return $this;
 }