public function treeGetChildsByIdAction()
{
$object = Object\AbstractObject::getById($this->getParam("node"));
$objectTypes = null;
$objects = [];
$cv = false;
$offset = 0;
$total = 0;
if ($object instanceof Object\Concrete) {
$class = $object->getClass();
if ($class->getShowVariants()) {
$objectTypes = [Object\AbstractObject::OBJECT_TYPE_FOLDER, Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_VARIANT];
}
}
if (!$objectTypes) {
$objectTypes = [Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_FOLDER];
}
if ($object->hasChilds($objectTypes)) {
$limit = intval($this->getParam("limit"));
if (!$this->getParam("limit")) {
$limit = 100000000;
}
$offset = intval($this->getParam("start"));
$childsList = new Object\Listing();
$condition = "objects.o_parentId = '" . $object->getId() . "'";
// custom views start
if ($this->getParam("view")) {
$cv = \Pimcore\Model\Element\Service::getCustomViewById($this->getParam("view"));
if ($cv["classes"]) {
$cvConditions = [];
$cvClasses = explode(",", $cv["classes"]);
foreach ($cvClasses as $cvClass) {
$cvConditions[] = "objects.o_classId = '" . $cvClass . "'";
}
$cvConditions[] = "objects.o_type = 'folder'";
if (count($cvConditions) > 0) {
$condition .= " AND (" . implode(" OR ", $cvConditions) . ")";
}
}
}
// custom views end
if (!$this->getUser()->isAdmin()) {
$userIds = $this->getUser()->getRoles();
$userIds[] = $this->getUser()->getId();
$condition .= " AND (\n (select list from users_workspaces_object where userId in (" . implode(',', $userIds) . ") and LOCATE(CONCAT(o_path,o_key),cpath)=1 ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n OR\n (select list from users_workspaces_object where userId in (" . implode(',', $userIds) . ") and LOCATE(cpath,CONCAT(o_path,o_key))=1 ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n )";
}
$childsList->setCondition($condition);
$childsList->setLimit($limit);
$childsList->setOffset($offset);
$childsList->setOrderKey("FIELD(objects.o_type, 'folder') DESC, objects.o_key ASC", false);
$childsList->setObjectTypes($objectTypes);
Element\Service::addTreeFilterJoins($cv, $childsList);
$childs = $childsList->load();
foreach ($childs as $child) {
$tmpObject = $this->getTreeNodeConfig($child);
if ($child->isAllowed("list")) {
$objects[] = $tmpObject;
}
}
//pagination for custom view
$total = $cv ? $childsList->count() : $object->getChildAmount([Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_FOLDER, Object\AbstractObject::OBJECT_TYPE_VARIANT], $this->getUser());
}
//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 Model\Tool\Admin\EventDataContainer($objects);
\Pimcore::getEventManager()->trigger("admin.object.treeGetChildsById.preSendData", $this, ["returnValueContainer" => $returnValueContainer]);
if ($this->getParam("limit")) {
$this->_helper->json(["offset" => $offset, "limit" => $limit, "total" => $total, "nodes" => $returnValueContainer->getData(), "fromPaging" => intval($this->getParam("fromPaging"))]);
} else {
$this->_helper->json($returnValueContainer->getData());
}
}