Author: sevein
Date: Thu Apr  7 08:42:49 2011
New Revision: 9065

Log:
Make QubitRepository::setTypeByName compatible with QubitObjectTermRelation and 
remove duplicated methods also available in QubitActor.

Modified:
   trunk/lib/model/QubitActor.php
   trunk/lib/model/QubitRepository.php

Modified: trunk/lib/model/QubitActor.php
==============================================================================
--- trunk/lib/model/QubitActor.php      Thu Apr  7 00:02:54 2011        (r9064)
+++ trunk/lib/model/QubitActor.php      Thu Apr  7 08:42:49 2011        (r9065)
@@ -404,7 +404,12 @@
     return $this->SubjectHitCount;
   }
 
-  //many-to-many Term Relations
+  /**
+   * Save new link to a term.
+   *
+   * @param integer $termId QubitTerm primary key
+   * @param string $relationNote DEPRECATED
+   */
   public function setTermRelation($termId, $relationNote = null)
   {
     $newTermRelation = new QubitObjectTermRelation;
@@ -416,6 +421,12 @@
     $newTermRelation->save();
   }
 
+  /**
+   * Get many-to-many links to QubitTerm objects
+   *
+   * @param mixed $taxonomyId  Limit results by taxonomy type
+   * @return QubitQuery collection of QubitObjectTermRelation objects
+   */
   public function getTermRelations($taxonomyId = 'all')
   {
     $criteria = new Criteria;

Modified: trunk/lib/model/QubitRepository.php
==============================================================================
--- trunk/lib/model/QubitRepository.php Thu Apr  7 00:02:54 2011        (r9064)
+++ trunk/lib/model/QubitRepository.php Thu Apr  7 08:42:49 2011        (r9065)
@@ -36,43 +36,6 @@
   }
 
   /**
-   * Save new link to a term.
-   *
-   * @param integer $termId QubitTerm primary key
-   * @param string $relationNote DEPRECATED
-   */
-  public function setTermRelation($termId, $relationNote = null)
-  {
-    $newTermRelation = new QubitObjectTermRelation;
-    $newTermRelation->setTermId($termId);
-
-    //TODO: move to QubitNote
-    //  $newTermRelation->setRelationNote($relationNote);
-    $newTermRelation->setObjectId($this->id);
-    $newTermRelation->save();
-  }
-
-  /**
-   * Get many-to-many links to QubitTerm objects
-   *
-   * @param mixed $taxonomyId  Limit results by taxonomy type
-   * @return QubitQuery collection of QubitObjectTermRelation objects
-   */
-  public function getTermRelations($taxonomyId = 'all')
-  {
-    $criteria = new Criteria;
-    $criteria->add(QubitObjectTermRelation::OBJECT_ID, $this->id);
-
-    if ($taxonomyId != 'all')
-    {
-      $criteria->addJoin(QubitObjectTermRelation::TERM_ID, QubitTERM::ID);
-      $criteria->add(QubitTerm::TAXONOMY_ID, $taxonomyId);
-    }
-
-    return QubitObjectTermRelation::get($criteria);
-  }
-
-  /**
    * Create new related QubitNote
    *
    * @param integer $userId     QubitUser id
@@ -193,24 +156,34 @@
   Import methods
   ***************/
 
-  public function setTypeByName($term)
+  public function setTypeByName($name)
   {
-    // see if type term already exists
+    // See if type term already exists
     $criteria = new Criteria;
     $criteria->addJoin(QubitTerm::ID, QubitTermI18n::ID);
     $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::REPOSITORY_TYPE_ID);
-    $criteria->add(QubitTermI18n::NAME, $term);
-    if ($existingTerm = QubitTerm::getOne($criteria))
+    $criteria->add(QubitTermI18n::NAME, $name);
+
+    if (null === $term = QubitTerm::getOne($criteria))
     {
-      $this->setTypeId($existingTerm->id);
+      $term = new QubitTerm;
+      $term->setTaxonomyId(QubitTaxonomy::REPOSITORY_TYPE_ID);
+      $term->setName($name);
+      $term->save();
     }
-    else
+
+    foreach (self::getTermRelations(QubitTaxonomy::REPOSITORY_TYPE_ID) as 
$item)
     {
-      $newTerm = new QubitTerm;
-      $newTerm->setTaxonomyId(QubitTaxonomy::REPOSITORY_TYPE_ID);
-      $newTerm->setName($term);
-      $newTerm->save();
-      $this->setTypeId($newTerm->id);
+      // Faster than $item->term == $term
+      if ($item->termId == $term->id)
+      {
+        return;
+      }
     }
+
+    $relation = new QubitObjectTermRelation;
+    $relation->term = $term;
+
+    $this->objectTermRelationsRelatedByobjectId[] = $relation;
   }
 }

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