Pimcore\Model\Document::getProperties PHP Method

getProperties() public method

Get a list of properties (including the inherited)
public getProperties ( ) : Property[]
return Property[]
    public function getProperties()
    {
        if ($this->properties === null) {
            // try to get from cache
            $cacheKey = "document_properties_" . $this->getId();
            $properties = \Pimcore\Cache::load($cacheKey);
            if (!is_array($properties)) {
                $properties = $this->getDao()->getProperties();
                $elementCacheTag = $this->getCacheTag();
                $cacheTags = ["document_properties" => "document_properties", $elementCacheTag => $elementCacheTag];
                \Pimcore\Cache::save($properties, $cacheKey, $cacheTags);
            }
            $this->setProperties($properties);
        }
        return $this->properties;
    }

Usage Example

Example #1
0
 /**
  * @param Model\Document $document
  * @throws \Zend_Json_Exception
  */
 protected function addPropertiesToDocument(Model\Document $document)
 {
     // properties
     if ($this->getParam("properties")) {
         $properties = array();
         // assign inherited properties
         foreach ($document->getProperties() as $p) {
             if ($p->isInherited()) {
                 $properties[$p->getName()] = $p;
             }
         }
         $propertiesData = \Zend_Json::decode($this->getParam("properties"));
         if (is_array($propertiesData)) {
             foreach ($propertiesData as $propertyName => $propertyData) {
                 $value = $propertyData["data"];
                 try {
                     $property = new Property();
                     $property->setType($propertyData["type"]);
                     $property->setName($propertyName);
                     $property->setCtype("document");
                     $property->setDataFromEditmode($value);
                     $property->setInheritable($propertyData["inheritable"]);
                     $properties[$propertyName] = $property;
                 } catch (\Exception $e) {
                     \Logger::warning("Can't add " . $propertyName . " to document " . $document->getFullPath());
                 }
             }
         }
         if ($document->isAllowed("properties")) {
             $document->setProperties($properties);
         }
     }
     // force loading of properties
     $document->getProperties();
 }
All Usage Examples Of Pimcore\Model\Document::getProperties