public function execute($request)
 {
     $criteria = new Criteria();
     $criteria = QubitTaxonomy::addEditableTaxonomyCriteria($criteria);
     $criteria->addJoin(QubitTaxonomy::ID, QubitTaxonomyI18n::ID);
     $criteria->add(QubitTaxonomyI18n::CULTURE, $this->context->user->getCulture());
     // Narrow results by query
     if (0 < strlen($request->query)) {
         $criteria->add(QubitTaxonomyI18n::NAME, "{$request->query}%", Criteria::LIKE);
     }
     // Limit results by ACL
     $criterion = QubitAcl::getFilterCriterion($criteria, QubitTaxonomy::getById(QubitTaxonomy::ROOT_ID), 'createTerm');
     if (isset($criterion) && true !== $criterion) {
         $criteria->addAnd($criterion);
     } else {
         if (false === $criterion) {
             // If access denied to all taxonomies, then return nothing
             return sfView::NONE;
         }
     }
     // Sort by name
     $criteria->addAscendingOrderByColumn(QubitTaxonomyI18n::NAME);
     // Show first 10 results
     $criteria->setLimit(10);
     $this->taxonomies = QubitTaxonomy::get($criteria);
 }
 public static function parse($doc, $options = array())
 {
     $terms = array();
     libxml_use_internal_errors(true);
     // Report XML errors
     if (!$doc) {
         foreach (libxml_get_errors() as $error) {
             //TODO echo errors in template. Use custom validator?
             var_dump($error);
         }
     }
     $skos = new sfSkosPlugin();
     $skos->xpath = new DOMXPath($doc);
     // Create Xpath object, register namespaces
     $skos->xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
     $skos->xpath->registerNamespace('skos', 'http://www.w3.org/2004/02/skos/core#');
     $skos->xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/');
     // Set taxonomy
     $skos->taxonomy = QubitTaxonomy::getById(QubitTaxonomy::SUBJECT_ID);
     if (isset($options['taxonomy'])) {
         $skos->taxonomy = $options['taxonomy'];
     }
     $skos->parent = QubitTerm::getById(QubitTerm::ROOT_ID);
     if (isset($options['parent'])) {
         $skos->parent = $options['parent'];
     }
     // XPath selector for expanded RDF syntax
     $rdfsel = "rdf:Description[rdf:type[@rdf:resource='http://www.w3.org/2004/02/skos/core#Concept']]";
     // Get all concepts
     $concepts = $skos->xpath->query("skos:Concept | {$rdfsel}");
     // Create terms from concepts
     foreach ($concepts as $concept) {
         if (!$concept instanceof domElement) {
             continue;
         }
         $skos->addTerm($concept);
     }
     // Built term associations (including hierarchy)
     foreach ($concepts as $concept) {
         if (!$concept instanceof domElement) {
             continue;
         }
         // Add parent
         if (0 < $skos->xpath->query('./skos:broader', $concept)->length) {
             $skos->setParent($concept);
         }
         // Add children
         if (0 < $skos->xpath->query('./skos:narrower', $concept)->length) {
             $skos->setChildren($concept);
         }
         // Add relations
         if (0 < $skos->xpath->query('./skos:related', $concept)->length) {
             $skos->addTermRelations($concept);
         }
     }
     return $skos;
 }
 public static function getEditableTaxonomies()
 {
     $criteria = new Criteria();
     $criteria = self::addEditableTaxonomyCriteria($criteria);
     // Add criteria to sort by name with culture fallback
     $criteria->addAscendingOrderByColumn('name');
     $options = array('returnClass' => 'QubitTaxonomy');
     $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 'QubitTaxonomy', $options);
     return QubitTaxonomy::get($criteria);
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'taxonomy':
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getEditableTaxonomies() as $taxonomy) {
                 $choices[$this->context->routing->generate(null, array($taxonomy, 'module' => 'taxonomy'))] = $taxonomy;
             }
             $this->form->setDefault($name, null);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' => $choices)));
             break;
     }
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'type':
             $this->form->setValidator('type', new sfValidatorString(array('required' => true)));
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::ACTOR_RELATION_TYPE_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('type', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         default:
             return parent::addField($name);
     }
 }
 public function execute($request)
 {
     $resource = $this->getRoute()->resource;
     if (!isset($resource)) {
         $this->forward404();
     }
     if ('QubitTerm' == $resource->className) {
         $term = QubitTerm::getById($resource->id);
         $this->terms = $term->descendants->andSelf()->orderBy('lft');
         $this->taxonomy = $term->taxonomy;
         $this->topLevelTerms = array($term);
     } else {
         $this->terms = QubitTaxonomy::getTaxonomyTerms($resource->id);
         $this->taxonomy = QubitTaxonomy::getById($resource->id);
         $this->topLevelTerms = QubitTaxonomy::getTaxonomyTerms($resource->id, array('level' => 'top'));
     }
 }
 public function execute($request)
 {
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $criteria = new Criteria();
     // Show only editable taxonomies
     $criteria = QubitTaxonomy::addEditableTaxonomyCriteria($criteria);
     // Do source culture fallback
     $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 'QubitTaxonomy');
     $criteria->addAscendingOrderByColumn('name');
     // Page results
     $this->pager = new QubitPager('QubitTaxonomy');
     $this->pager->setCriteria($criteria);
     $this->pager->setMaxPerPage($request->limit);
     $this->pager->setPage($request->page);
     $this->taxonomies = $this->pager->getResults();
 }
 /**
  * Add fields to form
  *
  * @param $name string
  * @return void
  */
 protected function addField($name)
 {
     switch ($name) {
         case 'type':
             $this->form->setDefault('type', $this->context->routing->generate(null, array($this->resource->type, 'module' => 'term')));
             $this->form->setValidator('type', new sfValidatorString());
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::FUNCTION_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('type', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'maintenanceNotes':
             $this->form->setDefault('maintenanceNotes', $this->isdf->maintenanceNotes);
             $this->form->setValidator('maintenanceNotes', new sfValidatorString());
             $this->form->setWidget('maintenanceNotes', new sfWidgetFormTextarea());
             break;
         case 'authorizedFormOfName':
         case 'classification':
         case 'dates':
         case 'descriptionIdentifier':
         case 'institutionIdentifier':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormInput());
             break;
         case 'history':
         case 'description':
         case 'legislation':
         case 'rules':
         case 'revisionHistory':
         case 'sources':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormTextarea());
             break;
         default:
             return parent::addField($name);
     }
 }
 public function execute($request)
 {
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     // HACK Use id deliberately, vs. slug, because "Subjects" and "Places"
     // menus still use id
     $this->resource = QubitTaxonomy::getById($request->id);
     if (!isset($this->resource)) {
         $this->forward404();
     }
     $criteria = new Criteria();
     $criteria->add(QubitTerm::TAXONOMY_ID, $this->resource->id);
     $criteria->addJoin(QubitTerm::ID, QubitObjectTermRelation::TERM_ID);
     $criteria->addJoin(QubitObjectTermRelation::OBJECT_ID, QubitInformationObject::ID);
     $criteria = QubitAcl::addFilterDraftsCriteria($criteria);
     // Do culture fallback
     $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 'QubitTerm');
     $criteria->addGroupByColumn(QubitTerm::ID);
     $criteria->addAsColumn('hits', 'COUNT(' . QubitTerm::ID . ')');
     switch ($request->sort) {
         case 'hitsDown':
             $criteria->addDescendingOrderByColumn('hits');
             break;
         case 'hitsUp':
             $criteria->addAscendingOrderByColumn('hits');
             break;
         case 'termNameDown':
             $criteria->addDescendingOrderByColumn('name');
             break;
         case 'termNameUp':
         default:
             $criteria->addAscendingOrderByColumn('name');
             break;
     }
     $this->pager = new QubitPager('QubitTerm');
     $this->pager->setCriteria($criteria);
     $this->pager->setMaxPerPage($request->limit);
     $this->pager->setPage($request->page);
     $this->terms = $this->pager->getResults();
 }
 public function execute($request)
 {
     $this->form = new sfForm();
     $this->resource = $this->getRoute()->resource;
     // Check that object exists and that it is not the root
     if (!isset($this->resource) || !isset($this->resource->parent)) {
         $this->forward404();
     }
     // Check user authorization
     if (!QubitAcl::check($this->resource, 'update')) {
         QubitAcl::forwardUnauthorized();
     }
     // Add javascript libraries
     $this->response->addJavaScript('/vendor/yui/logger/logger', 'last');
     $this->response->addJavaScript('/vendor/yui/uploader/uploader-min', 'last');
     $this->response->addJavaScript('multiFileUpload', 'last');
     // Get max upload size limits
     $this->maxUploadSize = QubitDigitalObject::getMaxUploadSize();
     // Paths for uploader javascript
     $this->uploadSwfPath = "{$this->request->getRelativeUrlRoot()}/vendor/yui/uploader/assets/uploader.swf";
     $this->uploadResponsePath = "{$this->context->routing->generate(null, array('module' => 'digitalobject', 'action' => 'upload'))}?" . http_build_query(array(session_name() => session_id()));
     $this->uploadTmpDir = "{$this->request->getRelativeUrlRoot()}/uploads/tmp";
     // Build form
     $this->form->setValidator('files', new QubitValidatorCountable(array('required' => true)));
     $this->form->setValidator('title', new sfValidatorString());
     $this->form->setWidget('title', new sfWidgetFormInput());
     $this->form->setDefault('title', 'image %dd%');
     $this->form->setValidator('levelOfDescription', new sfValidatorString());
     $choices = array();
     $choices[null] = null;
     foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::LEVEL_OF_DESCRIPTION_ID) as $item) {
         $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
     }
     $this->form->setWidget('levelOfDescription', new sfWidgetFormSelect(array('choices' => $choices)));
     if ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameters(), $request->getFiles());
         if ($this->form->isValid()) {
             $this->processForm();
         }
     }
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'entityType':
             $this->form->setDefault('entityType', $this->context->routing->generate(null, array($this->resource->entityType, 'module' => 'term')));
             $this->form->setValidator('entityType', new sfValidatorString());
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getTaxonomyTerms(QubitTaxonomy::ACTOR_ENTITY_TYPE_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('entityType', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'authorizedFormOfName':
         case 'corporateBodyIdentifiers':
         case 'datesOfExistence':
         case 'descriptionIdentifier':
         case 'institutionResponsibleIdentifier':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormInput());
             break;
         case 'functions':
         case 'generalContext':
         case 'history':
         case 'internalStructures':
         case 'legalStatus':
         case 'mandates':
         case 'places':
         case 'revisionHistory':
         case 'rules':
         case 'sources':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormTextarea());
             break;
         default:
             return parent::addField($name);
     }
 }
 public function execute($request)
 {
     $this->form = new sfForm();
     $this->timer = new QubitTimer();
     $this->terms = array();
     $this->termsPerPage = intval(sfConfig::get('app_hits_per_page'));
     $this->taxonomy = null;
     $this->parent = QubitTerm::getById(QubitTerm::ROOT_ID);
     if (isset($this->getRoute()->resource)) {
         $resource = $this->getRoute()->resource;
         if ('QubitTaxonomy' == $resource->className) {
             $this->taxonomy = QubitTaxonomy::getById($resource->id);
         } else {
             $this->parent = QubitTerm::getById($resource->id);
             $this->taxonomy = $this->parent->taxonomy;
         }
     }
     if (!isset($this->taxonomy)) {
         $this->forward404();
     }
     // Check user authorization
     if (!QubitAcl::check($this->parent, 'create')) {
         QubitAcl::forwardUnauthorized();
     }
     $this->form->setWidget('file', new sfWidgetFormInputFile());
     $this->form->setValidator('file', new sfValidatorFile());
     if ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameters(), $request->getFiles());
         if ($this->form->isValid()) {
             if (null !== ($file = $this->form->getValue('file'))) {
                 $doc = new domDocument();
                 $doc->substituteEntities = true;
                 $doc->load($file->getTempName());
                 $this->skos = sfSkosPlugin::parse($doc, array('taxonomy' => $this->taxonomy, 'parent' => $this->parent));
             }
         }
     } else {
         $this->setTemplate('importSelect');
     }
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'date':
             $this->form->setValidator('date', new sfValidatorString());
             $this->form->setWidget('date', new sfWidgetFormInput());
             $this->form->getWidgetSchema()->date->setHelp($this->context->i18n->__('Enter free-text information, including qualifiers or typographical symbols to express uncertainty, to change the way the date displays. If this field is not used, the default will be the start and end years only.'));
             break;
         case 'endDate':
             $this->form->setValidator('endDate', new sfValidatorString());
             $this->form->setWidget('endDate', new sfWidgetFormInput());
             $this->form->getWidgetSchema()->endDate->setHelp($this->context->i18n->__('Enter the end year. Do not use any qualifiers or typographical symbols to express uncertainty. If the start and end years are the same, enter data only in the "Date" field and leave the "End date" blank.'));
             $this->form->getWidgetSchema()->endDate->setLabel($this->context->i18n->__('End'));
             break;
         case 'startDate':
             $this->form->setValidator('startDate', new sfValidatorString());
             $this->form->setWidget('startDate', new sfWidgetFormInput());
             $this->form->getWidgetSchema()->startDate->setHelp($this->context->i18n->__('Enter the start year. Do not use any qualifiers or typographical symbols to express uncertainty.'));
             $this->form->getWidgetSchema()->startDate->setLabel($this->context->i18n->__('Start'));
             break;
         case 'type':
             // Event types, Dublin Core is restricted
             $eventTypes = QubitTaxonomy::getTermsById(QubitTaxonomy::EVENT_TYPE_ID);
             if ('sfDcPlugin' == $this->request->module) {
                 $eventTypes = sfDcPlugin::eventTypes();
             }
             $choices = array();
             foreach ($eventTypes as $item) {
                 // Default event type is creation
                 if (QubitTerm::CREATION_ID == $item->id) {
                     $this->form->setDefault('type', $this->context->routing->generate(null, array($item, 'module' => 'term')));
                 }
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item->__toString();
             }
             $this->form->setValidator('type', new sfValidatorString());
             $this->form->setWidget('type', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
     }
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'type':
             $criteria = new Criteria();
             $this->resource->addObjectTermRelationsRelatedByObjectIdCriteria($criteria);
             QubitObjectTermRelation::addJoinTermCriteria($criteria);
             $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::MODS_RESOURCE_TYPE_ID);
             $value = array();
             foreach ($this->relations = QubitObjectTermRelation::get($criteria) as $item) {
                 $value[] = $this->context->routing->generate(null, array($item->term, 'module' => 'term'));
             }
             $this->form->setDefault('type', $value);
             $this->form->setValidator('type', new sfValidatorPass());
             $choices = array();
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::MODS_RESOURCE_TYPE_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('type', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
         default:
             return parent::addField($name);
     }
 }
        <td colspan="<?php 
        echo $tableCols;
        ?>
"><strong>
        <?php 
        if ('' == $taxonomyId) {
            ?>
          <em><?php 
            echo __('All %1%', array('%1%' => sfConfig::get('app_ui_label_term')));
            ?>
</em>
        <?php 
        } else {
            ?>
          <?php 
            echo __('Taxonomy: %1%', array('%1%' => render_title(QubitTaxonomy::getById($taxonomyId))));
            ?>
        <?php 
        }
        ?>
        </strong></td>
      </tr>

    <?php 
        $row = 0;
        ?>
    <?php 
        foreach ($actions as $action => $groupPermission) {
            ?>
      <tr class="<?php 
            echo 0 == @++$row % 2 ? 'even' : 'odd';
?>
      <?php 
echo $form->placeAccessPoints->render(array('class' => 'form-autocomplete'));
?>
      <?php 
if (QubitAcl::check(QubitTaxonomy::getById(QubitTaxonomy::PLACE_ID), 'createTerm')) {
    ?>
        <input class="add" type="hidden" value="<?php 
    echo url_for(array('module' => 'term', 'action' => 'add', 'taxonomy' => url_for(array(QubitTaxonomy::getById(QubitTaxonomy::PLACE_ID), 'module' => 'taxonomy'))));
    ?>
 #name"/>
      <?php 
}
?>
      <input class="list" type="hidden" value="<?php 
echo url_for(array('module' => 'term', 'action' => 'autocomplete', 'taxonomy' => url_for(array(QubitTaxonomy::getById(QubitTaxonomy::PLACE_ID), 'module' => 'taxonomy'))));
?>
"/>
    </div>

    <div class="form-item">
      <?php 
echo $form->nameAccessPoints->label(__('Name access points (subjects)'))->renderLabel();
?>
      <?php 
echo $form->nameAccessPoints->render(array('class' => 'form-autocomplete'));
?>
      <?php 
if (QubitAcl::check(QubitActor::getRoot(), 'create')) {
    ?>
        <input class="add" type="hidden" value="<?php 
Beispiel #17
0
 /**
  * Return a list of all Relation Type terms
  *
  * @param array $options  option array to pass to Qubit Query object
  * @return QubitQuery object
  */
 public static function getRelationTypes($options = array())
 {
     return QubitTaxonomy::getTermsById(QubitTaxonomy::RELATION_TYPE_ID, $options);
 }
 protected function processDmdSec($xml, $informationObject = null)
 {
     if (!isset($informationObject)) {
         $informationObject = new QubitInformationObject();
     }
     foreach ($xml->xpath('.//mdWrap/xmlData/dublincore/*') as $item) {
         $value = $item->__toString();
         if (0 == strlen(trim($value))) {
             continue;
         }
         switch (str_replace('dcterms:', '', $item->getName())) {
             case 'title':
                 $informationObject->title = $value;
                 break;
             case 'creator':
                 $informationObject->setActorByName($value, array('event_type_id' => QubitTerm::CREATION_ID));
                 break;
             case 'coverage':
                 $informationObject->setAccessPointByName($value, array('type_id' => QubitTaxonomy::PLACE_ID));
                 break;
             case 'subject':
                 $informationObject->setAccessPointByName($value, array('type_id' => QubitTaxonomy::SUBJECT_ID));
                 break;
             case 'description':
                 $informationObject->scopeAndContent = $value;
                 break;
             case 'publisher':
                 $informationObject->setActorByName($value, array('event_type_id' => QubitTerm::PUBLICATION_ID));
                 break;
             case 'contributor':
                 $informationObject->setActorByName($value, array('event_type_id' => QubitTerm::CONTRIBUTION_ID));
                 break;
             case 'date':
                 $informationObject->setDates($value);
                 break;
             case 'type':
                 foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::DC_TYPE_ID) as $item) {
                     if (strtolower($value) == strtolower($item->__toString())) {
                         $relation = new QubitObjectTermRelation();
                         $relation->term = $item;
                         $informationObject->objectTermRelationsRelatedByobjectId[] = $relation;
                         break;
                     }
                 }
                 break;
             case 'format':
                 $informationObject->extentAndMedium = $value;
                 break;
             case 'identifier':
                 $informationObject->identifier = $value;
                 break;
             case 'source':
                 $informationObject->locationOfOriginals = $value;
                 break;
             case 'language':
                 $informationObject->language = array($value);
                 break;
             case 'isPartOf':
                 // TODO: ?
                 break;
             case 'rights':
                 $informationObject->accessConditions = $value;
                 break;
         }
     }
     return $informationObject;
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'type':
             $criteria = new Criteria();
             $criteria = $this->resource->addObjectTermRelationsRelatedByObjectIdCriteria($criteria);
             $criteria->addJoin(QubitObjectTermRelation::TERM_ID, QubitTerm::ID);
             $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::REPOSITORY_TYPE_ID);
             $value = array();
             foreach ($this->relations = QubitObjectTermRelation::get($criteria) as $item) {
                 $value[] = $this->context->routing->generate(null, array($item->term, 'module' => '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($item, 'module' => 'term'))] = $item->__toString();
             }
             $this->form->setWidget('type', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
         case 'descDetail':
         case 'descStatus':
             $this->form->setDefault($name, $this->context->routing->generate(null, array($this->resource[$name], 'module' => 'term')));
             $this->form->setValidator($name, new sfValidatorString());
             switch ($name) {
                 case 'descDetail':
                     $id = QubitTaxonomy::DESCRIPTION_DETAIL_LEVEL_ID;
                     break;
                 case 'descStatus':
                     $id = QubitTaxonomy::DESCRIPTION_STATUS_ID;
                     break;
             }
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getTermsById($id) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'identifier':
         case 'authorizedFormOfName':
         case 'descIdentifier':
         case 'descInstitutionIdentifier':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormInput());
             break;
         case 'history':
         case 'geoculturalContext':
         case 'mandates':
         case 'internalStructures':
         case 'collectingPolicies':
         case 'buildings':
         case 'holdings':
         case 'findingAids':
         case 'openingTimes':
         case 'accessConditions':
         case 'disabledAccess':
         case 'researchServices':
         case 'reproductionServices':
         case 'publicFacilities':
         case 'descRules':
         case 'descRevisionHistory':
         case 'descSources':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormTextarea());
             break;
         default:
             return parent::addField($name);
     }
 }
 public static function gettaxonomysRelatedByparentIdById($id, array $options = array())
 {
     $criteria = new Criteria();
     self::addtaxonomysRelatedByparentIdCriteriaById($criteria, $id);
     return QubitTaxonomy::get($criteria, $options);
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'endDate':
             $this->form->setValidator('endDate', new sfValidatorString());
             $this->form->setWidget('endDate', new sfWidgetFormInput());
             $this->form->getWidgetSchema()->endDate->setLabel($this->context->i18n->__('End'));
             break;
         case 'startDate':
             $dt = new DateTime();
             $this->form->setDefault('startDate', $dt->format('Y-m-d'));
             $this->form->setValidator('startDate', new sfValidatorString());
             $this->form->setWidget('startDate', new sfWidgetFormInput());
             $this->form->getWidgetSchema()->startDate->setLabel($this->context->i18n->__('Start'));
             break;
         case 'restriction':
             $choices[1] = $this->context->i18n->__('Allow');
             $choices[0] = $this->context->i18n->__('Disallow');
             $this->form->setValidator('restriction', new sfValidatorBoolean());
             $this->form->setWidget('restriction', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'statuteDeterminationDate':
         case 'copyrightStatusDate':
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormInput());
             break;
         case 'act':
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::RIGHT_ACT_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item->__toString();
             }
             $this->form->setValidator('act', new sfValidatorString());
             $this->form->setWidget('act', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'basis':
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::RIGHT_BASIS_ID) as $item) {
                 if (QubitTerm::RIGHT_BASIS_POLICY_ID == $item->id) {
                     $this->form->setDefault('basis', $this->context->routing->generate(null, array($item, 'module' => 'term')));
                 }
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item->__toString();
             }
             $this->form->setValidator('basis', new sfValidatorString());
             $this->form->setWidget('basis', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'copyrightStatus':
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::COPYRIGHT_STATUS_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item->__toString();
             }
             $this->form->setValidator('copyrightStatus', new sfValidatorString());
             $this->form->setWidget('copyrightStatus', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'rightsHolder':
             $this->form->setValidator('rightsHolder', new sfValidatorString());
             $this->form->setWidget('rightsHolder', new sfWidgetFormSelect(array('choices' => array())));
             break;
         case 'copyrightJurisdiction':
             $this->form->setValidator('copyrightJurisdiction', new sfValidatorI18nChoiceCountry());
             $this->form->setWidget('copyrightJurisdiction', new sfWidgetFormI18nChoiceCountry(array('add_empty' => true, 'culture' => $this->context->user->getCulture())));
             break;
         case 'copyrightNote':
         case 'licenseNote':
         case 'statuteJurisdiction':
         case 'statuteCitation':
         case 'statuteNote':
         case 'rightsNote':
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormTextarea());
             break;
         case 'licenseIdentifier':
         case 'licenseTerms':
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormInput());
             break;
     }
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'acquisitionType':
             $this->form->setDefault('acquisitionType', $this->context->routing->generate(null, array($this->resource->acquisitionType, 'module' => 'term')));
             $this->form->setValidator('acquisitionType', new sfValidatorString());
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::ACCESSION_ACQUISITION_TYPE_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('acquisitionType', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'processingPriority':
             $this->form->setDefault('processingPriority', $this->context->routing->generate(null, array($this->resource->processingPriority, 'module' => 'term')));
             $this->form->setValidator('processingPriority', new sfValidatorString());
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::ACCESSION_PROCESSING_PRIORITY_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('processingPriority', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'processingStatus':
             $this->form->setDefault('processingStatus', $this->context->routing->generate(null, array($this->resource->processingStatus, 'module' => 'term')));
             $this->form->setValidator('processingStatus', new sfValidatorString());
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::ACCESSION_PROCESSING_STATUS_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('processingStatus', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'resourceType':
             $this->form->setDefault('resourceType', $this->context->routing->generate(null, array($this->resource->resourceType, 'module' => 'term')));
             $this->form->setValidator('resourceType', new sfValidatorString());
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::ACCESSION_RESOURCE_TYPE_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('resourceType', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'creators':
             $value = $choices = array();
             foreach ($this->creators = QubitRelation::getRelationsByObjectId($this->resource->id, array('typeId' => QubitTerm::CREATION_ID)) as $item) {
                 $choices[$value[] = $this->context->routing->generate(null, array($item->subject, 'module' => 'actor'))] = $item->subject;
             }
             $this->form->setDefault('creators', $value);
             $this->form->setValidator('creators', new sfValidatorPass());
             $this->form->setWidget('creators', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
         case 'date':
             $this->form->setDefault('date', Qubit::renderDate($this->resource['date']));
             if (!isset($this->resource->id)) {
                 $dt = new DateTime();
                 $this->form->setDefault('date', $dt->format('Y-m-d'));
             }
             $this->form->setValidator('date', new sfValidatorString());
             $this->form->setWidget('date', new sfWidgetFormInput());
             break;
         case 'identifier':
             $this->form->setDefault('identifier', $this->resource['identifier']);
             if (!isset($this->resource->id)) {
                 $dt = new DateTime();
                 $this->form->setDefault('identifier', QubitAccession::generateAccessionIdentifier());
             }
             $this->form->setValidator('identifier', new sfValidatorString());
             $this->form->setWidget('identifier', new sfWidgetFormInput(array(), array('disabled' => 'disabled')));
             break;
         case 'receivedExtentUnits':
         case 'title':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormInput());
             break;
         case 'appraisal':
         case 'archivalHistory':
         case 'locationInformation':
         case 'physicalCharacteristics':
         case 'processingNotes':
         case 'scopeAndContent':
         case 'sourceOfAcquisition':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormTextarea());
             break;
         default:
             return parent::addField($name);
     }
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'levelOfDescription':
             $this->form->setDefault('levelOfDescription', $this->context->routing->generate(null, array($this->resource->levelOfDescription, 'module' => 'term')));
             $this->form->setValidator('levelOfDescription', new sfValidatorString());
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getTaxonomyTerms(QubitTaxonomy::LEVEL_OF_DESCRIPTION_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('levelOfDescription', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'publicationStatus':
             $publicationStatus = $this->resource->getStatus(array('typeId' => QubitTerm::STATUS_TYPE_PUBLICATION_ID));
             if (isset($publicationStatus)) {
                 $this->form->setDefault('publicationStatus', $publicationStatus->statusId);
             } else {
                 $this->form->setDefault('publicationStatus', sfConfig::get('app_defaultPubStatus'));
             }
             $this->form->setValidator('publicationStatus', new sfValidatorString());
             if (isset($this->resource) && QubitAcl::check($this->resource, 'publish') || !isset($this->resurce) && QubitAcl::check($this->parent, 'publish')) {
                 $choices = array();
                 foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::PUBLICATION_STATUS_ID) as $item) {
                     $choices[$item->id] = $item;
                 }
                 $this->form->setWidget('publicationStatus', new sfWidgetFormSelect(array('choices' => $choices)));
             } else {
                 $choices = array();
                 if (isset($publicationStatus)) {
                     $choices = array($publicationStatus->id => $publicationStatus->status->__toString());
                 } else {
                     $status = QubitTerm::getById(sfConfig::get('app_defaultPubStatus'));
                     $choices = array($status->id => $status->__toString());
                 }
                 // Disable widget if user doesn't have "publish" permission
                 $this->form->setWidget('publicationStatus', new sfWidgetFormSelect(array('choices' => $choices), array('disabled' => true)));
             }
             break;
         case 'repository':
             $this->form->setDefault('repository', $this->context->routing->generate(null, array($this->resource->repository, 'module' => 'repository')));
             $this->form->setValidator('repository', new sfValidatorString());
             $choices = array();
             if (isset($this->resource->repository)) {
                 $choices[$this->context->routing->generate(null, array($this->resource->repository, 'module' => 'repository'))] = $this->resource->repository;
             }
             $this->form->setWidget('repository', new sfWidgetFormSelect(array('choices' => $choices)));
             if (isset($this->getRoute()->resource)) {
                 $this->repoAcParams = array('module' => 'repository', 'action' => 'autocomplete', 'aclAction' => 'update');
             } else {
                 $this->repoAcParams = array('module' => 'repository', 'action' => 'autocomplete', 'aclAction' => 'create');
             }
             break;
         case 'accessConditions':
         case 'accruals':
         case 'acquisition':
         case 'archivalHistory':
         case 'arrangement':
         case 'extentAndMedium':
         case 'findingAids':
         case 'locationOfCopies':
         case 'locationOfOriginals':
         case 'physicalCharacteristics':
         case 'relatedUnitsOfDescription':
         case 'reproductionConditions':
         case 'revisionHistory':
         case 'rules':
         case 'scopeAndContent':
         case 'sources':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormTextarea());
             break;
         case 'descriptionIdentifier':
         case 'identifier':
         case 'institutionResponsibleIdentifier':
         case 'title':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormInput());
             break;
         case 'subjectAccessPoints':
         case 'placeAccessPoints':
             $criteria = new Criteria();
             $criteria->add(QubitObjectTermRelation::OBJECT_ID, $this->resource->id);
             $criteria->addJoin(QubitObjectTermRelation::TERM_ID, QubitTerm::ID);
             switch ($name) {
                 case 'subjectAccessPoints':
                     $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::SUBJECT_ID);
                     break;
                 case 'placeAccessPoints':
                     $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::PLACE_ID);
                     break;
             }
             $value = $choices = array();
             foreach ($this[$name] = QubitObjectTermRelation::get($criteria) as $item) {
                 $choices[$value[] = $this->context->routing->generate(null, array($item->term, 'module' => 'term'))] = $item->term;
             }
             $this->form->setDefault($name, $value);
             $this->form->setValidator($name, new sfValidatorPass());
             $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
         case 'nameAccessPoints':
             $criteria = new Criteria();
             $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
             $criteria->add(QubitRelation::TYPE_ID, QubitTerm::NAME_ACCESS_POINT_ID);
             $value = $choices = array();
             foreach ($this->nameAccessPoints = QubitRelation::get($criteria) as $item) {
                 $choices[$value[] = $this->context->routing->generate(null, array($item->object, 'module' => 'actor'))] = $item->object;
             }
             $this->form->setDefault($name, $value);
             $this->form->setValidator($name, new sfValidatorPass());
             $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
         default:
             return parent::addField($name);
     }
 }
    <?php 
if (0 < count($taxonomyPermissions)) {
    ?>

      <?php 
    foreach ($taxonomyPermissions as $key => $item) {
        ?>

        <div class="form-item">

          <table id="acl_<?php 
        echo $key;
        ?>
">
            <caption><?php 
        echo render_title(QubitTaxonomy::getById($key));
        ?>
</caption>
            <thead>
              <tr>
                <th scope="col"><?php 
        echo __('Action');
        ?>
</th>
                <th scope="col"><?php 
        echo __('Permission');
        ?>
</th>
              </tr>
            </thead><tbody>
              <?php 
 protected function addField($name)
 {
     switch ($name) {
         case 'alternateTitle':
         case 'edition':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormInput());
             break;
         case 'editionStatementOfResponsibility':
         case 'issuingJurisdictionAndDenomination':
         case 'noteOnPublishersSeries':
         case 'numberingWithinPublishersSeries':
         case 'otherTitleInformation':
         case 'otherTitleInformationOfPublishersSeries':
         case 'parallelTitleOfPublishersSeries':
         case 'standardNumber':
         case 'statementOfCoordinates':
         case 'statementOfProjection':
         case 'statementOfResponsibilityRelatingToPublishersSeries':
         case 'statementOfScaleArchitectural':
         case 'statementOfScaleCartographic':
         case 'titleStatementOfResponsibility':
         case 'titleProperOfPublishersSeries':
             $this->form->setDefault($name, $this->rad[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormInput());
             break;
         case 'type':
             $criteria = new Criteria();
             $this->resource->addObjectTermRelationsRelatedByObjectIdCriteria($criteria);
             QubitObjectTermRelation::addJoinTermCriteria($criteria);
             $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::MATERIAL_TYPE_ID);
             $value = array();
             foreach ($this->relations = QubitObjectTermRelation::get($criteria) as $item) {
                 $value[] = $this->context->routing->generate(null, array($item->term, 'module' => 'term'));
             }
             $this->form->setDefault('type', $value);
             $this->form->setValidator('type', new sfValidatorPass());
             $choices = array();
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::MATERIAL_TYPE_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('type', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
         default:
             return parent::addField($name);
     }
 }
 public function import($xmlFile, $options = array())
 {
     // load the XML document into a DOMXML object
     $importDOM = $this->loadXML($xmlFile, $options);
     // if we were unable to parse the XML file at all
     if (empty($importDOM->documentElement)) {
         $errorMsg = sfContext::getInstance()->i18n->__('Unable to parse XML file: malformed or unresolvable entities');
         throw new Exception($errorMsg);
     }
     // if libxml threw errors, populate them to show in the template
     if ($importDOM->libxmlerrors) {
         // warning condition, XML file has errors (perhaps not well-formed or invalid?)
         foreach ($importDOM->libxmlerrors as $libxmlerror) {
             $xmlerrors[] = sfContext::getInstance()->i18n->__('libxml error %code% on line %line% in input file: %message%', array('%code%' => $libxmlerror->code, '%message%' => $libxmlerror->message, '%line%' => $libxmlerror->line));
         }
         $this->errors = array_merge((array) $this->errors, $xmlerrors);
     }
     if ('eac-cpf' == $importDOM->documentElement->tagName) {
         $this->rootObject = new QubitActor();
         $this->rootObject->parentId = QubitActor::ROOT_ID;
         $eac = new sfEacPlugin($this->rootObject);
         $eac->parse($importDOM);
         $this->rootObject->save();
         return $this;
     }
     // FIXME hardcoded until we decide how these will be developed
     $validSchemas = array('+//ISBN 1-931666-00-8//DTD ead.dtd Encoded Archival Description (EAD) Version 2002//EN' => 'ead', '-//Society of American Archivists//DTD ead.dtd (Encoded Archival Description (EAD) Version 1.0)//EN' => 'ead1', 'http://www.loc.gov/METS/' => 'mets', 'http://www.loc.gov/mods/' => 'mods', 'http://www.loc.gov/MARC21/slim' => 'marc', 'record' => 'oai_dc_record', 'dc' => 'dc', 'oai_dc:dc' => 'dc', 'dublinCore' => 'dc', 'metadata' => 'dc', 'ead' => 'ead', 'add' => 'alouette', 'http://www.w3.org/2004/02/skos/core#' => 'skos');
     // determine what kind of schema we're trying to import
     $schemaDescriptors = array($importDOM->documentElement->tagName);
     if (!empty($importDOM->namespaces)) {
         krsort($importDOM->namespaces);
         $schemaDescriptors = array_merge($schemaDescriptors, $importDOM->namespaces);
     }
     if (!empty($importDOM->doctype)) {
         $schemaDescriptors = array_merge($schemaDescriptors, array($importDOM->doctype->name, $importDOM->doctype->systemId, $importDOM->doctype->publicId));
     }
     foreach ($schemaDescriptors as $descriptor) {
         if (array_key_exists($descriptor, $validSchemas)) {
             $importSchema = $validSchemas[$descriptor];
         }
     }
     switch ($importSchema) {
         case 'ead':
             // just validate EAD import for now until we can get StrictXMLParsing working for all schemas in the self::LoadXML function. Having problems right now loading schemas.
             $importDOM->validate();
             // if libxml threw errors, populate them to show in the template
             foreach (libxml_get_errors() as $libxmlerror) {
                 $this->errors[] = sfContext::getInstance()->i18n->__('libxml error %code% on line %line% in input file: %message%', array('%code%' => $libxmlerror->code, '%message%' => $libxmlerror->message, '%line%' => $libxmlerror->line));
             }
             break;
         case 'skos':
             $criteria = new Criteria();
             $criteria->add(QubitSetting::NAME, 'plugins');
             $setting = QubitSetting::getOne($criteria);
             if (null === $setting || !in_array('sfSkosPlugin', unserialize($setting->getValue(array('sourceCulture' => true))))) {
                 throw new sfException(sfContext::getInstance()->i18n->__('The SKOS plugin is not enabled'));
             }
             $importTerms = sfSkosPlugin::parse($importDOM);
             $this->rootObject = QubitTaxonomy::getById(QubitTaxonomy::SUBJECT_ID);
             $this->count = count($importTerms);
             return $this;
             break;
     }
     $importMap = sfConfig::get('sf_app_module_dir') . DIRECTORY_SEPARATOR . 'object' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'import' . DIRECTORY_SEPARATOR . $importSchema . '.yml';
     if (!file_exists($importMap)) {
         // error condition, unknown schema or no import filter
         $errorMsg = sfContext::getInstance()->i18n->__('Unknown schema or import format: "%format%"', array('%format%' => $importSchema));
         throw new Exception($errorMsg);
     }
     $this->schemaMap = sfYaml::load($importMap);
     // if XSLs are specified in the mapping, process them
     if (!empty($this->schemaMap['processXSLT'])) {
         // pre-filter through XSLs in order
         foreach ((array) $this->schemaMap['processXSLT'] as $importXSL) {
             $importXSL = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'xslt' . DIRECTORY_SEPARATOR . $importXSL;
             if (file_exists($importXSL)) {
                 // instantiate an XSLT parser
                 $xslDOM = new DOMDocument();
                 $xslDOM->load($importXSL);
                 // Configure the transformer
                 $xsltProc = new XSLTProcessor();
                 $xsltProc->registerPHPFunctions();
                 $xsltProc->importStyleSheet($xslDOM);
                 $importDOM->loadXML($xsltProc->transformToXML($importDOM));
                 unset($xslDOM);
                 unset($xsltProc);
             } else {
                 $this->errors[] = sfContext::getInstance()->i18n->__('Unable to load import XSL filter: "%importXSL%"', array('%importXSL%' => $importXSL));
             }
         }
         // re-initialize xpath on the new XML
         $importDOM->xpath = new DOMXPath($importDOM);
     }
     // switch source culture if langusage is set in an EAD document
     if ($importSchema == 'ead') {
         if (is_object($langusage = $importDOM->xpath->query('//eadheader/profiledesc/langusage/language/@langcode'))) {
             $sf_user = sfContext::getInstance()->user;
             $currentCulture = $sf_user->getCulture();
             $langCodeConvertor = new fbISO639_Map();
             foreach ($langusage as $language) {
                 $isocode = trim(preg_replace('/[\\n\\r\\s]+/', ' ', $language->nodeValue));
                 // convert to Symfony culture code
                 if (!($twoCharCode = strtolower($langCodeConvertor->getID2($isocode)))) {
                     $twoCharCode = $isocode;
                 }
                 // Check to make sure that the selected language is supported with a Symfony i18n data file.
                 // If not it will cause a fatal error in the Language List component on every response.
                 ProjectConfiguration::getActive()->loadHelpers('I18N');
                 try {
                     format_language($twoCharCode, $twoCharCode);
                 } catch (Exception $e) {
                     $this->errors[] = sfContext::getInstance()->i18n->__('EAD "langmaterial" is set to') . ': "' . $isocode . '". ' . sfContext::getInstance()->i18n->__('This language is currently not supported.');
                     continue;
                 }
                 if ($currentCulture !== $twoCharCode) {
                     $this->errors[] = sfContext::getInstance()->i18n->__('EAD "langmaterial" is set to') . ': "' . $isocode . '" (' . format_language($twoCharCode, 'en') . '). ' . sfContext::getInstance()->i18n->__('Your XML document has been saved in this language and your user interface has just been switched to this language.');
                 }
                 $sf_user->setCulture($twoCharCode);
                 // can only set to one language, so have to break once the first valid language is encountered
                 break;
             }
         }
     }
     unset($this->schemaMap['processXSLT']);
     // go through schema map and populate objects/properties
     foreach ($this->schemaMap as $name => $mapping) {
         // if object is not defined or a valid class, we can't process this mapping
         if (empty($mapping['Object']) || !class_exists('Qubit' . $mapping['Object'])) {
             $this->errors[] = sfContext::getInstance()->i18n->__('Non-existent class defined in import mapping: "%class%"', array('%class%' => 'Qubit' . $mapping['Object']));
             continue;
         }
         // get a list of XML nodes to process
         $nodeList = $importDOM->xpath->query($mapping['XPath']);
         foreach ($nodeList as $domNode) {
             // create a new object
             $class = 'Qubit' . $mapping['Object'];
             $currentObject = new $class();
             // set the rootObject to use for initial display in successful import
             if (!$this->rootObject) {
                 $this->rootObject = $currentObject;
             }
             // if a parent path is specified, try to parent the node
             if (empty($mapping['Parent'])) {
                 $parentNodes = new DOMNodeList();
             } else {
                 $parentNodes = $importDOM->xpath->query('(' . $mapping['Parent'] . ')', $domNode);
             }
             if ($parentNodes->length > 0) {
                 // parent ID comes from last node in the list because XPath forces forward document order
                 $parentId = $parentNodes->item($parentNodes->length - 1)->getAttribute('xml:id');
                 unset($parentNodes);
                 if (!empty($parentId) && is_callable(array($currentObject, 'setParentId'))) {
                     $currentObject->parentId = $parentId;
                 }
             } else {
                 // orphaned object, set root if possible
                 if (is_callable(array($currentObject, 'setRoot'))) {
                     $currentObject->setRoot();
                 }
             }
             // go through methods and populate properties
             foreach ($mapping['Methods'] as $name => $methodMap) {
                 // if method is not defined, we can't process this mapping
                 if (empty($methodMap['Method']) || !is_callable(array($currentObject, $methodMap['Method']))) {
                     $this->errors[] = sfContext::getInstance()->i18n->__('Non-existent method defined in import mapping: "%method%"', array('%method%' => $methodMap['Method']));
                     continue;
                 }
                 // get a list of XML nodes to process
                 $nodeList2 = $importDOM->xpath->query($methodMap['XPath'], $domNode);
                 if (is_object($nodeList2)) {
                     switch ($name) {
                         // hack: some multi-value elements (e.g. 'languages') need to get passed as one array instead of individual nodes values
                         case 'languages':
                             $langCodeConvertor = new fbISO639_Map();
                             $value = array();
                             foreach ($nodeList2 as $nodeee) {
                                 if ($twoCharCode = $langCodeConvertor->getID2($nodeee->nodeValue)) {
                                     $value[] = strtolower($twoCharCode);
                                 } else {
                                     $value[] = $nodeee->nodeValue;
                                 }
                             }
                             $currentObject->language = $value;
                             break;
                         case 'flocat':
                             $resources = array();
                             foreach ($nodeList2 as $nodeee) {
                                 $resources[] = $nodeee->nodeValue;
                             }
                             if (0 < count($resources)) {
                                 $currentObject->importDigitalObjectFromUri($resources);
                             }
                             break;
                         default:
                             foreach ($nodeList2 as $domNode2) {
                                 // normalize the node text (trim whitespace manually); NB: this will strip any child elements, eg. HTML tags
                                 $nodeValue = trim(preg_replace('/[\\n\\r\\s]+/', ' ', $domNode2->nodeValue));
                                 // if you want the full XML from the node, use this
                                 $nodeXML = $domNode2->ownerDocument->saveXML($domNode2);
                                 // set the parameters for the method call
                                 if (empty($methodMap['Parameters'])) {
                                     $parameters = array($nodeValue);
                                 } else {
                                     $parameters = array();
                                     foreach ((array) $methodMap['Parameters'] as $parameter) {
                                         // if the parameter begins with %, evaluate it as an XPath expression relative to the current node
                                         if ('%' == substr($parameter, 0, 1)) {
                                             // evaluate the XPath expression
                                             $xPath = substr($parameter, 1);
                                             $result = $importDOM->xpath->query($xPath, $domNode2);
                                             if ($result->length > 1) {
                                                 // convert nodelist into an array
                                                 foreach ($result as $element) {
                                                     $resultArray[] = $element->nodeValue;
                                                 }
                                                 $parameters[] = $resultArray;
                                             } else {
                                                 // pass the node value unaltered; this provides an alternative to $nodeValue above
                                                 $parameters[] = $result->item(0)->nodeValue;
                                             }
                                         } else {
                                             // Confirm DOMXML node exists to avoid warnings at run-time
                                             if (false !== preg_match_all('/\\$importDOM->xpath->query\\(\'@\\w+\', \\$domNode2\\)->item\\(0\\)->nodeValue/', $parameter, $matches)) {
                                                 foreach ($matches[0] as $match) {
                                                     $str = str_replace('->nodeValue', '', $match);
                                                     if (null !== ($node = eval('return ' . $str . ';'))) {
                                                         // Substitute node value for search string
                                                         $parameter = str_replace($match, '\'' . $node->nodeValue . '\'', $parameter);
                                                     } else {
                                                         // Replace empty nodes with null in parameter string
                                                         $parameter = str_replace($match, 'null', $parameter);
                                                     }
                                                 }
                                             }
                                             eval('$parameters[] = ' . $parameter . ';');
                                         }
                                     }
                                 }
                                 // invoke the object and method defined in the schema map
                                 call_user_func_array(array(&$currentObject, $methodMap['Method']), $parameters);
                             }
                     }
                     unset($nodeList2);
                 }
             }
             // make sure we have a publication status set before indexing
             if ($currentObject instanceof QubitInformationObject && count($currentObject->statuss) == 0) {
                 $currentObject->setPublicationStatus(sfConfig::get('app_defaultPubStatus', QubitTerm::PUBLICATION_STATUS_DRAFT_ID));
             }
             // save the object after it's fully-populated
             $currentObject->save();
             // write the ID onto the current XML node for tracking
             $domNode->setAttribute('xml:id', $currentObject->id);
         }
     }
     return $this;
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'descriptionDetail':
             $this->form->setDefault('descriptionDetail', $this->context->routing->generate(null, array($this->resource->descriptionDetail, 'module' => 'term')));
             $this->form->setValidator('descriptionDetail', new sfValidatorString());
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::DESCRIPTION_DETAIL_LEVEL_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('descriptionDetail', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'descriptionStatus':
             $this->form->setDefault('descriptionStatus', $this->context->routing->generate(null, array($this->resource->descriptionStatus, 'module' => 'term')));
             $this->form->setValidator('descriptionStatus', new sfValidatorString());
             $choices = array();
             $choices[null] = null;
             foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::DESCRIPTION_STATUS_ID) as $item) {
                 $choices[$this->context->routing->generate(null, array($item, 'module' => 'term'))] = $item;
             }
             $this->form->setWidget('descriptionStatus', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'language':
         case 'languageOfDescription':
             $this->form->setDefault($name, $this->resource[$name]);
             $this->form->setValidator($name, new sfValidatorI18nChoiceLanguage(array('multiple' => true)));
             $this->form->setWidget($name, new sfWidgetFormI18nChoiceLanguage(array('culture' => $this->context->user->getCulture(), 'multiple' => true)));
             break;
         case 'otherName':
         case 'parallelName':
         case 'standardizedName':
             $criteria = new Criteria();
             $criteria = $this->resource->addOtherNamesCriteria($criteria);
             switch ($name) {
                 case 'otherName':
                     $criteria->add(QubitOtherName::TYPE_ID, QubitTerm::OTHER_FORM_OF_NAME_ID);
                     break;
                 case 'parallelName':
                     $criteria->add(QubitOtherName::TYPE_ID, QubitTerm::PARALLEL_FORM_OF_NAME_ID);
                     break;
                 case 'standardizedName':
                     $criteria->add(QubitOtherName::TYPE_ID, QubitTerm::STANDARDIZED_FORM_OF_NAME_ID);
                     break;
             }
             $value = $defaults = array();
             foreach ($this[$name] = QubitOtherName::get($criteria) as $item) {
                 $defaults[$value[] = $item->id] = $item;
             }
             $this->form->setDefault($name, $value);
             $this->form->setValidator($name, new sfValidatorPass());
             $this->form->setWidget($name, new QubitWidgetFormInputMany(array('defaults' => $defaults)));
             break;
         case 'script':
         case 'scriptOfDescription':
             $this->form->setDefault($name, $this->resource[$name]);
             $c = sfCultureInfo::getInstance($this->context->user->getCulture());
             $this->form->setValidator($name, new sfValidatorChoice(array('choices' => array_keys($c->getScripts()), 'multiple' => true)));
             $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' => $c->getScripts(), 'multiple' => true)));
             break;
     }
 }