list.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * Configuration script for the Buy Courses plugin.
  5. *
  6. * @package chamilo.plugin.buycourses
  7. */
  8. use Doctrine\ORM\Tools\Pagination\Paginator;
  9. $cidReset = true;
  10. require_once __DIR__.'/../../../main/inc/global.inc.php';
  11. $plugin = BuyCoursesPlugin::create();
  12. $includeSession = $plugin->get('include_sessions') === 'true';
  13. $includeServices = $plugin->get('include_services') === 'true';
  14. $taxEnable = $plugin->get('tax_enable') === 'true';
  15. api_protect_admin_script(true);
  16. Display::addFlash(
  17. Display::return_message(
  18. get_lang('Information').' - '.$plugin->get_lang('CoursesInSessionsDoesntDisplayHere'),
  19. 'info'
  20. )
  21. );
  22. $pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
  23. $type = isset($_GET['type']) ? (int) $_GET['type'] : BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
  24. $currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
  25. $first = $pageSize * ($currentPage - 1);
  26. $qb = $plugin->getCourseList($first, $pageSize);
  27. $query = $qb->getQuery();
  28. $courses = new Paginator($query, $fetchJoinCollection = true);
  29. foreach ($courses as $course) {
  30. $item = $plugin->getItemByProduct($course->getId(), BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
  31. $course->buyCourseData = [];
  32. if ($item !== false) {
  33. $course->buyCourseData = $item;
  34. }
  35. }
  36. $totalItems = count($courses);
  37. $pagesCount = ceil($totalItems / $pageSize);
  38. $url = api_get_self().'?type='.$type;
  39. $pagination = Display::getPagination($url, $currentPage, $pagesCount, $totalItems);
  40. // breadcrumbs
  41. $interbreadcrumb[] = [
  42. 'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php',
  43. 'name' => $plugin->get_lang('plugin_title'),
  44. ];
  45. $templateName = $plugin->get_lang('AvailableCourses');
  46. $tpl = new Template($templateName);
  47. $tpl->assign('product_type_course', BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
  48. $tpl->assign('product_type_session', BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
  49. $tpl->assign('courses', $courses);
  50. $tpl->assign('course_pagination', $pagination);
  51. $tpl->assign('sessions_are_included', $includeSession);
  52. $tpl->assign('services_are_included', $includeServices);
  53. $tpl->assign('tax_enable', $taxEnable);
  54. if ($taxEnable) {
  55. $globalParameters = $plugin->getGlobalParameters();
  56. $tpl->assign('global_tax_perc', $globalParameters['global_tax_perc']);
  57. $tpl->assign('tax_applies_to', $globalParameters['tax_applies_to']);
  58. $tpl->assign('tax_name', $globalParameters['tax_name']);
  59. }
  60. $content = $tpl->fetch('buycourses/view/list.tpl');
  61. $tpl->assign('header', $templateName);
  62. $tpl->assign('content', $content);
  63. $tpl->display_one_col_template();