Author: jablko
Date: Wed Oct 13 19:35:56 2010
New Revision: 8093

Log:
Use $route->resource

Modified:
   
trunk/apps/qubit/modules/informationobject/actions/autocompleteAction.class.php
   trunk/apps/qubit/modules/informationobject/templates/_eventForm.php
   trunk/apps/qubit/modules/repository/actions/editAction.class.php
   trunk/plugins/sfIsadPlugin/modules/sfIsadPlugin/actions/editAction.class.php
   trunk/plugins/sfIsdiahPlugin/modules/sfIsdiahPlugin/templates/editSuccess.php

Modified: 
trunk/apps/qubit/modules/informationobject/actions/autocompleteAction.class.php
==============================================================================
--- 
trunk/apps/qubit/modules/informationobject/actions/autocompleteAction.class.php 
    Wed Oct 13 19:31:10 2010        (r8092)
+++ 
trunk/apps/qubit/modules/informationobject/actions/autocompleteAction.class.php 
    Wed Oct 13 19:35:56 2010        (r8093)
@@ -36,21 +36,21 @@
     }
 
     $criteria = new Criteria;
-    $criteria->addJoin(QubitInformationObject::ID, 
QubitInformationObjectI18n::ID, Criteria::INNER_JOIN);
+    $criteria->addJoin(QubitInformationObject::ID, 
QubitInformationObjectI18n::ID);
 
     // Search for matching title or identifier
     if (isset($request->query))
     {
-      $c1 = $criteria->getNewCriterion(QubitInformationObjectI18n::TITLE, 
$request->query.'%', Criteria::LIKE);
-      $c2 = $criteria->getNewCriterion(QubitInformationObject::IDENTIFIER, 
$request->query.'%', Criteria::LIKE);
+      $c1 = $criteria->getNewCriterion(QubitInformationObjectI18n::TITLE, 
"$request->query%", Criteria::LIKE);
+      $c2 = $criteria->getNewCriterion(QubitInformationObject::IDENTIFIER, 
"$request->query%", Criteria::LIKE);
       $c1->addOr($c2);
       $criteria->add($c1);
     }
 
-    // Exclude root node
+    // Exclude root
     $criteria->add(QubitInformationObject::ID, 
QubitInformationObject::ROOT_ID, Criteria::NOT_EQUAL);
 
-    $criteria->add(QubitInformationObjectI18n::CULTURE, 
$this->getUser()->getCulture(), Criteria::EQUAL);
+    $criteria->add(QubitInformationObjectI18n::CULTURE, 
$this->context->user->getCulture());
     
$criteria->addAscendingOrderByColumn(QubitInformationObject::LEVEL_OF_DESCRIPTION_ID);
     $criteria->addAscendingOrderByColumn(QubitInformationObject::IDENTIFIER);
     $criteria->addAscendingOrderByColumn(QubitInformationObjectI18n::TITLE);

Modified: trunk/apps/qubit/modules/informationobject/templates/_eventForm.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/templates/_eventForm.php Wed Oct 
13 19:31:10 2010        (r8092)
+++ trunk/apps/qubit/modules/informationobject/templates/_eventForm.php Wed Oct 
13 19:35:56 2010        (r8093)
@@ -75,9 +75,9 @@
     // Define dialog
     Qubit.dialog = new QubitDialog('updateEvent',
     {
-      "displayTable": "relatedEvents",
-      "newRowTemplate": '$rowTemplate',
-      "handleFieldRender": handleFieldRender
+      'displayTable': 'relatedEvents',
+      'newRowTemplate': '$rowTemplate',
+      'handleFieldRender': handleFieldRender
     }, jQuery);
 
     $addEditButtonJsCode

Modified: trunk/apps/qubit/modules/repository/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/repository/actions/editAction.class.php    Wed Oct 
13 19:31:10 2010        (r8092)
+++ trunk/apps/qubit/modules/repository/actions/editAction.class.php    Wed Oct 
13 19:35:56 2010        (r8093)
@@ -34,15 +34,11 @@
     $this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
 
     $this->resource = new QubitRepository;
-    if (isset($this->request->id))
+    if (isset($this->getRoute()->resource))
     {
-      $this->resource = QubitRepository::getById($this->request->id);
-
-      if (!isset($this->resource))
-      {
-        $this->forward404();
-      }
+      $this->resource = $this->getRoute()->resource;
 
+      // Check user authorization
       if (!QubitAcl::check($this->resource, 'update'))
       {
         QubitAcl::forwardUnauthorized();
@@ -55,6 +51,7 @@
     }
     else
     {
+      // Check user authorization
       if (!QubitAcl::check($this->resource, 'create'))
       {
         QubitAcl::forwardUnauthorized();
@@ -67,56 +64,51 @@
     switch ($name)
     {
       case 'type':
-        $values = array();
-        $choices = array();
-
         $criteria = new Criteria;
-        $criteria = 
$this->resource->addobjectTermRelationsRelatedByobjectIdCriteria($criteria);
-        $criteria->addJoin(QubitObjectTermRelation::TERM_ID, QubitTerm::ID, 
Criteria::INNER_JOIN);
+        $criteria = 
$this->resource->addObjectTermRelationsRelatedByObjectIdCriteria($criteria);
+        $criteria->addJoin(QubitObjectTermRelation::TERM_ID, QubitTerm::ID);
         $criteria->add(QubitTerm::TAXONOMY_ID, 
QubitTaxonomy::REPOSITORY_TYPE_ID);
 
-        foreach ($this->repoTypes = QubitObjectTermRelation::get($criteria) as 
$otRelation)
+        $value = array();
+        foreach ($this->relations = QubitObjectTermRelation::get($criteria) as 
$item)
         {
-          $values[] = $this->context->routing->generate(null, array('module' 
=> 'term', 'id' => $otRelation->termId));
+          $value[] = $this->context->routing->generate(null, array($item, 
'module' => 'term'));
         }
 
-        foreach 
(QubitTaxonomy::getTaxonomyTerms(QubitTaxonomy::REPOSITORY_TYPE_ID) as $term)
+        $this->form->setDefault('type', $value);
+        $this->form->setValidator('type', new sfValidatorPass);
+
+        $choices = array();
+        foreach 
(QubitTaxonomy::getTermsById(QubitTaxonomy::REPOSITORY_TYPE_ID) as $item)
         {
-          $choices[$this->context->routing->generate(null, array($term, 
'module' => 'term'))] = $term;
+          $choices[$this->context->routing->generate(null, array($item, 
'module' => 'term'))] = $item;
         }
 
-        $this->form->setDefault('type', $values);
-        $this->form->setValidator('type', new sfValidatorPass);
         $this->form->setWidget('type', new sfWidgetFormSelect(array('choices' 
=> $choices, 'multiple' => true)));
 
         break;
 
       case 'descStatus':
       case 'descDetail':
-
-        if (null !== $this->resource[$name.'Id'])
-        {
-          $this->form->setDefault($name, 
$this->context->routing->generate(null, array('module' => 'term', 'id' => 
$this->resource[$name.'Id'])));
-        }
-
-        $choices = array();
-        $choices[null] = null;
+        $this->form->setDefault($name, $this->context->routing->generate(null, 
array($this->resource[$name], 'module' => 'term')));
+        $this->form->setValidator($name, new sfValidatorString);
 
         if ('descStatus' == $name)
         {
-          $terms = 
QubitTaxonomy::getTermsById(QubitTaxonomy::DESCRIPTION_STATUS_ID);
+          $id = QubitTaxonomy::DESCRIPTION_STATUS_ID;
         }
         else
         {
-          $terms = 
QubitTaxonomy::getTermsById(QubitTaxonomy::DESCRIPTION_DETAIL_LEVEL_ID);
+          $id = QubitTaxonomy::DESCRIPTION_DETAIL_LEVEL_ID;
         }
 
-        foreach ($terms as $term)
+        $choices = array();
+        $choices[null] = null;
+        foreach (QubitTaxonomy::getTermsById($id) as $item)
         {
-          $choices[$this->context->routing->generate(null, array($term, 
'module' => 'term'))] = $term;
+          $choices[$this->context->routing->generate(null, array($item, 
'module' => 'term'))] = $item;
         }
 
-        $this->form->setValidator($name, new sfValidatorString);
         $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' 
=> $choices)));
 
         break;
@@ -184,45 +176,49 @@
    */
   protected function processField($field)
   {
-    switch ($name = $field->getName())
+    switch ($field->getName())
     {
       case 'type':
-        $current = $new = array();
-        foreach ($this->form->getValue('type') as $value)
+        $value = $filtered = array();
+        foreach ($this->form->getValue('type') as $item)
         {
-          $params = $this->context->routing->parse(Qubit::pathInfo($value));
-          $current[$params['id']] = $new[$params['id']] = $params['id'];
+          $params = $this->context->routing->parse(Qubit::pathInfo($item));
+          $resource = $params['_sf_route']->resource;
+          $value[$resource->id] = $filtered[$resource->id] = $resource;
         }
 
-        foreach ($this->repoTypes as $otRelation)
+        foreach ($this->relations as $item)
         {
-          if (isset($current[$otRelation->termId]))
+          if (isset($value[$item->termId]))
           {
-            // If it's current, then don't add/delete
-            unset($new[$otRelation->termId]);
+            unset($filtered[$item->termId]);
           }
           else
           {
-            // If not in current list, then delete
-            $otRelation->delete();
+            $item->delete();
           }
         }
 
-        // Create 'new' relations
-        foreach ($new as $id)
+        foreach ($filtered as $item)
         {
-          $otRelation = new QubitObjectTermRelation;
-          $otRelation->termId = $id;
+          $relation = new QubitObjectTermRelation;
+          $relation->term = $item;
 
-          $this->resource->objectTermRelationsRelatedByobjectId[] = 
$otRelation;
+          $this->resource->objectTermRelationsRelatedByobjectId[] = $relation;
         }
 
         break;
+
       case 'descStatus':
       case 'descDetail':
-        $params = 
$this->context->routing->parse(Qubit::pathInfo($this->form->getValue($name)));
-        $fieldId = (isset($params['id'])) ? $params['id'] : null;
-        $this->resource[$name.'Id'] = $fieldId;
+        unset($this->resource[$field->getName()]);
+
+        $value = $this->form->getValue($field->getName());
+        if (isset($value))
+        {
+          $params = $this->context->routing->parse(Qubit::pathInfo($value));
+          $this->resource[$field->getName()] = $params['_sf_route']->resource;
+        }
 
         break;
 

Modified: 
trunk/plugins/sfIsadPlugin/modules/sfIsadPlugin/actions/editAction.class.php
==============================================================================
--- 
trunk/plugins/sfIsadPlugin/modules/sfIsadPlugin/actions/editAction.class.php    
    Wed Oct 13 19:31:10 2010        (r8092)
+++ 
trunk/plugins/sfIsadPlugin/modules/sfIsadPlugin/actions/editAction.class.php    
    Wed Oct 13 19:35:56 2010        (r8093)
@@ -100,8 +100,7 @@
         $criteria->add(QubitEvent::ACTOR_ID, null, Criteria::ISNOTNULL);
         $criteria->add(QubitEvent::TYPE_ID, QubitTerm::CREATION_ID);
 
-        $value = array();
-        $choices = array();
+        $value = $choices = array();
         foreach ($this->events = QubitEvent::get($criteria) as $item)
         {
           $value[] = $this->context->routing->generate(null, 
array($item->actor, 'module' => 'actor'));

Modified: 
trunk/plugins/sfIsdiahPlugin/modules/sfIsdiahPlugin/templates/editSuccess.php
==============================================================================
--- 
trunk/plugins/sfIsdiahPlugin/modules/sfIsdiahPlugin/templates/editSuccess.php   
    Wed Oct 13 19:31:10 2010        (r8092)
+++ 
trunk/plugins/sfIsdiahPlugin/modules/sfIsdiahPlugin/templates/editSuccess.php   
    Wed Oct 13 19:35:56 2010        (r8093)
@@ -2,7 +2,7 @@
 
 <h1 class="label"><?php echo render_title($resource) ?></h1>
 
-<?php if (isset($sf_request->id)): ?>
+<?php if (isset($sf_request->getAttribute('sf_route')->resource)): ?>
   <?php echo $form->renderFormTag(url_for(array($resource, 'module' => 
'repository', 'action' => 'edit'))) ?>
 <?php else: ?>
   <?php echo $form->renderFormTag(url_for(array('module' => 'repository', 
'action' => 'create'))) ?>
@@ -23,7 +23,7 @@
 
     <?php echo render_field($form->authorizedFormOfName
       ->help(__('"Record the standardised form of name of the institution, 
adding appropriate qualifiers (for instance dates, place, etc.), if necessary. 
Specify separately in the Rules and/or conventions used element (5.6.3) which 
set of rules has been applied for this element." (ISDIAH 5.1.2)'))
-      ->label(link_to_if(isset($sf_request->id), __('Authorized form of 
name'), array($resource, 'module' => 'actor', 'action' => 'edit', 
'repositoryReroute' => $resource->id)).' <span class="form-required" 
title="'.__('This is a mandatory element').'">*</span>'), $resource) ?>
+      
->label(link_to_if(isset($sf_request->getAttribute('sf_route')->resource), 
__('Authorized form of name'), array($resource, 'module' => 'actor', 'action' 
=> 'edit', 'repositoryReroute' => $resource->id)).' <span class="form-required" 
title="'.__('This is a mandatory element').'">*</span>'), $resource) ?>
 
     <?php echo $form->parallelName
       ->help(__('"Purpose: To indicate the various forms in which the 
authorised form of name of an institution occurs in other languages or script 
form(s). Rule: Record the parallel form(s) of name of the institution in 
accordance with any relevant national or international conventions or rules 
applied by the agency that created the description, including any necessary sub 
elements and/or qualifiers required by those conventions or rules. Specify in 
the Rules and/or conventions used element (5.6.3) which rules have been 
applied." (ISDIAH 5.1.3)'))
@@ -70,7 +70,7 @@
       <table class="inline">
         <tr>
           <th colspan="4" style="margin-top: 5px; border-top: 2px solid 
#999999; width: 95%">
-            <?php echo __('New contact information') ?>
+            <?php echo __('Add new contact information') ?>
           </th>
         </tr><tr>
           <th>
@@ -270,12 +270,10 @@
 
     <?php echo $form->language
       ->help(__('Select the language(s) of this record from the drop-down 
menu; enter the first few letters to narrow the choices. (ISDIAH 5.6.7)'))
-      ->label('Language(s)')
       ->renderRow(array('class' => 'form-autocomplete')) ?>
 
     <?php echo $form->script
       ->help(__('Select the script(s) of this record from the drop-down menu; 
enter the first few letters to narrow the choices. (ISDIAH 5.6.7)'))
-      ->label('Script(s)')
       ->renderRow(array('class' => 'form-autocomplete')) ?>
 
     <?php echo render_field($form->descSources
@@ -293,7 +291,7 @@
 
     <div class="content">
       <ul class="clearfix links">
-        <?php if (isset($sf_request->id)): ?>
+        <?php if (isset($sf_request->getAttribute('sf_route')->resource)): ?>
           <li><?php echo link_to(__('Cancel'), array($resource, 'module' => 
'repository'), array('title' => __('Cancel'))) ?></li>
           <li><input class="form-submit" type="submit" value="<?php echo 
__('Save') ?>"/></li>
         <?php else: ?>

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