Author: jablko
Date: Mon Oct 25 08:33:59 2010
New Revision: 8460
Log:
Cosmetic changes
Modified:
trunk/apps/qubit/modules/term/actions/editAction.class.php
Modified: trunk/apps/qubit/modules/term/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/term/actions/editAction.class.php Mon Oct 25
08:31:40 2010 (r8459)
+++ trunk/apps/qubit/modules/term/actions/editAction.class.php Mon Oct 25
08:33:59 2010 (r8460)
@@ -19,27 +19,25 @@
class TermEditAction extends sfAction
{
- /**
- * Define form field names
- *
- * @var string
- */
+ // Arrays not allowed in class constants
public static
$NAMES = array(
'altLabels',
'code',
'displayNote',
'name',
- 'taxonomy', /* This position is intentional since narrowTerms
- processField code depends on the taxonomy */
+
+ // This position is intentional because narrowTerms ->processField()
+ // depends on the taxonomy
+ 'taxonomy',
+
'narrowTerms',
'parent',
'relatedTerms',
'scopeNote',
- 'sourceNote'
- );
+ 'sourceNote');
- public
+ protected
$updatedLabel = false;
protected function addField($name)
@@ -51,86 +49,78 @@
$criteria->add(QubitOtherName::OBJECT_ID, $this->term->id);
$criteria->add(QubitOtherName::TYPE_ID,
QubitTerm::ALTERNATIVE_LABEL_ID);
- $values = $defaults = array();
- if (0 < count($altLabels = QubitOtherName::get($criteria)))
+ $value = $defaults = array();
+ foreach (QubitOtherName::get($criteria) as $item)
{
- foreach ($altLabels as $altLabel)
- {
- $values[] = $altLabel->id;
- $defaults[$altLabel->id] = $altLabel;
- }
+ $defaults[$value[] = $item->id] = $item;
}
- $this->form->setDefault($name, $values);
- $this->form->setValidator($name, new sfValidatorPass);
- $this->form->setWidget($name, new
QubitWidgetFormInputMany(array('defaults' => $defaults)));
+ $this->form->setDefault('altLabels', $value);
+ $this->form->setValidator('altLabels', new sfValidatorPass);
+ $this->form->setWidget('altLabels', new
QubitWidgetFormInputMany(array('defaults' => $defaults)));
break;
case 'code':
- $this->form->setDefault($name, $this->term[$name]);
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormInput);
+ $this->form->setDefault('code', $this->term->code);
+ $this->form->setValidator('code', new sfValidatorString);
+ $this->form->setWidget('code', new sfWidgetFormInput);
break;
case 'name':
- $this->form->setDefault($name, $this->term[$name]);
- $this->form->setValidator($name, new
sfValidatorString(array('required' => true), array('required' =>
$this->context->i18n->__('This is a mandatory element.'))));
- $this->form->setWidget($name, new sfWidgetFormInput);
+ $this->form->setDefault('name', $this->term->name);
+ $this->form->setValidator('name', new
sfValidatorString(array('required' => true), array('required' =>
$this->context->i18n->__('This is a mandatory element.'))));
+ $this->form->setWidget('name', new sfWidgetFormInput);
break;
case 'narrowTerms':
- $this->form->setValidator($name, new sfValidatorPass);
- $this->form->setWidget($name, new
QubitWidgetFormInputMany(array('defaults' => array())));
+ $this->form->setValidator('narrowTerms', new sfValidatorPass);
+ $this->form->setWidget('narrowTerms', new
QubitWidgetFormInputMany(array('defaults' => array())));
break;
case 'parent':
- $choices = array();
+ $this->form->setDefault('parent',
$this->context->routing->generate(null, array($this->term->parent, 'module' =>
'term')));
+ $this->form->setValidator('parent', new sfValidatorString);
+ $choices = array();
if (isset($this->term->parent))
{
- $this->form->setDefault($name,
$this->context->routing->generate(null, array($this->term->parent, 'module' =>
'term')));
- $choices = array($this->context->routing->generate(null,
array('module' => 'term', 'id' => $this->term->parentId)) =>
$this->term->parent);
+ $choices[$this->context->routing->generate(null,
array($this->term->parent, 'module' => 'term'))] = $this->term->parent;
}
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
+ $this->form->setWidget('parent', new
sfWidgetFormSelect(array('choices' => $choices)));
break;
case 'relatedTerms':
$this->relations =
QubitRelation::getBySubjectOrObjectId($this->term->getId(), array('typeId' =>
QubitTerm::TERM_RELATION_ASSOCIATIVE_ID));
- $choices = array();
- $values = array();
- if (0 < count($this->relations))
+ $value = $choices = array();
+ foreach ($this->relations as $relation)
{
- foreach ($this->relations as $relation)
- {
- $choices[$values[] = $this->context->routing->generate(null,
array($relation->object, 'module' => 'term'))] = $relation->object;
- }
+ $choices[$value[] = $this->context->routing->generate(null,
array($relation->object, 'module' => 'term'))] = $relation->object;
}
- $this->form->setDefault('relatedTerms', $values);
+ $this->form->setDefault('relatedTerms', $value);
$this->form->setValidator('relatedTerms', new sfValidatorPass);
$this->form->setWidget('relatedTerms', new
sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
break;
case 'taxonomy':
- $choices = array();
+ $this->form->setDefault('taxonomy',
$this->context->routing->generate(null, array($this->term->taxonomy, 'module'
=> 'taxonomy')));
+ $this->form->setValidator('taxonomy', new
sfValidatorString(array('required' => true), array('required' =>
$this->context->i18n->__('This is a mandatory element.'))));
- if (isset($this->term->taxonomyId))
+ $choices = array();
+ if (isset($this->term->taxonomy))
{
- $this->form->setDefault($name,
$this->context->routing->generate(null, array($this->term->taxonomy, 'module'
=> 'taxonomy')));
- $choices = array($this->context->routing->generate(null,
array($this->term->taxonomy, 'module' => 'taxonomy')) => $this->term->taxonomy);
+ $choices[$this->context->routing->generate(null,
array($this->term->taxonomy, 'module' => 'taxonomy'))] = $this->term->taxonomy;
}
- $this->form->setValidator($name, new
sfValidatorString(array('required' => true), array('required' =>
$this->context->i18n->__('This is a mandatory element.'))));
- $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
+ $this->form->setWidget('taxonomy', new
sfWidgetFormSelect(array('choices' => $choices)));
break;
@@ -158,17 +148,13 @@
break;
}
- $values = $defaults = array();
- if (0 < count($notes = QubitNote::get($criteria)))
+ $value = $defaults = array();
+ foreach (QubitNote::get($criteria) as $item)
{
- foreach ($notes as $note)
- {
- $values[] = $note->id;
- $defaults[$note->id] = $note;
- }
+ $defaults[$value[] = $item->id] = $item;
}
- $this->form->setDefault($name, $values);
+ $this->form->setDefault($name, $value);
$this->form->setValidator($name, new sfValidatorPass);
$this->form->setWidget($name, new
QubitWidgetFormInputMany(array('defaults' => $defaults, 'fieldname' =>
'content')));
@@ -184,39 +170,36 @@
*/
protected function processField($field)
{
- switch ($name = $field->getName())
+ switch ($field->getName())
{
case 'altLabels':
- $defaults = $this->form->getWidget($name)->getOption('defaults');
+ $defaults = $this->form->getWidget('altLabels')->getOption('defaults');
- if (null !== $this->form->getValue($name))
+ foreach ($this->form->getValue('altLabels') as $key => $newName)
{
- foreach ($this->form->getValue($name) as $key => $newName)
+ if ('new' == substr($key, 0, 3) && 0 < strlen(trim($newName)))
{
- if ('new' == substr($key, 0, 3) && 0 < strlen(trim($newName)))
+ $otherName = new QubitOtherName;
+ $otherName->typeId = QubitTerm::ALTERNATIVE_LABEL_ID;
+ }
+ else
+ {
+ $otherName = QubitOtherName::getById($key);
+ if (null === $otherName)
{
- $otherName = new QubitOtherName;
- $otherName->typeId = QubitTerm::ALTERNATIVE_LABEL_ID;
+ continue;
}
- else
- {
- $otherName = QubitOtherName::getById($key);
- if (null === $otherName)
- {
- continue;
- }
- // Don't delete this name
- unset($defaults[$key]);
- }
+ // Don't delete this name
+ unset($defaults[$key]);
+ }
- if ($otherName->name != $newName)
- {
- $otherName->name = $newName;
- $this->updatedLabel = true;
- }
- $this->term->otherNames[] = $otherName;
+ if ($otherName->name != $newName)
+ {
+ $otherName->name = $newName;
+ $this->updatedLabel = true;
}
+ $this->term->otherNames[] = $otherName;
}
// Delete any names that are missing from form data
@@ -232,26 +215,26 @@
case 'parent':
case 'taxonomy':
- $params =
$this->context->routing->parse(Qubit::pathInfo($this->form->getValue($name)));
+ $params =
$this->context->routing->parse(Qubit::pathInfo($this->form->getValue($field->getName())));
$fieldId = (isset($params['id']) && 0 < strlen($params['id'])) ?
$params['id'] : null;
- $this->term[$name.'Id'] = $fieldId;
+ $this->term[$field->getName().'Id'] = $fieldId;
break;
case 'scopeNote':
case 'sourceNote':
case 'displayNote':
- $defaults = $this->form->getWidget($name)->getOption('defaults');
+ $defaults =
$this->form->getWidget($field->getName())->getOption('defaults');
- if (null !== $this->form->getValue($name))
+ if (null !== $this->form->getValue($field->getName()))
{
- foreach ($this->form->getValue($name) as $key => $thisContent)
+ foreach ($this->form->getValue($field->getName()) as $key =>
$thisContent)
{
if ('new' == substr($key, 0, 3) && 0 < strlen(trim($thisContent)))
{
$note = new QubitNote;
- switch ($name)
+ switch ($field->getName())
{
case 'scopeNote':
$note->typeId = QubitTerm::SCOPE_NOTE_ID;
@@ -299,30 +282,27 @@
case 'narrowTerms':
- if (null !== $this->form->getValue($name))
+ foreach ($this->form->getValue('narrowTerms') as $key => $thisName)
{
- foreach ($this->form->getValue($name) as $key => $thisName)
+ if (0 < strlen($thisName = trim($thisName)))
{
- if (0 < strlen($thisName = trim($thisName)))
+ // Test to make sure term doesn't already exist
+ $criteria = new Criteria;
+ $criteria->addJoin(QubitTerm::ID, QubitTermI18n::ID);
+ $criteria->add(QubitTerm::TAXONOMY_ID, $this->term->taxonomyId);
+ $criteria->add(QubitTermI18n::NAME, $thisName);
+ $criteria->add(QubitTermI18n::CULTURE,
$this->context->user->getCulture());
+ if (0 < count(QubitTermI18n::get($criteria)))
{
- // Test to make sure term doesn't already exist
- $criteria = new Criteria;
- $criteria->addJoin(QubitTerm::ID, QubitTermI18n::ID);
- $criteria->add(QubitTerm::TAXONOMY_ID, $this->term->taxonomyId);
- $criteria->add(QubitTermI18n::NAME, $thisName);
- $criteria->add(QubitTermI18n::CULTURE,
$this->context->user->getCulture());
- if (0 < count(QubitTermI18n::get($criteria)))
- {
- continue;
- }
+ continue;
+ }
- // Add term as child
- $nt = new QubitTerm;
- $nt->taxonomyId = $this->term->taxonomyId;
- $nt->name = $thisName;
+ // Add term as child
+ $nt = new QubitTerm;
+ $nt->taxonomyId = $this->term->taxonomyId;
+ $nt->name = $thisName;
- $this->term->termsRelatedByparentId[] = $nt;
- }
+ $this->term->termsRelatedByparentId[] = $nt;
}
}
@@ -345,36 +325,29 @@
break;
case 'relatedTerms':
-
$current = $new = array();
- if ('' !== $this->form->getValue($name))
+ foreach ($this->form->getValue('relatedTerms') as $value)
{
- foreach ($this->form->getValue($name) as $value)
- {
- $params = $this->context->routing->parse(Qubit::pathInfo($value));
- $current[$params['id']] = $new[$params['id']] = $params['id'];
- }
+ $params = $this->context->routing->parse(Qubit::pathInfo($value));
+ $current[$params['id']] = $new[$params['id']] = $params['id'];
}
- if (0 < count($this->relations))
+ foreach ($this->relations as $relation)
{
- foreach ($this->relations as $relation)
+ if (isset($current[$relation->objectId]))
{
- if (isset($current[$relation->objectId]))
- {
- // If it's current, then don't add/delete
- unset($new[$relation->objectId]);
- }
- else
- {
- // If not in current list, then delete
- $relation->delete();
- }
+ // If it's current, then don't add/delete
+ unset($new[$relation->objectId]);
+ }
+ else
+ {
+ // If not in current list, then delete
+ $relation->delete();
}
}
- // Create 'new' relations
+ // Create "new" relations
foreach ($new as $id)
{
$relation = new QubitRelation;
@@ -425,7 +398,6 @@
$this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
$this->term = new QubitTerm;
-
if (isset($request->id))
{
$this->term = QubitTerm::getById($request->id);
@@ -472,9 +444,7 @@
}
}
- $request->setAttribute('term', $this->term);
-
- // HACK: Use static::$NAMES in PHP 5.3,
+ // HACK Use static::$NAMES in PHP 5.3,
// http://php.net/oop5.late-static-bindings
$class = new ReflectionClass($this);
foreach ($class->getStaticPropertyValue('NAMES') as $name)
@@ -486,7 +456,6 @@
if ($request->isMethod('post'))
{
$this->form->bind($request->getPostParameters());
-
if ($this->form->isValid())
{
$this->processForm();
@@ -496,16 +465,13 @@
}
}
- public function updateLinkedInfoObjects()
+ protected function updateLinkedInfoObjects()
{
- if (0 < count($this->term->objectTermRelations))
+ foreach ($this->term->objectTermRelations as $item)
{
- foreach ($this->term->objectTermRelations as $objectTermRelation)
+ if ($item->object instanceof QubitInformationObject)
{
- if ($objectTermRelation->object instanceof QubitInformationObject)
- {
- SearchIndex::updateTranslatedLanguages($objectTermRelation->object);
- }
+ SearchIndex::updateTranslatedLanguages($item->object);
}
}
--
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.com/group/qubit-commits?hl=en.