Explorar o código

WIP plugin buy course: Add course/session/service pagination #2987

By default the page size is 2, just for tests.
Julio Montoya %!s(int64=5) %!d(string=hai) anos
pai
achega
819ec58f0f

+ 32 - 23
main/inc/lib/CoursesAndSessionsCatalog.class.php

@@ -566,46 +566,55 @@ class CoursesAndSessionsCatalog
      *
      * @return array The session list
      */
-    public static function browseSessions($date = null, $limit = [])
+    public static function browseSessions($date = null, $limit = [], $returnQueryBuilder = false)
     {
-        $em = Database::getManager();
         $urlId = api_get_current_access_url_id();
 
-        $sql = "SELECT s.id FROM session s 
-                INNER JOIN access_url_rel_session ars
-                ON s.id = ars.session_id
-                WHERE 
-                      s.nbr_courses > 0 AND 
-                      ars.access_url_id = $urlId";
+        $dql = "SELECT s
+                FROM ChamiloCoreBundle:Session s
+                WHERE EXISTS 
+                    (
+                        SELECT url.sessionId FROM ChamiloCoreBundle:AccessUrlRelSession url 
+                        WHERE url.sessionId = s.id AND url.accessUrlId = $urlId
+                    ) AND
+                    s.nbrCourses > 0
+                ";
 
+        //('$date' BETWEEN s.accessStartDate AND s.accessEndDate)
         if (!is_null($date)) {
             $date = Database::escape_string($date);
-            $sql .= "
+            $dql .= "
                 AND (
-                    ('$date' BETWEEN DATE(s.access_start_date) AND DATE(s.access_end_date)) OR 
-                    (s.access_end_date IS NULL) OR 
+                    (s.accessEndDate IS NULL) 
+                    OR
+                    ( 
+                    s.accessStartDate IS NOT NULL AND  
+                    s.accessEndDate IS NOT NULL AND
+                    s.accessStartDate >= '$date' AND s.accessEndDate <= '$date')                    
+                    OR 
                     (
-                        s.access_start_date IS NULL AND 
-                        s.access_end_date IS NOT NULL AND 
-                        DATE(s.access_end_date) >= '$date'
+                        s.accessStartDate IS NULL AND 
+                        s.accessEndDate IS NOT NULL AND 
+                        s.accessStartDate >= '$date'
                     )
                 )
             ";
         }
 
+        $qb = Database::getManager()->createQuery($dql);
+
         if (!empty($limit)) {
-            $limit['start'] = (int) $limit['start'];
-            $limit['length'] = (int) $limit['length'];
-            $sql .= "LIMIT {$limit['start']}, {$limit['length']} ";
+            $qb
+                ->setFirstResult($limit['start'])
+                ->setMaxResults($limit['length'])
+            ;
         }
 
-        $list = Database::store_result(Database::query($sql), 'ASSOC');
-        $sessions = [];
-        foreach ($list as $sessionData) {
-            $sessions[] = $em->find('ChamiloCoreBundle:Session', $sessionData['id']);
+        if ($returnQueryBuilder) {
+            return $qb;
         }
 
-        return $sessions;
+        return $qb->getResult();
     }
 
     /**
@@ -683,7 +692,7 @@ class CoursesAndSessionsCatalog
                 'frt.fieldId = f.id'
             )
             ->where(
-                $qb->expr()->like('t.tag', ":tag")
+                $qb->expr()->like('t.tag', ':tag')
             )
             ->andWhere(
                 $qb->expr()->eq('f.extraFieldType', ExtraField::COURSE_FIELD_TYPE)

+ 21 - 3
main/inc/lib/database.lib.php

@@ -555,7 +555,7 @@ class Database
      * @param mixed  $columns     array (or string if only one column)
      * @param string $table_name
      * @param array  $conditions
-     * @param string $type_result
+     * @param string $type_result all|first|count
      * @param string $option
      * @param bool   $debug
      *
@@ -569,26 +569,44 @@ class Database
         $option = 'ASSOC',
         $debug = false
     ) {
+        if ($type_result === 'count') {
+            $conditions['LIMIT'] = null;
+            $conditions['limit'] = null;
+        }
+
         $conditions = self::parse_conditions($conditions);
 
         //@todo we could do a describe here to check the columns ...
         if (is_array($columns)) {
             $clean_columns = implode(',', $columns);
         } else {
-            if ($columns == '*') {
+            if ($columns === '*') {
                 $clean_columns = '*';
             } else {
                 $clean_columns = (string) $columns;
             }
         }
 
+        if ($type_result === 'count') {
+            $clean_columns = ' count(*) count ';
+        }
+
         $sql = "SELECT $clean_columns FROM $table_name $conditions";
         if ($debug) {
             var_dump($sql);
         }
         $result = self::query($sql);
-        $array = [];
 
+        if ($type_result === 'count') {
+            $row = self::fetch_array($result, $option);
+            if ($row) {
+                return (int) $row['count'];
+            }
+
+            return 0;
+        }
+
+        $array = [];
         if ($type_result === 'all') {
             while ($row = self::fetch_array($result, $option)) {
                 if (isset($row['id'])) {

+ 28 - 0
main/inc/lib/display.lib.php

@@ -2449,6 +2449,34 @@ class Display
         return $html;
     }
 
+    /**
+     * @param $url
+     * @param $currentPage
+     * @param $pagesCount
+     * @param $totalItems
+     *
+     * @return string
+     */
+    public static function getPagination($url, $currentPage, $pagesCount, $totalItems)
+    {
+        $pagination = '';
+        if ($totalItems > 1) {
+            $pagination .= '<ul class="pagination">';
+            for ($i = 0; $i < $pagesCount; $i++) {
+                $newPage = $i + 1;
+                if ($currentPage == $newPage) {
+                    $pagination .= '<li class="active"><a href="'.$url.'&page='.$newPage.'">'.$newPage.'</a></li>';
+                } else {
+                    $pagination .= '<li><a href="'.$url.'&page='.$newPage.'">'.$newPage.'</a></li>';
+                }
+            }
+            $pagination .= '</ul>';
+        }
+
+        return $pagination;
+    }
+
+
     /**
      * Adds a message in the queue.
      *

+ 31 - 42
plugin/buycourses/src/buy_course_plugin.class.php

@@ -56,6 +56,7 @@ class BuyCoursesPlugin extends Plugin
     const TAX_APPLIES_TO_ONLY_COURSE = 2;
     const TAX_APPLIES_TO_ONLY_SESSION = 3;
     const TAX_APPLIES_TO_ONLY_SERVICES = 4;
+    const PAGINATION_PAGE_SIZE = 2;
 
     public $isAdminPlugin = true;
 
@@ -352,7 +353,8 @@ class BuyCoursesPlugin extends Plugin
     public function returnBuyCourseButton($productId, $productType)
     {
         $productId = (int) $productId;
-        $url = api_get_path(WEB_PLUGIN_PATH).'buycourses/src/process.php?i='.$productId.'&t='.Security::remove_XSS($productType);
+        $productType = (int) $productType;
+        $url = api_get_path(WEB_PLUGIN_PATH).'buycourses/src/process.php?i='.$productId.'&t='.$productType;
         $html = '<a class="btn btn-success btn-sm" title="'.$this->get_lang('Buy').'" href="'.$url.'">'.
             Display::returnFontAwesomeIcon('shopping-cart').'</a>';
 
@@ -394,7 +396,7 @@ class BuyCoursesPlugin extends Plugin
      *
      * @param int $selectedId The currency Id
      */
-    public function selectCurrency($selectedId)
+    public function saveCurrency($selectedId)
     {
         $currencyTable = Database::get_main_table(
             self::TABLE_CURRENCY
@@ -560,42 +562,25 @@ class BuyCoursesPlugin extends Plugin
      *
      * @return array
      */
-    public function getCoursesForConfiguration()
+    public function getCourseList($first, $maxResults)
     {
-        $courses = $this->getCourses();
+        return $this->getCourses($first, $maxResults);
 
         if (empty($courses)) {
             return [];
         }
 
-        $configurationCourses = [];
         $currency = $this->getSelectedCurrency();
 
+        $courseList = [];
         foreach ($courses as $course) {
-            $configurationCourses[] = $this->getCourseForConfiguration(
+            $courseList[] = $this->getCourseForConfiguration(
                 $course,
                 $currency
             );
         }
 
-        return $configurationCourses;
-    }
-
-    /**
-     * List sessions details from the buy-session table and the session table.
-     *
-     * @return array The sessions. Otherwise return false
-     */
-    public function getSessionsForConfiguration()
-    {
-        $sessions = CoursesAndSessionsCatalog::browseSessions();
-        $currency = $this->getSelectedCurrency();
-        $items = [];
-        foreach ($sessions as $session) {
-            $items[] = $this->getSessionForConfiguration($session, $currency);
-        }
-
-        return $items;
+        return $courseList;
     }
 
     /**
@@ -2043,6 +2028,12 @@ class BuyCoursesPlugin extends Plugin
         );
     }
 
+    /**
+     * @param array $product
+     * @param int   $productType
+     *
+     * @return bool
+     */
     public function setPriceSettings(&$product, $productType)
     {
         if (empty($product)) {
@@ -2099,15 +2090,9 @@ class BuyCoursesPlugin extends Plugin
         $globalParameters = $this->getGlobalParameters();
 
         $this->setPriceSettings($service, self::TAX_APPLIES_TO_ONLY_SERVICES);
-        /*$service['tax_perc'] = $return['tax_perc'];
-        $service['price_with_tax'] = $return['total_price_formatted'];
-        $service['price_without_tax'] = $return['price_formatted'];
-        $service['tax_amount'] = $return['tax_amount_formatted'];
-        $service['tax_perc_show'] = $return['tax_perc_show'];*/
 
         $service['price_with_tax'] = $service['total_price_formatted'];
         $service['price_without_tax'] = $service['price_formatted'];
-
         $service['tax_name'] = $globalParameters['tax_name'];
         $service['tax_enable'] = $this->checkTaxEnabledInProduct(self::TAX_APPLIES_TO_ONLY_SERVICES);
         $service['owner_name'] = api_get_person_name($service['firstname'], $service['lastname']);
@@ -2121,21 +2106,27 @@ class BuyCoursesPlugin extends Plugin
      *
      * @return array
      */
-    public function getServices()
+    public function getServices($start, $end, $typeResult = 'all')
     {
         $servicesTable = Database::get_main_table(self::TABLE_SERVICES);
         $userTable = Database::get_main_table(TABLE_MAIN_USER);
 
-        $conditions = null;
-        $showData = 'all';
+        $start = (int) $start;
+        $end = (int) $end;
+
+        $conditions = ['LIMIT' => "$start, $end"];
         $innerJoins = "INNER JOIN $userTable u ON s.owner_id = u.id";
         $return = Database::select(
             's.id',
             "$servicesTable s $innerJoins",
             $conditions,
-            $showData
+            $typeResult
         );
 
+        if ($typeResult === 'count') {
+            return $return;
+        }
+
         $services = [];
         foreach ($return as $index => $service) {
             $services[$index] = $this->getService($service['id']);
@@ -2686,9 +2677,8 @@ class BuyCoursesPlugin extends Plugin
     /**
      * Filter the registered courses for show in plugin catalog.
      *
-     * @return array
      */
-    private function getCourses()
+    private function getCourses($first, $maxResults)
     {
         $em = Database::getManager();
         $urlId = api_get_current_access_url_id();
@@ -2730,11 +2720,10 @@ class BuyCoursesPlugin extends Plugin
                         ->getDQL()
                 )
             )
-            ->getQuery();
-
-        $courses = $qb->getResult();
+        ->setFirstResult($first)
+        ->setMaxResults($maxResults);
 
-        return $courses;
+        return $qb;
     }
 
     /**
@@ -2774,7 +2763,7 @@ class BuyCoursesPlugin extends Plugin
         );
 
         if ($sale['qty'] > 0) {
-            return "TMP";
+            return 'TMP';
         }
 
         // Check if user is already subscribe to session
@@ -2826,7 +2815,7 @@ class BuyCoursesPlugin extends Plugin
         );
 
         if ($sale['qty'] > 0) {
-            return "TMP";
+            return 'TMP';
         }
 
         // Check if user is already subscribe to course

+ 2 - 2
plugin/buycourses/src/configure_course.php

@@ -52,9 +52,9 @@ if ($editingCourse) {
         api_not_allowed(true);
     }
 
-    if (!$plugin->isValidCourse($course)) {
+    /*if (!$plugin->isValidCourse($course)) {
         api_not_allowed(true);
-    }
+    }*/
 
     $courseItem = $plugin->getCourseForConfiguration($course, $currency);
     $defaultBeneficiaries = [];

+ 25 - 11
plugin/buycourses/src/list.php

@@ -5,6 +5,9 @@
  *
  * @package chamilo.plugin.buycourses
  */
+
+use Doctrine\ORM\Tools\Pagination\Paginator;
+
 $cidReset = true;
 
 require_once __DIR__.'/../../../main/inc/global.inc.php';
@@ -23,7 +26,27 @@ Display::addFlash(
     )
 );
 
-$courses = $plugin->getCoursesForConfiguration();
+$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[] = [
@@ -38,20 +61,11 @@ $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 ($includeSession) {
-    $sessions = $plugin->getSessionsForConfiguration();
-    $tpl->assign('sessions', $sessions);
-}
-
-if ($includeServices) {
-    $services = $plugin->getServices();
-    $tpl->assign('services', $services);
-}
-
 if ($taxEnable) {
     $globalParameters = $plugin->getGlobalParameters();
     $tpl->assign('global_tax_perc', $globalParameters['global_tax_perc']);

+ 73 - 0
plugin/buycourses/src/list_service.php

@@ -0,0 +1,73 @@
+<?php
+/* For license terms, see /license.txt */
+/**
+ * Configuration script for the Buy Courses plugin.
+ *
+ * @package chamilo.plugin.buycourses
+ */
+
+use Doctrine\ORM\Tools\Pagination\Paginator;
+
+$cidReset = true;
+
+require_once __DIR__.'/../../../main/inc/global.inc.php';
+
+$plugin = BuyCoursesPlugin::create();
+$includeSession = $plugin->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();

+ 83 - 0
plugin/buycourses/src/list_session.php

@@ -0,0 +1,83 @@
+<?php
+/* For license terms, see /license.txt */
+/**
+ * Configuration script for the Buy Courses plugin.
+ *
+ * @package chamilo.plugin.buycourses
+ */
+
+use Doctrine\ORM\Tools\Pagination\Paginator;
+
+$cidReset = true;
+
+require_once __DIR__.'/../../../main/inc/global.inc.php';
+
+$plugin = BuyCoursesPlugin::create();
+$includeSession = $plugin->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();

+ 1 - 1
plugin/buycourses/src/paymentsetup.php

@@ -37,7 +37,7 @@ $globalSettingForm = new FormValidator('currency');
 if ($globalSettingForm->validate()) {
     $globalSettingFormValues = $globalSettingForm->getSubmitValues();
 
-    $plugin->selectCurrency($globalSettingFormValues['currency']);
+    $plugin->saveCurrency($globalSettingFormValues['currency']);
     unset($globalSettingFormValues['currency']);
     $plugin->saveGlobalParameters($globalSettingFormValues);
 

+ 39 - 36
plugin/buycourses/view/list.tpl

@@ -2,18 +2,20 @@
 
 {% if sessions_are_included or services_are_included %}
     <ul class="nav nav-tabs buy-courses-tabs" role="tablist">
-        <li role="presentation" class="active">
-            <a href="#courses" aria-controls="courses" role="tab" data-toggle="tab">{{ 'Courses'|get_lang }}</a>
+        <li role="presentation" class="{{ courses ? 'active' : '' }}">
+            <a href="{{ _p.web_plugin ~ 'buycourses/src/list.php' }}" >
+                {{ 'Courses'|get_lang }}
+            </a>
         </li>
         {% if sessions_are_included %}
-        <li role="presentation">
-            <a href="#sessions" aria-controls="sessions" role="tab" data-toggle="tab">{{ 'Sessions'|get_lang }}</a>
+        <li role="presentation" class="{{ sessions ? 'active' : '' }}">
+            <a href="{{ _p.web_plugin ~ 'buycourses/src/list_session.php' }}" >
+                {{ 'Sessions'|get_lang }}</a>
         </li>
         {% endif %}
         {% if services_are_included %}
-            <li role="presentation">
-                <a href="#services" aria-controls="services" role="tab"
-                   data-toggle="tab">
+            <li role="presentation" class="{{ services ? 'active' : '' }}">
+                <a href="{{ _p.web_plugin ~ 'buycourses/src/list_service.php' }}">
                     {{ 'Services'|get_plugin_lang('BuyCoursesPlugin') }}
                 </a>
             </li>
@@ -22,7 +24,7 @@
 {% endif %}
 
 <div class="tab-content">
-    <div role="tabpanel" class="tab-pane fade in active" id="courses">
+    <div role="tabpanel" class="tab-pane {{ courses ? 'fade in active' : '' }} " id="courses">
         <div class="table-responsive">
             <table id="courses_table" class="table table-striped table-hover">
                 <thead>
@@ -37,57 +39,55 @@
                     <th class="text-right">{{ 'Options'|get_lang }}</th>
                 </tr>
                 </thead>
-
                 <tbody>
                 {% for item in courses %}
-                    <tr data-item="{{ item.course_id }}" data-type="course">
+                    <tr data-item="{{ item.id }}" data-type="course">
                         <td>
-                            {% if item.course_visibility == 0 %}
+                            {% if item.visibility == 0 %}
                                 <img src="{{ 'bullet_red.png'|icon() }}" alt="{{ 'CourseVisibilityClosed'|get_lang }}"
                                      title="{{ 'CourseVisibilityClosed'|get_lang }}">
-                            {% elseif item.course_visibility == 1 %}
+                            {% elseif item.visibility == 1 %}
                                 <img src="{{ 'bullet_orange.png'|icon() }}" alt="{{ 'Private'|get_lang }}"
                                      title="{{ 'Private'|get_lang }}">
-                            {% elseif item.course_visibility == 2 %}
+                            {% elseif item.visibility == 2 %}
                                 <img src="{{ 'bullet_green.png'|icon() }}" alt="{{ 'OpenToThePlatform'|get_lang }}"
                                      title="{{ 'OpenToThePlatform'|get_lang }}">
-                            {% elseif item.course_visibility == 3 %}
+                            {% elseif item.visibility == 3 %}
                                 <img src="{{ 'bullet_blue.png'|icon() }}" alt="{{ 'OpenToTheWorld'|get_lang }}"
                                      title="{{ 'OpenToTheWorld'|get_lang }}">
-                            {% elseif item.course_visibility == 4 %}
+                            {% elseif item.visibility == 4 %}
                                 <img src="{{ 'bullet_grey.png'|icon() }}" alt="{{ 'CourseVisibilityHidden'|get_lang }}"
                                      title="{{ 'CourseVisibilityHidden'|get_lang }}">
                             {% endif %}
-
-                            <a href="{{ _p.web_course ~ item.course_directory ~ '/index.php' }}">
-                                {{ item.course_title }}
+                            <a href="{{ _p.web_course ~ item.path ~ item.code~ '/index.php' }}">
+                                {{ item.title }}
                             </a>
-                            <span class="label label-info">{{ item.course_visual_code }}</span>
+                            <span class="label label-info">{{ item.code }}</span>
                         </td>
                         <td class="text-center">
-                            {{ item.course_code }}
+                            {{ item.code }}
                         </td>
                         <td class="text-center">
-                            {% if item.visible %}
+                            {% if item.buyCourseData %}
                                 <em class="fa fa-fw fa-check-square-o"></em>
                             {% else %}
                                 <em class="fa fa-fw fa-square-o"></em>
                             {% endif %}
                         </td>
                         <td width="200" class="text-right">
-                            {{ "#{item.price} #{tem.currency ?: item.currency}" }}
+                            {{ "#{item.buyCourseData.price} #{item.buyCourseData.currency ?: item.buyCourseData.currency}" }}
                         </td>
                         {% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 2) %}
                             <td class="text-center">
                                 {% if item.tax_perc is null %}
                                     {{ global_tax_perc }} %
                                 {% else %}
-                                    {{ item.tax_perc }} %
+                                    {{ item.buyCourseData.tax_perc }} %
                                 {% endif %}
                             </td>
                         {% endif %}
                         <td class="text-right">
-                            <a href="{{ _p.web_plugin ~ 'buycourses/src/configure_course.php?' ~ {'id': item.course_id, 'type':product_type_course}|url_encode() }}"
+                            <a href="{{ _p.web_plugin ~ 'buycourses/src/configure_course.php?' ~ {'id': item.id, 'type':product_type_course}|url_encode() }}"
                                class="btn btn-info btn-sm">
                                 <em class="fa fa-wrench fa-fw"></em> {{ 'Configure'|get_lang }}
                             </a>
@@ -97,12 +97,13 @@
                 </tbody>
             </table>
         </div>
+        {{ course_pagination }}
     </div>
 
     {% if sessions_are_included %}
-        <div role="tabpanel" class="tab-pane" id="sessions">
+        <div role="tabpanel" class="tab-pane {{ sessions ? 'fade in active' : '' }} " id="sessions">
             <div class="table-responsive">
-                <table id="courses_table" class="table">
+                <table id="session_table" class="table">
                     <thead>
                     <tr>
                         <th>{{ 'Title'|get_lang }}</th>
@@ -118,37 +119,37 @@
                     </thead>
                     <tbody>
                     {% for item in sessions %}
-                        <tr data-item="{{ item.session_id }}" data-type="session">
+                        <tr data-item="{{ item.id }}" data-type="session">
                             <td>
-                                <a href="{{ _p.web_main ~ 'session/index.php?' ~ {'session_id': item.session_id}|url_encode() }}">{{ item.session_name }}</a>
+                                <a href="{{ _p.web_main ~ 'session/index.php?' ~ {'session_id': item.id}|url_encode() }}">{{ item.name }}</a>
                             </td>
                             <td class="text-center">
-                                {{ item.session_display_start_date }}
+                                {{ item.displayStartDate | api_convert_and_format_date(6)}}
                             </td>
                             <td class="text-center">
-                                {{ item.session_display_end_date }}
+                                {{ item.displayEndDate |api_convert_and_format_date(6)}}
                             </td>
                             <td class="text-center">
-                                {% if item.visible %}
+                                {% if item.buyCourseData %}
                                     <em class="fa fa-fw fa-check-square-o"></em>
                                 {% else %}
                                     <em class="fa fa-fw fa-square-o"></em>
                                 {% endif %}
                             </td>
                             <td class="text-right" width="200">
-                                {{ "#{item.price} #{tem.currency ?: item.currency}" }}
+                                {{ "#{item.buyCourseData.price} #{tem.currency ?: item.buyCourseData.currency}" }}
                             </td>
                             {% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 3) %}
                                 <td class="text-center">
-                                    {% if item.tax_perc is null %}
+                                    {% if item.buyCourseData.tax_perc is null %}
                                         {{ global_tax_perc }} %
                                     {% else %}
-                                        {{ item.tax_perc }} %
+                                        {{ item.buyCourseData.tax_perc }} %
                                     {% endif %}
                                 </td>
                             {% endif %}
                             <td class="text-right">
-                                <a href="{{ _p.web_plugin ~ 'buycourses/src/configure_course.php?' ~ {'id': item.session_id, 'type': product_type_session}|url_encode() }}"
+                                <a href="{{ _p.web_plugin ~ 'buycourses/src/configure_course.php?' ~ {'id': item.id, 'type': product_type_session}|url_encode() }}"
                                    class="btn btn-info btn-sm">
                                     <em class="fa fa-wrench fa-fw"></em>
                                     {{ 'Configure'|get_lang }}
@@ -158,11 +159,12 @@
                     {% endfor %}
                     </tbody>
                 </table>
+                {{ session_pagination }}
             </div>
         </div>
     {% endif %}
     {% if services_are_included %}
-        <div role="tabpanel" class="tab-pane" id="services">
+        <div role="tabpanel" class="tab-pane {{ services ? 'fade in active' : '' }} " id="services">
             <div class="table-responsive">
                 <a href="{{ _p.web_plugin ~ 'buycourses/src/services_add.php' }}" class="btn btn-primary">
                     <em class="fa fa-cart-plus fa-fw"></em> {{ 'NewService'| get_plugin_lang('BuyCoursesPlugin') }}
@@ -233,6 +235,7 @@
                     </tbody>
                 </table>
             </div>
+            {{ service_pagination }}
         </div>
     {% endif %}
 </div>