Code Duplication    Length = 20-27 lines in 3 locations

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

@@ 851-870 (lines=20) @@
848
     * @param int $paymentType The payment type to filter (default : Paypal)
849
     * @return array The sale list. Otherwise return false
850
     */
851
    public function getSaleListByPaymentType($paymentType = self::PAYMENT_TYPE_PAYPAL)
852
    {
853
        $saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
854
        $currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
855
        $userTable = Database::get_main_table(TABLE_MAIN_USER);
856
857
        $innerJoins = "
858
            INNER JOIN $currencyTable c ON s.currency_id = c.id
859
            INNER JOIN $userTable u ON s.user_id = u.id
860
        ";
861
862
        return Database::select(
863
            ['c.iso_code', 'u.firstname', 'u.lastname', 's.*'],
864
            "$saleTable s $innerJoins",
865
            [
866
                'where' => ['s.payment_type = ? AND s.status = ?' => [intval($paymentType), self::SALE_STATUS_COMPLETED]],
867
                'order' => 'id DESC'
868
            ]
869
        );
870
    }
871
872
    /**
873
     * Get currency data by ID
@@ 972-991 (lines=20) @@
969
     * @param int $status The status to filter
970
     * @return array The sale list. Otherwise return false
971
     */
972
    public function getSaleListByStatus($status = self::SALE_STATUS_PENDING)
973
    {
974
        $saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
975
        $currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
976
        $userTable = Database::get_main_table(TABLE_MAIN_USER);
977
978
        $innerJoins = "
979
            INNER JOIN $currencyTable c ON s.currency_id = c.id
980
            INNER JOIN $userTable u ON s.user_id = u.id
981
        ";
982
983
        return Database::select(
984
            ['c.iso_code', 'u.firstname', 'u.lastname', 's.*'],
985
            "$saleTable s $innerJoins",
986
            [
987
                'where' => ['s.status = ?' => intval($status)],
988
                'order' => 'id DESC'
989
            ]
990
        );
991
    }
992
993
    /**
994
     * Get the statuses for sales
@@ 1233-1259 (lines=27) @@
1230
     * @param int $id The user id
1231
     * @return array The sale list. Otherwise return false
1232
     */
1233
    public function getSaleListByUserId($id)
1234
    {
1235
1236
        if (empty($id)) {
1237
            return [];
1238
        }
1239
1240
        $saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
1241
        $currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
1242
        $userTable = Database::get_main_table(TABLE_MAIN_USER);
1243
1244
        $innerJoins = "
1245
            INNER JOIN $currencyTable c ON s.currency_id = c.id
1246
            INNER JOIN $userTable u ON s.user_id = u.id
1247
        ";
1248
1249
        return Database::select(
1250
            ['c.iso_code', 'u.firstname', 'u.lastname', 's.*'],
1251
            "$saleTable s $innerJoins",
1252
            [
1253
                'where' => [
1254
                    'u.id = ? AND s.status = ?' => [intval($id), BuyCoursesPlugin::SALE_STATUS_COMPLETED]
1255
                ],
1256
                'order' => 'id DESC'
1257
            ]
1258
        );
1259
    }
1260
1261
    /**
1262
     * Convert the course info to array with necessary course data for save item