Pimcore\Model\Object\Data\KeyValue::getProperties PHP Метод

getProperties() публичный Метод

public getProperties ( boolean $forEditMode = false ) : array
$forEditMode boolean
Результат array
    public function getProperties($forEditMode = false)
    {
        $result = [];
        $object = Object::getById($this->objectId);
        if (!$object) {
            throw new \Exception('Object with Id ' . $this->objectId . ' not found');
        }
        $objectName = $object->getKey();
        $internalKeys = [];
        foreach ($this->arr as $pair) {
            $pair["inherited"] = false;
            $pair["source"] = $object->getId();
            $pair["groupId"] = Object\KeyValue\KeyConfig::getById($pair['key'])->getGroup();
            $result[] = $pair;
            $internalKeys[] = $pair["key"];
        }
        $blacklist = $internalKeys;
        $parent = Object\Service::hasInheritableParentObject($object);
        while ($parent) {
            $kv = $parent->getKeyvaluepairs();
            $parentProperties = $kv ? $kv->getInternalProperties() : [];
            $addedKeys = [];
            foreach ($parentProperties as $parentPair) {
                $parentKeyId = $parentPair["key"];
                $parentValue = $parentPair["value"];
                if (in_array($parentKeyId, $blacklist)) {
                    continue;
                }
                if ($this->multivalent && !$forEditMode && in_array($parentKeyId, $internalKeys)) {
                    continue;
                }
                $add = true;
                for ($i = 0; $i < count($result); ++$i) {
                    $resultPair = $result[$i];
                    $resultKey = $resultPair["key"];
                    $existingPair = null;
                    if ($resultKey == $parentKeyId) {
                        if ($this->multivalent && !in_array($resultKey, $blacklist)) {
                        } else {
                            $add = false;
                        }
                        // if the parent's key is already in the (internal) result list then
                        // we don't add it => not inherited.
                        if (!$this->multivalent) {
                            $add = false;
                            if (empty($resultPair["altSource"])) {
                                $resultPair["altSource"] = $parent->getId();
                                $resultPair["altValue"] = $parentPair["value"];
                            }
                        }
                        $result[$i] = $resultPair;
                    }
                    if (!$this->multivalent) {
                        break;
                    }
                }
                $addedKeys[] = $parentPair["key"];
                if ($add) {
                    $parentPair["inherited"] = true;
                    $parentPair["source"] = $parent->getId();
                    $parentPair["altSource"] = $parent->getId();
                    $parentPair["altValue"] = $parentPair["value"];
                    $parentPair["groupId"] = Object\KeyValue\KeyConfig::getById($parentPair['key'])->getGroup();
                    $result[] = $parentPair;
                }
            }
            foreach ($parentProperties as $parentPair) {
                $parentKeyId = $parentPair["key"];
                $blacklist[] = $parentKeyId;
            }
            $parent = Object\Service::hasInheritableParentObject($parent);
        }
        return $result;
    }

Usage Example

Пример #1
0
 /**
  * @see Object\ClassDefinition\Data::getDataForEditmode
  * @param Object\Data\KeyValue $data
  * @param null|Model\Object\AbstractObject $object
  * @param mixed $params
  * @return tbd
  */
 public function getDataForEditmode($data, $object = null, $params = [])
 {
     $result = [];
     if (!$data) {
         return $result;
     }
     $properties = $data->getProperties(true);
     foreach ($properties as $key => $property) {
         $key = $property["key"];
         $keyConfig = Object\KeyValue\KeyConfig::getById($key);
         $property["type"] = $keyConfig->getType();
         $property["possiblevalues"] = $keyConfig->getPossibleValues();
         $groupId = $keyConfig->getGroup();
         if ($groupId) {
             $group = Object\KeyValue\GroupConfig::getById($groupId);
             $property["group"] = $group->getName();
             $property["groupDesc"] = $group->getDescription();
         }
         $property["unit"] = $keyConfig->getUnit();
         $property["keyName"] = $keyConfig->getName();
         $property["keyDesc"] = $keyConfig->getDescription();
         $property["mandatory"] = $keyConfig->getMandatory();
         $result[] = $property;
     }
     return $result;
 }