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'));
     }
 }
 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);
     }
 }
Esempio n. 3
0
 public static function getLevelsOfDescription($options = array())
 {
     return QubitTaxonomy::getTaxonomyTerms(QubitTaxonomy::LEVEL_OF_DESCRIPTION_ID, $options);
 }
 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);
     }
 }