Esempio n. 1
0
 /**
  * Sets the attribute of a user info object to the specified value, and saves it in the database.
  *
  * @param AttributeKeyInterface | string $ak
  * @param mixed $value
  */
 public function setAttribute($ak, $value)
 {
     $orm = \Database::connection()->getEntityManager();
     $this->clearAttribute($ak);
     // Create the attribute category value.
     $attributeValue = $this->getAttributeValueObject($ak, true);
     $orm->persist($attributeValue);
     $orm->flush();
     // Create the generic value. This gets joined to any specific Attribute value objects later on.
     $genericValue = new Value();
     $genericValue->setAttributeKey($attributeValue->getAttributeKey());
     $orm->persist($genericValue);
     $orm->flush();
     // Set the generic value to the attribute category value.
     $attributeValue->setGenericValue($genericValue);
     $orm->persist($attributeValue);
     $orm->flush();
     $controller = $attributeValue->getAttributeKey()->getController();
     $controller->setAttributeValue($attributeValue);
     if (!$value instanceof AttributeValue\AbstractValue) {
         if ($value instanceof EmptyRequestAttributeValue) {
             // LEGACY SUPPORT
             // If the passed $value object == EmptyRequestAttributeValue, we know we are dealing
             // with a legacy attribute type that's not using Doctrine. We have not returned an

             // attribute value value object.
             $controller->saveForm($controller->post());
             unset($value);
         } else {
             /**
              * @var $value AttributeValue\AbstractValue
              */
             $value = $controller->createAttributeValue($value);
         }
     }
     if ($value) {
         $value->setGenericValue($genericValue);
         $orm->persist($value);
         $orm->flush();
     }
     $category = $this->getObjectAttributeCategory();
     $indexer = $category->getSearchIndexer();
     if ($indexer) {
         $indexer->indexEntry($category, $attributeValue, $this);
     }
     return $attributeValue;
 }
Esempio n. 2
0
 /**
  * @deprecated
  */
 public function addAttributeValue()
 {
     $orm = \Database::connection()->getEntityManager();
     $genericValue = new Value();
     $genericValue->setAttributeKey($this->legacyAttributeKey);
     $orm->persist($genericValue);
     $orm->flush();
     $value = new LegacyValue();
     $value->setAttributeKey($this->legacyAttributeKey);
     $value->setGenericValue($genericValue);
     return $value;
 }