Code Duplication    Length = 25-27 lines in 2 locations

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

@@ 3646-3670 (lines=25) @@
3643
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3644
     * @return array
3645
     */
3646
    public function getAllChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3647
    {
3648
3649
        $cacheKey = md5(print_r(func_get_args(), true));
3650
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3651
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3652
        }
3653
3654
        $tblsc = $this->getFullTableName("site_content");
3655
        $tbldg = $this->getFullTableName("document_groups");
3656
        // modify field names to use sc. table reference
3657
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3658
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3659
        // get document groups for current user
3660
        if ($docgrp = $this->getUserDocGroups()) {
3661
            $docgrp = implode(",", $docgrp);
3662
        }
3663
        // build query
3664
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
3665
        $result = $this->db->select("DISTINCT {$fields}", "{$tblsc} sc
3666
                LEFT JOIN {$tbldg} dg on dg.document = sc.id", "sc.parent = '{$id}' AND ({$access}) GROUP BY sc.id", "{$sort} {$dir}");
3667
        $resourceArray = $this->db->makeArray($result);
3668
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
3669
        return $resourceArray;
3670
    }
3671
3672
    /**
3673
     * Gets all active child documents of the specified document, i.e. those which published and not deleted.
@@ 3683-3709 (lines=27) @@
3680
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3681
     * @return array
3682
     */
3683
    public function getActiveChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3684
    {
3685
        $cacheKey = md5(print_r(func_get_args(), true));
3686
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3687
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3688
        }
3689
3690
        $tblsc = $this->getFullTableName("site_content");
3691
        $tbldg = $this->getFullTableName("document_groups");
3692
3693
        // modify field names to use sc. table reference
3694
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3695
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3696
        // get document groups for current user
3697
        if ($docgrp = $this->getUserDocGroups()) {
3698
            $docgrp = implode(",", $docgrp);
3699
        }
3700
        // build query
3701
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
3702
        $result = $this->db->select("DISTINCT {$fields}", "{$tblsc} sc
3703
                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}");
3704
        $resourceArray = $this->db->makeArray($result);
3705
3706
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
3707
3708
        return $resourceArray;
3709
    }
3710
3711
    /**
3712
     * getDocumentChildren