getRawValue() public method

Raw value is normalized value which is suitable unique identification and storing.
public getRawValue ( string $name ) : mixed
$name string
return mixed
Beispiel #1
0
 /**
  * Returns entity relationships as array, 0 => pre, 1 => post, 2 => nulls
  * @param  IEntity  $entity
  * @return array
  */
 public static function getRelationships(IEntity $entity)
 {
     $return = [[], [], []];
     foreach ($entity->getMetadata()->getProperties() as $propertyMeta) {
         if ($propertyMeta->relationship === null) {
             continue;
         }
         $name = $propertyMeta->name;
         if (!$propertyMeta->relationship->cascade['remove']) {
             $return[2][$name] = $propertyMeta;
             continue;
         }
         $rawValue = $entity->getRawValue($name);
         if ($rawValue === null && $propertyMeta->isNullable) {
             continue;
         }
         $property = $entity->getProperty($name);
         if ($property instanceof IRelationshipContainer) {
             $value = $entity->getValue($name);
             if ($value) {
                 if ($propertyMeta->relationship->type === Relationship::ONE_HAS_ONE && !$propertyMeta->relationship->isMain) {
                     $return[0][$name] = $value;
                 } else {
                     $return[1][$name] = $value;
                 }
             }
         } elseif ($property instanceof IRelationshipCollection) {
             $return[0][$name] = $entity->getValue($name);
         }
     }
     return $return;
 }
 protected function execute(DbalCollection $collection, IEntity $parent)
 {
     $builder = $collection->getQueryBuilder();
     $preloadContainer = $parent->getPreloadContainer();
     $values = $preloadContainer ? $preloadContainer->getPreloadValues($this->metadata->name) : [$parent->getRawValue($this->metadata->name)];
     $cacheKey = $this->calculateCacheKey($builder, $values);
     $data =& $this->cacheEntityContainers[$cacheKey];
     if ($data) {
         return $data;
     }
     $data = $this->fetch(clone $builder, stripos($cacheKey, 'JOIN') !== FALSE, $values);
     return $data;
 }
 protected function execute(ICollection $collection, IEntity $parent)
 {
     $collectionMapper = $collection->getCollectionMapper();
     if (!$collectionMapper instanceof CollectionMapper) {
         throw new LogicException();
     }
     $builder = $collectionMapper->getSqlBuilder();
     $preloadIterator = $parent->getPreloadContainer();
     $values = $preloadIterator ? $preloadIterator->getPreloadValues($this->metadata->name) : [$parent->getRawValue($this->metadata->name)];
     $cacheKey = md5($builder->buildSelectQuery() . json_encode($values));
     $data =& $this->cacheEntityContainers[$cacheKey];
     if ($data) {
         return $data;
     }
     $data = $this->fetch(clone $builder, stripos($cacheKey, 'JOIN') !== FALSE, $values);
     return $data;
 }
Beispiel #4
0
 protected function addProperty(Nextras\Orm\Entity\Reflection\PropertyMetadata $metadata)
 {
     $component = $this->addPropertyComponent($metadata);
     switch (TRUE) {
         case $component instanceof Nette\Forms\Controls\BaseControl:
             if (!$component instanceof Nette\Forms\Controls\Checkbox) {
                 $component->setRequired(!$metadata->isNullable);
             }
             $component->setDisabled($metadata->isReadonly);
             $component->setDefaultValue($this->entity->getRawValue($metadata->name));
             $component->setAttribute('placeholder', $this->formatPropertyPlaceholder($metadata));
             break;
         case $component instanceof Nette\ComponentModel\IContainer:
             if ($metadata->isReadonly) {
                 foreach ($component->getComponents(TRUE, Nette\Forms\Controls\BaseControl::class) as $control) {
                     $value = $control->getValue();
                     $control->setDisabled();
                     $control->setDefaultValue($value);
                 }
             }
             break;
     }
     return $component;
 }
 public function getIterator(IEntity $parent, ICollection $collection)
 {
     $key = $parent->getRawValue($this->metadata->name);
     return [$key ? $collection->getBy(['id' => $key]) : NULL];
 }