Code Duplication    Length = 20-27 lines in 3 locations

plugin/buycourses/src/buy_course_plugin.class.php 3 locations

@@ 798-817 (lines=20) @@
795
     * @param int $paymentType The payment type to filter (default : Paypal)
796
     * @return array The sale list. Otherwise return false
797
     */
798
    public function getSaleListByPaymentType($paymentType = self::PAYMENT_TYPE_PAYPAL)
799
    {
800
        $saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
801
        $currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
802
        $userTable = Database::get_main_table(TABLE_MAIN_USER);
803
804
        $innerJoins = "
805
            INNER JOIN $currencyTable c ON s.currency_id = c.id
806
            INNER JOIN $userTable u ON s.user_id = u.id
807
        ";
808
809
        return Database::select(
810
            ['c.iso_code', 'u.firstname', 'u.lastname', 's.*'],
811
            "$saleTable s $innerJoins",
812
            [
813
                'where' => ['s.payment_type = ? AND s.status = ?' => [intval($paymentType), self::SALE_STATUS_COMPLETED]],
814
                'order' => 'id DESC'
815
            ]
816
        );
817
    }
818
819
    /**
820
     * Get currency data by ID
@@ 936-955 (lines=20) @@
933
     * @param int $status The status to filter
934
     * @return array The sale list. Otherwise return false
935
     */
936
    public function getSaleListByStatus($status = self::SALE_STATUS_PENDING)
937
    {
938
        $saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
939
        $currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
940
        $userTable = Database::get_main_table(TABLE_MAIN_USER);
941
942
        $innerJoins = "
943
            INNER JOIN $currencyTable c ON s.currency_id = c.id
944
            INNER JOIN $userTable u ON s.user_id = u.id
945
        ";
946
947
        return Database::select(
948
            ['c.iso_code', 'u.firstname', 'u.lastname', 's.*'],
949
            "$saleTable s $innerJoins",
950
            [
951
                'where' => ['s.status = ?' => intval($status)],
952
                'order' => 'id DESC'
953
            ]
954
        );
955
    }
956
957
    /**
958
     * Get the statuses for sales
@@ 1223-1249 (lines=27) @@
1220
     * @param int $id The user id
1221
     * @return array The sale list. Otherwise return false
1222
     */
1223
    public function getSaleListByUserId($id)
1224
    {
1225
1226
        if (empty($id)) {
1227
            return [];
1228
        }
1229
1230
        $saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
1231
        $currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
1232
        $userTable = Database::get_main_table(TABLE_MAIN_USER);
1233
1234
        $innerJoins = "
1235
            INNER JOIN $currencyTable c ON s.currency_id = c.id
1236
            INNER JOIN $userTable u ON s.user_id = u.id
1237
        ";
1238
1239
        return Database::select(
1240
            ['c.iso_code', 'u.firstname', 'u.lastname', 's.*'],
1241
            "$saleTable s $innerJoins",
1242
            [
1243
                'where' => [
1244
                    'u.id = ? AND s.status = ?' => [intval($id), BuyCoursesPlugin::SALE_STATUS_COMPLETED]
1245
                ],
1246
                'order' => 'id DESC'
1247
            ]
1248
        );
1249
    }
1250
1251
    /**
1252
     * Convert the course info to array with necessary course data for save item