public function parse($doc)
 {
     require_once sfConfig::get('sf_root_dir') . '/vendor/FluentDOM/FluentDOM.php';
     $fd = FluentDOM($doc)->namespaces(array('eac' => 'urn:isbn:1-931666-33-4'));
     $this->resource->sourceStandard = 'http://eac.staatsbibliothek-berlin.de/schema/cpf.xsd';
     $this->resource->descriptionIdentifier = $fd->find('eac:control/eac:recordId')->text();
     //$fd->find('eac:control/eac:otherRecordId');
     $this->maintenanceStatus = $fd->find('eac:control/eac:maintenanceStatus')->text();
     $this->publicationStatus = $fd->find('eac:control/eac:publicationStatus')->text();
     // TODO <descriptiveNote/>, <otherAgencyCode/>
     $this->resource->institutionResponsibleIdentifier = $fd->find('eac:control/eac:maintenanceAgency/eac:agencyName')->text();
     // TODO <descriptiveNote/>
     foreach ($fd->find('eac:control/eac:languageDeclaration/eac:language/@languageCode') as $node) {
         $this->resource->language[] = $node->textContent;
     }
     foreach ($fd->find('eac:control/eac:languageDeclaration/eac:script/@scriptCode') as $node) {
         $this->resource->script[] = $node->textContent;
     }
     // conventionDeclaration/abbreviation is an identifier, referenced by e.g.
     // <authorizedForm/> and <alternativeForm/>
     //
     // TODO <descriptiveNote/>
     $this->resource->rules = $fd->find('eac:control/eac:conventionDeclaration/eac:citation')->text();
     // TODO <abbreviation/>, <descriptiveNote/>
     //$fd->find('eac:control/eac:localTypeDeclaration');
     // TODO <date/>, <dateRange/>, <term/>
     //$this->resource->descriptionDetail = $fd->find('eac:control/eac:localControl')->text();
     $this->maintenanceHistory = $fd->find('eac:control/eac:maintenanceHistory');
     // TODO <descriptiveNote/>, @lastDateTimeVerified
     $this->resource->sources = $fd->find('eac:control/eac:sources/eac:source/eac:sourceEntry')->text();
     // TODO eac:cpfDescription/eac:identity/@identityType
     $this->resource->corporateBodyIdentifiers = $fd->find('eac:cpfDescription/eac:identity/eac:entityId')->text();
     $this->entityType = $fd->find('eac:cpfDescription/eac:identity/eac:entityType')->text();
     // TODO <nameEntryParallel/>, <useDates/>
     $this->resource->authorizedFormOfName = $fd->find('eac:cpfDescription/eac:identity/eac:nameEntry[eac:authorizedForm]/eac:part')->text();
     foreach ($fd->find('eac:cpfDescription/eac:identity/eac:nameEntry[not(eac:authorizedForm)]') as $node) {
         $item = new QubitOtherName();
         $item->name = $fd->spawn()->add($node)->find('eac:part')->text();
         $item->typeId = QubitTerm::OTHER_FORM_OF_NAME_ID;
         $this->resource->otherNames[] = $item;
     }
     //$fd->find('eac:cpfDescription/eac:identity/eac:nameEntry/eac:authorizedForm');
     //$fd->find('eac:cpfDescription/eac:identity/eac:nameEntry/eac:alternativeForm');
     //$fd->find('eac:cpfDescription/eac:identity/eac:nameEntry/eac:preferredForm');
     // TODO eac:cpfDescription/eac:identity/eac:descriptiveNote
     $this->existDates = $fd->find('eac:cpfDescription/eac:description/eac:existDates');
     // TODO <address/>, <addressLine/>, <date/>, <dateRange/>, <dateSet/>,
     // <descriptiveNote/>, <placeRole/>, <term/>, @accuracy, @altitude,
     // @countryCode, @latitude, @longitude, @vocabularySource
     $this->resource->places = $fd->find('eac:cpfDescription/eac:description/eac:place/eac:placeEntry|eac:cpfDescription/eac:description/eac:places/eac:place/eac:placeEntry')->text();
     // TODO <date/>, <dateRange/>, <dateSet/>, <descriptiveNote/>,
     // <placeEntry/>, <term/>
     //$fd->find('eac:cpfDescription/eac:description/eac:localDescription');
     //$fd->find('eac:cpfDescription/eac:description/eac:localDescriptions');
     // TODO <date/>, <dateRange/>, <dateSet/>, <descriptiveNote/>,
     // <placeEntry/>
     $this->resource->legalStatus = $fd->find('eac:cpfDescription/eac:description/eac:legalStatus/eac:term|eac:cpfDescription/eac:description/eac:legalStatuses/eac:legalStatus/eac:term')->text();
     // TODO <date/>, <dateRange/>, <dateSet/>, <descriptiveNote/>,
     // <placeEntry/>
     $this->resource->functions = $fd->find('eac:cpfDescription/eac:description/eac:function/eac:term|eac:cpfDescription/eac:description/eac:functions/eac:function/eac:term|eac:cpfDescription/eac:description/eac:occupation/eac:term|eac:cpfDescription/eac:description/eac:occupations/eac:occupation/eac:term')->text();
     //$fd->find('eac:cpfDescription/eac:description/eac:languageUsed');
     // TODO <date/>, <dateRange/>, <dateSet/>, <descriptiveNote/>,
     // <placeEntry/>
     $this->resource->mandates = $fd->find('eac:cpfDescription/eac:description/eac:mandate/eac:term|eac:cpfDescription/eac:description/eac:mandates/eac:mandate/eac:term')->text();
     $this->internalStructures = $fd->find('eac:cpfDescription/eac:description/eac:structureOrGenealogy');
     $this->generalContext = $fd->find('eac:cpfDescription/eac:description/eac:generalContext');
     // TODO <abstract/>, <chronList/>
     $this->biogHist = $fd->find('eac:cpfDescription/eac:description/eac:biogHist');
     // TODO @lastDateTimeVerified, <date/>, <dateRange/>, <dateSet/>,
     // <descriptiveNote/>, <placeEntry/>
     foreach ($fd->find('eac:cpfDescription/eac:relations/eac:cpfRelation') as $node) {
         $url = preg_replace('/^(?:[^:]+:\\/\\/[^\\/]+)?' . preg_quote(sfContext::getInstance()->request->getPathInfoPrefix(), '/') . '/', null, $node->getAttributeNS('http://www.w3.org/1999/xlink', 'href'), -1, $count);
         // @href is one of our resources
         if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href') && 0 < $count) {
             $params = sfContext::getInstance()->routing->parse($url);
             $item = $params['_sf_route']->resource;
         } else {
             $item = new QubitActor();
             $item->authorizedFormOfName = $fd->spawn()->add($node)->find('eac:relationEntry')->text();
             // TODO Cascade save through QubitEvent
             $item->save();
         }
         $relation = new QubitRelation();
         $relation->object = $item;
         $relation->typeId = self::fromCpfRelationType($node->getAttribute('cpfRelationType'));
         if (0 < count($date = self::parseDates($node))) {
             $relation->startDate = $date[0][0];
             $relation->endDate = $date[count($date) - 1][1];
         }
         // Multiple, non-contiguous dates
         if (1 < count($date)) {
             foreach ($date as $key => $value) {
                 $date[$key] = Qubit::renderDate($value[0]) . ' - ' . Qubit::renderDate($value[1]);
             }
             $note = new QubitNote();
             $note->typeId = QubitTerm::RELATION_NOTE_DATE_ID;
             $note->scope = 'QubitRelation';
             $note->content = implode(', ', $date);
             $relation->notes[] = $note;
         }
         $this->resource->relationsRelatedBysubjectId[] = $relation;
     }
     // TODO @lastDateTimeVerified, <date/>, <dateRange/>, <dateSet/>,
     // <descriptiveNote/>, <placeEntry/>
     foreach ($fd->find('eac:cpfDescription/eac:relations/eac:resourceRelation') as $node) {
         $url = preg_replace('/^(?:[^:]+:\\/\\/[^\\/]+)?' . preg_quote(sfContext::getInstance()->request->getPathInfoPrefix(), '/') . '/', null, $node->getAttributeNS('http://www.w3.org/1999/xlink', 'href'), -1, $count);
         // @href is one of our resources
         if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href') && 0 < $count) {
             $params = sfContext::getInstance()->routing->parse($url);
             $item = $params['_sf_route']->resource;
         } else {
             $item = new QubitInformationObject();
             $item->parentId = QubitInformationObject::ROOT_ID;
             $item->title = $fd->spawn()->add($node)->find('eac:relationEntry')->text();
             // TODO Cascade save through QubitEvent
             $item->save();
         }
         $event = new QubitEvent();
         $event->informationObject = $item;
         $event->typeId = self::fromResourceRelationType($node->getAttribute('resourceRelationType'));
         if (0 < count($date = self::parseDates($node))) {
             $event->startDate = $date[0][0];
             $event->endDate = $date[count($date) - 1][1];
         }
         // Multiple, non-contiguous dates
         if (1 < count($date)) {
             foreach ($date as $key => $value) {
                 $date[$key] = Qubit::renderDate($value[0]) . ' - ' . Qubit::renderDate($value[1]);
             }
             $event->date = implode(', ', $date);
         }
         $this->resource->events[] = $event;
     }
     // TODO <date/>, <dateRange/>, <dateSet/>, <descriptiveNote/>,
     // <placeEntry/>, @lastDateTimeVerified
     foreach ($fd->find('eac:cpfDescription/eac:relations/eac:functionRelation') as $node) {
         $url = preg_replace('/^(?:[^:]+:\\/\\/[^\\/]+)?' . preg_quote(sfContext::getInstance()->request->getPathInfoPrefix(), '/') . '/', null, $node->getAttributeNS('http://www.w3.org/1999/xlink', 'href'), -1, $count);
         // @href is one of our resources
         if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href') && 0 < $count) {
             $params = sfContext::getInstance()->routing->parse($url);
             $item = $params['_sf_route']->resource;
         } else {
             $item = new QubitFunction();
             $item->authorizedFormOfName = $fd->spawn()->add($node)->find('eac:relationEntry')->text();
             // TODO Cascade save through QubitEvent
             $item->save();
         }
         $relation = new QubitRelation();
         $relation->subject = $item;
         // TODO Set $relation->type by mapping to controlled vocabulary
         $this->resource->relationsRelatedByobjectId[] = $relation;
     }
     // TODO <alternativeSet/>
     return $this;
 }
 public static function loadData()
 {
     $object = new QubitInformationObject();
     $object->id = QubitInformationObject::ROOT_ID;
     $object->save();
     $object = new QubitActor();
     $object->id = QubitActor::ROOT_ID;
     $object->save();
     $object = new QubitSetting();
     $object->name = 'plugins';
     $object->value = serialize(array('sfCaribouPlugin', 'sfEhriThemePlugin', 'sfDcPlugin', 'sfEacPlugin', 'sfEadPlugin', 'sfIsaarPlugin', 'sfIsadPlugin', 'sfEhriIsadPlugin', 'sfIsdfPlugin', 'sfIsdiahPlugin', 'sfEhriIsdiahPlugin', 'sfModsPlugin', 'sfRadPlugin', 'sfSkosPlugin'));
     $object->save();
     $dispatcher = sfContext::getInstance()->getEventDispatcher();
     $formatter = new sfAnsiColorFormatter();
     chdir(sfConfig::get('sf_root_dir'));
     $loadData = new sfPropelDataLoadTask($dispatcher, $formatter);
     $loadData->run();
 }
 public function addCreatorsAndHistory($parameters)
 {
     $creators = $histories = array();
     $i = 0;
     $updated = false;
     // Get array of existing actors
     $this->getActors();
     if (isset($parameters['creatorHistory'])) {
         $histories = explode('|', $parameters['creatorHistory']);
     }
     foreach (explode('|', $parameters['creators']) as $creator) {
         if (0 == strlen(trim($creator))) {
             continue;
         }
         if (isset($this->actors[$creator])) {
             $actor = $this->actors[$creator];
         } else {
             $actor = new QubitActor();
             $actor->authorizedFormOfName = $creator;
             $updated = true;
             // Add to array of existing actors
             $this->actors[$creator] = $actor;
         }
         if (isset($histories[$i])) {
             $actor->history = $histories[$i];
             $updated = true;
         }
         if ($updated) {
             $actor->save();
         }
         $creators[] = $actor;
         $i++;
     }
     return $creators;
 }
 public function setActorByName($name, $options)
 {
     // Only create an linked Actor if the event or relation type is indicated
     if (!isset($options['event_type_id']) && !isset($options['relation_type_id'])) {
         return;
     }
     // See if the Actor record already exists, if not create it
     $criteria = new Criteria();
     $criteria->addJoin(QubitActor::ID, QubitActorI18n::ID);
     $criteria->add(QubitActorI18n::AUTHORIZED_FORM_OF_NAME, $name);
     if (null === ($actor = QubitActor::getOne($criteria))) {
         $actor = new QubitActor();
         // Make root actor the parent of new actors
         $actor->parentId = QubitActor::ROOT_ID;
         $actor->setAuthorizedFormOfName($name);
         if (isset($options['entity_type_id'])) {
             // set actor entityTypeId
             $actor->setEntityTypeId($options['entity_type_id']);
         }
         if (isset($options['source'])) {
             // set actor entityTypeId
             $actor->setSources($options['source']);
         }
         if (isset($options['rules'])) {
             // set actor entityTypeId
             $actor->setRules($options['rules']);
         }
         if (isset($options['history'])) {
             $actor->setHistory($options['history']);
         }
         $actor->save();
     }
     if (isset($options['event_type_id'])) {
         // create an event object to link the information object and actor
         $event = new QubitEvent();
         $event->setActorId($actor->id);
         $event->setTypeId($options['event_type_id']);
         if (isset($options['dates'])) {
             $event->setDate($options['dates']);
         }
         $this->events[] = $event;
     } else {
         if (isset($options['relation_type_id'])) {
             // only add Actor as name access point if they are not already linked to
             // an event (i.e. they are not already a "creator", "accumulator", etc.)
             $existingRelation = false;
             foreach ($this->events as $existingEvent) {
                 if ($actor->id == $existingEvent->actorId) {
                     $existingRelation = true;
                     break;
                 }
             }
             if (!$existingRelation) {
                 $relation = new QubitRelation();
                 $relation->objectId = $actor->id;
                 $relation->typeId = QubitTerm::NAME_ACCESS_POINT_ID;
                 $this->relationsRelatedBysubjectId[] = $relation;
             }
         }
     }
 }
 public function save($connection = null)
 {
     parent::save($connection);
     foreach ($this->repositoryI18ns as $repositoryI18n) {
         $repositoryI18n->id = $this->id;
         $repositoryI18n->save($connection);
     }
     return $this;
 }