Pimcore\Model\Document::setId PHP Method

setId() public method

Set the id of the document.
public setId ( integer $id ) : Document
$id integer
return Document
    public function setId($id)
    {
        $this->id = (int) $id;
        return $this;
    }

Usage Example

 /** end point for document related data.
  * - get document by id
  *      GET http://[YOUR-DOMAIN]/webservice/rest/document/id/1281?apikey=[API-KEY]
  *      returns json-encoded document data.
  * - delete document by id
  *      DELETE http://[YOUR-DOMAIN]/webservice/rest/document/id/1281?apikey=[API-KEY]
  *      returns json encoded success value
  * - create document
  *      PUT or POST http://[YOUR-DOMAIN]/webservice/rest/document?apikey=[API-KEY]
  *      body: json-encoded document data in the same format as returned by get document by id
  *              but with missing id field or id set to 0
  *      returns json encoded document id
  * - update document
  *      PUT or POST http://[YOUR-DOMAIN]/webservice/rest/document?apikey=[API-KEY]
  *      body: same as for create document but with object id
  *      returns json encoded success value
  * @throws \Exception
  */
 public function documentAction()
 {
     $id = $this->getParam("id");
     $success = false;
     try {
         if ($this->isGet()) {
             $doc = Document::getById($id);
             if (!$doc) {
                 $this->encoder->encode(array("success" => false, "msg" => "Document does not exist", "code" => self::ELEMENT_DOES_NOT_EXIST));
                 return;
             }
             $this->checkPermission($doc, "get");
             if ($doc) {
                 $type = $doc->getType();
                 $getter = "getDocument" . ucfirst($type) . "ById";
                 if (method_exists($this->service, $getter)) {
                     $object = $this->service->{$getter}($id);
                 } else {
                     // check if the getter is implemented by a plugin
                     $class = "\\Pimcore\\Model\\Webservice\\Data\\Document\\" . ucfirst($type) . "\\Out";
                     if (Tool::classExists($class)) {
                         Document\Service::loadAllDocumentFields($doc);
                         $object = Webservice\Data\Mapper::map($doc, $class, "out");
                     } else {
                         throw new \Exception("unknown type");
                     }
                 }
             }
             if (!$object) {
                 throw new \Exception("could not find document");
             }
             @$this->encoder->encode(array("success" => true, "data" => $object));
             return;
         } else {
             if ($this->isDelete()) {
                 $doc = Document::getById($id);
                 if ($doc) {
                     $this->checkPermission($doc, "delete");
                 }
                 $success = $this->service->deleteDocument($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;
                     $typeUpper = ucfirst($type);
                     $className = "\\Pimcore\\Model\\Webservice\\Data\\Document\\" . $typeUpper . "\\In";
                     if ($data["id"]) {
                         $doc = Document::getById($data["id"]);
                         if ($doc) {
                             $this->checkPermission($doc, "update");
                         }
                         $isUpdate = true;
                         $setter = "updateDocument" . $typeUpper;
                         if (!method_exists($this->service, $setter)) {
                             throw new \Exception("method does not exist " . $setter);
                         }
                         $wsData = self::fillWebserviceData($className, $data);
                         $success = $this->service->{$setter}($wsData);
                     } else {
                         $setter = "createDocument" . $typeUpper;
                         if (!method_exists($this->service, $setter)) {
                             throw new \Exception("method does not exist " . $setter);
                         }
                         $wsData = self::fillWebserviceData($className, $data);
                         $doc = new Document();
                         $doc->setId($wsData->parentId);
                         $this->checkPermission($doc, "create");
                         $id = $this->service->{$setter}($wsData);
                     }
                     if (!$isUpdate) {
                         $success = $id != null;
                     }
                     if ($success && !$isUpdate) {
                         $this->encoder->encode(array("success" => $success, "id" => $id));
                     } else {
                         $this->encoder->encode(array("success" => $success));
                     }
                     return;
                 }
             }
         }
     } catch (\Exception $e) {
         $this->encoder->encode(array("success" => false, "msg" => (string) $e));
     }
     $this->encoder->encode(array("success" => false));
 }
All Usage Examples Of Pimcore\Model\Document::setId