Code Duplication    Length = 25-27 lines in 2 locations

manager/includes/src/Core.php 2 locations

@@ 3666-3690 (lines=25) @@
3663
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3664
     * @return array
3665
     */
3666
    public function getAllChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3667
    {
3668
3669
        $cacheKey = md5(print_r(func_get_args(), true));
3670
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3671
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3672
        }
3673
3674
        $tblsc = $this->getFullTableName("site_content");
3675
        $tbldg = $this->getFullTableName("document_groups");
3676
        // modify field names to use sc. table reference
3677
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3678
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3679
        // get document groups for current user
3680
        if ($docgrp = $this->getUserDocGroups()) {
3681
            $docgrp = implode(",", $docgrp);
3682
        }
3683
        // build query
3684
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
3685
        $result = $this->db->select("DISTINCT {$fields}", "{$tblsc} sc
3686
                LEFT JOIN {$tbldg} dg on dg.document = sc.id", "sc.parent = '{$id}' AND ({$access}) GROUP BY sc.id", "{$sort} {$dir}");
3687
        $resourceArray = $this->db->makeArray($result);
3688
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
3689
        return $resourceArray;
3690
    }
3691
3692
    /**
3693
     * Gets all active child documents of the specified document, i.e. those which published and not deleted.
@@ 3703-3729 (lines=27) @@
3700
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3701
     * @return array
3702
     */
3703
    public function getActiveChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3704
    {
3705
        $cacheKey = md5(print_r(func_get_args(), true));
3706
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3707
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3708
        }
3709
3710
        $tblsc = $this->getFullTableName("site_content");
3711
        $tbldg = $this->getFullTableName("document_groups");
3712
3713
        // modify field names to use sc. table reference
3714
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3715
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3716
        // get document groups for current user
3717
        if ($docgrp = $this->getUserDocGroups()) {
3718
            $docgrp = implode(",", $docgrp);
3719
        }
3720
        // build query
3721
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
3722
        $result = $this->db->select("DISTINCT {$fields}", "{$tblsc} sc
3723
                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}");
3724
        $resourceArray = $this->db->makeArray($result);
3725
3726
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
3727
3728
        return $resourceArray;
3729
    }
3730
3731
    /**
3732
     * getDocumentChildren