Author: jablko
Date: Mon Oct 18 15:43:09 2010
New Revision: 8245

Log:
Use $route->resource

Modified:
   trunk/apps/qubit/modules/relation/actions/deleteAction.class.php
   trunk/apps/qubit/modules/relation/actions/indexAction.class.php

Modified: trunk/apps/qubit/modules/relation/actions/deleteAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/relation/actions/deleteAction.class.php    Mon Oct 
18 15:21:22 2010        (r8244)
+++ trunk/apps/qubit/modules/relation/actions/deleteAction.class.php    Mon Oct 
18 15:43:09 2010        (r8245)
@@ -18,7 +18,7 @@
  */
 
 /**
- * Unlink information object from physical object 
+ * Unlink information object from physical object
  *
  * @package qubit
  * @subpackage informationobject
@@ -29,18 +29,27 @@
 {
   public function execute($request)
   {
-    $this->relation = QubitRelation::getById($this->request->id);
-    $this->forward404Unless($this->relation);
-    
-    // Make the $next parameter into an absolute URL because redirect() expects
-    // an absolute URL or an array containing module and action
-    // (Pre-pend code copied from sfWebController->genUrl() method)  
-    $next = 'http'.($request->isSecure() ? 's' : 
'').'://'.$request->getHost().$this->request->next;
-    $this->forward404Unless($next);
-    
-    // Do delete
-    $this->relation->delete();
-     
-    $this->redirect($next);
+    $this->form = new sfForm;
+
+    $this->resource = $this->getRoute()->resource;
+
+    $this->form->setDefault('next', $request->getReferer());
+    $this->form->setValidator('next', new sfValidatorString);
+    $this->form->setWidget('next', new sfWidgetFormInputHidden);
+
+    if ($request->isMethod('delete'))
+    {
+      $this->form->bind($request->getParamters());
+      if ($this->form->isValid())
+      {
+        $this->resource->delete();
+
+        $value = $this->form->getValue('next');
+        if (isset($value))
+        {
+          $this->redirect($value);
+        }
+      }
+    }
   }
 }

Modified: trunk/apps/qubit/modules/relation/actions/indexAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/relation/actions/indexAction.class.php     Mon Oct 
18 15:21:22 2010        (r8244)
+++ trunk/apps/qubit/modules/relation/actions/indexAction.class.php     Mon Oct 
18 15:43:09 2010        (r8245)
@@ -29,43 +29,40 @@
 {
   public function execute($request)
   {
-    $relation = QubitRelation::getById($request->id);
+    $this->resource = $this->getRoute()->resource;
 
-    if (!isset($relation))
+    $value = array();
+
+    $note = 
$this->resource->getNoteByTypeId(QubitTerm::RELATION_NOTE_DATE_DISPLAY_ID);
+    if (isset($note))
     {
-      $this->forward404();
+      $value['dateDisplay'] = $note->content;
     }
 
-    $columns = array();
-    $columns['id'] = $relation->id;
-    $columns['object'] = $this->getUri($relation->object);
-    $columns['subject'] = $this->getUri($relation->subject);
-    $columns['type'] = $this->getUri($relation->type);
-    $columns['startDate'] = Qubit::renderDate($relation->startDate);
-    $columns['endDate'] = Qubit::renderDate($relation->endDate);
+    $value['endDate'] = Qubit::renderDate($this->resource->endDate);
+    $value['startDate'] = Qubit::renderDate($this->resource->startDate);
 
-    $columns['dateDisplay'] = null;
-    if (null !== ($displayNote = 
$relation->getNoteByTypeId(QubitTerm::RELATION_NOTE_DATE_DISPLAY_ID)))
+    $note = 
$this->resource->getNoteByTypeId(QubitTerm::RELATION_NOTE_DESCRIPTION_ID);
+    if (isset($note))
     {
-      $columns['dateDisplay'] = $displayNote->getContent();
+      $value['description'] = $note->content;
     }
 
-    $columns['description'] = null;
-    if (null !== ($descriptionNote = 
$relation->getNoteByTypeId(QubitTerm::RELATION_NOTE_DESCRIPTION_ID)))
+    if (isset($this->resource->object))
     {
-      $columns['description'] = $descriptionNote->getContent();
+      $value['object'] = $this->context->routing->generate(null, 
array($this->resource->object, 'module' => 'default'));
     }
 
-    return $this->renderText(json_encode($columns));
-  }
-
-  protected function getUri($object)
-  {
-    if (null != $object)
+    if (isset($this->resource->subject))
     {
-      $moduleName = strtolower(str_replace('Qubit', '', get_class($object)));
+      $value['subject'] = $this->context->routing->generate(null, 
array($this->resource->subject, 'module' => 'default'));
+    }
 
-      return $this->context->routing->generate(null, array($object, 'module' 
=> $moduleName));
+    if (isset($this->resource->type))
+    {
+      $value['type'] = $this->context->routing->generate(null, 
array($this->resource->type));
     }
+
+    return $this->renderText(json_encode($value));
   }
 }

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