diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index 5f2d48c41d..5cfd538fdc 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -1127,4 +1127,40 @@ class BuyCoursesPlugin extends Plugin ); } + /** + * Get a list of sales by the user + * @param string $term The search term + * @return array The sale list. Otherwise return false + */ + public function getSaleListByUser($term) + { + $term = trim($term); + + if (empty($term)) { + return []; + } + + $saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE); + $currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY); + $userTable = Database::get_main_table(TABLE_MAIN_USER); + + $innerJoins = " + INNER JOIN $currencyTable c ON s.currency_id = c.id + INNER JOIN $userTable u ON s.user_id = u.id + "; + + return Database::select( + ['c.iso_code', 'u.firstname', 'u.lastname', 's.*'], + "$saleTable s $innerJoins", + [ + 'where' => [ + 'u.username LIKE %?% OR ' => $term, + 'u.lastname LIKE %?% OR ' => $term, + 'u.firstname LIKE %?%' => $term + ], + 'order' => 'id DESC' + ] + ); + } + } diff --git a/plugin/buycourses/src/sales_report.php b/plugin/buycourses/src/sales_report.php index 3aa02b040e..0854d5bfcf 100644 --- a/plugin/buycourses/src/sales_report.php +++ b/plugin/buycourses/src/sales_report.php @@ -61,24 +61,54 @@ if (isset($_GET['order'])) { $productTypes = $plugin->getProductTypes(); $saleStatuses = $plugin->getSaleStatuses(); + +$selectedFilterType = '0'; $selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::SALE_STATUS_PENDING; $selectedSale = isset($_GET['sale']) ? intval($_GET['sale']) : 0; +$searchTerm = ''; $form = new FormValidator('search', 'get'); if ($form->validate()) { + $selectedFilterType = $form->getSubmitValue('filter_type'); $selectedStatus = $form->getSubmitValue('status'); + $searchTerm = $form->getSubmitValue('user'); if ($selectedStatus === false) { $selectedStatus = BuyCoursesPlugin::SALE_STATUS_PENDING; } + + if ($selectedFilterType === false) { + $selectedFilterType = '0'; + } } +$form->addRadio( + 'filter_type', + get_lang('FilterBy'), + [$plugin->get_lang('ByStatus'), $plugin->get_lang('ByUser')] +); +$form->addHtml('