コード例 #1
0
 public function setPhysicalObjectByName($physicalObjectName, $options)
 {
     // see if physical object already exists, otherwise create a new physical object
     $criteria = new Criteria();
     $criteria->addJoin(QubitPhysicalObject::ID, QubitPhysicalObjectI18n::ID);
     $criteria->add(QubitPhysicalObjectI18n::NAME, $physicalObjectName);
     if ($existingPhysicalObject = QubitPhysicalObject::getOne($criteria)) {
         $this->addPhysicalObject($existingPhysicalObject);
     } else {
         $newPhysicalObject = new QubitPhysicalObject();
         $newPhysicalObject->setName($physicalObjectName);
         // see if physical object type already exists, otherwise create a new one
         if ($options['type']) {
             $criteria = new Criteria();
             $criteria->addJoin(QubitTerm::ID, QubitTermI18n::ID);
             $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::PHYSICAL_OBJECT_TYPE_ID);
             $criteria->add(QubitTermI18n::NAME, $options['type']);
             if ($physicalObjectType = QubitTerm::getOne($criteria)) {
                 $newPhysicalObject->setTypeId($physicalObjectType->id);
             } else {
                 $newTerm = new QubitTerm();
                 $newTerm->setTaxonomyId(QubitTaxonomy::PHYSICAL_OBJECT_TYPE_ID);
                 $newTerm->setName($options['type']);
                 $newTerm->parentId = QubitTerm::CONTAINER_ID;
                 $newTerm->save();
                 $newPhysicalObject->setTypeId($newTerm->id);
             }
         }
         if (isset($options['location'])) {
             $newPhysicalObject->setLocation($options['location']);
         }
         $newPhysicalObject->save();
         $this->addPhysicalObject($newPhysicalObject);
     }
 }
コード例 #2
0
 public function setTypeByName($name)
 {
     // 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, $name);
     if (null === ($term = QubitTerm::getOne($criteria))) {
         $term = new QubitTerm();
         $term->setTaxonomyId(QubitTaxonomy::REPOSITORY_TYPE_ID);
         $term->setName($name);
         $term->setRoot();
         $term->save();
     }
     foreach (self::getTermRelations(QubitTaxonomy::REPOSITORY_TYPE_ID) as $item) {
         // Faster than $item->term == $term
         if ($item->termId == $term->id) {
             return;
         }
     }
     $relation = new QubitObjectTermRelation();
     $relation->term = $term;
     $this->objectTermRelationsRelatedByobjectId[] = $relation;
 }