Code Duplication    Length = 28-34 lines in 2 locations

main/lp/learnpath.class.php 2 locations

@@ 1577-1610 (lines=34) @@
1574
     * @param    integer $id Item ID
1575
     * @return    array    A list of all the "brother items" (or an empty array on failure)
1576
     */
1577
    public function getSiblingDirectories($id)
1578
    {
1579
        $course_id = api_get_course_int_id();
1580
        if ($this->debug > 0) {
1581
            error_log('New LP - In learnpath::getSiblingDirectories()', 0);
1582
        }
1583
1584
        if (empty($id) || $id != strval(intval($id))) {
1585
1586
            return array();
1587
        }
1588
1589
        $lp_item = Database::get_course_table(TABLE_LP_ITEM);
1590
        $sql_parent = "SELECT * FROM $lp_item
1591
                       WHERE c_id = ".$course_id." AND id = $id AND item_type='dir'";
1592
        $res_parent = Database::query($sql_parent);
1593
        if (Database::num_rows($res_parent) > 0) {
1594
            $row_parent = Database::fetch_array($res_parent);
1595
            $parent = $row_parent['parent_item_id'];
1596
            $sql = "SELECT * FROM $lp_item
1597
                    WHERE
1598
                        c_id = ".$course_id." AND
1599
                        parent_item_id = $parent AND
1600
                        id = $id AND
1601
                        item_type='dir'
1602
                    ORDER BY display_order";
1603
            $res_bros = Database::query($sql);
1604
1605
            $list = array();
1606
            while ($row_bro = Database::fetch_array($res_bros)) {
1607
                $list[] = $row_bro;
1608
            }
1609
1610
            return $list;
1611
        }
1612
1613
        return array();
@@ 1622-1649 (lines=28) @@
1619
     * @param    integer $id Item ID
1620
     * @return    array    A list of all the "brother items" (or an empty array on failure)
1621
     */
1622
    public function get_brother_items($id)
1623
    {
1624
        $course_id = api_get_course_int_id();
1625
        if ($this->debug > 0) {
1626
            error_log('New LP - In learnpath::get_brother_items('.$id.')', 0);
1627
        }
1628
1629
        if (empty($id) || $id != strval(intval($id))) {
1630
            return array();
1631
        }
1632
1633
        $lp_item = Database::get_course_table(TABLE_LP_ITEM);
1634
        $sql_parent = "SELECT * FROM $lp_item WHERE c_id = $course_id AND id = $id";
1635
        $res_parent = Database::query($sql_parent);
1636
        if (Database::num_rows($res_parent) > 0) {
1637
            $row_parent = Database::fetch_array($res_parent);
1638
            $parent = $row_parent['parent_item_id'];
1639
            $sql_bros = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND parent_item_id = $parent
1640
                         ORDER BY display_order";
1641
            $res_bros = Database::query($sql_bros);
1642
            $list = [];
1643
            while ($row_bro = Database::fetch_array($res_bros)) {
1644
                $list[] = $row_bro;
1645
            }
1646
            return $list;
1647
        }
1648
        return [];
1649
    }
1650
1651
    /**
1652
     * Get the specific prefix index terms of this learning path