From 68af9cd421086a7d0a121036168dd7effb84fd15 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Sep 2019 12:44:02 +0200 Subject: [PATCH] Minor - merge with 1.11.x files added --- main/inc/lib/SortableTableFromArray.php | 88 +++++++ main/inc/lib/SortableTableFromArrayConfig.php | 112 +++++++++ plugin/buycourses/src/list.php | 79 ++++++ plugin/buycourses/src/list_service.php | 70 ++++++ plugin/buycourses/src/list_session.php | 82 ++++++ plugin/buycourses/view/list.tpl | 233 ++++++++++++++++++ 6 files changed, 664 insertions(+) create mode 100644 main/inc/lib/SortableTableFromArray.php create mode 100644 main/inc/lib/SortableTableFromArrayConfig.php create mode 100644 plugin/buycourses/src/list.php create mode 100644 plugin/buycourses/src/list_service.php create mode 100644 plugin/buycourses/src/list_session.php create mode 100644 plugin/buycourses/view/list.tpl diff --git a/main/inc/lib/SortableTableFromArray.php b/main/inc/lib/SortableTableFromArray.php new file mode 100644 index 0000000000..a666417586 --- /dev/null +++ b/main/inc/lib/SortableTableFromArray.php @@ -0,0 +1,88 @@ +table_data = $table_data; + } + + /** + * Get table data to show on current page. + * + * @see SortableTable#get_table_data + */ + public function get_table_data( + $from = 1, + $per_page = null, + $column = null, + $direction = null, + $sort = true + ) { + if ($sort) { + $content = TableSort::sort_table( + $this->table_data, + $this->column, + $this->direction === 'ASC' ? SORT_ASC : SORT_DESC + ); + } else { + $content = $this->table_data; + } + + return array_slice($content, $from, $this->per_page); + } + + /** + * Get total number of items. + * + * @see SortableTable#get_total_number_of_items + */ + public function get_total_number_of_items() + { + if (isset($this->total_number_of_items) && !empty($this->total_number_of_items)) { + return $this->total_number_of_items; + } else { + if (!empty($this->table_data)) { + return count($this->table_data); + } + + return 0; + } + } +} diff --git a/main/inc/lib/SortableTableFromArrayConfig.php b/main/inc/lib/SortableTableFromArrayConfig.php new file mode 100644 index 0000000000..bba9bf7b54 --- /dev/null +++ b/main/inc/lib/SortableTableFromArrayConfig.php @@ -0,0 +1,112 @@ +column_show = $column_show; + $this->column_order = $column_order; + $this->doc_filter = $doc_filter; + + parent::__construct( + $tableName, + null, + null, + $column, + $itemsPerPage, + $direction + ); + $this->table_data = $data; + } + + /** + * Get table data to show on current page. + * + * @see SortableTable#get_table_data + */ + public function get_table_data( + $from = 1, + $per_page = null, + $column = null, + $direction = null, + $sort = true + ) { + $table = TableSort::sort_table_config( + $this->table_data, + $this->column, + $this->direction === 'ASC' ? SORT_ASC : SORT_DESC, + $this->column_show, + $this->column_order, + SORT_REGULAR, + $this->doc_filter + ); + +// return array_slice($table, $from, $this->per_page); + return $table; + } + + /** + * Get total number of items. + * + * @see SortableTable#get_total_number_of_items + */ + public function get_total_number_of_items() + { + if (isset($this->total_number_of_items) && !empty($this->total_number_of_items)) { + return $this->total_number_of_items; + } else { + if (!empty($this->table_data)) { + return count($this->table_data); + } + + return 0; + } + } +} diff --git a/plugin/buycourses/src/list.php b/plugin/buycourses/src/list.php new file mode 100644 index 0000000000..e404b8a836 --- /dev/null +++ b/plugin/buycourses/src/list.php @@ -0,0 +1,79 @@ +get('include_sessions') === 'true'; +$includeServices = $plugin->get('include_services') === 'true'; +$taxEnable = $plugin->get('tax_enable') === 'true'; + +api_protect_admin_script(true); + +Display::addFlash( + Display::return_message( + get_lang('Info').' - '.$plugin->get_lang('CoursesInSessionsDoesntDisplayHere'), + 'info' + ) +); + +$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE; +$type = isset($_GET['type']) ? (int) $_GET['type'] : BuyCoursesPlugin::PRODUCT_TYPE_COURSE; +$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1; +$first = $pageSize * ($currentPage - 1); + +$qb = $plugin->getCourseList($first, $pageSize); +$query = $qb->getQuery(); +$courses = new Paginator($query, $fetchJoinCollection = true); +foreach ($courses as $course) { + $item = $plugin->getItemByProduct($course->getId(), BuyCoursesPlugin::PRODUCT_TYPE_COURSE); + $course->buyCourseData = []; + if ($item !== false) { + $course->buyCourseData = $item; + } +} + +$totalItems = count($courses); +$pagesCount = ceil($totalItems / $pageSize); + +$url = api_get_self().'?type='.$type; +$pagination = Display::getPagination($url, $currentPage, $pagesCount, $totalItems); + +// breadcrumbs +$interbreadcrumb[] = [ + 'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php', + 'name' => $plugin->get_lang('plugin_title'), +]; + +$templateName = $plugin->get_lang('AvailableCourses'); + +$tpl = new Template($templateName); + +$tpl->assign('product_type_course', BuyCoursesPlugin::PRODUCT_TYPE_COURSE); +$tpl->assign('product_type_session', BuyCoursesPlugin::PRODUCT_TYPE_SESSION); +$tpl->assign('courses', $courses); +$tpl->assign('course_pagination', $pagination); +$tpl->assign('sessions_are_included', $includeSession); +$tpl->assign('services_are_included', $includeServices); +$tpl->assign('tax_enable', $taxEnable); + +if ($taxEnable) { + $globalParameters = $plugin->getGlobalParameters(); + $tpl->assign('global_tax_perc', $globalParameters['global_tax_perc']); + $tpl->assign('tax_applies_to', $globalParameters['tax_applies_to']); + $tpl->assign('tax_name', $globalParameters['tax_name']); +} + +$content = $tpl->fetch('buycourses/view/list.tpl'); + +$tpl->assign('header', $templateName); +$tpl->assign('content', $content); +$tpl->display_one_col_template(); diff --git a/plugin/buycourses/src/list_service.php b/plugin/buycourses/src/list_service.php new file mode 100644 index 0000000000..488d87b563 --- /dev/null +++ b/plugin/buycourses/src/list_service.php @@ -0,0 +1,70 @@ +get('include_sessions') === 'true'; +$includeServices = $plugin->get('include_services') === 'true'; +if (!$includeServices) { + api_not_allowed(true); +} + +$taxEnable = $plugin->get('tax_enable') === 'true'; + +api_protect_admin_script(true); + +Display::addFlash( + Display::return_message( + get_lang('Info').' - '.$plugin->get_lang('CoursesInSessionsDoesntDisplayHere'), + 'info' + ) +); + +$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE; +$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1; +$first = $pageSize * ($currentPage - 1); + +$services = $plugin->getServices($first, $pageSize); +$totalItems = $plugin->getServices(null, null, 'count'); +$pagesCount = ceil($totalItems / $pageSize); + +$url = api_get_self().'?'; +$pagination = Display::getPagination($url, $currentPage, $pagesCount, $totalItems); + +// breadcrumbs +$interbreadcrumb[] = [ + 'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php', + 'name' => $plugin->get_lang('plugin_title'), +]; + +$templateName = $plugin->get_lang('AvailableCourses'); + +$tpl = new Template($templateName); + +$tpl->assign('product_type_course', BuyCoursesPlugin::PRODUCT_TYPE_COURSE); +$tpl->assign('product_type_session', BuyCoursesPlugin::PRODUCT_TYPE_SESSION); +$tpl->assign('sessions_are_included', $includeSession); +$tpl->assign('services_are_included', $includeServices); +$tpl->assign('tax_enable', $taxEnable); +$tpl->assign('services', $services); +$tpl->assign('service_pagination', $pagination); + +if ($taxEnable) { + $globalParameters = $plugin->getGlobalParameters(); + $tpl->assign('global_tax_perc', $globalParameters['global_tax_perc']); + $tpl->assign('tax_applies_to', $globalParameters['tax_applies_to']); + $tpl->assign('tax_name', $globalParameters['tax_name']); +} + +$content = $tpl->fetch('buycourses/view/list.tpl'); + +$tpl->assign('header', $templateName); +$tpl->assign('content', $content); +$tpl->display_one_col_template(); diff --git a/plugin/buycourses/src/list_session.php b/plugin/buycourses/src/list_session.php new file mode 100644 index 0000000000..6a280027ea --- /dev/null +++ b/plugin/buycourses/src/list_session.php @@ -0,0 +1,82 @@ +get('include_sessions') === 'true'; + +if (!$includeSession) { + api_not_allowed(true); +} +$includeServices = $plugin->get('include_services') === 'true'; +$taxEnable = $plugin->get('tax_enable') === 'true'; + +api_protect_admin_script(true); + +Display::addFlash( + Display::return_message( + get_lang('Info').' - '.$plugin->get_lang('CoursesInSessionsDoesntDisplayHere'), + 'info' + ) +); + +$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE; +$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1; +$first = $pageSize * ($currentPage - 1); + +// breadcrumbs +$interbreadcrumb[] = [ + 'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php', + 'name' => $plugin->get_lang('plugin_title'), +]; + +$templateName = $plugin->get_lang('AvailableCourses'); + +$tpl = new Template($templateName); + +$tpl->assign('product_type_course', BuyCoursesPlugin::PRODUCT_TYPE_COURSE); +$tpl->assign('product_type_session', BuyCoursesPlugin::PRODUCT_TYPE_SESSION); +$tpl->assign('sessions_are_included', $includeSession); +$tpl->assign('services_are_included', $includeServices); +$tpl->assign('tax_enable', $taxEnable); + +$query = CoursesAndSessionsCatalog::browseSessions(null, ['start' => $first, 'length' => $pageSize], true); +$sessions = new Paginator($query, $fetchJoinCollection = true); +foreach ($sessions as $session) { + $item = $plugin->getItemByProduct($session->getId(), BuyCoursesPlugin::PRODUCT_TYPE_SESSION); + $session->buyCourseData = []; + if ($item !== false) { + $session->buyCourseData = $item; + } +} + +$totalItems = count($sessions); +$pagesCount = ceil($totalItems / $pageSize); + +$url = api_get_self().'?type='.BuyCoursesPlugin::PRODUCT_TYPE_SESSION; +$pagination = Display::getPagination($url, $currentPage, $pagesCount, $totalItems); + +$tpl->assign('sessions', $sessions); +$tpl->assign('session_pagination', $pagination); + +if ($taxEnable) { + $globalParameters = $plugin->getGlobalParameters(); + $tpl->assign('global_tax_perc', $globalParameters['global_tax_perc']); + $tpl->assign('tax_applies_to', $globalParameters['tax_applies_to']); + $tpl->assign('tax_name', $globalParameters['tax_name']); +} + +$content = $tpl->fetch('buycourses/view/list.tpl'); + +$tpl->assign('header', $templateName); +$tpl->assign('content', $content); +$tpl->display_one_col_template(); diff --git a/plugin/buycourses/view/list.tpl b/plugin/buycourses/view/list.tpl new file mode 100644 index 0000000000..fe8f2aef28 --- /dev/null +++ b/plugin/buycourses/view/list.tpl @@ -0,0 +1,233 @@ + + +{% if sessions_are_included or services_are_included %} + +{% endif %} + +
+
+
+ + + + + + + + {% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 2) %} + + {% endif %} + + + + + {% for item in courses %} + + + + + + {% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 2) %} + + {% endif %} + + + {% endfor %} + +
{{ 'Title'|get_lang }}{{ 'OfficialCode'|get_lang }}{{ 'VisibleInCatalog'|get_plugin_lang('BuyCoursesPlugin') }}{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}{{ tax_name }}{{ 'Options'|get_lang }}
+ {% if item.visibility == 0 %} + {{ 'CourseVisibilityClosed'|get_lang }} + {% elseif item.visibility == 1 %} + {{ 'Private'|get_lang }} + {% elseif item.visibility == 2 %} + {{ 'OpenToThePlatform'|get_lang }} + {% elseif item.visibility == 3 %} + {{ 'OpenToTheWorld'|get_lang }} + {% elseif item.visibility == 4 %} + {{ 'CourseVisibilityHidden'|get_lang }} + {% endif %} + + {{ item.title }} + + {{ item.code }} + + {{ item.code }} + + {% if item.buyCourseData %} + + {% else %} + + {% endif %} + + {{ item.buyCourseData.price_formatted }} + + {{ item.buyCourseData.tax_perc_show }} % + + + {{ 'Configure'|get_lang }} + +
+
+ {{ course_pagination }} +
+ + {% if sessions_are_included %} +
+
+ + + + + + + + + {% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 3) %} + + {% endif %} + + + + + {% for item in sessions %} + + + + + + + {% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 3) %} + + {% endif %} + + + {% endfor %} + +
{{ 'Title'|get_lang }}{{ 'StartDate'|get_lang }}{{ 'EndDate'|get_lang }}{{ 'VisibleInCatalog'|get_plugin_lang('BuyCoursesPlugin') }}{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}{{ tax_name }}{{ 'Options'|get_lang }}
+ {{ item.name }} + + {{ item.displayStartDate | api_convert_and_format_date(6)}} + + {{ item.displayEndDate |api_convert_and_format_date(6)}} + + {% if item.buyCourseData %} + + {% else %} + + {% endif %} + + {{ item.buyCourseData.price_formatted }} + + {{ item.buyCourseData.tax_perc_show }} % + + + + {{ 'Configure'|get_lang }} + +
+ {{ session_pagination }} +
+
+ {% endif %} + {% if services_are_included %} +
+
+ + {{ 'NewService'| get_plugin_lang('BuyCoursesPlugin') }} + +
+
+ + + + + + + + + + {% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 4) %} + + {% endif %} + + + + + {% for item in services %} + + + + + + + + {% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 4) %} + + {% endif %} + + + {% endfor %} + +
{{ 'Service'|get_plugin_lang('BuyCoursesPlugin') }}{{ 'Description'|get_lang }}{{ 'Duration'|get_plugin_lang('BuyCoursesPlugin') }}{{ 'VisibleInCatalog'|get_plugin_lang('BuyCoursesPlugin') }}{{ 'Owner'|get_lang }}{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}{{ tax_name }}{{ 'Options'|get_lang }}
+ {{ item.name }} + + {{ item.description }} + + {% if item.duration_days == 0 %} + {{ 'NoLimit'|get_lang }} + {% else %} + {{ item.duration_days }} {{ 'Days'|get_lang }} + {% endif %} + + {% if item.visibility == 1 %} + + {% else %} + + {% endif %} + + {{ item.owner_name }} + + {{ item.price_formatted }} + + {% if item.tax_perc is null %} + {{ global_tax_perc }} % + {% else %} + {{ item.tax_perc }} % + {% endif %} + + + {{ 'Edit'|get_lang }} + +
+
+ {{ service_pagination }} +
+ {% endif %} +