Author: jablko
Date: Fri Aug 28 16:03:06 2009
New Revision: 3105
Log:
Factor language and script getters and setters from actions to model
Modified:
trunk/apps/qubit/modules/informationobject/actions/editAction.class.php
trunk/lib/model/QubitInformationObject.php
Modified:
trunk/apps/qubit/modules/informationobject/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/actions/editAction.class.php
Fri Aug 28 14:08:43 2009 (r3104)
+++ trunk/apps/qubit/modules/informationobject/actions/editAction.class.php
Fri Aug 28 16:03:06 2009 (r3105)
@@ -64,16 +64,7 @@
case 'language':
case 'languageOfDescription':
- $criteria = new Criteria;
- $this->informationObject->addPropertysCriteria($criteria);
- $criteria->add(QubitProperty::NAME, $name);
-
- if (1 == count($query = QubitProperty::get($criteria)))
- {
- $this[$name] = $query[0];
- $this->form->setDefault($name,
unserialize($this[$name]->__get('value', array('sourceCulture' => true))));
- }
-
+ $this->form->setDefault($name, $this->informationObject[$name]);
$this->form->setValidator($name, new
sfValidatorI18nChoiceLanguage(array('multiple' => true)));
$this->form->setWidget($name, new
sfWidgetFormI18nSelectLanguage(array('culture' =>
$this->context->user->getCulture(), 'multiple' => true)));
@@ -96,16 +87,7 @@
case 'script':
case 'scriptOfDescription':
- $criteria = new Criteria;
- $this->informationObject->addPropertysCriteria($criteria);
- $criteria->add(QubitProperty::NAME, $name);
-
- if (1 == count($query = QubitProperty::get($criteria)))
- {
- $this[$name] = $query[0];
- $this->form->setDefault($name,
unserialize($this[$name]->__get('value', array('sourceCulture' => true))));
- }
-
+ $this->form->setDefault($name, $this->informationObject[$name]);
$this->form->setValidator($name, new sfValidatorPass);
$c = new sfCultureInfo($this->context->user->getCulture());
@@ -228,22 +210,6 @@
{
switch ($field->getName())
{
- case 'language':
- case 'languageOfDescription':
- case 'script':
- case 'scriptOfDescription':
-
- if (!isset($this[$field->getName()]))
- {
- $this[$field->getName()] = new QubitProperty;
- $this[$field->getName()]->name = $field->getName();
- $this->informationObject->propertys[] = $this[$field->getName()];
- }
-
- $this[$field->getName()]->__set('value',
serialize($this->form->getValue($field->getName())), array('sourceCulture' =>
true));
-
- break;
-
default:
$this->informationObject[$field->getName()] =
$this->form->getValue($field->getName());
}
Modified: trunk/lib/model/QubitInformationObject.php
==============================================================================
--- trunk/lib/model/QubitInformationObject.php Fri Aug 28 14:08:43 2009
(r3104)
+++ trunk/lib/model/QubitInformationObject.php Fri Aug 28 16:03:06 2009
(r3105)
@@ -48,6 +48,76 @@
return (string) $title;
}
+ public function __get($name)
+ {
+ $args = func_get_args();
+
+ $options = array();
+ if (1 < count($args))
+ {
+ $options = $args[1];
+ }
+
+ switch ($name)
+ {
+ case 'language':
+ case 'languageOfDescription':
+ case 'script':
+ case 'scriptOfDescription':
+ $criteria = new Criteria;
+ $this->addPropertysCriteria($criteria);
+ $criteria->add(QubitProperty::NAME, $name);
+
+ if (1 == count($query = QubitProperty::get($criteria)))
+ {
+ return unserialize($query[0]->__get('value', $options +
array('sourceCulture' => true)));
+ }
+
+ return;
+ }
+
+ return call_user_func_array(array($this, 'BaseInformationObject::__get'),
$args);
+ }
+
+ public function __set($name, $value)
+ {
+ $args = func_get_args();
+
+ $options = array();
+ if (2 < count($args))
+ {
+ $options = $args[2];
+ }
+
+ switch ($name)
+ {
+ case 'language':
+ case 'languageOfDescription':
+ case 'script':
+ case 'scriptOfDescription':
+ $criteria = new Criteria;
+ $this->addPropertysCriteria($criteria);
+ $criteria->add(QubitProperty::NAME, $name);
+
+ if (1 == count($query = QubitProperty::get($criteria)))
+ {
+ $property = $query[0];
+ }
+ else
+ {
+ $property = new QubitProperty;
+ $property->name = $name;
+ $this->propertys[] = $property;
+ }
+
+ $property->__set('value', serialize($value), $options +
array('sourceCulture' => true));
+
+ return $this;
+ }
+
+ return call_user_func_array(array($this, 'BaseInformationObject::__set'),
$args);
+ }
+
public function save($connection = null)
{
parent::save($connection);
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---