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