public function execute($request) { $this->form = new sfForm(); if (!$this->context->user->hasCredential('administrator')) { QubitAcl::forwardUnauthorized(); } $criteria = new Criteria(); $criteria->add(QubitSetting::NAME, 'plugins'); if (1 == count($query = QubitSetting::get($criteria))) { $setting = $query[0]; $this->form->setDefault('enabled', unserialize($setting->__get('value', array('sourceCulture' => true)))); } $configuration = ProjectConfiguration::getActive(); $pluginPaths = $configuration->getAllPluginPaths(); foreach (sfPluginAdminPluginConfiguration::$pluginNames as $name) { unset($pluginPaths[$name]); } $this->plugins = array(); foreach ($pluginPaths as $name => $path) { $className = $name . 'Configuration'; if (sfConfig::get('sf_plugins_dir') == substr($path, 0, strlen(sfConfig::get('sf_plugins_dir'))) && is_readable($classPath = $path . '/config/' . $className . '.class.php')) { $this->installPluginAssets($name, $path); require_once $classPath; $class = new $className($configuration); // Build a list of themes if (isset($class::$summary) && 1 === preg_match('/theme/i', $class::$summary)) { $this->plugins[$name] = $class; } } } if ($request->isMethod('post')) { $this->form->setValidators(array('enabled' => new sfValidatorChoice(array('choices' => array_keys($this->plugins), 'empty_value' => array(), 'multiple' => true)))); $this->form->bind($request->getPostParameters()); if ($this->form->isValid()) { if (1 != count($query)) { $setting = new QubitSetting(); $setting->name = 'plugins'; } $settings = unserialize($setting->__get('value', array('sourceCulture' => true))); foreach (array_keys($this->plugins) as $item) { if (in_array($item, (array) $this->form->getValue('enabled'))) { $settings[] = $item; } else { if (false !== ($key = array_search($item, $settings))) { unset($settings[$key]); } } } $setting->__set('value', serialize(array_unique($settings))); $setting->save(); // Clear cache $cacheClear = new sfCacheClearTask(sfContext::getInstance()->getEventDispatcher(), new sfFormatter()); $cacheClear->run(); $this->redirect(array('module' => 'sfPluginAdminPlugin', 'action' => 'themes')); } } }
public function execute($request) { $this->form = new sfForm(); $this->form->setWidgets(array('toggleDescription' => new sfWidgetFormInputCheckbox(), 'toggleLogo' => new sfWidgetFormInputCheckbox(), 'toggleTitle' => new sfWidgetFormInputCheckbox())); $criteria = new Criteria(); $criteria->add(QubitSetting::NAME, 'toggleDescription'); if (1 == count($toggleDescriptionQuery = QubitSetting::get($criteria))) { $toggleDescriptionSetting = $toggleDescriptionQuery[0]; $this->form->setDefault('toggleDescription', $toggleDescriptionSetting->__get('value', array('sourceCulture' => true))); } $criteria = new Criteria(); $criteria->add(QubitSetting::NAME, 'toggleLogo'); if (1 == count($toggleLogoQuery = QubitSetting::get($criteria))) { $toggleLogoSetting = $toggleLogoQuery[0]; $this->form->setDefault('toggleLogo', $toggleLogoSetting->__get('value', array('sourceCulture' => true))); } $criteria = new Criteria(); $criteria->add(QubitSetting::NAME, 'toggleTitle'); if (1 == count($toggleTitleQuery = QubitSetting::get($criteria))) { $toggleTitleSetting = $toggleTitleQuery[0]; $this->form->setDefault('toggleTitle', $toggleTitleSetting->__get('value', array('sourceCulture' => true))); } if ($request->isMethod('post')) { $this->form->setValidators(array('toggleDescription' => new sfValidatorBoolean(), 'toggleLogo' => new sfValidatorBoolean(), 'toggleTitle' => new sfValidatorBoolean())); $this->form->bind($request->getPostParameters()); if ($this->form->isValid()) { if (1 != count($toggleDescriptionQuery)) { $toggleDescriptionSetting = new QubitSetting(); $toggleDescriptionSetting->name = 'toggleDescription'; } $toggleDescriptionSetting->__set('value', $this->form->getValue('toggleDescription'), array('sourceCulture' => true)); $toggleDescriptionSetting->save(); if (1 != count($toggleLogoQuery)) { $toggleLogoSetting = new QubitSetting(); $toggleLogoSetting->name = 'toggleLogo'; } $toggleLogoSetting->__set('value', $this->form->getValue('toggleLogo'), array('sourceCulture' => true)); $toggleLogoSetting->save(); if (1 != count($toggleTitleQuery)) { $toggleTitleSetting = new QubitSetting(); $toggleTitleSetting->name = 'toggleTitle'; } $toggleTitleSetting->__set('value', $this->form->getValue('toggleTitle'), array('sourceCulture' => true)); $toggleTitleSetting->save(); $this->redirect(array('module' => 'settings', 'action' => 'list')); } } }
public function execute($request) { $this->form = new sfForm(); $this->form->setValidator('confirmPassword', new sfValidatorString(array('required' => true))); $this->form->setWidget('confirmPassword', new sfWidgetFormInputPassword()); $this->form->setValidator('email', new sfValidatorEmail(array('required' => true))); $this->form->setWidget('email', new sfWidgetFormInput()); $this->form->setValidator('password', new sfValidatorString(array('required' => true))); $this->form->setWidget('password', new sfWidgetFormInputPassword()); $this->form->setValidator('siteDescription', new sfValidatorString()); $this->form->setWidget('siteDescription', new sfWidgetFormInput()); $this->form->setValidator('siteTitle', new sfValidatorString(array('required' => true))); $this->form->setWidget('siteTitle', new sfWidgetFormInput()); $this->form->setValidator('username', new sfValidatorString(array('required' => true))); $this->form->setWidget('username', new sfWidgetFormInput()); $this->form->getValidatorSchema()->setPostValidator(new sfValidatorSchemaCompare('password', '==', 'confirmPassword')); if ($request->isMethod('post')) { $this->form->bind($request->getPostParameters()); if ($this->form->isValid()) { $setting = new QubitSetting(); $setting->name = 'siteTitle'; $setting->value = $this->form->getValue('siteTitle'); $setting->save(); $setting = new QubitSetting(); $setting->name = 'siteDescription'; $setting->value = $this->form->getValue('siteDescription'); $setting->save(); $user = new QubitUser(); $user->username = $this->form->getValue('username'); $user->email = $this->form->getValue('email'); $user->setPassword($this->form->getValue('password')); $user->save(); $aclUserGroup = new QubitAclUserGroup(); $aclUserGroup->userId = $user->id; $aclUserGroup->groupId = QubitAclGroup::ADMINISTRATOR_ID; $aclUserGroup->save(); $this->redirect(array('module' => 'sfInstallPlugin', 'action' => 'clearCache')); } } }
public function execute($request) { $this->form = new sfForm(); $this->culture = $this->context->user->getCulture(); $this->globalForm = new SettingsGlobalForm(); $this->siteInformationForm = new SettingsSiteInformationForm(); $this->defaultTemplateForm = new SettingsDefaultTemplateForm(); $this->uiLabelForm = new SettingsGenericForm(array(), array('settings' => QubitSetting::getByScope('ui_label'), 'scope' => 'ui_label', 'fieldsRequired' => false)); $this->oaiRepositoryForm = new SettingsOaiRepositoryForm(); $this->initializeDefaultPageElementsForm(); // Handle POST data (form submit) if ($request->isMethod('post')) { // Clean cache $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_app_cache_dir') . '/settings')); $cache->clean(); // Global settings form submission if (null !== $request->global_settings) { // Hack to populate "version" field so it displays // if validation fails. By default, their values are not included in // $request->parameterHolder (and thus are not bound) because their // <input> field is disabled. $version = null !== ($setting = QubitSetting::getSettingByName('version')) ? $setting->getValue(array('sourceCulture' => true)) : null; $this->globalForm->bind(array_merge($request->global_settings, array('version' => $version))); if ($this->globalForm->isValid()) { // Do update and redirect to avoid repeat submit wackiness $this->updateGlobalSettings(); $this->redirect('settings/list'); } } // Handle site information form submission if (null !== $request->site_information) { $this->siteInformationForm->bind($request->site_information); if ($this->siteInformationForm->isValid()) { // Do update and redirect to avoid repeat submit wackiness $this->updateSiteInformationSettings(); $this->redirect('settings/list'); } } // Handle default template form submission if (null !== $request->default_template) { $this->defaultTemplateForm->bind($request->default_template); if ($this->defaultTemplateForm->isValid()) { // Do update and redirect to avoid repeat submit wackiness $this->updateDefaultTemplateSettings($this->defaultTemplateForm); $this->redirect('settings/list'); } } // Handle default template form submission if (null !== $request->ui_label) { $this->uiLabelForm->bind($request->ui_label); if ($this->uiLabelForm->isValid()) { // Do update and redirect to avoid repeat submit wackiness $this->updateUiLabelSettings($this->uiLabelForm); $this->redirect('settings/list'); } } // Handle OAI Repository form submission if (null !== $request->oai_repository) { $this->oaiRepositoryForm->bind($request->oai_repository); if ($this->oaiRepositoryForm->isValid()) { // Do update and redirect to avoid repeat submit wackiness $this->updateOaiRepositorySettings($this->oaiRepositoryForm); $this->redirect('settings/list'); } } if (null !== ($languageCode = $request->languageCode)) { try { format_language($languageCode, $languageCode); } catch (Exception $e) { $this->redirect(array('module' => 'settings', 'action' => 'list')); } $setting = new QubitSetting(); $setting->name = $languageCode; $setting->scope = 'i18n_languages'; $setting->value = $languageCode; $setting->deleteable = true; $setting->editable = true; $setting->getCurrentSettingI18n()->setCulture('en'); $setting->sourceCulture = 'en'; $setting->save(); } } // Populate forms $this->populateGlobalForm(); $this->populateSiteInformationForm(); $this->populateDefaultTemplateForm($this->defaultTemplateForm); $this->populateUiLabelForm($this->uiLabelForm); $this->populateOaiRepositoryForm($this->oaiRepositoryForm); // Last symfony 1.0 forms holdout $this->i18nLanguages = QubitSetting::getByScope('i18n_languages'); $this->form->setValidator('languageCode', new sfValidatorI18nChoiceLanguage()); $this->form->setWidget('languageCode', new sfWidgetFormI18nChoiceLanguage(array('add_empty' => true, 'culture' => $this->context->user->getCulture()))); // make vars available to template $this->availableLanguages = self::$availableLanguges; }
public static function loadData() { $object = new QubitInformationObject(); $object->id = QubitInformationObject::ROOT_ID; $object->save(); $object = new QubitActor(); $object->id = QubitActor::ROOT_ID; $object->save(); $object = new QubitSetting(); $object->name = 'plugins'; $object->value = serialize(array('sfCaribouPlugin', 'sfEhriThemePlugin', 'sfDcPlugin', 'sfEacPlugin', 'sfEadPlugin', 'sfIsaarPlugin', 'sfIsadPlugin', 'sfEhriIsadPlugin', 'sfIsdfPlugin', 'sfIsdiahPlugin', 'sfEhriIsdiahPlugin', 'sfModsPlugin', 'sfRadPlugin', 'sfSkosPlugin')); $object->save(); $dispatcher = sfContext::getInstance()->getEventDispatcher(); $formatter = new sfAnsiColorFormatter(); chdir(sfConfig::get('sf_root_dir')); $loadData = new sfPropelDataLoadTask($dispatcher, $formatter); $loadData->run(); }
/** * Find a setting, and save a new value to it * * @return QubitSetting object. */ public static function findAndSave($name, $value, $options) { // Search for existing setting by name (optionally, scope) $criteria = new Criteria(); $criteria->add(QubitSetting::NAME, $name); if (isset($options['scope'])) { $criteria->add(QubitSetting::SCOPE, $options['scope']); } // If setting doesn't already exist, create a new one if // $options['createNew'] is true if (null === ($setting = QubitSetting::getOne($criteria)) && $options['createNew'] === true) { $setting = new QubitSetting(); $setting->setName($name); if (isset($options['scope'])) { $setting->setScope($options['scope']); } } // Set value and save setting if (null !== $setting) { $setting->setValue($value, $options); $setting->save(); } return $setting; }