Author: jablko
Date: Tue Oct 12 17:47:05 2010
New Revision: 8075

Log:
Use symfony form to update event properties, fixes issue 1775

Modified:
   
trunk/apps/qubit/modules/informationobject/actions/eventFormComponent.class.php

Modified: 
trunk/apps/qubit/modules/informationobject/actions/eventFormComponent.class.php
==============================================================================
--- 
trunk/apps/qubit/modules/informationobject/actions/eventFormComponent.class.php 
    Tue Oct 12 17:07:24 2010        (r8074)
+++ 
trunk/apps/qubit/modules/informationobject/actions/eventFormComponent.class.php 
    Tue Oct 12 17:47:05 2010        (r8075)
@@ -39,6 +39,7 @@
 
     foreach ($updatedEvents as $item)
     {
+      // Continue only if user typed something
       foreach ($item as $value)
       {
         if (0 < strlen($value))
@@ -62,62 +63,53 @@
       $this->form->bind($item);
       if ($this->form->isValid())
       {
-        // Use existing actor if one is selected (overrides new actor creation)
-        if (0 < strlen($item['actor']))
+        $value = $this->form->getValue('actor');
+        if (isset($value))
         {
-          $params = 
$this->context->routing->parse(Qubit::pathInfo($item['actor']));
-          $event->actorId = $params['id'];
+          $params = $this->context->routing->parse(Qubit::pathInfo($value));
+          $event->actor = $params['_sf_route']->resource;
         }
 
-        $event->startDate = $item['startDate'];
-        $event->endDate = $item['endDate'];
-        $event->dateDisplay = $item['dateDisplay'];
+        $event->dateDisplay = $this->form->getValue('dateDisplay');
+        $event->description = $this->form->getValue('description');
+        $event->endDate = $this->form->getValue('endDate');
 
-        if (0 < strlen($item['type']))
+        $value = $this->form->getValue('place');
+        if (isset($value))
         {
-          $params = 
$this->context->routing->parse(Qubit::pathInfo($item['type']));
-          $event->typeId = $params['id'];
+          $params = $this->context->routing->parse(Qubit::pathInfo($value));
         }
 
-        if (0 < strlen($item['description']))
+        foreach ($event->objectTermRelationsrelatedByObjectId as $item)
         {
-          $event->description = $item['description'];
-        }
-        else
-        {
-          unset($event->description);
+          if (isset($value) && $params['_sf_route']->resource->id == $item->id)
+          {
+            unset($value);
+          }
+          else
+          {
+            $item->delete();
+          }
         }
 
-        // Save the event if it's valid (has an actor OR date)
-        if (0 < strlen($item['actor'])
-          || 0 < strlen($item['startDate'])
-          || 0 < strlen($item['endDate'])
-          || 0 < strlen($item['dateDisplay']))
+        if (isset($value))
         {
-          // Update the "place" object term relation object
-          if (0 < strlen($item['place']))
-          {
-            // If this event didn't exist or didn't have a 'place' associated
-            if (null === $event->id || null === ($place = 
QubitObjectTermRelation::getOneByObjectId($event->id)))
-            {
-              $place = new QubitObjectTermRelation;
-            }
+          $relation = new QubitObjectTermRelation;
+          $relation->term = $params['_sf_route']->resource;
 
-            $params = 
$this->context->routing->parse(Qubit::pathInfo($item['place']));
-            $place->termId = $params['id'];
+          $event->objectTermRelationsRelatedByobjectId[] = $relation;
+        }
 
-            $event->objectTermRelationsRelatedByobjectId[] = $place;
-          }
+        $event->startDate = $this->form->getValue('startDate');
 
-          // Or delete an existing "place" object term relation, if it's no
-          // longer needed
-          else if (0 < $event->getId() && null !== ($place = 
QubitObjectTermRelation::getOneByObjectId($event->getId())))
-          {
-            $place->delete();
-          }
-
-          $this->resource->events[] = $event;
+        $value = $this->form->getValue('type');
+        if (isset($value))
+        {
+          $params = $this->context->routing->parse(Qubit::pathInfo($value));
+          $event->type = $params['_sf_route']->resource;
         }
+
+        $this->resource->events[] = $event;
       }
     }
 

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