Author: david
Date: 2008-10-21 12:10:37 -0700 (Tue, 21 Oct 2008)
New Revision: 1484
Added:
trunk/qubit/lib/form/SettingsSiteInformationForm.class.php
Modified:
trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
trunk/qubit/apps/qubit/modules/settings/actions/updateAction.class.php
trunk/qubit/apps/qubit/modules/settings/templates/listSuccess.php
trunk/qubit/lib/form/SettingsGlobalForm.class.php
Log:
- Add SettingsSiteInformationForm.class.php to define site information form on
settings/list page.
- Update settings/list and settings/update action and template pages to allow
editing of site information settings "site_title" and "site_description"
- Change namespace for global settings form to "global_settings" for clarity
and to avoid namespace clashes with multiple settings forms.
- Add logic for new "multi_repository", "site_name", and "site_title" settings
to gracefully handle update action when settings are not already in the
database. Allows backwards compatibility with 1.0.3 without a data reload.
Fixes issue #478
Modified: trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
===================================================================
--- trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
2008-10-21 19:01:51 UTC (rev 1483)
+++ trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
2008-10-21 19:10:37 UTC (rev 1484)
@@ -56,38 +56,47 @@
public function execute($request)
{
+ $this->culture = $this->getUser()->getCulture();
+
$this->globalForm = new SettingsGlobalForm;
+ $this->siteInformationForm = new SettingsSiteInformationForm;
// Validate submitted data, and forward to 'updateAction' if validation
succeeds
if ($request->isMethod('post'))
{
- // Hack to populate "version" and "upload_dir" fields 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;
- $uploadDir = (null !== $setting =
QubitSetting::getSettingByName('upload_dir')) ?
$setting->getValue(array('sourceCulture'=>true)) : null;
- $this->globalForm->bind(array_merge($request->getParameter('settings'),
array('version'=>$version, 'upload_dir'=>$uploadDir)));
- if ($this->globalForm->isValid())
+
+ // Global settings form submission
+ if (null !== $request->getParameter('global_settings'))
{
-
$this->redirect('settings/update?'.http_build_query($this->globalForm->getValues()));
+ // Hack to populate "version" and "upload_dir" fields 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;
+ $uploadDir = (null !== $setting =
QubitSetting::getSettingByName('upload_dir')) ?
$setting->getValue(array('sourceCulture'=>true)) : null;
+
$this->globalForm->bind(array_merge($request->getParameter('global_settings'),
array('version'=>$version, 'upload_dir'=>$uploadDir)));
+ if ($this->globalForm->isValid())
+ {
+ $values = array_map('urlencode', $this->globalForm->getValues());
+ $this->redirect('settings/update?'.http_build_query($values));
+ }
}
+
+ // Site information form submission
+ if (null !== $request->getParameter('site_information'))
+ {
+
$this->siteInformationForm->bind($request->getParameter('site_information'));
+ if ($this->siteInformationForm->isValid())
+ {
+ // URL encode values before building url
+ $values = array_map('urlencode',
$this->siteInformationForm->getValues());
+ $this->redirect('settings/update?'.http_build_query($values));
+ }
+ }
}
- // Get global settings
- $version = QubitSetting::getSettingByName('version');
- $uploadDir = QubitSetting::getSettingByName('upload_dir');
- $refImageMaxWidth =
QubitSetting::getSettingByName('reference_image_maxwidth');
- $hitsPerPage = QubitSetting::getSettingByName('hits_per_page');
- $multiRepository = QubitSetting::getSettingByName('multi_repository');
-
- // Set defaults for global form
- $this->globalForm->setDefaults(array(
- 'version' => (isset($version)) ?
$version->getValue(array('sourceCulture'=>true)) : null,
- 'upload_dir' => (isset($uploadDir)) ?
$uploadDir->getValue(array('sourceCulture'=>true)) : null,
- 'reference_image_maxwidth' => (isset($refImageMaxWidth)) ?
$refImageMaxWidth->getValue(array('sourceCulture'=>true)) : null,
- 'hits_per_page' => (isset($hitsPerPage)) ?
$hitsPerPage->getValue(array('sourceCulture'=>true)) : null,
- 'multi_repository' => (isset($multiRepository)) ?
intval($multiRepository->getValue(array('sourceCulture'=>true))) : 1
- ));
+ // Populate forms
+ $this->populateGlobalForm();
+ $this->populateSiteInformationForm();
// Get local settings
$localSettings = QubitSetting::getLocalSettings();
@@ -105,4 +114,45 @@
$this->settingsGroups = $settingsGroups;
$this->availableLanguages = self::$availableLanguges;
}
+
+ /**
+ * Populate the Global form with database values
+ */
+ protected function populateGlobalForm()
+ {
+ // Get global settings
+ $version = QubitSetting::getSettingByName('version');
+ $uploadDir = QubitSetting::getSettingByName('upload_dir');
+ $refImageMaxWidth =
QubitSetting::getSettingByName('reference_image_maxwidth');
+ $hitsPerPage = QubitSetting::getSettingByName('hits_per_page');
+ $multiRepository = QubitSetting::getSettingByName('multi_repository');
+
+ // Set defaults for global form
+ $this->globalForm->setDefaults(array(
+ 'version' => (isset($version)) ?
$version->getValue(array('sourceCulture'=>true)) : null,
+ 'upload_dir' => (isset($uploadDir)) ?
$uploadDir->getValue(array('sourceCulture'=>true)) : null,
+ 'reference_image_maxwidth' => (isset($refImageMaxWidth)) ?
$refImageMaxWidth->getValue(array('sourceCulture'=>true)) : null,
+ 'hits_per_page' => (isset($hitsPerPage)) ?
$hitsPerPage->getValue(array('sourceCulture'=>true)) : null,
+ 'multi_repository' => (isset($multiRepository)) ?
intval($multiRepository->getValue(array('sourceCulture'=>true))) : 1
+ ));
+ }
+
+ /**
+ * Populate the site information form with database values
+ */
+ protected function populateSiteInformationForm()
+ {
+ // Get site information settings
+ $this->siteTitle = (null !== $siteTitle =
QubitSetting::getSettingByName('site_title')) ? $siteTitle : new QubitSetting;
+ $this->siteDescription = (null !== $siteDescription =
QubitSetting::getSettingByName('site_description')) ? $siteDescription : new
QubitSetting;
+
+ // Set defaults values
+ $this->siteInformationForm->setDefaults(array(
+ 'site_title' => $this->siteTitle->getValue(array('culture' =>
$this->culture)),
+ 'site_description' => $this->siteDescription->getValue(array('culture'
=> $this->culture))
+ ));
+ }
}
+
+
+
Modified: trunk/qubit/apps/qubit/modules/settings/actions/updateAction.class.php
===================================================================
--- trunk/qubit/apps/qubit/modules/settings/actions/updateAction.class.php
2008-10-21 19:01:51 UTC (rev 1483)
+++ trunk/qubit/apps/qubit/modules/settings/actions/updateAction.class.php
2008-10-21 19:10:37 UTC (rev 1484)
@@ -84,6 +84,7 @@
// update global settings
$this->updateGlobalSettings($request);
+ $this->updateSiteInformationSettings($request);
$this->refreshSettings();
return $this->redirect('settings/list');
@@ -91,9 +92,9 @@
private function refreshSettings()
{
- // clear the file cache containing the settings
- $fileCache = new sfFileCache(array('cache_dir' =>
sfConfig::get('sf_app_cache_dir').'/settings'));
- $fileCache->clean();
+ // clear the file cache containing the settings
+ $fileCache = new sfFileCache(array('cache_dir' =>
sfConfig::get('sf_app_cache_dir').'/settings'));
+ $fileCache->clean();
}
/**
@@ -103,7 +104,7 @@
*/
protected function updateGlobalSettings($request)
{
- // Reference Image Max Width
+ // Reference image max width
if (null !== $refMaxWidth =
$request->getParameter('reference_image_maxwidth')) {
if (intval($refMaxWidth) && $refMaxWidth > 0)
{
@@ -130,6 +131,13 @@
// Multi-repository radio button
if (null !== $multiRepositoryValue =
$request->getParameter('multi_repository')) {
$setting = QubitSetting::getSettingByName('multi_repository');
+
+ // Add setting if it's not already in the sampleData.yml file for
+ // backwards compatiblity with v1.0.3 sampleData.yml file
+ if (null === $setting)
+ {
+ $setting = QubitSetting::createNewSetting('multi_repository', null,
array('deleteable'=>false));
+ }
// Force sourceCulture update to prevent discrepency in settings between
cultures
$setting->setValue($multiRepositoryValue, array('sourceCulture'=>true));
@@ -137,4 +145,39 @@
}
}
+ /**
+ * Update site information settings
+ *
+ * @param sfRequest $request Current request object
+ */
+ protected function updateSiteInformationSettings($request)
+ {
+ if (strlen($siteTitle = $request->getParameter('site_title'))) {
+ $setting = QubitSetting::getSettingByName('site_title');
+
+ // Create new QubitSetting if site_title doesn't already exist (backwards
+ // compatiblity with v1.0.3 sampleData.yml file)
+ if (null === $setting)
+ {
+ $setting = QubitSetting::createNewSetting('site_title', null,
array('scope'=>'site_information', 'deleteable'=>false));
+ }
+ $setting->setValue($siteTitle);
+ $setting->save();
+ }
+
+
+ if (strlen($siteDescription = $request->getParameter('site_description')))
{
+ $setting = QubitSetting::getSettingByName('site_description');
+
+ // Create new QubitSetting if site_description doesn't already exist
+ // (backwards compatiblity with v1.0.3 sampleData.yml file)
+ if (null === $setting)
+ {
+ $setting = QubitSetting::createNewSetting('site_description', null,
array('scope'=>'site_information', 'deleteable'=>false));
+ }
+ $setting->setValue($siteDescription);
+ $setting->save();
+ }
+ }
+
}
Modified: trunk/qubit/apps/qubit/modules/settings/templates/listSuccess.php
===================================================================
--- trunk/qubit/apps/qubit/modules/settings/templates/listSuccess.php
2008-10-21 19:01:51 UTC (rev 1483)
+++ trunk/qubit/apps/qubit/modules/settings/templates/listSuccess.php
2008-10-21 19:10:37 UTC (rev 1484)
@@ -2,7 +2,6 @@
<!-- Global settings table -->
<div class="tableHeader" style="margin-bottom: 10px;"><?php echo __('global')
?></div>
-
<fieldset class="collapsible collapsed">
<legend><?php echo __('global') ?></legend>
<form action="<?php echo url_for('settings/list') ?>" method="POST">
@@ -28,6 +27,56 @@
</form>
</fieldset>
+<!-- Site information table -->
+<div class="tableHeader" style="margin-bottom: 10px;"><?php echo __('site
information') ?></div>
+<fieldset class="collapsible collapsed">
+ <legend><?php echo __('site information') ?></legend>
+ <form action="<?php echo url_for('settings/list') ?>" method="POST">
+ <table class="list">
+ <thead>
+ <tr>
+ <th><?php echo __('name')?></th>
+ <th><?php echo __('value')?></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><?php echo $siteInformationForm['site_title']->renderLabel(null,
+ array('title' => __('The name of the website for display in the
header'))) ?></td>
+ <td>
+ <?php if (strlen($error =
$siteInformationForm['site_title']->renderError())): ?>
+ <?php echo $error ?>
+ <?php elseif ($sourceCultureHelper =
$siteTitle->getSourceCultureHelper($culture)): ?>
+ <div class="default-translation"><?php echo
nl2br($sourceCultureHelper) ?></div>
+ <?php endif; ?>
+ <?php echo $siteInformationForm['site_title']->render() ?>
+ </td>
+ </tr>
+ <tr>
+ <td><?php echo
$siteInformationForm['site_description']->renderLabel(null,
+ array('title' => __('A brief site description or "tagline"
for the header'))) ?></td>
+ <td>
+ <?php if (strlen($error =
$siteInformationForm['site_description']->renderError())): ?>
+ <?php echo $error ?>
+ <?php elseif ($sourceCultureHelper =
$siteDescription->getSourceCultureHelper($culture)): ?>
+ <div class="default-translation"><?php echo
nl2br($sourceCultureHelper) ?></div>
+ <?php endif; ?>
+ <?php echo $siteInformationForm['site_description']->render() ?>
+ </td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td>
+ <div style="float: right; margin: 3px 8px 0 0;">
+ <?php echo my_submit_tag(__('save'), array('style' => 'width:
auto;')) ?>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </form>
+</fieldset>
+
<?php foreach ($settingsGroups as $scope => $settings): ?>
<?php echo form_tag('settings/update') ?>
<?php echo input_hidden_tag('fieldset', $scope) ?>
@@ -60,7 +109,7 @@
<?php elseif ($setting->isEditable()): ?>
<?php echo input_tag($setting->getId(), $setting->getValue()) ?>
<?php else: ?>
- <?php echo $setting->getValue() ?>
+ <?php echo $setting->getValue(array('cultureFallback' => true)) ?>
<?php endif; ?>
</td>
<td>
Modified: trunk/qubit/lib/form/SettingsGlobalForm.class.php
===================================================================
--- trunk/qubit/lib/form/SettingsGlobalForm.class.php 2008-10-21 19:01:51 UTC
(rev 1483)
+++ trunk/qubit/lib/form/SettingsGlobalForm.class.php 2008-10-21 19:10:37 UTC
(rev 1484)
@@ -102,6 +102,6 @@
$this->widgetSchema->setFormFormatterName('list');
// Set wrapper text for global form settings
- $this->widgetSchema->setNameFormat('settings[%s]');
+ $this->widgetSchema->setNameFormat('global_settings[%s]');
}
}
\ No newline at end of file
Added: trunk/qubit/lib/form/SettingsSiteInformationForm.class.php
===================================================================
--- trunk/qubit/lib/form/SettingsSiteInformationForm.class.php
(rev 0)
+++ trunk/qubit/lib/form/SettingsSiteInformationForm.class.php 2008-10-21
19:10:37 UTC (rev 1484)
@@ -0,0 +1,65 @@
+<?php
+
+/*
+ * This file is part of the Qubit Toolkit.
+ * Copyright (C) 2006-2008 Peter Van Garderen <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/**
+ * Settings module - "site information" form definition
+ *
+ * @package qubit
+ * @subpackage settings
+ * @version svn: $Id$
+ * @author David Juhasz <[EMAIL PROTECTED]>
+ */
+class SettingsSiteInformationForm extends sfForm
+{
+ public function configure()
+ {
+ // Build widgets
+ $this->setWidgets(array(
+ 'site_title' => new sfWidgetFormInput,
+ 'site_description' => new sfWidgetFormInput
+ ));
+
+ // Add labels
+ $this->widgetSchema->setLabels(array(
+ 'site_title' => 'site title',
+ 'site_description' => 'site description'
+ ));
+
+ // Add helper text
+ // NOTE: This is implemented in the template because it was too much
+ // trouble to integrate the helper text without rendering the whole form
+ // row due to the lack of a renderHelp() method in sfFormField.class.php
+ //
+ // $this->widgetSchema->setHelps();
+
+ // Validators
+ $this->validatorSchema['site_title'] = new sfValidatorString;
+ $this->validatorSchema['site_description'] = new sfValidatorString;
+
+ // Set decorator
+ $decorator = new QubitWidgetFormSchemaFormatterList($this->widgetSchema);
+ $this->widgetSchema->addFormFormatter('list', $decorator);
+ $this->widgetSchema->setFormFormatterName('list');
+
+ // Set wrapper text for global form settings
+ $this->widgetSchema->setNameFormat('site_information[%s]');
+ }
+}
\ No newline at end of file
Property changes on: trunk/qubit/lib/form/SettingsSiteInformationForm.class.php
___________________________________________________________________
Added: svn:keywords
+ Author Id Revision
Added: svn:eol-style
+ native
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---