public function getVersionsAction()
{
$id = intval($this->getParam("id"));
$type = $this->getParam("controller");
$allowedTypes = ["asset", "document", "object"];
if ($id && in_array($type, $allowedTypes)) {
$element = Model\Element\Service::getElementById($type, $id);
if ($element) {
if ($element->isAllowed("versions")) {
$schedule = $element->getScheduledTasks();
$schedules = [];
foreach ($schedule as $task) {
if ($task->getActive()) {
$schedules[$task->getVersion()] = $task->getDate();
}
}
$versions = $element->getVersions();
$versions = Model\Element\Service::getSafeVersionInfo($versions);
foreach ($versions as &$version) {
$version["scheduled"] = null;
if (array_key_exists($version["id"], $schedules)) {
$version["scheduled"] = $schedules[$version["id"]];
}
}
$this->_helper->json(["versions" => $versions]);
} else {
throw new \Exception("Permission denied, " . $type . " id [" . $id . "]");
}
} else {
throw new \Exception($type . " with id [" . $id . "] doesn't exist");
}
}
}