Skip to content
Snippets Groups Projects
Commit b67ed26b authored by damjan's avatar damjan
Browse files

[BUGFIX] Using array instead of object for json_encode.

json_encode(object) was returning empty braces "{}"
parent ea7892da
No related branches found
No related tags found
No related merge requests found
......@@ -320,4 +320,47 @@ class Attribute {
return $this;
}
/**
* Writes object properties to associative array. NULL and not-set properties are ignored.
*
* @return array
*/
public function toArray() {
$attributeArray = [];
if (isset($this->id)) {
$attributeArray ['id'] = $this->id;
}
if (isset($this->name)) {
$attributeArray ['name'] = $this->name;
}
if (isset($this->description)) {
$attributeArray ['description'] = $this->description;
}
if (isset($this->default)) {
$attributeArray ['default'] = $this->default;
}
if (isset($this->minVersion)) {
$attributeArray ['minVersion'] = $this->minVersion;
}
if (isset($this->maxVersion)) {
$attributeArray ['maxVersion'] = $this->maxVersion;
}
if (isset($this->parent)) {
$attributeArray ['parent'] = $this->parent->getId();
}
if (isset($this->type)) {
$attributeArray ['type'] = $this->type->getId();
}
if (isset($this->typo3Group)) {
$attributeArray ['typo3Group'] = $this->typo3Group;
}
if (isset($this->deleted)) {
$attributeArray ['deleted'] = $this->deleted;
}
if (isset($this->isType)) {
$attributeArray ['isType'] = $this->isType;
}
return $attributeArray;
}
}
......@@ -172,11 +172,7 @@ class TsrefRestService {
* @return mixed
*/
public function addNewAttribute(Attribute $attribute) {
$attributeJson = json_encode($attribute);
echo 'AttributeName: ' . $attribute->getName();
echo 'Attribute JSON: ' . $attributeJson;
// json that works example: '{"name":"testNamePUT","description":"Testing PUT modify. cetvrtak","minVersion":"4.2","maxVersion":"7.2","typo3Group":2,"isType":false,"deleted":false, "parent":"181"}'
$attributeJson = json_encode($attribute->toArray());
$curlHandle = $this->initialiseCurl();
curl_setopt($curlHandle, CURLOPT_POST, 1);
......@@ -185,7 +181,7 @@ class TsrefRestService {
'accesstoken: ' . self::AUTHENTICATION_TOKEN
]);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $attributeJson);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, TRUE);
// Download the given URL, and return output
$output = curl_exec($curlHandle);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment