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