public function getOtherNames($options = array())
 {
     $criteria = new Criteria();
     $criteria->add(QubitOtherName::OBJECT_ID, $this->id);
     if (isset($options['typeId'])) {
         $criteria->add(QubitOtherName::TYPE_ID, $options['typeId']);
     }
     return QubitOtherName::get($criteria);
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'ehriCopyrightIssue':
             $this->form->setDefault('ehriCopyrightIssue', $this->isad->ehriCopyrightIssue);
             $this->form->setValidator('ehriCopyrightIssue', new sfValidatorBoolean());
             $this->form->setWidget('ehriCopyrightIssue', new sfWidgetFormInputCheckbox());
             break;
         case 'ehriScope':
             $this->form->setDefault('ehriScope', $this->isad->ehriScope);
             $this->form->setValidator('ehriScope', new sfValidatorString());
             $this->form->setWidget('ehriScope', new sfWidgetFormSelect(array("choices" => array("High" => "High", "Medium" => "Medium", "Low" => "Low"))));
             break;
         case 'ehriPriority':
             $this->form->setDefault('ehriPriority', $this->isad->ehriPriority);
             $this->form->setValidator('ehriPriority', new sfValidatorString());
             $this->form->setWidget('ehriPriority', new sfWidgetFormSelect(array("choices" => $this->isad->priorities)));
             break;
         case 'otherName':
             $criteria = new Criteria();
             $criteria = $this->resource->addOtherNamesCriteria($criteria);
             $criteria->add(QubitOtherName::TYPE_ID, QubitTerm::OTHER_FORM_OF_NAME_ID);
             $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;
         default:
             return parent::addField($name);
     }
 }
Example #3
0
 public static function getotherNamesById($id, array $options = array())
 {
     $criteria = new Criteria();
     self::addotherNamesCriteriaById($criteria, $id);
     return QubitOtherName::get($criteria, $options);
 }
 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;
     }
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'code':
             $this->form->setDefault('code', $this->resource->code);
             $this->form->setValidator('code', new sfValidatorString());
             $this->form->setWidget('code', new sfWidgetFormInput());
             break;
         case 'displayNote':
         case 'scopeNote':
         case 'sourceNote':
             $criteria = new Criteria();
             $criteria->add(QubitNote::OBJECT_ID, $this->resource->id);
             switch ($name) {
                 case 'scopeNote':
                     $criteria->add(QubitNote::TYPE_ID, QubitTerm::SCOPE_NOTE_ID);
                     break;
                 case 'sourceNote':
                     $criteria->add(QubitNote::TYPE_ID, QubitTerm::SOURCE_NOTE_ID);
                     break;
                 case 'displayNote':
                     $criteria->add(QubitNote::TYPE_ID, QubitTerm::DISPLAY_NOTE_ID);
                     break;
             }
             $value = $defaults = array();
             foreach ($this[$name] = QubitNote::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, 'fieldname' => 'content')));
             break;
         case 'name':
             $this->form->setDefault('name', $this->resource->name);
             $this->form->setValidator('name', new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('This is a mandatory element.'))));
             $this->form->setWidget('name', new sfWidgetFormInput());
             break;
         case 'narrowTerms':
             $this->form->setValidator('narrowTerms', new sfValidatorPass());
             $this->form->setWidget('narrowTerms', new QubitWidgetFormInputMany(array('defaults' => array())));
             break;
         case 'parent':
             $this->form->setDefault('parent', $this->context->routing->generate(null, array($this->resource->parent, 'module' => 'term')));
             $this->form->setValidator('parent', new sfValidatorString());
             $choices = array();
             if (isset($this->resource->parent)) {
                 $choices[$this->context->routing->generate(null, array($this->resource->parent, 'module' => 'term'))] = $this->resource->parent;
             }
             if (isset($this->request->parent)) {
                 $this->form->setDefault('parent', $this->request->parent);
                 $params = $this->context->routing->parse(Qubit::pathInfo($this->request->parent));
                 $choices[$this->request->parent] = $params['_sf_route']->resource;
             }
             $this->form->setWidget('parent', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'relatedTerms':
             $value = $choices = array();
             foreach ($this->relations = QubitRelation::getBySubjectOrObjectId($this->resource->id, array('typeId' => QubitTerm::TERM_RELATION_ASSOCIATIVE_ID)) as $item) {
                 $choices[$value[] = $this->context->routing->generate(null, array($item->object, 'module' => 'term'))] = $item->object;
             }
             $this->form->setDefault('relatedTerms', $value);
             $this->form->setValidator('relatedTerms', new sfValidatorPass());
             $this->form->setWidget('relatedTerms', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
         case 'taxonomy':
             $this->form->setDefault('taxonomy', $this->context->routing->generate(null, array($this->resource->taxonomy, 'module' => 'taxonomy')));
             $this->form->setValidator('taxonomy', new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('This is a mandatory element.'))));
             $choices = array();
             if (isset($this->resource->taxonomy)) {
                 $choices[$this->context->routing->generate(null, array($this->resource->taxonomy, 'module' => 'taxonomy'))] = $this->resource->taxonomy;
             }
             if (isset($this->request->taxonomy)) {
                 $this->form->setDefault('taxonomy', $this->request->taxonomy);
                 $params = $this->context->routing->parse(Qubit::pathInfo($this->request->taxonomy));
                 $choices[$this->request->taxonomy] = $params['_sf_route']->resource;
             }
             $this->form->setWidget('taxonomy', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'useFor':
             $criteria = new Criteria();
             $criteria->add(QubitOtherName::OBJECT_ID, $this->resource->id);
             $criteria->add(QubitOtherName::TYPE_ID, QubitTerm::ALTERNATIVE_LABEL_ID);
             $value = $defaults = array();
             foreach ($this->useFor = QubitOtherName::get($criteria) as $item) {
                 $defaults[$value[] = $item->id] = $item;
             }
             $this->form->setDefault('useFor', $value);
             $this->form->setValidator('useFor', new sfValidatorPass());
             $this->form->setWidget('useFor', new QubitWidgetFormInputMany(array('defaults' => $defaults)));
             break;
         default:
             return parent::addField($name);
     }
 }