/**
  * {@inheritdoc}
  * @throws ValidatorException
  */
 public function saveSettings($namespace, Settings $settings)
 {
     $schema = $this->schemaRegistry->getSchema($namespace);
     $settingsBuilder = new SettingsBuilder();
     $schema->buildSettings($settingsBuilder);
     $parameters = $settingsBuilder->resolve($settings->getParameters());
     foreach ($settingsBuilder->getTransformers() as $parameter => $transformer) {
         if (array_key_exists($parameter, $parameters)) {
             $parameters[$parameter] = $transformer->transform($parameters[$parameter]);
         }
     }
     if (isset($this->resolvedSettings[$namespace])) {
         $this->resolvedSettings[$namespace]->setParameters($parameters);
     }
     $persistedParameters = $this->parameterRepository->findBy(array('category' => $namespace, 'cId' => $this->getCourse()->getId()));
     $persistedParametersMap = array();
     foreach ($persistedParameters as $parameter) {
         $persistedParametersMap[$parameter->getName()] = $parameter;
     }
     foreach ($parameters as $name => $value) {
         if (isset($persistedParametersMap[$name])) {
             $persistedParametersMap[$name]->setValue($value);
         } else {
             /** @var CCourseSetting $parameter */
             //$parameter = $this->parameterFactory->createNew();
             $parameter = new CCourseSetting();
             $parameter->setNamespace($namespace)->setName($name)->setValue($value)->setCId($this->getCourse()->getId());
             /* @var $errors ConstraintViolationListInterface */
             $errors = $this->validator->validate($parameter);
             if (0 < $errors->count()) {
                 throw new ValidatorException($errors->get(0)->getMessage());
             }
             $this->parameterManager->persist($parameter);
         }
     }
     $this->parameterManager->flush();
     $this->cache->save($namespace, $parameters);
 }
 /**
  * {@inheritdoc}
  * @throws ValidatorException
  */
 public function saveSettings($namespace, Settings $settings)
 {
     $schema = $this->schemaRegistry->getSchema($namespace);
     $settingsBuilder = new SettingsBuilder();
     $schema->buildSettings($settingsBuilder);
     $parameters = $settingsBuilder->resolve($settings->getParameters());
     foreach ($settingsBuilder->getTransformers() as $parameter => $transformer) {
         if (array_key_exists($parameter, $parameters)) {
             $parameters[$parameter] = $transformer->transform($parameters[$parameter]);
         }
     }
     if (isset($this->resolvedSettings[$namespace])) {
         $this->resolvedSettings[$namespace]->setParameters($parameters);
     }
     $persistedParameters = $this->parameterRepository->findBy(array('category' => $namespace));
     $persistedParametersMap = array();
     foreach ($persistedParameters as $parameter) {
         $persistedParametersMap[$parameter->getName()] = $parameter;
     }
     $event = $this->eventDispatcher->dispatch(SettingsEvent::PRE_SAVE, new SettingsEvent($namespace, $settings, $parameters));
     $url = $event->getArgument('url');
     foreach ($parameters as $name => $value) {
         if (isset($persistedParametersMap[$name])) {
             $persistedParametersMap[$name]->setValue($value);
         } else {
             /** @var SettingsCurrent $parameter */
             $parameter = $this->parameterFactory->createNew();
             $parameter->setNamespace($namespace)->setName($name)->setValue($value)->setUrl($url)->setAccessUrl(1)->setAccessUrlLocked(0)->setAccessUrlChangeable(1);
             /* @var $errors ConstraintViolationListInterface */
             $errors = $this->validator->validate($parameter);
             if (0 < $errors->count()) {
                 throw new ValidatorException($errors->get(0)->getMessage());
             }
             $this->parameterManager->persist($parameter);
         }
     }
     $this->parameterManager->flush();
     $this->eventDispatcher->dispatch(SettingsEvent::POST_SAVE, new SettingsEvent($namespace, $settings, $parameters));
     $this->cache->save($namespace, $parameters);
 }