Code Duplication    Length = 25-27 lines in 2 locations

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

@@ 3628-3652 (lines=25) @@
3625
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3626
     * @return array
3627
     */
3628
    public function getAllChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3629
    {
3630
3631
        $cacheKey = md5(print_r(func_get_args(), true));
3632
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3633
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3634
        }
3635
3636
        $tblsc = $this->getFullTableName("site_content");
3637
        $tbldg = $this->getFullTableName("document_groups");
3638
        // modify field names to use sc. table reference
3639
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3640
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3641
        // get document groups for current user
3642
        if ($docgrp = $this->getUserDocGroups()) {
3643
            $docgrp = implode(",", $docgrp);
3644
        }
3645
        // build query
3646
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
3647
        $result = $this->db->select("DISTINCT {$fields}", "{$tblsc} sc
3648
                LEFT JOIN {$tbldg} dg on dg.document = sc.id", "sc.parent = '{$id}' AND ({$access}) GROUP BY sc.id", "{$sort} {$dir}");
3649
        $resourceArray = $this->db->makeArray($result);
3650
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
3651
        return $resourceArray;
3652
    }
3653
3654
    /**
3655
     * Gets all active child documents of the specified document, i.e. those which published and not deleted.
@@ 3665-3691 (lines=27) @@
3662
     * @param string $fields Default: id, pagetitle, description, parent, alias, menutitle
3663
     * @return array
3664
     */
3665
    public function getActiveChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fields = 'id, pagetitle, description, parent, alias, menutitle')
3666
    {
3667
        $cacheKey = md5(print_r(func_get_args(), true));
3668
        if (isset($this->tmpCache[__FUNCTION__][$cacheKey])) {
3669
            return $this->tmpCache[__FUNCTION__][$cacheKey];
3670
        }
3671
3672
        $tblsc = $this->getFullTableName("site_content");
3673
        $tbldg = $this->getFullTableName("document_groups");
3674
3675
        // modify field names to use sc. table reference
3676
        $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields))));
3677
        $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort))));
3678
        // get document groups for current user
3679
        if ($docgrp = $this->getUserDocGroups()) {
3680
            $docgrp = implode(",", $docgrp);
3681
        }
3682
        // build query
3683
        $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
3684
        $result = $this->db->select("DISTINCT {$fields}", "{$tblsc} sc
3685
                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}");
3686
        $resourceArray = $this->db->makeArray($result);
3687
3688
        $this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
3689
3690
        return $resourceArray;
3691
    }
3692
3693
    /**
3694
     * getDocumentChildren