Pimcore\Model\Element\Service::getSafeVersionInfo PHP Method

getSafeVersionInfo() public static method

public static getSafeVersionInfo ( $versions )
    public static function getSafeVersionInfo($versions)
    {
        if (is_array($versions)) {
            $versions = json_decode(json_encode($versions), true);
            $result = [];
            foreach ($versions as $version) {
                $name = $version["user"]["name"];
                $id = $version["user"]["id"];
                unset($version["user"]);
                $version["user"]["name"] = $name;
                $version["user"]["id"] = $id;
                $result[] = $version;
            }
            return $result;
        }
    }

Usage Example

Ejemplo n.º 1
0
 public function getDataByIdAction()
 {
     // check for lock
     if (Element\Editlock::isLocked($this->getParam("id"), "document")) {
         $this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")]);
     }
     Element\Editlock::lock($this->getParam("id"), "document");
     $email = Document\Newsletter::getById($this->getParam("id"));
     $email = clone $email;
     $email = $this->getLatestVersion($email);
     $versions = Element\Service::getSafeVersionInfo($email->getVersions());
     $email->setVersions(array_splice($versions, 0, 1));
     $email->idPath = Element\Service::getIdPath($email);
     $email->userPermissions = $email->getUserPermissions();
     $email->setLocked($email->isLocked());
     $email->setParent(null);
     // unset useless data
     $email->setElements(null);
     $email->childs = null;
     $this->addTranslationsData($email);
     $this->minimizeProperties($email);
     //Hook for modifying return value - e.g. for changing permissions based on object data
     //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values
     $returnValueContainer = new \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($email));
     \Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $email, "returnValueContainer" => $returnValueContainer]);
     if ($email->isAllowed("view")) {
         $this->_helper->json($returnValueContainer->getData());
     }
     $this->_helper->json(false);
 }
All Usage Examples Of Pimcore\Model\Element\Service::getSafeVersionInfo