addTreeFilterJoins() public static method

Changes the query according to the custom view config
public static addTreeFilterJoins ( $cv, $childsList )
$cv array
$childsList
Esempio n. 1
0
 public function treeGetChildsByIdAction()
 {
     $document = Document::getById($this->getParam("node"));
     $documents = [];
     $cv = false;
     if ($document->hasChilds()) {
         $limit = intval($this->getParam("limit"));
         if (!$this->getParam("limit")) {
             $limit = 100000000;
         }
         $offset = intval($this->getParam("start"));
         if ($this->getParam("view")) {
             $cv = \Pimcore\Model\Element\Service::getCustomViewById($this->getParam("view"));
         }
         $list = new Document\Listing();
         if ($this->getUser()->isAdmin()) {
             $list->setCondition("parentId = ? ", $document->getId());
         } else {
             $userIds = $this->getUser()->getRoles();
             $userIds[] = $this->getUser()->getId();
             $list->setCondition("parentId = ? and\n                                        (\n                                        (select list from users_workspaces_document where userId in (" . implode(',', $userIds) . ") and LOCATE(CONCAT(path,`key`),cpath)=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n                                        or\n                                        (select list from users_workspaces_document where userId in (" . implode(',', $userIds) . ") and LOCATE(cpath,CONCAT(path,`key`))=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n                                        )", $document->getId());
         }
         $list->setOrderKey(["index", "id"]);
         $list->setOrder(["asc", "asc"]);
         $list->setLimit($limit);
         $list->setOffset($offset);
         \Pimcore\Model\Element\Service::addTreeFilterJoins($cv, $list);
         $childsList = $list->load();
         foreach ($childsList as $childDocument) {
             // only display document if listing is allowed for the current user
             if ($childDocument->isAllowed("list")) {
                 $documents[] = $this->getTreeNodeConfig($childDocument);
             }
         }
     }
     if ($this->getParam("limit")) {
         $this->_helper->json(["offset" => $offset, "limit" => $limit, "total" => $document->getChildAmount($this->getUser()), "nodes" => $documents]);
     } else {
         $this->_helper->json($documents);
     }
     $this->_helper->json(false);
 }
Esempio n. 2
0
 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());
     }
 }
Esempio n. 3
0
 public function treeGetChildsByIdAction()
 {
     $assets = [];
     $cv = false;
     $asset = Asset::getById($this->getParam("node"));
     if ($asset->hasChilds()) {
         $limit = intval($this->getParam("limit"));
         if (!$this->getParam("limit")) {
             $limit = 100000000;
         }
         $offset = intval($this->getParam("start"));
         if ($this->getParam("view")) {
             $cv = \Pimcore\Model\Element\Service::getCustomViewById($this->getParam("view"));
         }
         // get assets
         $childsList = new Asset\Listing();
         if ($this->getUser()->isAdmin()) {
             $childsList->setCondition("parentId = ? ", $asset->getId());
         } else {
             $userIds = $this->getUser()->getRoles();
             $userIds[] = $this->getUser()->getId();
             $childsList->setCondition("parentId = ? and\n                    (\n                    (select list from users_workspaces_asset where userId in (" . implode(',', $userIds) . ") and LOCATE(CONCAT(path,filename),cpath)=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n                    or\n                    (select list from users_workspaces_asset where userId in (" . implode(',', $userIds) . ") and LOCATE(cpath,CONCAT(path,filename))=1  ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n                    )", $asset->getId());
         }
         $childsList->setLimit($limit);
         $childsList->setOffset($offset);
         $childsList->setOrderKey("FIELD(assets.type, 'folder') DESC, assets.filename ASC", false);
         \Pimcore\Model\Element\Service::addTreeFilterJoins($cv, $childsList);
         $childs = $childsList->load();
         foreach ($childs as $childAsset) {
             if ($childAsset->isAllowed("list")) {
                 $assets[] = $this->getTreeNodeConfig($childAsset);
             }
         }
     }
     if ($this->getParam("limit")) {
         $this->_helper->json(["offset" => $offset, "limit" => $limit, "total" => $asset->getChildAmount($this->getUser()), "nodes" => $assets]);
     } else {
         $this->_helper->json($assets);
     }
     $this->_helper->json(false);
 }