/** end point for object related data. * - get object by id * GET http://[YOUR-DOMAIN]/webservice/rest/object/id/1281?apikey=[API-KEY] * returns json-encoded object data. * - delete object by id * DELETE http://[YOUR-DOMAIN]/webservice/rest/object/id/1281?apikey=[API-KEY] * returns json encoded success value * - create object * PUT or POST http://[YOUR-DOMAIN]/webservice/rest/object?apikey=[API-KEY] * body: json-encoded object data in the same format as returned by get object by id * but with missing id field or id set to 0 * returns json encoded object id * - update object * PUT or POST http://[YOUR-DOMAIN]/webservice/rest/object?apikey=[API-KEY] * body: same as for create object but with object id * returns json encoded success value * @throws \Exception */ public function objectAction() { $id = $this->getParam("id"); $success = false; try { if ($this->isGet()) { if ($id) { $profile = $this->getParam("profiling"); if ($profile) { $startTs = microtime(true); } $object = Object::getById($id); if (!$object) { $this->encoder->encode(array("success" => false, "msg" => "Object does not exist", "code" => self::ELEMENT_DOES_NOT_EXIST)); return; } if ($profile) { $timeConsumedGet = round(microtime(true) - $startTs, 3) * 1000; $startTs = microtime(true); } $this->checkPermission($object, "get"); if ($profile) { $timeConsumedPerm = round(microtime(true) - $startTs, 3) * 1000; $startTs = microtime(true); } if ($object instanceof Object\Folder) { $object = $this->service->getObjectFolderById($id); } else { $object = $this->service->getObjectConcreteById($id); } if ($profile) { $timeConsumedGetWebservice = round(microtime(true) - $startTs, 3) * 1000; } if ($profile) { $profiling = array(); $profiling["get"] = $timeConsumedGet; $profiling["perm"] = $timeConsumedPerm; $profiling["ws"] = $timeConsumedGetWebservice; $profiling["init"] = $this->timeConsumedInit; $result = array("success" => true, "profiling" => $profiling, "data" => $object); } else { $result = array("success" => true, "data" => $object); } $this->encoder->encode($result); return; } } else { if ($this->isDelete()) { $object = Object::getById($id); if ($object) { $this->checkPermission($object, "delete"); } $success = $this->service->deleteObject($id); $this->encoder->encode(array("success" => $success)); return; } else { if ($this->isPost() || $this->isPut()) { $data = file_get_contents("php://input"); $data = \Zend_Json::decode($data); $type = $data["type"]; $id = null; if ($data["id"]) { $obj = Object::getById($data["id"]); if ($obj) { $this->checkPermission($obj, "update"); } $isUpdate = true; if ($type == "folder") { $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Object\\Folder\\In", $data); $success = $this->service->updateObjectFolder($wsData); } else { $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Object\\Concrete\\In", $data); $success = $this->service->updateObjectConcrete($wsData); } } else { if ($type == "folder") { $class = "\\Pimcore\\Model\\Webservice\\Data\\Object\\Folder\\In"; $method = "createObjectFolder"; } else { $class = "\\Pimcore\\Model\\Webservice\\Data\\Object\\Concrete\\In"; $method = "createObjectConcrete"; } $wsData = self::fillWebserviceData($class, $data); $obj = new Object(); $obj->setId($wsData->parentId); $this->checkPermission($obj, "create"); $id = $this->service->{$method}($wsData); } if (!$isUpdate) { $success = $id != null; } $result = array("success" => $success); if ($success && !$isUpdate) { $result["id"] = $id; } $this->encoder->encode($result); return; } } } } catch (\Exception $e) { \Logger::error($e); $this->encoder->encode(array("success" => false, "msg" => (string) $e)); } throw new \Exception("not implemented"); }
/** end point for object related data. * - get object by id * GET http://[YOUR-DOMAIN]/webservice/rest/object/id/1281?apikey=[API-KEY] * returns json-encoded object data. * - delete object by id * DELETE http://[YOUR-DOMAIN]/webservice/rest/object/id/1281?apikey=[API-KEY] * returns json encoded success value * - create object * PUT or POST http://[YOUR-DOMAIN]/webservice/rest/object?apikey=[API-KEY] * body: json-encoded object data in the same format as returned by get object by id * but with missing id field or id set to 0 * returns json encoded object id * - update object * PUT or POST http://[YOUR-DOMAIN]/webservice/rest/object?apikey=[API-KEY] * body: same as for create object but with object id * returns json encoded success value * @throws \Exception */ public function objectAction() { $id = $this->getParam("id"); $success = false; try { if ($this->isGet()) { /** * @api {get} /object Get object data * @apiName Get object by id * @apiGroup Object * @apiSampleRequest off * @apiParam {int} id an object id * @apiParam {string} apikey your access token * @apiParamExample {json} Request-Example: * { * "id": 1, * "apikey": "21314njdsfn1342134" * } * @apiSuccess {json} success parameter of the returned data = true * @apiError {json} success parameter of the returned data = false * @apiErrorExample {json} Error-Response: * {"success":false, "msg":"exception 'Exception' with message '....'"} * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * { * "success": true * "data": { * "path": "/crm/inquiries/", * "creationDate": 1368630916, * "modificationDate": 1388409137, * "userModification": null, * "childs": null, * "elements": [ * { * "type": "gender", * "value": "female", * "name": "gender", * "language": null * }, * * ... * * } */ if ($id) { $profile = $this->getParam("profiling"); if ($profile) { $startTs = microtime(true); } $object = Object::getById($id); if (!$object) { $this->encoder->encode(["success" => false, "msg" => "Object does not exist", "code" => self::ELEMENT_DOES_NOT_EXIST]); return; } if ($profile) { $timeConsumedGet = round(microtime(true) - $startTs, 3) * 1000; $startTs = microtime(true); } $this->checkPermission($object, "get"); if ($profile) { $timeConsumedPerm = round(microtime(true) - $startTs, 3) * 1000; $startTs = microtime(true); } if ($object instanceof Object\Folder) { $object = $this->service->getObjectFolderById($id); } else { $object = $this->service->getObjectConcreteById($id); } if ($profile) { $timeConsumedGetWebservice = round(microtime(true) - $startTs, 3) * 1000; } if ($profile) { $profiling = []; $profiling["get"] = $timeConsumedGet; $profiling["perm"] = $timeConsumedPerm; $profiling["ws"] = $timeConsumedGetWebservice; $profiling["init"] = $this->timeConsumedInit; $result = ["success" => true, "profiling" => $profiling, "data" => $object]; } else { $result = ["success" => true, "data" => $object]; } $this->encoder->encode($result); return; } } elseif ($this->isDelete()) { /** * @api {delete} /object Delete object * @apiName Delete object * @apiGroup Object * @apiSampleRequest off * @apiParam {int} id an object id * @apiParam {string} apikey your access token * @apiParamExample {json} Request-Example: * { * "id": 1, * "apikey": "21314njdsfn1342134" * } * @apiSuccess {json} success parameter of the returned data = true * @apiError {json} success parameter of the returned data = false * @apiErrorExample {json} Error-Response: * {"success":false, "msg":"exception 'Exception' with message '....'"} * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * { * "success": true, * } * * */ $object = Object::getById($id); if ($object) { $this->checkPermission($object, "delete"); } $success = $this->service->deleteObject($id); $this->encoder->encode(["success" => $success]); return; } elseif ($this->isPost() || $this->isPut()) { $data = file_get_contents("php://input"); $data = \Zend_Json::decode($data); $type = $data["type"]; $id = null; if ($data["id"]) { /** * @api {put} /object Create a new object * @apiName Create a new object * @apiGroup Object * @apiSampleRequest off * @apiDescription * Request body: JSON-encoded object data in the same format as returned by get object by id for the data segment but with missing id field or id set to 0 * * @apiParam {json} data a new object data * @apiParam {string} apikey your access token * @apiParamExample {json} Request-Example: * { * "apikey": "21314njdsfn1342134", * "id": 66 * "data": { * "parentId": 48, * "key": "test-product-key", * "className": "product", * "type": "object", * "elements": [ * { * "type": "input", * "value": "some identyfier", * "name": "identyfier", * "language": null * }, * { * "type": "localizedfields", * "value": [ * { * "type": "input", * "value": "Test new", * "name": "name1", * "language": "en" * }, * { * "type": "input", * "value": "1", * "name": "name2", * "language": "en" * }, * { * "type": "input", * "value": null, * "name": "name1", * "language": "de" * }, * { * "type": "input", * "value": "aaa", * "name": "name2", * "language": "de" * } * ], * "name": "localizedfields", * "language": null * } * ] * } * } * @apiSuccess {json} success parameter of the returned data = true * @apiError {json} success parameter of the returned data = false * @apiErrorExample {json} Error-Response: * {"success":false, "msg":"exception 'Exception' with message '....'"} * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * { * "success": true, * "id": 66 * } */ $obj = Object::getById($data["id"]); if ($obj) { $this->checkPermission($obj, "update"); } $isUpdate = true; if ($type == "folder") { $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Object\\Folder\\In", $data); $success = $this->service->updateObjectFolder($wsData); } else { $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Object\\Concrete\\In", $data); $success = $this->service->updateObjectConcrete($wsData); } } else { /** * @api {put} /object Create a new object * @apiName Create a new object * @apiGroup Object * @apiSampleRequest off * @apiDescription * Request body: JSON-encoded object data in the same format as returned by get object by id for the data segment but with missing id field or id set to 0 * * @apiParam {json} data a new object data * @apiParam {string} apikey your access token * @apiParamExample {json} Request-Example: * { * "apikey": "21314njdsfn1342134", * "data": { * "id": 61, * "parentId": 48, * "key": "test-product-key", * "className": "product", * "type": "object", * "elements": [ * { * "type": "input", * "value": "some identyfier", * "name": "identyfier", * "language": null * }, * { * "type": "localizedfields", * "value": [ * { * "type": "input", * "value": "Test", * "name": "name1", * "language": "en" * }, * { * "type": "input", * "value": "1", * "name": "name2", * "language": "en" * }, * { * "type": "input", * "value": null, * "name": "name1", * "language": "de" * }, * { * "type": "input", * "value": "aaa", * "name": "name2", * "language": "de" * } * ], * "name": "localizedfields", * "language": null * } * ] * } * } * @apiSuccess {json} success parameter of the returned data = true * @apiError {json} success parameter of the returned data = false * @apiErrorExample {json} Error-Response: * {"success":false, "msg":"exception 'Exception' with message '....'"} * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * { * "success": true * } */ if ($type == "folder") { $class = "\\Pimcore\\Model\\Webservice\\Data\\Object\\Folder\\In"; $method = "createObjectFolder"; } else { $class = "\\Pimcore\\Model\\Webservice\\Data\\Object\\Concrete\\In"; $method = "createObjectConcrete"; } $wsData = self::fillWebserviceData($class, $data); $obj = new Object(); $obj->setId($wsData->parentId); $this->checkPermission($obj, "create"); $id = $this->service->{$method}($wsData); } if (!$isUpdate) { $success = $id != null; } $result = ["success" => $success]; if ($success && !$isUpdate) { $result["id"] = $id; } $this->encoder->encode($result); return; } } catch (\Exception $e) { Logger::error($e); $this->encoder->encode(["success" => false, "msg" => (string) $e]); } throw new \Exception("not implemented"); }