Code Duplication    Length = 25-27 lines in 2 locations

manager/includes/src/Core.php 2 locations

@@ 3944-3968 (lines=25) @@
3941
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3942
     * @return array
3943
     */
3944
    public function getAllChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3945
    {
3946
3947
        $cacheKey = md5(print_r(func_get_args(), true));
3948
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3949
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3950
        }
3951
3952
        $tblsc = $this->getDatabase()->getFullTableName("site_content");
3953
        $tbldg = $this->getDatabase()->getFullTableName("document_groups");
3954
        // modify field names to use sc. table reference
3955
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3956
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3957
        // get document groups for current user
3958
        if ($docgrp = $this->getUserDocGroups()) {
3959
            $docgrp = implode(",", $docgrp);
3960
        }
3961
        // build query
3962
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
3963
        $result = $this->getDatabase()->select("DISTINCT {$fields}", "{$tblsc} sc
3964
                LEFT JOIN {$tbldg} dg on dg.document = sc.id", "sc.parent = '{$id}' AND ({$access}) GROUP BY sc.id", "{$sort} {$dir}");
3965
        $resourceArray = $this->getDatabase()->makeArray($result);
3966
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
3967
        return $resourceArray;
3968
    }
3969
3970
    /**
3971
     * Gets all active child documents of the specified document, i.e. those which published and not deleted.
@@ 3981-4007 (lines=27) @@
3978
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3979
     * @return array
3980
     */
3981
    public function getActiveChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3982
    {
3983
        $cacheKey = md5(print_r(func_get_args(), true));
3984
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3985
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3986
        }
3987
3988
        $tblsc = $this->getDatabase()->getFullTableName("site_content");
3989
        $tbldg = $this->getDatabase()->getFullTableName("document_groups");
3990
3991
        // modify field names to use sc. table reference
3992
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3993
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3994
        // get document groups for current user
3995
        if ($docgrp = $this->getUserDocGroups()) {
3996
            $docgrp = implode(",", $docgrp);
3997
        }
3998
        // build query
3999
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
4000
        $result = $this->getDatabase()->select("DISTINCT {$fields}", "{$tblsc} sc
4001
                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}");
4002
        $resourceArray = $this->getDatabase()->makeArray($result);
4003
4004
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
4005
4006
        return $resourceArray;
4007
    }
4008
4009
    /**
4010
     * getDocumentChildren