public static function generateAccessionIdentifier($incrementCounter = false)
 {
     return preg_replace_callback('/([#%])([A-z]+)/', function ($match) use($incrementCounter) {
         if ('%' == $match[1]) {
             return strftime('%' . $match[2]);
         } else {
             if ('#' == $match[1]) {
                 if (0 < preg_match('/^i+$/', $match[2], $matches)) {
                     $pad = strlen($matches[0]);
                     $number = QubitAccession::getAccessionNumber($incrementCounter);
                     return str_pad($number, $pad, 0, STR_PAD_LEFT);
                     // return sprintf('%0' . $pad . 'd', $number);
                 } else {
                     return $match[2];
                 }
             }
         }
     }, sfConfig::get('app_accession_mask'));
 }
 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);
     }
 }
Esempio n. 3
0
 public static function getaccessionsRelatedByresourceTypeIdById($id, array $options = array())
 {
     $criteria = new Criteria();
     self::addaccessionsRelatedByresourceTypeIdCriteriaById($criteria, $id);
     return QubitAccession::get($criteria, $options);
 }