Author: david
Date: 2008-11-07 12:00:55 -0800 (Fri, 07 Nov 2008)
New Revision: 1535
Added:
trunk/qubit/lib/form/SettingsDefaultTemplateForm.class.php
Modified:
trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
trunk/qubit/lib/model/QubitSetting.php
Log:
Update admin > settings > default template with select boxes to chose default
templates.
- Add methods to QubitSettings to find and set settings via name and scope,
- Create lib/form/SettingsDefaultTemplateForm.class.php and switch to using it
on settings page,
- Update settings/listAction to work with new default template form
Modified: trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
===================================================================
--- trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
2008-11-07 18:28:28 UTC (rev 1534)
+++ trunk/qubit/apps/qubit/modules/settings/actions/listAction.class.php
2008-11-07 20:00:55 UTC (rev 1535)
@@ -54,28 +54,13 @@
'sl' => 'slovenščina'
);
- // Available templates
- protected static $informationobjectTemplates = array(
- 'isad' => 'ISAD(G), International Council on Archives',
- 'rad' => 'RAD, Canadian Council on Archives'
- );
-
- protected static $actorTemplates = array(
- 'isaar' => 'ISAAR(CPF), International Council on Archives'
- );
-
- protected static $repositoryTemplates = array(
- 'isdiah' => 'ISDIAH, International Council on Archives'
- );
-
public function execute($request)
{
$this->culture = $this->getUser()->getCulture();
$this->globalForm = new SettingsGlobalForm;
$this->siteInformationForm = new SettingsSiteInformationForm;
- $this->defaultTemplateForm = new SettingsGenericForm(array(), array(
- 'settings' => QubitSetting::getByScope('default_template'),
'scope'=>'default_template'));
+ $this->defaultTemplateForm = new SettingsDefaultTemplateForm;
$this->uiLabelForm = new SettingsGenericForm(array(), array(
'settings' => QubitSetting::getByScope('ui_label'), 'scope'=>'ui_label',
'fieldsRequired' => false));
@@ -288,10 +273,16 @@
*/
protected function populateDefaultTemplateForm($form)
{
- foreach ($form->getSettings() as $setting)
- {
- $form->setDefault($setting->getName(),
$setting->getValue(array('sourceCulture' => true)));
- }
+ $infoObjectTemplate = QubitSetting::getByNameAndScope('informationobject',
'default_template');
+ $actorTemplate = QubitSetting::getByNameAndScope('actor',
'default_template');
+ $repositoryTemplate = QubitSetting::getByNameAndScope('repository',
'default_template');
+
+ // Set defaults for global form
+ $this->defaultTemplateForm->setDefaults(array(
+ 'informationobject' => (isset($infoObjectTemplate)) ?
$infoObjectTemplate->getValue(array('sourceCulture'=>true)) : null,
+ 'actor' => (isset($actorTemplate)) ?
$actorTemplate->getValue(array('sourceCulture'=>true)) : null,
+ 'repository' => (isset($repositoryTemplate)) ?
$repositoryTemplate->getValue(array('sourceCulture'=>true)) : null,
+ ));
}
/**
@@ -301,22 +292,24 @@
*/
protected function updateDefaultTemplateSettings($form)
{
- foreach ($form->getSettings() as $setting)
+ if (null !== $newValue = $form->getValue('informationobject'))
{
- if (null !== $value = $form->getValue($setting->getName()))
- {
- $setting->setValue($value, array('sourceCulture'=>true)); // Force
source culture update
- $setting->save();
- }
+ $setting = QubitSetting::findAndSave('informationobject', $newValue,
array(
+ 'scope'=>'default_template', 'createNew'=>true,
'sourceCulture'=>true));
}
- // Add a new default template
- if ($newName = $form->getValue('new_setting_name') && strlen($newValue =
$form->getValue('new_setting_value')))
+ if (null !== $newValue = $form->getValue('actor'))
{
- $setting = QubitSetting::createNewSetting($newName, $newValue,
array('scope'=>$form->getScope()));
- $setting->save();
+ $setting = QubitSetting::findAndSave('actor', $newValue, array(
+ 'scope'=>'default_template', 'createNew'=>true,
'sourceCulture'=>true));
}
+ if (null !== $newValue = $form->getValue('repository'))
+ {
+ $setting = QubitSetting::findAndSave('repository', $newValue, array(
+ 'scope'=>'default_template', 'createNew'=>true,
'sourceCulture'=>true));
+ }
+
return $this;
}
Added: trunk/qubit/lib/form/SettingsDefaultTemplateForm.class.php
===================================================================
--- trunk/qubit/lib/form/SettingsDefaultTemplateForm.class.php
(rev 0)
+++ trunk/qubit/lib/form/SettingsDefaultTemplateForm.class.php 2008-11-07
20:00:55 UTC (rev 1535)
@@ -0,0 +1,82 @@
+<?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 SettingsDefaultTemplateForm extends sfForm
+{
+ // Available templates
+ protected static $informationObjectTemplates = array(
+ 'isad' => 'ISAD(G), International Council on Archives',
+ 'rad' => 'RAD, Canadian Council on Archives'
+ );
+
+ protected static $actorTemplates = array(
+ 'isaar' => 'ISAAR(CPF), International Council on Archives'
+ );
+
+ protected static $repositoryTemplates = array(
+ 'isdiah' => 'ISDIAH, International Council on Archives'
+ );
+
+ public function configure()
+ {
+ // Build widgets
+ $this->setWidgets(array(
+ 'informationobject' => new
sfWidgetFormSelect(array('choices'=>self::$informationObjectTemplates)),
+ 'actor' => new sfWidgetFormSelect(array('choices'=>self::$actorTemplates)),
+ 'repository' => new
sfWidgetFormSelect(array('choices'=>self::$repositoryTemplates)),
+ ));
+
+ // Add labels
+ $this->widgetSchema->setLabels(array(
+ 'informationobject' => 'information object',
+ 'actor' => 'actor',
+ 'repository' => 'repository'
+ ));
+
+ // 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['informationobject'] = new sfValidatorString;
+ $this->validatorSchema['actor'] = new sfValidatorString;
+ $this->validatorSchema['repository'] = 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('default_template[%s]');
+ }
+}
\ No newline at end of file
Property changes on: trunk/qubit/lib/form/SettingsDefaultTemplateForm.class.php
___________________________________________________________________
Added: svn:keywords
+ Author Id Revision
Added: svn:eol-style
+ native
Modified: trunk/qubit/lib/model/QubitSetting.php
===================================================================
--- trunk/qubit/lib/model/QubitSetting.php 2008-11-07 18:28:28 UTC (rev
1534)
+++ trunk/qubit/lib/model/QubitSetting.php 2008-11-07 20:00:55 UTC (rev
1535)
@@ -2,7 +2,7 @@
/**
* Extend BaseSetting functionality.
- *
+ *
* @package qubit
* @subpackage model
* @version svn: $Id$
@@ -23,8 +23,8 @@
}
/**
- * Get all values from QubitSetting table, in appropriate culture, in
- * sfConfig array format.
+ * Get all values from QubitSetting table, in appropriate culture, in
+ * sfConfig array format.
*
* @return array name/value pairs formatted for addition to sfConfig array.
*/
@@ -42,8 +42,8 @@
{
$key = 'app_'.$qubitSetting->getName();
}
-
- // Determine appropriate culture for return value
+
+ // Determine appropriate culture for return value
switch ($qubitSetting->getScope())
{
// Localized values
@@ -51,15 +51,15 @@
case 'site_information':
$settings[$key] = $qubitSetting->getValue(array('cultureFallback' =>
true));
break;
- // Special case - language names are stored in their own culture but
- // are non-localized (always sourceCulture = 'en')
+ // Special case - language names are stored in their own culture but
+ // are non-localized (always sourceCulture = 'en')
case 'i18n_languages':
// Get language label as written in that language
$settings[$key] = $qubitSetting->getValue(array('culture' =>
$qubitSetting->getName()));
break;
- // non-localized values (default)
+ // non-localized values (default)
default:
- $settings[$key] = $qubitSetting->getValue(array('sourceCulture' =>
true));
+ $settings[$key] = $qubitSetting->getValue(array('sourceCulture' =>
true));
}
}
@@ -74,10 +74,10 @@
return $settingI18n->getCulture();
}
}
-
+
/**
* Return the source culture value for this setting, when current context is
- * not the source culture. This is used on edit forms to show the source
+ * not the source culture. This is used on edit forms to show the source
* culture value for a field as an aid for tranlslation.
*
* @param string $culture current culture context
@@ -87,13 +87,13 @@
{
if (strlen($sourceCultureValue = $this->getValue(array('sourceCulture' =>
true))) > 0 && $culture != $this->getSourceCulture())
{
-
+
return $sourceCultureValue;
}
-
+
return null;
}
-
+
/**
* Get all system settings that are "non-global" (scope <> NULL) and not
* "site information" settings
@@ -103,12 +103,12 @@
static public function getLocalSettings()
{
$criteria = new Criteria;
- $criteria->add(QubitSetting::SCOPE, NULL, Criteria::ISNOTNULL);
+ $criteria->add(QubitSetting::SCOPE, null, Criteria::ISNOTNULL);
$criteria->add(QubitSetting::SCOPE, 'site_information',
Criteria::NOT_EQUAL);
-
+
return QubitSetting::get($criteria);
}
-
+
/**
* Get all settings matching $scope parameter.
*
@@ -125,10 +125,10 @@
{
$criteria->add(QubitSetting::SCOPE, null, Criteria::ISNULL);
}
-
+
return QubitSetting::get($criteria);
}
-
+
/**
* Get a setting by it's name
*
@@ -138,11 +138,64 @@
{
$criteria = new Criteria;
$criteria->add(QubitSetting::NAME, $name, Criteria::EQUAL);
-
+
return QubitSetting::getOne($criteria);
}
-
+
/**
+ * Get a setting by it's name & scope
+ *
+ * @return QubitSetting object.
+ */
+ static public function getByNameAndScope($name, $scope)
+ {
+ $criteria = new Criteria;
+ $criteria->add(QubitSetting::NAME, $name, Criteria::EQUAL);
+ $criteria->add(QubitSetting::SCOPE, $scope, Criteria::EQUAL);
+
+ return QubitSetting::getOne($criteria);
+ }
+
+ /**
+ * Find a setting, and save a new value to it
+ *
+ * @return QubitSetting object.
+ */
+ static public 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;
+ }
+
+ /**
* Create a new setting object with some default properties
*
* @param string $name object name
@@ -154,38 +207,38 @@
$setting = new QubitSetting;
$setting->setName($name);
$setting->setValue($value);
-
+
if (isset($options['scope']))
{
$setting->setScope($options['scope']);
}
-
+
// Default "editable" to true, unless forced to false
$setting->setEditable(1);
if (isset($options['editable']) && $options['editable'] == false)
{
$setting->setEditable(0);
}
-
+
// Default "deleteable" to true, unless forced to false
$setting->setDeleteable(1);
if (isset($options['deleteable']) && $options['deleteable'] == false)
{
$setting->setDeleteable(0);
}
-
+
// Set the source culture option
if (isset($options['sourceCulture']))
{
$setting->setSourceCulture($options['sourceCulture']);
}
-
+
// Set the culture option
if (isset($options['culture']))
{
$setting->setCulture($options['culture']);
}
-
+
return $setting;
}
}
\ No newline at end of file
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---