@@ 3488-3518 (lines=31) @@ | ||
3485 | * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle |
|
3486 | * @return array |
|
3487 | */ |
|
3488 | public function getAllChildren( |
|
3489 | $id = 0, |
|
3490 | $sort = 'menuindex', |
|
3491 | $dir = 'ASC', |
|
3492 | $fields = 'id, pagetitle, description, parent, alias, menutitle' |
|
3493 | ) { |
|
3494 | ||
3495 | $cacheKey = md5(print_r(func_get_args(), true)); |
|
3496 | if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) { |
|
3497 | return $this->tmpCache[__FUNCTION__][$cacheKey]; |
|
3498 | } |
|
3499 | ||
3500 | $tblsc = $this->getDatabase()->getFullTableName("site_content"); |
|
3501 | $tbldg = $this->getDatabase()->getFullTableName("document_groups"); |
|
3502 | // modify field names to use sc. table reference |
|
3503 | $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
3504 | $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort)))); |
|
3505 | // get document groups for current user |
|
3506 | if ($docgrp = $this->getUserDocGroups()) { |
|
3507 | $docgrp = implode(",", $docgrp); |
|
3508 | } |
|
3509 | // build query |
|
3510 | $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)"); |
|
3511 | $result = $this->getDatabase()->select("DISTINCT {$fields}", "{$tblsc} sc |
|
3512 | LEFT JOIN {$tbldg} dg on dg.document = sc.id", "sc.parent = '{$id}' AND ({$access}) GROUP BY sc.id", |
|
3513 | "{$sort} {$dir}"); |
|
3514 | $resourceArray = $this->getDatabase()->makeArray($result); |
|
3515 | $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray; |
|
3516 | ||
3517 | return $resourceArray; |
|
3518 | } |
|
3519 | ||
3520 | /** |
|
3521 | * Gets all active child documents of the specified document, i.e. those which published and not deleted. |
|
@@ 3531-3562 (lines=32) @@ | ||
3528 | * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle |
|
3529 | * @return array |
|
3530 | */ |
|
3531 | public function getActiveChildren( |
|
3532 | $id = 0, |
|
3533 | $sort = 'menuindex', |
|
3534 | $dir = 'ASC', |
|
3535 | $fields = 'id, pagetitle, description, parent, alias, menutitle' |
|
3536 | ) { |
|
3537 | $cacheKey = md5(print_r(func_get_args(), true)); |
|
3538 | if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) { |
|
3539 | return $this->tmpCache[__FUNCTION__][$cacheKey]; |
|
3540 | } |
|
3541 | ||
3542 | $tblsc = $this->getDatabase()->getFullTableName("site_content"); |
|
3543 | $tbldg = $this->getDatabase()->getFullTableName("document_groups"); |
|
3544 | ||
3545 | // modify field names to use sc. table reference |
|
3546 | $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
3547 | $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort)))); |
|
3548 | // get document groups for current user |
|
3549 | if ($docgrp = $this->getUserDocGroups()) { |
|
3550 | $docgrp = implode(",", $docgrp); |
|
3551 | } |
|
3552 | // build query |
|
3553 | $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)"); |
|
3554 | $result = $this->getDatabase()->select("DISTINCT {$fields}", "{$tblsc} sc |
|
3555 | LEFT JOIN {$tbldg} dg on dg.document = sc.id", |
|
3556 | "sc.parent = '{$id}' AND sc.published=1 AND sc.deleted=0 AND ({$access}) GROUP BY sc.id", "{$sort} {$dir}"); |
|
3557 | $resourceArray = $this->getDatabase()->makeArray($result); |
|
3558 | ||
3559 | $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray; |
|
3560 | ||
3561 | return $resourceArray; |
|
3562 | } |
|
3563 | ||
3564 | /** |
|
3565 | * getDocumentChildren |