Code Duplication    Length = 25-27 lines in 2 locations

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

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