Code Duplication    Length = 25-27 lines in 2 locations

manager/includes/document.parser.class.inc.php 2 locations

@@ 3623-3647 (lines=25) @@
3620
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3621
     * @return array
3622
     */
3623
    public function getAllChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3624
    {
3625
3626
        $cacheKey = md5(print_r(func_get_args(), true));
3627
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3628
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3629
        }
3630
3631
        $tblsc = $this->getFullTableName("site_content");
3632
        $tbldg = $this->getFullTableName("document_groups");
3633
        // modify field names to use sc. table reference
3634
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3635
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3636
        // get document groups for current user
3637
        if ($docgrp = $this->getUserDocGroups()) {
3638
            $docgrp = implode(",", $docgrp);
3639
        }
3640
        // build query
3641
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
3642
        $result = $this->db->select("DISTINCT {$fields}", "{$tblsc} sc
3643
                LEFT JOIN {$tbldg} dg on dg.document = sc.id", "sc.parent = '{$id}' AND ({$access}) GROUP BY sc.id", "{$sort} {$dir}");
3644
        $resourceArray = $this->db->makeArray($result);
3645
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
3646
        return $resourceArray;
3647
    }
3648
3649
    /**
3650
     * Gets all active child documents of the specified document, i.e. those which published and not deleted.
@@ 3660-3686 (lines=27) @@
3657
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3658
     * @return array
3659
     */
3660
    public function getActiveChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3661
    {
3662
        $cacheKey = md5(print_r(func_get_args(), true));
3663
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3664
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3665
        }
3666
3667
        $tblsc = $this->getFullTableName("site_content");
3668
        $tbldg = $this->getFullTableName("document_groups");
3669
3670
        // modify field names to use sc. table reference
3671
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3672
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3673
        // get document groups for current user
3674
        if ($docgrp = $this->getUserDocGroups()) {
3675
            $docgrp = implode(",", $docgrp);
3676
        }
3677
        // build query
3678
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
3679
        $result = $this->db->select("DISTINCT {$fields}", "{$tblsc} sc
3680
                LEFT JOIN {$tbldg} dg on dg.document = sc.id", "sc.parent = '{$id}' AND sc.published=1 AND sc.deleted=0 AND ({$access}) GROUP BY sc.id", "{$sort} {$dir}");
3681
        $resourceArray = $this->db->makeArray($result);
3682
3683
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
3684
3685
        return $resourceArray;
3686
    }
3687
3688
    /**
3689
     * getDocumentChildren