Code Duplication    Length = 25-27 lines in 2 locations

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

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