Exemplo n.º 1
0
 protected function getCsvFieldData($field, $object)
 {
     //check if field is systemfield
     $systemFieldMap = ['id' => "getId", 'fullpath' => "getFullPath", 'published' => "getPublished", 'creationDate' => "getCreationDate", 'modificationDate' => "getModificationDate", 'filename' => "getKey", 'classname' => "getClassname"];
     if (in_array($field, array_keys($systemFieldMap))) {
         return $object->{$systemFieldMap[$field]}();
     } else {
         //check if field is standard object field
         $fieldDefinition = $object->getClass()->getFieldDefinition($field);
         if ($fieldDefinition) {
             return $fieldDefinition->getForCsvExport($object);
         } else {
             $fieldParts = explode("~", $field);
             // check for objects bricks and localized fields
             if (substr($field, 0, 1) == "~") {
                 //key value store - ignore for now
             } else {
                 if (count($fieldParts) > 1) {
                     // brick
                     $brickType = $fieldParts[0];
                     $brickKey = $fieldParts[1];
                     $key = Object\Service::getFieldForBrickType($object->getClass(), $brickType);
                     $brickClass = Pimcore\Model\Object\Objectbrick\Definition::getByKey($brickType);
                     $fieldDefinition = $brickClass->getFieldDefinition($brickKey);
                     if ($fieldDefinition) {
                         $brickContainer = $object->{"get" . ucfirst($key)}();
                         if ($brickContainer && !empty($brickKey)) {
                             $brick = $brickContainer->{"get" . ucfirst($brickType)}();
                             if ($brick) {
                                 return $fieldDefinition->getForCsvExport($brick);
                             }
                         }
                     }
                 } else {
                     if ($locFields = $object->getClass()->getFieldDefinition("localizedfields")) {
                         // if the definition is not set try to get the definition from localized fields
                         $fieldDefinition = $locFields->getFieldDefinition($field);
                         if ($fieldDefinition) {
                             $needLocalizedPermissions = true;
                             return $fieldDefinition->getForCsvExport($object->getLocalizedFields(), ["language" => $this->getParam("language")]);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 protected function getCsvFieldData($field, $object, $requestedLanguage)
 {
     //check if field is systemfield
     $systemFieldMap = ['id' => "getId", 'fullpath' => "getRealFullPath", 'published' => "getPublished", 'creationDate' => "getCreationDate", 'modificationDate' => "getModificationDate", 'filename' => "getKey", 'classname' => "getClassname"];
     if (in_array($field, array_keys($systemFieldMap))) {
         return $object->{$systemFieldMap[$field]}();
     } else {
         //check if field is standard object field
         $fieldDefinition = $object->getClass()->getFieldDefinition($field);
         if ($fieldDefinition) {
             return $fieldDefinition->getForCsvExport($object);
         } else {
             $fieldParts = explode("~", $field);
             // check for objects bricks and localized fields
             if (substr($field, 0, 1) == "~") {
                 $type = $fieldParts[1];
                 if ($type == "classificationstore") {
                     $fieldname = $fieldParts[2];
                     $groupKeyId = explode("-", $fieldParts[3]);
                     $groupId = $groupKeyId[0];
                     $keyId = $groupKeyId[1];
                     $getter = "get" . ucfirst($fieldname);
                     if (method_exists($object, $getter)) {
                         /** @var  $classificationStoreData Classificationstore */
                         $keyConfig = Pimcore\Model\Object\Classificationstore\KeyConfig::getById($keyId);
                         $type = $keyConfig->getType();
                         $definition = json_decode($keyConfig->getDefinition());
                         $fieldDefinition = \Pimcore\Model\Object\Classificationstore\Service::getFieldDefinitionFromJson($definition, $type);
                         return $fieldDefinition->getForCsvExport($object, ["context" => ["containerType" => "classificationstore", "fieldname" => $fieldname, "groupId" => $groupId, "keyId" => $keyId, "language" => $requestedLanguage]]);
                     }
                 }
                 //key value store - ignore for now
             } elseif (count($fieldParts) > 1) {
                 // brick
                 $brickType = $fieldParts[0];
                 $brickKey = $fieldParts[1];
                 $key = Object\Service::getFieldForBrickType($object->getClass(), $brickType);
                 $brickClass = Pimcore\Model\Object\Objectbrick\Definition::getByKey($brickType);
                 $fieldDefinition = $brickClass->getFieldDefinition($brickKey);
                 if ($fieldDefinition) {
                     $brickContainer = $object->{"get" . ucfirst($key)}();
                     if ($brickContainer && !empty($brickKey)) {
                         $brick = $brickContainer->{"get" . ucfirst($brickType)}();
                         if ($brick) {
                             return $fieldDefinition->getForCsvExport($brick);
                         }
                     }
                 }
             } elseif ($locFields = $object->getClass()->getFieldDefinition("localizedfields")) {
                 // if the definition is not set try to get the definition from localized fields
                 $fieldDefinition = $locFields->getFieldDefinition($field);
                 if ($fieldDefinition) {
                     $needLocalizedPermissions = true;
                     return $fieldDefinition->getForCsvExport($object->getLocalizedFields(), ["language" => $this->getParam("language")]);
                 }
             }
         }
     }
 }