Added Service Catalog and Reports Handler - Refs BT#12077

pull/2487/head
José Loguercio 9 years ago
parent 633b276403
commit 073df113a1
  1. 3
      .htaccess
  2. 4
      plugin/buycourses/lang/spanish.php
  3. 75
      plugin/buycourses/src/buy_course_plugin.class.php
  4. 2
      plugin/buycourses/src/configuration.php
  5. 2
      plugin/buycourses/src/course_catalog.php
  6. 89
      plugin/buycourses/src/service_catalog.php
  7. 39
      plugin/buycourses/src/service_information.php
  8. 6
      plugin/buycourses/src/service_sales_report.php
  9. 2
      plugin/buycourses/src/session_catalog.php
  10. 3
      plugin/buycourses/uploads/services/images/.gitignore
  11. 56
      plugin/buycourses/view/catalog.tpl
  12. 80
      plugin/buycourses/view/service_information.tpl
  13. 20
      plugin/buycourses/view/service_sales_report.tpl

@ -53,5 +53,8 @@ RewriteRule ^main/exercice/(.*)$ main/exercise/$1 [QSA,L]
# Support old URLs using the newscorm folder rather than lp
RewriteRule ^main/newscorm/(.*)$ main/lp/$1 [QSA,L]
# service Information
RewriteRule ^service/(\d{1,})$ plugin/buycourses/src/service_information.php?service_id=$1 [L]
# Deny access
RewriteRule ^(tests|.git) - [F,L,NC]

@ -39,7 +39,7 @@ $strings['Buyer'] = "Comprador";
$strings['BankTransfer'] = "Transferencia Bancaria";
$strings['SaleInfo'] = "Información de la venta";
$strings['SaleStatusPending'] = "Venta pendiente";
$strings['SaleStatusCanceled'] = "Venta cancelada";
$strings['SaleStatusCancelled'] = "Venta cancelada";
$strings['SaleStatusCompleted'] = "Venta completada";
$strings['PayoutStatusPending'] = "Pago pendiente";
$strings['PayoutStatusCanceled'] = "Pago cancelado";
@ -143,3 +143,5 @@ $strings['ServiceInformation'] = "Información del servicio";
$strings['EditService'] = "Editar servicio";
$strings['ServiceAdded'] = "Servicio agregado";
$strings['ServiceEdited'] = "Servicio editado";
$strings['ServiceSaleInfo'] = "Información del servicio";
$strings['ListOfServicesOnSale'] = "Lista de servicios a la venta";

@ -38,6 +38,9 @@ class BuyCoursesPlugin extends Plugin
const SERVICE_STATUS_PENDING = 0;
const SERVICE_STATUS_COMPLETED = 1;
const SERVICE_STATUS_CANCELLED = -1;
const SERVICE_TYPE_USER = 1;
const SERVICE_TYPE_COURSE = 2;
const SERVICE_TYPE_SESSION = 3;
/**
*
@ -1699,7 +1702,7 @@ class BuyCoursesPlugin extends Plugin
);
if ($return) {
$img = str_replace('data:image/png;base64,', '', $service['cropResult']);
$img = str_replace('data:image/png;base64,', '', $service['picture_crop_image_base_64']);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = api_get_path(SYS_PLUGIN_PATH).'buycourses/uploads/services/images/simg-'.$return.'.png';
@ -1725,9 +1728,8 @@ class BuyCoursesPlugin extends Plugin
public function updateService($service, $id)
{
$servicesTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SERVICES);
if (!empty($service['cropResult'])) {
$img = str_replace('data:image/png;base64,', '', $service['cropResult']);
if (!empty($service['picture_crop_image_base_64'])) {
$img = str_replace('data:image/png;base64,', '', $service['picture_crop_image_base_64']);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = api_get_path(SYS_PLUGIN_PATH).'buycourses/uploads/services/images/simg-'.$id.'.png';
@ -1889,6 +1891,7 @@ class BuyCoursesPlugin extends Plugin
$hot = "count(ss.service_id) as hot, ";
$conditions = ['ORDER' => 'hot DESC', 'LIMIT' => '6'];
$groupBy = "GROUP BY ss.service_id";
"clean_teacher_files.php";
}
$innerJoins = "INNER JOIN $servicesTable s ON ss.service_id = s.id $groupBy";
@ -2002,4 +2005,68 @@ class BuyCoursesPlugin extends Plugin
return true;
}
/**
* Lists current service details
* @param string $name Optional. The name filter
* @param int $min Optional. The minimum price filter
* @param int $max Optional. The maximum price filter
* @param int $appliesTo Optional.
* @return array
*/
public function getCatalogServiceList($name = null, $min = 0, $max = 0, $appliesTo = '')
{
$servicesTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SERVICES);
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$whereConditions = [
's.id <> ? ' => 0
];
if (!empty($name)) {
$whereConditions['AND s.name LIKE %?%'] = $name;
}
if (!empty($min)) {
$whereConditions['AND s.price >= ?'] = $min;
}
if (!empty($max)) {
$whereConditions['AND s.price <= ?'] = $max;
}
if (!$appliesTo == '') {
$whereConditions['AND s.applies_to = ?'] = $appliesTo;
}
$innerJoins = "INNER JOIN $userTable u ON s.owner_id = u.id";
$currency = $this->getSelectedCurrency();
$isoCode = $currency['iso_code'];
$return = Database::select(
"s.*, '$isoCode' as currency, u.firstname, u.lastname",
"$servicesTable s $innerJoins",
['WHERE' => $whereConditions]
);
$services = [];
foreach ($return as $index => $service) {
$services[$index]['id'] = $service['id'];
$services[$index]['name'] = $service['name'];
$services[$index]['description'] = $service['description'];
$services[$index]['price'] = $service['price'];
$services[$index]['currency'] = $service['currency'];
$services[$index]['duration_days'] = $service['duration_days'];
$services[$index]['applies_to'] = $service['applies_to'];
$services[$index]['owner_id'] = $service['owner_id'];
$services[$index]['owner_name'] = api_get_person_name($service['firstname'], $service['lastname']);
$services[$index]['visibility'] = $service['visibility'];
$services[$index]['image'] = api_get_path(WEB_PLUGIN_PATH).'buycourses/uploads/services/images/'.$service['image'];
$services[$index]['video_url'] = $service['video_url'];
$services[$index]['service_information'] = $service['service_information'];
}
return $services;
}
}

@ -24,7 +24,7 @@ $courses = $plugin->getCoursesForConfiguration();
// breadcrumbs
$interbreadcrumb[] = [
'url' => api_get_path(WEB_PLUGIN_PATH) . 'buycourses/index.php',
'name' => $plugin->get_lang('Home')
'name' => $plugin->get_lang('plugin_title')
];
$templateName = $plugin->get_lang('AvailableCourses');

@ -12,6 +12,7 @@ require_once __DIR__.'/../../../main/inc/global.inc.php';
$plugin = BuyCoursesPlugin::create();
$includeSessions = $plugin->get('include_sessions') === 'true';
$includeServices = $plugin->get('include_services') === 'true';
$nameFilter = null;
$minFilter = 0;
@ -68,6 +69,7 @@ $tpl->assign('search_filter_form', $form->returnForm());
$tpl->assign('showing_courses', true);
$tpl->assign('courses', $courseList);
$tpl->assign('sessions_are_included', $includeSessions);
$tpl->assign('services_are_included', $includeServices);
$content = $tpl->fetch('buycourses/view/catalog.tpl');

@ -0,0 +1,89 @@
<?php
/**
* List of services
* @package chamilo.plugin.buycourses
*/
/**
* Initialization
*/
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
$plugin = BuyCoursesPlugin::create();
$includeSessions = $plugin->get('include_sessions') === 'true';
$includeServices = $plugin->get('include_services') === 'true';
$nameFilter = null;
$minFilter = 0;
$maxFilter = 0;
$appliesToFilter = '';
$form = new FormValidator('search_filter_form', 'get', null, null, [], FormValidator::LAYOUT_INLINE);
if ($form->validate()) {
$formValues = $form->getSubmitValues();
$nameFilter = isset($formValues['name']) ? $formValues['name'] : null;
$minFilter = isset($formValues['min']) ? $formValues['min'] : 0;
$maxFilter = isset($formValues['max']) ? $formValues['max'] : 0;
$appliesToFilter = isset($formValues['applies_to']) ? $formValues['applies_to'] : '';
}
$form->addHeader($plugin->get_lang('SearchFilter'));
$form->addText('name', $plugin->get_lang('ServiceName'), false);
$form->addElement(
'number',
'min',
$plugin->get_lang('MinimumPrice'),
['step' => '0.01', 'min' => '0']
);
$form->addElement(
'number',
'max',
$plugin->get_lang('MaximumPrice'),
['step' => '0.01', 'min' => '0']
);
$appliesToOptions = [
'' => get_lang('Any'),
0 => get_lang('None'),
1 => get_lang('User'),
2 => get_lang('Course'),
3 => get_lang('Session')
];
$form->addSelect('applies_to', $plugin->get_lang('AppliesTo'), $appliesToOptions);
$form->addHtml('<hr>');
$form->addButtonFilter(get_lang('Search'));
$serviceList = $plugin->getCatalogServiceList($nameFilter, $minFilter, $maxFilter, $appliesToFilter);
//View
if (api_is_platform_admin()) {
$interbreadcrumb[] = [
'url' => 'configuration.php',
'name' => $plugin->get_lang('AvailableCoursesConfiguration')
];
$interbreadcrumb[] = [
'url' => 'paymentsetup.php',
'name' => $plugin->get_lang('PaymentsConfiguration')
];
} else {
$interbreadcrumb[] = [
'url' => '../index.php',
'name' => $plugin->get_lang('UserPanel')
];
}
$templateName = $plugin->get_lang('ListOfServicesOnSale');
$tpl = new Template($templateName);
$tpl->assign('search_filter_form', $form->returnForm());
$tpl->assign('showing_services', true);
$tpl->assign('services', $serviceList);
$tpl->assign('sessions_are_included', $includeSessions);
$tpl->assign('services_are_included', $includeServices);
$content = $tpl->fetch('buycourses/view/catalog.tpl');
$tpl->assign('header', $templateName);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -0,0 +1,39 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Service information page
* Show information about a service (for custom purposes)
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
* @package chamilo.buycourses_plugin
*/
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
$serviceId = isset($_GET['service_id']) ? intval($_GET['service_id']) : false;
$plugin = BuyCoursesPlugin::create();
$includeServices = $plugin->get('include_services') === 'true';
if (!$includeServices) {
api_not_allowed(true);
}
$service = $plugin->getServices($serviceId);
if (!$service['id']) {
api_not_allowed(true);
}
$template = new Template(false);
$template->assign('pageUrl', api_get_path(WEB_PATH) . "service/{$serviceId}/information/");
$template->assign('service', $service);
$template->assign('essence', Essence\Essence::instance());
$content = $template->fetch('buycourses/view/service_information.tpl');
$template->assign('content', $content);
$template->display_one_col_template();

@ -17,7 +17,6 @@ $plugin = BuyCoursesPlugin::create();
$paypalEnable = $plugin->get('paypal_enable');
$commissionsEnable = $plugin->get('commissions_enable');
$includeServices = $plugin->get('include_services');
$servicesOnly = $plugin->get('show_services_only');
$saleStatuses = $plugin->getServiceSaleStatuses();
$paymentTypes = $plugin->getPaymentTypes();
@ -41,9 +40,7 @@ foreach ($servicesSales as $sale) {
'price' => $sale['price'],
'service_type' => $sale['service']['applies_to'],
'service_name' => $sale['service']['name'],
'complete_user_name' => $sale['buyer']['name'],
'recurring_payment' => $sale['recurring_payment'],
'payment_type' => $paymentTypes[$sale['payment_type']]
'complete_user_name' => $sale['buyer']['name']
];
}
@ -85,7 +82,6 @@ if ($commissionsEnable == 'true') {
}
$template->assign('form', $form->returnForm());
$template->assign('showing_services', true);
$template->assign('show_services_only', $servicesOnly);
$template->assign('services_are_included', $includeServices);
$template->assign('sale_list', $serviceSaleList);
$template->assign('sale_status_cancelled', BuyCoursesPlugin::SERVICE_STATUS_CANCELLED);

@ -12,6 +12,7 @@ require_once __DIR__.'/../../../main/inc/global.inc.php';
$plugin = BuyCoursesPlugin::create();
$includeSessions = $plugin->get('include_sessions') === 'true';
$includeServices = $plugin->get('include_services') === 'true';
if (!$includeSessions) {
api_not_allowed(true);
@ -66,6 +67,7 @@ $templateName = $plugin->get_lang('CourseListOnSale');
$template = new Template($templateName);
$template->assign('search_filter_form', $form->returnForm());
$template->assign('sessions_are_included', $includeSessions);
$template->assign('services_are_included', $includeServices);
$template->assign('showing_sessions', true);
$template->assign('sessions', $sessionList);

@ -9,6 +9,11 @@
<li id="buy-sessions-tab" class="{{ showing_sessions ? 'active' : '' }}" role="presentation">
<a href="session_catalog.php" aria-controls="buy-sessions" role="tab">{{ 'Sessions'|get_lang }}</a>
</li>
{% if services_are_included %}
<li id="buy-services-tab" class="{{ showing_services ? 'active' : '' }}" role="presentation">
<a href="service_catalog.php" aria-controls="buy-services" role="tab">{{ 'Services'|get_plugin_lang('BuyCoursesPlugin') }}</a>
</li>
{% endif %}
</ul>
{% endif %}
@ -104,6 +109,57 @@
</div>
{% endfor %}
{% endif %}
{% if showing_services %}
{% for service in services %}
<div class="col-md-4 col-sm-6">
<div class="items-course">
<div class="items-course-image">
<a href="{{ _p.web }}service/{{ service.id }}"><img alt="{{ service.name }}" class="img-responsive" src="{{ service.image }}"></a>
</div>
<div class="items-course-info">
<h4 class="title">
<a title="{{ service.name }}" href="{{ _p.web }}service/{{ service.id }}" >
{{ service.name }}
</a>
</h4>
<ul class="list-unstyled">
<li><em class="fa fa-clock-o"></em> {{ 'Duration'|get_plugin_lang('BuyCoursesPlugin') }} : {{ service.duration_days == 0 ? 'NoLimit' | get_lang : service.duration_days ~ ' ' ~ 'Days' | get_lang }}</li>
{% if service.applies_to == 0 %}
<li><em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'None' | get_lang }}</li>
{% elseif service.applies_to == 1 %}
<li><em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'User' | get_lang }}</li>
{% elseif service.applies_to == 2 %}
<li><em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Course' | get_lang }}</li>
{% elseif service.applies_to == 3 %}
<li><em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Session' | get_lang }}</li>
{% elseif service.applies_to == 4 %}
<li><em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'SubscriptionPackage' | get_plugin_lang('BuyCoursesPlugin') }}</li>
{% endif %}
<li><em class="fa fa-user"></em> {{ service.owner_name }}</li>
</ul>
<p class="text-right">
<span class="label label-primary">
{{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }}
</span>
</p>
<div class="toolbar">
<a class="btn btn-info btn-block btn-sm" title="" href="{{ _p.web }}service/{{ service.id }}">
<em class="fa fa-info-circle"></em> {{ 'ServiceInformation'|get_plugin_lang('BuyCoursesPlugin') }}
</a>
<a class="btn btn-success btn-block btn-sm" title="" href="{{ _p.web_plugin ~ 'buycourses/src/service_process.php?' ~ {'i': service.id, 't': service.applies_to}|url_encode() }}">
{% if service.allow_trial %}
<em class="fa fa-shopping-cart"></em> {{ 'TryItNowFree'|get_plugin_lang('BuyCoursesPlugin') }}
{% else %}
<em class="fa fa-shopping-cart"></em> {{ 'Buy'|get_plugin_lang('BuyCoursesPlugin') }}
{% endif %}
</a>
</div>
</div>
</div>
</div>
{% endfor %}
{% endif %}
</div>
</div>
</div>

@ -0,0 +1,80 @@
<link rel="stylesheet" type="text/css" href="{{ _p.web_plugin ~ 'buycourses/resources/css/style.css' }}"/>
<div id="service-information">
<div class="row">
<div class="col-xs-12">
<h3 class="text-uppercase buy-courses-title-color">{{ service.name }}</h3>
</div>
{% if service.video_url %}
<div class="col-sm-6 col-md-7 col-xs-12">
<div class="embed-responsive embed-responsive-16by9">
{{ essence.replace(service.video_url) }}
</div>
</div>
{% endif %}
<div class="{{ service.video_url ? 'col-sm-6 col-md-5 col-xs-12' : 'col-sm-12 col-xs-12' }}">
<div class="block">
<div class="panel panel-default">
<div class="panel-heading">
<h4>{{ "Description"|get_lang }}</h4>
</div>
<div class="panel-body">
<p><em class="fa fa-flag-o"></em> <b>{{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }}</b> :
{% if service.applies_to == 1 %}
{{ 'User' | get_lang }}
{% elseif service.applies_to == 2 %}
{{ 'Course' | get_lang }}
{% elseif service.applies_to == 3 %}
{{ 'Session' | get_lang }}
{% endif %}
</p>
<p><em class="fa fa-money"></em> <b>{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}</b> : {{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }}</p>
<p><em class="fa fa-align-justify"></em> <b>{{ 'Details' | get_lang }}</b> : {{ service.description }}</p>
<div class="text-right" style="padding-bottom: 20px;">
<a href="{{ _p.web_plugin ~ 'buycourses/src/service_process.php?t=4&i=' ~ service.id }}" class="btn btn-success btn-lg">
<em class="fa fa-shopping-cart"></em> {{ 'Buy'|get_plugin_lang('BuyCoursesPlugin') }}
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</br>
</br>
<div class="row info-course">
<div class="col-xs-12 col-md-7">
<div class="panel panel-default">
<div class="panel-heading">
<h4>{{ 'ServiceInformation'|get_plugin_lang('BuyCoursesPlugin') }}</h4>
</div>
<div class="panel-body">
{{ service.service_information }}
</div>
</div>
</div>
<div class="col-xs-12 col-md-5">
<div class="panel panel-default social-share">
<div class="panel-heading">
<h4>{{ "ShareWithYourFriends"|get_lang }}</h4>
</div>
<div class="panel-body">
<div class="icons-social text-center">
<a href="https://www.facebook.com/sharer/sharer.php?{{ {'u': pageUrl}|url_encode }}" target="_blank" class="btn bnt-link btn-lg">
<em class="fa fa-facebook fa-2x"></em>
</a>
<a href="https://twitter.com/home?{{ {'status': session.getName() ~ ' ' ~ pageUrl}|url_encode }}" target="_blank" class="btn bnt-link btn-lg">
<em class="fa fa-twitter fa-2x"></em>
</a>
<a href="https://www.linkedin.com/shareArticle?{{ {'mini': 'true', 'url': pageUrl, 'title': session.getName() }|url_encode }}" target="_blank" class="btn bnt-link btn-lg">
<em class="fa fa-linkedin fa-2x"></em>
</a>
</div>
</div>
</div>
</div>
</div>
</div>

@ -1,7 +1,19 @@
<link rel="stylesheet" type="text/css" href="../resources/css/style.css"/>
<script type="text/javascript" src="../resources/js/modals.js"></script>
<ul class="nav nav-tabs buy-courses-sessions-tabs" role="tablist">
<li id="buy-courses-sessions-tab" class="" role="presentation">
<a href="sales_report.php" aria-controls="buy-courses_sessions" role="tab">{{ 'CourseSessionBlock'|get_lang }}</a>
</li>
<li id="buy-services-tab" class="active" role="presentation">
<a href="service_sales_report.php" aria-controls="buy-services" role="tab">{{ 'Services'|get_plugin_lang('BuyCoursesPlugin') }}</a>
</li>
</ul>
</br>
</br>
<div class="row">
<div class="col-md-3 col-sm-12 col-xs-12">
<h4><b>{{ 'Filter' | get_lang }}</b></h4>
{{ form }}
</div>
<div class="col-md-9 col-sm-12 col-xs-12">
@ -14,7 +26,6 @@
<th class="text-center">{{ 'OrderStatus'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'OrderDate'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-right">{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'Renewable'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'ServiceSaleInfo'|get_plugin_lang('BuyCoursesPlugin') }}</th>
</tr>
</thead>
@ -34,13 +45,6 @@
</td>
<td class="text-center">{{ sale.date }}</td>
<td class="text-right">{{ sale.currency ~ ' ' ~ sale.price }}</td>
{% if sale.recurring_payment == 0 %}
<td class="text-center">{{ 'No' | get_lang }}</td>
{% else %}
<td class="text-center">
<a id="renewable_info" tag="{{ sale.id }}" name="r_{{ sale.id }}" class="btn btn-warning btn-sm">{{ 'Info' | get_lang }}</a>
</td>
{% endif %}
<td class="text-center">
<a id="service_sale_info" tag="{{ sale.id }}" name="s_{{ sale.id }}" class="btn btn-info btn-sm">{{ 'Info' | get_lang }}</a>
</td>

Loading…
Cancel
Save