コード例 #1
0
 /**
  * Determine if a property matching passed values already exists.
  *
  * @param integer $objectId foreign key to QubitObject::ID
  * @param string $name  name of property
  * @param string $value value of property
  * @param string $options array of optional parameters
  * @return boolean true if QubitProperty exists
  */
 public static function isExistent($objectId, $name, $value, $options = array())
 {
     $propertyExists = false;
     $criteria = new Criteria();
     $criteria->addJoin(QubitProperty::ID, QubitPropertyI18n::ID);
     $criteria->add(QubitProperty::OBJECT_ID, $objectId);
     $criteria->add(QubitProperty::NAME, $name);
     $criteria->add(QubitPropertyI18n::VALUE, $value);
     if (isset($options['culture'])) {
         $criteria->add(QubitPropertyI18n::CULTURE, $options['culture']);
     } else {
         if (isset($options['sourceCulture'])) {
             $criteria->add(QubitPropertyI18n::CULTURE, QubitProperty::SOURCE_CULTURE . ' = ' . QubitPropertyI18n::CULTURE, Criteria::CUSTOM);
         } else {
             $criteria->add(QubitPropertyI18n::CULTURE, sfPropel::getDefaultCulture());
         }
     }
     if (isset($options['scope'])) {
         $criteria->add(QubitProperty::SCOPE, $options['scope']);
     }
     // See if search returns a hit.
     if (($property = QubitProperty::getOne($criteria)) !== null) {
         $propertyExists = true;
     }
     return $propertyExists;
 }
コード例 #2
0
 /**
  * Setter for "displayAsCompound" property
  *
  * @param string $value new value for property
  * @return QubitInformationObject this object
  */
 public function setDisplayAsCompoundObject($value)
 {
     $criteria = new Criteria();
     $criteria->add(QubitProperty::OBJECT_ID, $this->id);
     $criteria->add(QubitProperty::NAME, 'displayAsCompound');
     $displayAsCompoundProp = QubitProperty::getOne($criteria);
     if (is_null($displayAsCompoundProp)) {
         $displayAsCompoundProp = new QubitProperty();
         $displayAsCompoundProp->setObjectId($this->id);
         $displayAsCompoundProp->setName('displayAsCompound');
     }
     $displayAsCompoundProp->setValue($value, array('sourceCulture' => true));
     $displayAsCompoundProp->save();
     return $this;
 }
コード例 #3
0
 protected function addFormFields()
 {
     // Media type field
     $choices = array();
     $criteria = new Criteria();
     $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::MEDIA_TYPE_ID);
     foreach (QubitTerm::get($criteria) as $item) {
         $choices[$item->id] = $item->getName(array('cultureFallback' => true));
     }
     asort($choices);
     // Sort media types by name
     $this->form->setValidator('mediaType', new sfValidatorChoice(array('choices' => array_keys($choices))));
     $this->form->setWidget('mediaType', new sfWidgetFormSelect(array('choices' => $choices)));
     $this->form->setDefault('mediaType', $this->resource->mediaTypeId);
     // Only display "compound digital object" toggle if we have a child with a
     // digital object
     $this->showCompoundObjectToggle = false;
     foreach ($this->informationObject->getChildren() as $item) {
         if (null !== $item->getDigitalObject()) {
             $this->showCompoundObjectToggle = true;
             break;
         }
     }
     if ($this->showCompoundObjectToggle) {
         $this->form->setValidator('displayAsCompound', new sfValidatorBoolean());
         $this->form->setWidget('displayAsCompound', new sfWidgetFormSelectRadio(array('choices' => array('1' => $this->context->i18n->__('Yes'), '0' => $this->context->i18n->__('No')))));
         // Set "displayAsCompound" value from QubitProperty
         $criteria = new Criteria();
         $criteria->add(QubitProperty::OBJECT_ID, $this->resource->id);
         $criteria->add(QubitProperty::NAME, 'displayAsCompound');
         if (null != ($compoundProperty = QubitProperty::getOne($criteria))) {
             $this->form->setDefault('displayAsCompound', $compoundProperty->getValue(array('sourceCulture' => true)));
         }
     }
     // Add rights component
     $this->rightEditComponent = new RightEditComponent($this->context, 'right', 'edit');
     $this->rightEditComponent->resource = $this->resource;
     $this->rightEditComponent->execute($this->request);
     $maxUploadSize = QubitDigitalObject::getMaxUploadSize();
     ProjectConfiguration::getActive()->loadHelpers('Qubit');
     // If reference representation doesn't exist, include upload widget
     foreach ($this->representations as $usageId => $representation) {
         if (null === $representation) {
             $repName = "repFile_{$usageId}";
             $derName = "generateDerivative_{$usageId}";
             $this->form->setValidator($repName, new sfValidatorFile());
             $this->form->setWidget($repName, new sfWidgetFormInputFile());
             if (-1 < $maxUploadSize) {
                 $this->form->getWidgetSchema()->{$repName}->setHelp($this->context->i18n->__('Max. size ~%1%', array('%1%' => hr_filesize($maxUploadSize))));
             } else {
                 $this->form->getWidgetSchema()->{$repName}->setHelp('');
             }
             // Add "auto-generate" checkbox
             $this->form->setValidator($derName, new sfValidatorBoolean());
             $this->form->setWidget($derName, new sfWidgetFormInputCheckbox(array(), array('value' => 1)));
         } else {
             $this["rightEditComponent_{$usageId}"] = new RightEditComponent($this->context, 'right', 'edit');
             $this["rightEditComponent_{$usageId}"]->resource = $representation;
             $this["rightEditComponent_{$usageId}"]->nameFormat = 'editRight' . $usageId . '[%s]';
             $this["rightEditComponent_{$usageId}"]->execute($this->request);
         }
     }
 }