course_catalog.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * List of courses.
  5. *
  6. * @package chamilo.plugin.buycourses
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../../../main/inc/global.inc.php';
  10. $plugin = BuyCoursesPlugin::create();
  11. $includeSessions = $plugin->get('include_sessions') === 'true';
  12. $includeServices = $plugin->get('include_services') === 'true';
  13. $nameFilter = '';
  14. $minFilter = 0;
  15. $maxFilter = 0;
  16. $form = new FormValidator(
  17. 'search_filter_form',
  18. 'get',
  19. null,
  20. null,
  21. [],
  22. FormValidator::LAYOUT_INLINE
  23. );
  24. if ($form->validate()) {
  25. $formValues = $form->getSubmitValues();
  26. $nameFilter = isset($formValues['name']) ? $formValues['name'] : null;
  27. $minFilter = isset($formValues['min']) ? $formValues['min'] : 0;
  28. $maxFilter = isset($formValues['max']) ? $formValues['max'] : 0;
  29. }
  30. $form->addHeader($plugin->get_lang('SearchFilter'));
  31. $form->addText('name', get_lang('CourseName'), false);
  32. $form->addElement(
  33. 'number',
  34. 'min',
  35. $plugin->get_lang('MinimumPrice'),
  36. ['step' => '0.01', 'min' => '0']
  37. );
  38. $form->addElement(
  39. 'number',
  40. 'max',
  41. $plugin->get_lang('MaximumPrice'),
  42. ['step' => '0.01', 'min' => '0']
  43. );
  44. $form->addHtml('<hr>');
  45. $form->addButtonFilter(get_lang('Search'));
  46. $pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
  47. $currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
  48. $first = $pageSize * ($currentPage - 1);
  49. $courseList = $plugin->getCatalogCourseList($first, $pageSize, $nameFilter, $minFilter, $maxFilter);
  50. $totalItems = $plugin->getCatalogCourseList($first, $pageSize, $nameFilter, $minFilter, $maxFilter, 'count');
  51. $pagesCount = ceil($totalItems / $pageSize);
  52. $url = api_get_self().'?';
  53. $pagination = Display::getPagination($url, $currentPage, $pagesCount, $totalItems);
  54. // View
  55. if (api_is_platform_admin()) {
  56. $interbreadcrumb[] = [
  57. 'url' => 'list.php',
  58. 'name' => $plugin->get_lang('AvailableCoursesConfiguration'),
  59. ];
  60. $interbreadcrumb[] = [
  61. 'url' => 'paymentsetup.php',
  62. 'name' => $plugin->get_lang('PaymentsConfiguration'),
  63. ];
  64. } else {
  65. $interbreadcrumb[] = [
  66. 'url' => 'course_panel.php',
  67. 'name' => get_lang('TabsDashboard'),
  68. ];
  69. }
  70. $templateName = $plugin->get_lang('CourseListOnSale');
  71. $tpl = new Template($templateName);
  72. $tpl->assign('search_filter_form', $form->returnForm());
  73. $tpl->assign('showing_courses', true);
  74. $tpl->assign('courses', $courseList);
  75. $tpl->assign('sessions_are_included', $includeSessions);
  76. $tpl->assign('services_are_included', $includeServices);
  77. $tpl->assign('pagination', $pagination);
  78. $content = $tpl->fetch('buycourses/view/catalog.tpl');
  79. $tpl->assign('header', $templateName);
  80. $tpl->assign('content', $content);
  81. $tpl->display_one_col_template();