Code Duplication    Length = 20-27 lines in 3 locations

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

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