public function __set($name, $value)
 {
     $args = func_get_args();
     $options = array();
     if (2 < count($args)) {
         $options = $args[2];
     }
     switch ($name) {
         case 'language':
         case 'script':
             if (!isset($this->values[$name])) {
                 $criteria = new Criteria();
                 $this->addPropertysCriteria($criteria);
                 $criteria->add(QubitProperty::NAME, $name);
                 if (1 == count($query = QubitProperty::get($criteria))) {
                     $this->values[$name] = $query[0];
                 } else {
                     $this->values[$name] = new QubitProperty();
                     $this->values[$name]->name = $name;
                     $this->propertys[] = $this->values[$name];
                 }
             }
             $this->values[$name]->__set('value', serialize($value), $options + array('sourceCulture' => true));
             return $this;
     }
     return call_user_func_array(array($this, 'BaseFunction::__set'), $args);
 }
 public function __get($name)
 {
     switch ($name) {
         case '_ehriMeta':
             if (!isset($this->_meta)) {
                 $criteria = new Criteria();
                 $this->resource->addPropertysCriteria($criteria);
                 $criteria->add(QubitProperty::NAME, "ehrimeta");
                 if (1 == count($query = QubitProperty::get($criteria))) {
                     $this->_meta = $query[0];
                 } else {
                     $this->_meta = new QubitProperty();
                     $this->_meta->name = "ehrimeta";
                     $this->_meta->value = serialize(array());
                     $this->resource->propertys[] = $this->_meta;
                 }
             }
             return $this->_meta;
         case 'ehriCopyrightIssue':
         case 'ehriPriority':
             $meta = unserialize($this->_ehriMeta->value);
             return array_key_exists($name, $meta) ? $meta[$name] : NULL;
         default:
             return parent::__get($name);
     }
 }
 protected function property($name)
 {
     if (!isset($this->property[$name])) {
         $criteria = new Criteria();
         $this->resource->addPropertysCriteria($criteria);
         $criteria->add(QubitProperty::NAME, $name);
         if (1 == count($query = QubitProperty::get($criteria))) {
             $this->property[$name] = $query[0];
         } else {
             $this->property[$name] = new QubitProperty();
             $this->property[$name]->name = $name;
             $this->resource->propertys[] = $this->property[$name];
         }
     }
     return $this->property[$name];
 }
 /**
  * Decide whether to show child digital objects as a compound object based
  * on 'displayAsCompound' toggle and available digital objects.
  *
  * @return boolean
  */
 public function showAsCompoundDigitalObject()
 {
     // Return false if this digital object is not linked directly to an
     // information object
     if (null === $this->informationObjectId) {
         return false;
     }
     // Return false if "show compound" toggle is not set to '1' (yes)
     $showCompoundProp = QubitProperty::getOneByObjectIdAndName($this->id, 'displayAsCompound');
     if (null === $showCompoundProp || '1' != $showCompoundProp->getValue(array('sourceCulture' => true))) {
         return false;
     }
     // Return false if this object has no children with digital objects
     $criteria = new Criteria();
     $criteria->addJoin(QubitInformationObject::ID, QubitDigitalObject::INFORMATION_OBJECT_ID);
     $criteria->add(QubitInformationObject::PARENT_ID, $this->informationObjectId);
     if (0 === count(QubitDigitalObject::get($criteria))) {
         return false;
     }
     return true;
 }
Example #5
0
 public function getProperties($name = null, $scope = null)
 {
     $criteria = new Criteria();
     $criteria->add(QubitProperty::OBJECT_ID, $this->id);
     if ($name) {
         $criteria->add(QubitProperty::NAME, $name);
     }
     if ($scope) {
         $criteria->add(QubitProperty::SCOPE, $scope);
     }
     return QubitProperty::get($criteria);
 }
 /**
  * Save a related property and create a new property if a matching one doesn't
  * already exist.
  *
  * @param string $name name of property
  * @param string $value new value to set
  * @param array $options array of options
  * @return QubitInformationObject
  */
 public function saveProperty($name, $value, $options = array())
 {
     // Get existing property if possible
     if (null === ($property = QubitProperty::getOneByObjectIdAndName($this->id, $name, $options))) {
         // Create a new property if required
         $property = new QubitProperty();
         $property->setObjectId($this->id);
         $property->setName($name);
         if (isset($options['scope'])) {
             $property->setScope($options['scope']);
         }
     }
     $property->setValue($value, $options);
     $property->save();
     return $this;
 }
 /**
  * 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;
 }
 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);
         }
     }
 }
Example #9
0
 public static function getpropertysById($id, array $options = array())
 {
     $criteria = new Criteria();
     self::addpropertysCriteriaById($criteria, $id);
     return QubitProperty::get($criteria, $options);
 }