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;
 }
 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);
     }
 }
 protected function mapInformationObject($parameters)
 {
     // NB: any value for publication status means set to published
     if (!empty($parameters['publicationStatus'])) {
         $parameters['publicationStatus'] = QubitTerm::PUBLICATION_STATUS_PUBLISHED_ID;
     }
     if (!empty($parameters['repository'])) {
         $repo = QubitRepository::getByAuthorizedFormOfName($parameters['repository']);
         // if the repository does not exist, create it
         if (empty($repo)) {
             $repo = new QubitRepository();
             $repo->authorizedFormOfName = $parameters['repository'];
             $repo->save();
         }
         $parameters['repository'] = $this->context->routing->generate(null, array($repo, 'module' => 'repository'));
     }
     // subject access points
     if (!isset($this->subjects)) {
         foreach (QubitTerm::getSubjects() as $term) {
             $this->subjects[$term->__toString()] = $term;
         }
     }
     $n = 0;
     foreach (explode('|', $parameters['subjectAccessPoints']) as $new_subjectAccessPoint) {
         if (0 == strlen(trim($new_subjectAccessPoint))) {
             continue;
         }
         // if the subject does not exist, create it
         if (!in_array($new_subjectAccessPoint, $this->subjects) && !empty($new_subjectAccessPoint)) {
             $subject = new QubitTerm();
             $subject->taxonomyId = QubitTaxonomy::SUBJECT_ID;
             $subject->name = $new_subjectAccessPoint;
             $subject->save();
             $this->subjects[$subject->__toString()] = $subject;
         }
         $new_subjectAccessPoints['new' . $n] = $this->context->routing->generate(null, array($this->subjects[$new_subjectAccessPoint], 'module' => 'term'));
         $n++;
     }
     $parameters['subjectAccessPoints'] = $new_subjectAccessPoints;
     // place access points
     if (!isset($this->places)) {
         foreach (QubitTerm::getPlaces() as $term) {
             $this->places[$term->__toString()] = $term;
         }
     }
     $n = 0;
     foreach (explode('|', $parameters['placeAccessPoints']) as $new_placeAccessPoint) {
         if (0 == strlen(trim($new_placeAccessPoint))) {
             continue;
         }
         // if the place does not exist, create it
         if (!in_array($new_placeAccessPoint, $this->places) && !empty($new_placeAccessPoint)) {
             $place = new QubitTerm();
             $place->taxonomyId = QubitTaxonomy::PLACE_ID;
             $place->name = $new_placeAccessPoint;
             $place->save();
             $this->places[$place->__toString()] = $place;
         }
         $new_placeAccessPoints['new' . $n] = $this->context->routing->generate(null, array($this->places[$new_placeAccessPoint], 'module' => 'term'));
         $n++;
     }
     $parameters['placeAccessPoints'] = $new_placeAccessPoints;
     // name access points
     $n = 0;
     $this->getActors();
     foreach (explode('|', $parameters['nameAccessPoints']) as $new_nameAccessPoint) {
         if (0 == strlen(trim($new_nameAccessPoint))) {
             continue;
         }
         // if the name does not exist, create it
         if (!isset($this->actors[$new_nameAccessPoint])) {
             $name = new QubitActor();
             $name->authorizedFormOfName = $new_nameAccessPoint;
             $name->save();
             $this->actors[$name->__toString()] = $name;
         }
         $new_nameAccessPoints['new' . $n] = $this->context->routing->generate(null, array($this->actors[$new_nameAccessPoint], 'module' => 'actor'));
         $n++;
     }
     $parameters['nameAccessPoints'] = $new_nameAccessPoints;
     return $parameters;
 }