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

addTreeFilterJoins() public static method

Changes the query according to the custom view config
public static addTreeFilterJoins ( $cv, $childsList )
$cv array
$childsList
    public static function addTreeFilterJoins($cv, $childsList)
    {
        if ($cv) {
            $childsList->onCreateQuery(function (\Zend_Db_Select $select) use($cv, $childsList) {
                $where = $cv["where"];
                if ($where) {
                    $select->where($where);
                }
                $customViewJoins = $cv["joins"];
                if ($customViewJoins) {
                    foreach ($customViewJoins as $joinConfig) {
                        $type = $joinConfig["type"];
                        $method = $type == "left" || $type == "right" ? $method = "join" . ucfirst($type) : "join";
                        $name = $joinConfig["name"];
                        $condition = $joinConfig["condition"];
                        $columns = $joinConfig["columns"];
                        $select->{$method}($name, $condition, $columns);
                    }
                }
                if ($cv["having"]) {
                    $select->having($cv["having"]);
                }
            });
        }
    }

Usage Example

Example #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);
 }
All Usage Examples Of Pimcore\Model\Element\Service::addTreeFilterJoins