Code Duplication    Length = 28-34 lines in 2 locations

main/lp/learnpath.class.php 2 locations

@@ 1598-1631 (lines=34) @@
1595
     * @param    integer $id Item ID
1596
     * @return    array    A list of all the "brother items" (or an empty array on failure)
1597
     */
1598
    public function getSiblingDirectories($id)
1599
    {
1600
        $course_id = api_get_course_int_id();
1601
        if ($this->debug > 0) {
1602
            error_log('New LP - In learnpath::getSiblingDirectories()', 0);
1603
        }
1604
1605
        if (empty($id) || $id != strval(intval($id))) {
1606
            return array();
1607
        }
1608
1609
        $lp_item = Database::get_course_table(TABLE_LP_ITEM);
1610
        $sql_parent = "SELECT * FROM $lp_item
1611
                       WHERE c_id = ".$course_id." AND id = $id AND item_type='dir'";
1612
        $res_parent = Database::query($sql_parent);
1613
        if (Database::num_rows($res_parent) > 0) {
1614
            $row_parent = Database::fetch_array($res_parent);
1615
            $parent = $row_parent['parent_item_id'];
1616
            $sql = "SELECT * FROM $lp_item
1617
                    WHERE
1618
                        c_id = ".$course_id." AND
1619
                        parent_item_id = $parent AND
1620
                        id = $id AND
1621
                        item_type='dir'
1622
                    ORDER BY display_order";
1623
            $res_bros = Database::query($sql);
1624
1625
            $list = array();
1626
            while ($row_bro = Database::fetch_array($res_bros)) {
1627
                $list[] = $row_bro;
1628
            }
1629
1630
            return $list;
1631
        }
1632
1633
        return array();
1634
    }
@@ 1642-1669 (lines=28) @@
1639
     * @param    integer $id Item ID
1640
     * @return    array    A list of all the "brother items" (or an empty array on failure)
1641
     */
1642
    public function get_brother_items($id)
1643
    {
1644
        $course_id = api_get_course_int_id();
1645
        if ($this->debug > 0) {
1646
            error_log('New LP - In learnpath::get_brother_items('.$id.')', 0);
1647
        }
1648
1649
        if (empty($id) || $id != strval(intval($id))) {
1650
            return array();
1651
        }
1652
1653
        $lp_item = Database::get_course_table(TABLE_LP_ITEM);
1654
        $sql_parent = "SELECT * FROM $lp_item WHERE c_id = $course_id AND id = $id";
1655
        $res_parent = Database::query($sql_parent);
1656
        if (Database::num_rows($res_parent) > 0) {
1657
            $row_parent = Database::fetch_array($res_parent);
1658
            $parent = $row_parent['parent_item_id'];
1659
            $sql_bros = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND parent_item_id = $parent
1660
                         ORDER BY display_order";
1661
            $res_bros = Database::query($sql_bros);
1662
            $list = [];
1663
            while ($row_bro = Database::fetch_array($res_bros)) {
1664
                $list[] = $row_bro;
1665
            }
1666
            return $list;
1667
        }
1668
        return [];
1669
    }
1670
1671
    /**
1672
     * Get the specific prefix index terms of this learning path