Minor - merge with 1.11.x files added

pull/3006/head
Julio Montoya 5 years ago
parent b3ebd5d221
commit 68af9cd421
  1. 88
      main/inc/lib/SortableTableFromArray.php
  2. 112
      main/inc/lib/SortableTableFromArrayConfig.php
  3. 79
      plugin/buycourses/src/list.php
  4. 70
      plugin/buycourses/src/list_service.php
  5. 82
      plugin/buycourses/src/list_session.php
  6. 233
      plugin/buycourses/view/list.tpl

@ -0,0 +1,88 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Sortable table which can be used for data available in an array.
*
* @package chamilo.library
*/
class SortableTableFromArray extends SortableTable
{
/**
* The array containing all data for this table.
*/
public $table_data;
/**
* Constructor.
*
* @param array $table_data
* @param int $default_column
* @param int $default_items_per_page
* @param string $tableName
* @param string $get_total_number_function
* @param string $tableId
*/
public function __construct(
$table_data,
$default_column = 1,
$default_items_per_page = 20,
$tableName = 'tablename',
$get_total_number_function = null,
$tableId = ''
) {
parent:: __construct(
$tableName,
$get_total_number_function,
null,
$default_column,
$default_items_per_page,
null,
$tableId
);
$this->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;
}
}
}

@ -0,0 +1,112 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Sortable table which can be used for data available in an array.
*
* Is a variation of SortableTableFromArray because we add 2 new arrays $column_show and $column_order
* $column_show is an array that lets us decide which are going to be the columns to show
* $column_order is an array that lets us decide the ordering of the columns
* i.e: $column_header=array('a','b','c','d','e'); $column_order=array(1,2,5,4,5);
* These means that the 3th column (letter "c") will be sort like the order we use in the 5th column
*
* @package chamilo.library
*/
class SortableTableFromArrayConfig extends SortableTable
{
/**
* The array containing the columns that will be show
* i.e $column_show=array('1','0','0'); we will show only the 1st column.
*/
private $column_show;
/**
* The array containing the real sort column
* $column_order=array('1''4','3','4');
* The 2nd column will be order like the 4th column.
*/
private $column_order;
private $doc_filter;
/**
* Constructor.
*
* @param array $data All the information of the table
* @param int $column Default column that will be use in the sorts functions
* @param int $itemsPerPage quantity of pages that we are going to see
* @param string $tableName Name of the table
* @param array $column_show An array with binary values 1: we show the column 2: we don't show it
* @param array $column_order an array of integers that let us decide how the columns are going to be sort
* @param string $direction
* @param bool $doc_filter special modification to fix the document name order
*/
public function __construct(
$data,
$column = 1,
$itemsPerPage = 20,
$tableName = 'tablename',
$column_show = [],
$column_order = [],
$direction = 'ASC',
$doc_filter = false
) {
$this->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;
}
}
}

@ -0,0 +1,79 @@
<?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';
$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();

@ -0,0 +1,70 @@
<?php
/* For license terms, see /license.txt */
/**
* Configuration script for the Buy Courses plugin.
*
* @package chamilo.plugin.buycourses
*/
$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();

@ -0,0 +1,82 @@
<?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();

@ -0,0 +1,233 @@
<link rel="stylesheet" type="text/css" href="../resources/css/style.css"/>
{% if sessions_are_included or services_are_included %}
<ul class="nav nav-tabs buy-courses-tabs" role="tablist">
<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" 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" class="{{ services ? 'active' : '' }}">
<a href="{{ _p.web_plugin ~ 'buycourses/src/list_service.php' }}">
{{ 'Services'|get_plugin_lang('BuyCoursesPlugin') }}
</a>
</li>
{% endif %}
</ul>
{% endif %}
<div class="tab-content">
<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>
<tr>
<th>{{ 'Title'|get_lang }}</th>
<th class="text-center">{{ 'OfficialCode'|get_lang }}</th>
<th class="text-center">{{ 'VisibleInCatalog'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-right" width="200">{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}</th>
{% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 2) %}
<th class="text-center" width="100">{{ tax_name }}</th>
{% endif %}
<th class="text-right">{{ 'Options'|get_lang }}</th>
</tr>
</thead>
<tbody>
{% for item in courses %}
<tr data-item="{{ item.id }}" data-type="course">
<td>
{% if item.visibility == 0 %}
<img src="{{ 'bullet_red.png'|icon() }}" alt="{{ 'CourseVisibilityClosed'|get_lang }}"
title="{{ 'CourseVisibilityClosed'|get_lang }}">
{% elseif item.visibility == 1 %}
<img src="{{ 'bullet_orange.png'|icon() }}" alt="{{ 'Private'|get_lang }}"
title="{{ 'Private'|get_lang }}">
{% elseif item.visibility == 2 %}
<img src="{{ 'bullet_green.png'|icon() }}" alt="{{ 'OpenToThePlatform'|get_lang }}"
title="{{ 'OpenToThePlatform'|get_lang }}">
{% elseif item.visibility == 3 %}
<img src="{{ 'bullet_blue.png'|icon() }}" alt="{{ 'OpenToTheWorld'|get_lang }}"
title="{{ 'OpenToTheWorld'|get_lang }}">
{% 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.path ~ item.code~ '/index.php' }}">
{{ item.title }}
</a>
<span class="label label-info">{{ item.code }}</span>
</td>
<td class="text-center">
{{ item.code }}
</td>
<td class="text-center">
{% 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.buyCourseData.price_formatted }}
</td>
{% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 2) %}
<td class="text-center">
{{ item.buyCourseData.tax_perc_show }} %
</td>
{% endif %}
<td class="text-right">
<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>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{{ course_pagination }}
</div>
{% if sessions_are_included %}
<div role="tabpanel" class="tab-pane {{ sessions ? 'fade in active' : '' }} " id="sessions">
<div class="table-responsive">
<table id="session_table" class="table">
<thead>
<tr>
<th>{{ 'Title'|get_lang }}</th>
<th class="text-center">{{ 'StartDate'|get_lang }}</th>
<th class="text-center">{{ 'EndDate'|get_lang }}</th>
<th class="text-center">{{ 'VisibleInCatalog'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-right">{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}</th>
{% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 3) %}
<th class="text-center" width="100">{{ tax_name }}</th>
{% endif %}
<th class="text-right">{{ 'Options'|get_lang }}</th>
</tr>
</thead>
<tbody>
{% for item in sessions %}
<tr data-item="{{ item.id }}" data-type="session">
<td>
<a href="{{ _p.web_main ~ 'session/index.php?' ~ {'session_id': item.id}|url_encode() }}">{{ item.name }}</a>
</td>
<td class="text-center">
{{ item.displayStartDate | api_convert_and_format_date(6)}}
</td>
<td class="text-center">
{{ item.displayEndDate |api_convert_and_format_date(6)}}
</td>
<td class="text-center">
{% 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.buyCourseData.price_formatted }}
</td>
{% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 3) %}
<td class="text-center">
{{ item.buyCourseData.tax_perc_show }} %
</td>
{% endif %}
<td class="text-right">
<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 }}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{{ session_pagination }}
</div>
</div>
{% endif %}
{% if services_are_included %}
<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') }}
</a>
</br>
</br>
<table id="services_table" class="table">
<thead>
<tr>
<th>{{ 'Service'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th>{{ 'Description'|get_lang }}</th>
<th class="text-center">{{ 'Duration'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'VisibleInCatalog'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'Owner'|get_lang }}</th>
<th class="text-right">{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}</th>
{% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 4) %}
<th class="text-center" width="100">{{ tax_name }}</th>
{% endif %}
<th class="text-right">{{ 'Options'|get_lang }}</th>
</tr>
</thead>
<tbody>
{% for item in services %}
<tr data-item="{{ item.id }}" data-type="service">
<td>
{{ item.name }}
</td>
<td>
{{ item.description }}
</td>
<td class="text-center">
{% if item.duration_days == 0 %}
{{ 'NoLimit'|get_lang }}
{% else %}
{{ item.duration_days }} {{ 'Days'|get_lang }}
{% endif %}
</td>
<td class="text-center">
{% if item.visibility == 1 %}
<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-center">
{{ item.owner_name }}
</td>
<td class="text-right" width="200">
{{ item.price_formatted }}
</td>
{% if tax_enable and (tax_applies_to == 1 or tax_applies_to == 4) %}
<td class="text-center">
{% if item.tax_perc is null %}
{{ global_tax_perc }} %
{% else %}
{{ item.tax_perc }} %
{% endif %}
</td>
{% endif %}
<td class="text-right">
<a href="{{ _p.web_plugin ~ 'buycourses/src/services_edit.php?' ~ {'id': item.id}|url_encode() }}"
class="btn btn-info btn-sm">
<em class="fa fa-wrench fa-fw"></em> {{ 'Edit'|get_lang }}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{{ service_pagination }}
</div>
{% endif %}
</div>
Loading…
Cancel
Save