Code Duplication    Length = 25-27 lines in 2 locations

manager/includes/src/Core.php 2 locations

@@ 3917-3941 (lines=25) @@
3914
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3915
     * @return array
3916
     */
3917
    public function getAllChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3918
    {
3919
3920
        $cacheKey = md5(print_r(func_get_args(), true));
3921
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3922
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3923
        }
3924
3925
        $tblsc = $this->getDatabase()->getFullTableName("site_content");
3926
        $tbldg = $this->getDatabase()->getFullTableName("document_groups");
3927
        // modify field names to use sc. table reference
3928
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3929
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3930
        // get document groups for current user
3931
        if ($docgrp = $this->getUserDocGroups()) {
3932
            $docgrp = implode(",", $docgrp);
3933
        }
3934
        // build query
3935
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
3936
        $result = $this->getDatabase()->select("DISTINCT {$fields}", "{$tblsc} sc
3937
                LEFT JOIN {$tbldg} dg on dg.document = sc.id", "sc.parent = '{$id}' AND ({$access}) GROUP BY sc.id", "{$sort} {$dir}");
3938
        $resourceArray = $this->getDatabase()->makeArray($result);
3939
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
3940
        return $resourceArray;
3941
    }
3942
3943
    /**
3944
     * Gets all active child documents of the specified document, i.e. those which published and not deleted.
@@ 3954-3980 (lines=27) @@
3951
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3952
     * @return array
3953
     */
3954
    public function getActiveChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3955
    {
3956
        $cacheKey = md5(print_r(func_get_args(), true));
3957
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3958
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3959
        }
3960
3961
        $tblsc = $this->getDatabase()->getFullTableName("site_content");
3962
        $tbldg = $this->getDatabase()->getFullTableName("document_groups");
3963
3964
        // modify field names to use sc. table reference
3965
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3966
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3967
        // get document groups for current user
3968
        if ($docgrp = $this->getUserDocGroups()) {
3969
            $docgrp = implode(",", $docgrp);
3970
        }
3971
        // build query
3972
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
3973
        $result = $this->getDatabase()->select("DISTINCT {$fields}", "{$tblsc} sc
3974
                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}");
3975
        $resourceArray = $this->getDatabase()->makeArray($result);
3976
3977
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
3978
3979
        return $resourceArray;
3980
    }
3981
3982
    /**
3983
     * getDocumentChildren