Author: jablko
Date: Mon Oct 25 11:14:40 2010
New Revision: 8471

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 
10:32:29 2010        (r8470)
+++ trunk/apps/qubit/modules/term/actions/editAction.class.php  Mon Oct 25 
11:14:40 2010        (r8471)
@@ -22,7 +22,6 @@
   // Arrays not allowed in class constants
   public static
     $NAMES = array(
-      'useFor',
       'code',
       'displayNote',
       'name',
@@ -35,7 +34,8 @@
       'parent',
       'relatedTerms',
       'scopeNote',
-      'sourceNote');
+      'sourceNote',
+      'useFor');
 
   protected 
     $updatedLabel = false;
@@ -82,27 +82,45 @@
   {
     switch ($name)
     {
-      case 'useFor':
+      case 'code':
+        $this->form->setDefault('code', $this->resource->code);
+        $this->form->setValidator('code', new sfValidatorString);
+        $this->form->setWidget('code', new sfWidgetFormInput);
+
+        break;
+
+      case 'displayNote':
+      case 'scopeNote':
+      case 'sourceNote':
         $criteria = new Criteria;
-        $criteria->add(QubitOtherName::OBJECT_ID, $this->resource->id);
-        $criteria->add(QubitOtherName::TYPE_ID, 
QubitTerm::ALTERNATIVE_LABEL_ID);
+        $criteria->add(QubitNote::OBJECT_ID, $this->resource->id);
+        switch ($name)
+        {
+          case 'scopeNote':
+            $criteria->add(QubitNote::TYPE_ID, QubitTerm::SCOPE_NOTE_ID);
+
+            break;
+
+          case 'sourceNote':
+            $criteria->add(QubitNote::TYPE_ID, QubitTerm::SOURCE_NOTE_ID);
+
+            break;
+
+          case 'displayNote':
+            $criteria->add(QubitNote::TYPE_ID, QubitTerm::DISPLAY_NOTE_ID);
+
+            break;
+        }
 
         $value = $defaults = array();
-        foreach (QubitOtherName::get($criteria) as $item)
+        foreach ($this[$name] = QubitNote::get($criteria) as $item)
         {
           $defaults[$value[] = $item->id] = $item;
         }
 
-        $this->form->setDefault('useFor', $value);
-        $this->form->setValidator('useFor', new sfValidatorPass);
-        $this->form->setWidget('useFor', new 
QubitWidgetFormInputMany(array('defaults' => $defaults)));
-
-        break;
-
-      case 'code':
-        $this->form->setDefault('code', $this->resource->code);
-        $this->form->setValidator('code', new sfValidatorString);
-        $this->form->setWidget('code', new sfWidgetFormInput);
+        $this->form->setDefault($name, $value);
+        $this->form->setValidator($name, new sfValidatorPass);
+        $this->form->setWidget($name, new 
QubitWidgetFormInputMany(array('defaults' => $defaults, 'fieldname' => 
'content')));
 
         break;
 
@@ -121,11 +139,6 @@
 
       case 'parent':
         $this->form->setDefault('parent', 
$this->context->routing->generate(null, array($this->resource->parent, 'module' 
=> 'term')));
-        if (isset($this->request->parent))
-        {
-          $this->form->setDefault('parent', $this->request->parent);
-        }
-
         $this->form->setValidator('parent', new sfValidatorString);
 
         $choices = array();
@@ -134,17 +147,23 @@
           $choices[$this->context->routing->generate(null, 
array($this->resource->parent, 'module' => 'term'))] = $this->resource->parent;
         }
 
+        if (isset($this->request->parent))
+        {
+          $this->form->setDefault('parent', $this->request->parent);
+
+          $params = 
$this->context->routing->parse(Qubit::pathInfo($this->request->parent));
+          $choices[$this->request->parent] = $params['_sf_route']->resource;
+        }
+
         $this->form->setWidget('parent', new 
sfWidgetFormSelect(array('choices' => $choices)));
 
         break;
 
       case 'relatedTerms':
-        $this->relations = 
QubitRelation::getBySubjectOrObjectId($this->resource->id, array('typeId' => 
QubitTerm::TERM_RELATION_ASSOCIATIVE_ID));
-
         $value = $choices = array();
-        foreach ($this->relations as $relation)
+        foreach ($this->relations = 
QubitRelation::getBySubjectOrObjectId($this->resource->id, array('typeId' => 
QubitTerm::TERM_RELATION_ASSOCIATIVE_ID)) as $item)
         {
-          $choices[$value[] = $this->context->routing->generate(null, 
array($relation->object, 'module' => 'term'))] = $relation->object;
+          $choices[$value[] = $this->context->routing->generate(null, 
array($item->object, 'module' => 'term'))] = $item->object;
         }
 
         $this->form->setDefault('relatedTerms', $value);
@@ -155,11 +174,6 @@
 
       case 'taxonomy':
         $this->form->setDefault('taxonomy', 
$this->context->routing->generate(null, array($this->resource->taxonomy, 
'module' => 'taxonomy')));
-        if (isset($this->request->taxonomy))
-        {
-          $this->form->setDefault('taxonomy', $this->request->taxonomy);
-        }
-
         $this->form->setValidator('taxonomy', new 
sfValidatorString(array('required' => true), array('required' => 
$this->context->i18n->__('This is a mandatory element.'))));
 
         $choices = array();
@@ -168,43 +182,32 @@
           $choices[$this->context->routing->generate(null, 
array($this->resource->taxonomy, 'module' => 'taxonomy'))] = 
$this->resource->taxonomy;
         }
 
-        $this->form->setWidget('taxonomy', new 
sfWidgetFormSelect(array('choices' => $choices)));
-
-        break;
-
-      case 'displayNote':
-      case 'scopeNote':
-      case 'sourceNote':
-        $criteria = new Criteria;
-        $criteria->add(QubitNote::OBJECT_ID, $this->resource->id);
-
-        switch ($name)
+        if (isset($this->request->taxonomy))
         {
-          case 'scopeNote':
-            $criteria->add(QubitNote::TYPE_ID, QubitTerm::SCOPE_NOTE_ID);
-
-            break;
+          $this->form->setDefault('taxonomy', $this->request->taxonomy);
 
-          case 'sourceNote':
-            $criteria->add(QubitNote::TYPE_ID, QubitTerm::SOURCE_NOTE_ID);
+          $params = 
$this->context->routing->parse(Qubit::pathInfo($this->request->taxonomy));
+          $choices[$this->request->taxonomy] = $params['_sf_route']->resource;
+        }
 
-            break;
+        $this->form->setWidget('taxonomy', new 
sfWidgetFormSelect(array('choices' => $choices)));
 
-          case 'displayNote':
-            $criteria->add(QubitNote::TYPE_ID, QubitTerm::DISPLAY_NOTE_ID);
+        break;
 
-            break;
-        }
+      case 'useFor':
+        $criteria = new Criteria;
+        $criteria->add(QubitOtherName::OBJECT_ID, $this->resource->id);
+        $criteria->add(QubitOtherName::TYPE_ID, 
QubitTerm::ALTERNATIVE_LABEL_ID);
 
         $value = $defaults = array();
-        foreach (QubitNote::get($criteria) as $item)
+        foreach ($this->useFor = QubitOtherName::get($criteria) as $item)
         {
           $defaults[$value[] = $item->id] = $item;
         }
 
-        $this->form->setDefault($name, $value);
-        $this->form->setValidator($name, new sfValidatorPass);
-        $this->form->setWidget($name, new 
QubitWidgetFormInputMany(array('defaults' => $defaults, 'fieldname' => 
'content')));
+        $this->form->setDefault('useFor', $value);
+        $this->form->setValidator('useFor', new sfValidatorPass);
+        $this->form->setWidget('useFor', new 
QubitWidgetFormInputMany(array('defaults' => $defaults)));
 
         break;
 
@@ -224,43 +227,88 @@
   {
     switch ($field->getName())
     {
-      case 'useFor':
-        $defaults = $this->form->getWidget('useFor')->getOption('defaults');
+      case 'displayNote':
+      case 'scopeNote':
+      case 'sourceNote':
+        $value = $filtered = $this->form->getValue($field->getName());
 
-        foreach ($this->form->getValue('useFor') as $key => $newName)
+        foreach ($this[$field->getName()] as $item)
         {
-          if ('new' == substr($key, 0, 3) && 0 < strlen(trim($newName)))
+          if (isset($value[$item->id]))
           {
-            $otherName = new QubitOtherName;
-            $otherName->typeId = QubitTerm::ALTERNATIVE_LABEL_ID;
+            $item->content = $value[$item->id];
+            unset($filtered[$item->id]);
           }
           else
           {
-            $otherName = QubitOtherName::getById($key);
-            if (null === $otherName)
-            {
-              continue;
-            }
-
-            // Don't delete this name
-            unset($defaults[$key]);
+            $item->delete();
           }
+        }
 
-          if ($otherName->name != $newName)
+        foreach ($filtered as $item)
+        {
+          $note = new QubitNote;
+          $note->content = $item;
+          switch ($field->getName())
           {
-            $otherName->name = $newName;
-            $this->updatedLabel = true;
+            case 'scopeNote':
+              $note->typeId = QubitTerm::SCOPE_NOTE_ID;
+
+              break;
+
+            case 'sourceNote':
+              $note->typeId = QubitTerm::SOURCE_NOTE_ID;
+
+              break;
+
+            case 'displayNote':
+              $note->typeId = QubitTerm::DISPLAY_NOTE_ID;
+
+              break;
           }
-          $this->resource->otherNames[] = $otherName;
+
+          $this->resource->notes[] = $note;
+        }
+
+        break;
+
+      case 'name':
+
+        if (!$this->resource->isProtected()
+            && $this->resource->name != $this->form->getValue('name'))
+        {
+          $this->resource->name = $this->form->getValue('name');
+          $this->updatedLabel = true;
         }
 
-        // Delete any names that are missing from form data
-        foreach ($defaults as $key => $val)
+        break;
+
+      case 'narrowTerms':
+
+        foreach ($this->form->getValue('narrowTerms') as $item)
         {
-          if (null !== ($otherName = QubitOtherName::getById($key)))
+          if (1 > strlen($item = trim($item)))
           {
-            $otherName->delete();
+            continue;
           }
+
+          // Test to make sure term doesn't already exist
+          $criteria = new Criteria;
+          $criteria->add(QubitTerm::TAXONOMY_ID, $this->resource->taxonomyId);
+          $criteria->addJoin(QubitTerm::ID, QubitTermI18n::ID);
+          $criteria->add(QubitTermI18n::CULTURE, 
$this->context->user->getCulture());
+          $criteria->add(QubitTermI18n::NAME, $item);
+          if (0 < count(QubitTermI18n::get($criteria)))
+          {
+            continue;
+          }
+
+          // Add term as child
+          $term = new QubitTerm;
+          $term->name = $item;
+          $term->taxonomyId = $this->resource->taxonomyId;
+
+          $this->resource->termsRelatedByparentId[] = $term;
         }
 
         break;
@@ -278,140 +326,61 @@
 
         break;
 
-      case 'scopeNote':
-      case 'sourceNote':
-      case 'displayNote':
-        $defaults = 
$this->form->getWidget($field->getName())->getOption('defaults');
-
-        if (null !== $this->form->getValue($field->getName()))
+      case 'relatedTerms':
+        $value = $filtered = array();
+        foreach ($this->form->getValue('relatedTerms') as $item)
         {
-          foreach ($this->form->getValue($field->getName()) as $key => 
$thisContent)
-          {
-            if ('new' == substr($key, 0, 3) && 0 < strlen(trim($thisContent)))
-            {
-              $note = new QubitNote;
-
-              switch ($field->getName())
-              {
-                case 'scopeNote':
-                  $note->typeId = QubitTerm::SCOPE_NOTE_ID;
-
-                  break;
-
-                case 'sourceNote':
-                  $note->typeId = QubitTerm::SOURCE_NOTE_ID;
-
-                  break;
-
-                case 'displayNote':
-                  $note->typeId = QubitTerm::DISPLAY_NOTE_ID;
-
-                  break;
-              }
-            }
-            else
-            {
-              $note = QubitNote::getById($key);
-              if (!isset($note))
-              {
-                continue;
-              }
-
-              // Don't delete this name
-              unset($defaults[$key]);
-            }
-
-            $note->content = $thisContent;
-            $this->resource->notes[] = $note;
-          }
+          $params = $this->context->routing->parse(Qubit::pathInfo($item));
+          $resource = $params['_sf_route']->resource;
+          $value[$resource->id] = $filtered[$resource->id] = $resource;
         }
 
-        // Delete any names that are missing from form data
-        foreach ($defaults as $key => $val)
+        foreach ($this->relations as $item)
         {
-          if (null !== ($note = QubitNote::getById($key)))
+          if (isset($value[$item->objectId]))
           {
-            $note->delete();
+            unset($filtered[$item->objectId]);
           }
-        }
-
-        break;
-
-      case 'narrowTerms':
-
-        foreach ($this->form->getValue('narrowTerms') as $key => $thisName)
-        {
-          if (0 < strlen($thisName = trim($thisName)))
+          else
           {
-            // Test to make sure term doesn't already exist
-            $criteria = new Criteria;
-            $criteria->addJoin(QubitTerm::ID, QubitTermI18n::ID);
-            $criteria->add(QubitTerm::TAXONOMY_ID, 
$this->resource->taxonomyId);
-            $criteria->add(QubitTermI18n::NAME, $thisName);
-            $criteria->add(QubitTermI18n::CULTURE, 
$this->context->user->getCulture());
-            if (0 < count(QubitTermI18n::get($criteria)))
-            {
-              continue;
-            }
-
-            // Add term as child
-            $nt = new QubitTerm;
-            $nt->taxonomyId = $this->resource->taxonomyId;
-            $nt->name = $thisName;
-
-            $this->resource->termsRelatedByparentId[] = $nt;
+            $item->delete();
           }
         }
 
-        break;
-
-      case 'name':
-
-        if (!$this->resource->isProtected())
+        foreach ($filtered as $item)
         {
-          $oldName = $this->resource->name;
-          $newName = $this->form->getValue('name');
+          $relation = new QubitRelation;
+          $relation->object = $item;
+          $relation->typeId = QubitTerm::TERM_RELATION_ASSOCIATIVE_ID;
 
-          if ($oldName != $newName)
-          {
-            $this->resource->name = $newName;
-            $this->updatedLabel = true;
-          }
+          $this->resource->relationsRelatedBysubjectId[] = $relation;
         }
 
         break;
 
-      case 'relatedTerms':
-        $current = $new = array();
-
-        foreach ($this->form->getValue('relatedTerms') as $value)
-        {
-          $params = $this->context->routing->parse(Qubit::pathInfo($value));
-          $current[$params['id']] = $new[$params['id']] = $params['id'];
-        }
+      case 'useFor':
+        $value = $filtered = $this->form->getValue($field->getName());
 
-        foreach ($this->relations as $relation)
+        foreach ($this->useFor as $item)
         {
-          if (isset($current[$relation->objectId]))
+          if (isset($value[$item->id]))
           {
-            // If it's current, then don't add/delete
-            unset($new[$relation->objectId]);
+            $item->name = $value[$item->id];
+            unset($filtered[$item->id]);
           }
           else
           {
-            // If not in current list, then delete
-            $relation->delete();
+            $item->delete();
           }
         }
 
-        // Create "new" relations
-        foreach ($new as $id)
+        foreach ($filtered as $item)
         {
-          $relation = new QubitRelation;
-          $relation->objectId = $id;
-          $relation->typeId = QubitTerm::TERM_RELATION_ASSOCIATIVE_ID;
+          $otherName = new QubitOtherName;
+          $otherName->name = $item;
+          $otherName->typeId = QubitTerm::ALTERNATIVE_LABEL_ID;
 
-          $this->resource->relationsRelatedBysubjectId[] = $relation;
+          $this->resource->otherNames[] = $otherName;
         }
 
         break;

-- 
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.

Reply via email to