Implement better design to grid course catalog and add a validation to BuyCourse Plugin

pull/2487/head
José Loguercio 10 years ago
parent 883ffe2c8e
commit b705b79c1e
  1. 9
      app/Resources/public/css/base.css
  2. 40
      main/inc/lib/course.lib.php
  3. 58
      main/template/default/auth/courses_categories.php
  4. 8
      main/template/default/layout/hot_course_item.tpl
  5. 1
      plugin/buycourses/lang/brazilian.php
  6. 1
      plugin/buycourses/lang/english.php
  7. 1
      plugin/buycourses/lang/french.php
  8. 1
      plugin/buycourses/lang/spanish.php
  9. 49
      plugin/buycourses/src/buy_course_plugin.class.php
  10. 6
      plugin/buycourses/src/process.php

@ -4910,9 +4910,16 @@ div#chat-remote-video video {
transition: all 0.3s ease 0s;
}
.grid-courses .items .notifications{
margin-top: 5px;
padding-top: 5px;
text-align: center;
}
.grid-courses .items .buycourses-price{
margin-top: 5px;
text-align: left;
}
.grid-courses .items .separator{
margin-top: 5px;
}
.grid-courses .items .admin-actions, .grid-courses .items .user-actions{
position: absolute;
bottom: 0px;

@ -4624,6 +4624,8 @@ class CourseManager
$stok = Security::get_existing_token();
$user_id = api_get_user_id();
foreach ($courses as $courseId) {
$course_info = api_get_course_info_by_id($courseId['c_id']);
$courseCode = $course_info['code'];
@ -4638,6 +4640,30 @@ class CourseManager
$my_course_code_list
);
$user_registerd_in_course = CourseManager::is_user_subscribed_in_course($user_id, $course_info['code']);
$user_registerd_in_course_as_teacher = CourseManager::is_course_teacher($user_id, $course_info['code']);
$user_registerd_in_course_as_student = ($user_registerd_in_course && !$user_registerd_in_course_as_teacher);
// if user registered as student
if ($user_registerd_in_course_as_student) {
$icon = '<em class="fa fa-graduation-cap"></em>';
$title = get_lang("AlreadyRegisteredToCourse");
$my_course['already_register_as'] = Display::tag(
'button',
$icon,
array('id' => 'register', 'class' => 'btn btn-default btn-sm', 'title' => $title)
);
} elseif ($user_registerd_in_course_as_teacher) {
// if user registered as teacher
$icon = '<em class="fa fa-suitcase"></em>';
$title = get_lang("YouAreATeacherOfThisCourse");
$my_course['already_register_as'] = Display::tag(
'button',
$icon,
array('id' => 'register', 'class' => 'btn btn-default btn-sm', 'title' => $title)
);
}
//Course visibility
if ($access_link && in_array('register', $access_link)) {
$my_course['register_button'] = Display::url(
@ -4662,6 +4688,20 @@ class CourseManager
array('class' => 'btn btn-danger btn-sm', 'title' => get_lang('Unreg')));
}
// start buycourse validation
// display the course price and buy button if the buycourses plugin is enabled and this course is configured
$plugin = BuyCoursesPlugin::create();
$isThisCourseInSale = $plugin->buyCoursesForGridCatalogVerificator($course_info);
if ($isThisCourseInSale) {
// set the price label
$my_course['price'] = $isThisCourseInSale['html'];
// set the Buy button instead register.
if ($isThisCourseInSale['verificator']) {
$my_course['register_button'] = $plugin->returnBuyCourseButton($course_info);
}
}
// end buycourse validation
//Description
$my_course['description_button'] = '';
/* if ($course_info['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || in_array($course_info['real_id'],

@ -130,7 +130,7 @@ $code = isset($code) ? $code : null;
<?php
$webAction = api_get_path(WEB_CODE_PATH).'auth/courses.php';
$action = (!empty($_REQUEST['action'])?Security::remove_XSS($_REQUEST['action']):'display_courses');
$action = (!empty($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']):'display_courses');
$pageLength = (!empty($_REQUEST['pageLength'])?intval($_REQUEST['pageLength']):10);
$pageCurrent = (!empty($_REQUEST['pageCurrent'])?intval($_REQUEST['pageCurrent']):1);
$form = '<form action="'.$webAction.'" method="GET" class="form-horizontal">';
@ -214,8 +214,7 @@ if ($showCourses && $action != 'display_sessions') {
$course_unsubscribe_allowed = ($course['unsubscribe'] == 1);
$count_connections = $course['count_connections'];
$creation_date = substr($course['creation_date'],0,10);
$icon_title = null;
$html = null;
// display the course bloc
$html .= '<div class="col-xs-6 col-sm-6 col-md-3"><div class="items">';
@ -223,16 +222,33 @@ if ($showCourses && $action != 'display_sessions') {
// display thumbnail
$html .= returnThumbnail($course);
$separator = '<div class="separator">&nbsp;</div>';
$subscribeButton = return_register_button($course, $stok, $code, $search_term);
// start buycourse validation
// display the course price and buy button if the buycourses plugin is enabled and this course is configured
$plugin = BuyCoursesPlugin::create();
$isThisCourseInSale = $plugin->buyCoursesForGridCatalogVerificator($course);
if ($isThisCourseInSale) {
// set the Price label
$separator = $isThisCourseInSale['html'];
// set the Buy button instead register.
if ($isThisCourseInSale['verificator']) {
$subscribeButton = $plugin->returnBuyCourseButton($course);
}
}
// end buycourse validation
// display course title and button bloc
$html .= '<div class="description">';
$html .= return_title($course);
$html .= $separator;
// display button line
$html .= '<div class="toolbar">';
$html .= '<div class="btn-group">';
// if user registered as student
$html .= return_description_button($course, $icon_title);
if ($user_registerd_in_course_as_student) {
$html .= return_already_registered_label('student');
@ -243,8 +259,6 @@ if ($showCourses && $action != 'display_sessions') {
}
} elseif ($user_registerd_in_course_as_teacher) {
// if user registered as teacher
if ($course_unsubscribe_allowed) {
$html .= return_unregister_button($course, $stok, $search_term, $code);
}
@ -254,9 +268,8 @@ if ($showCourses && $action != 'display_sessions') {
// if user not registered in the course
if (!$course_closed) {
if (!$course_private) {
if ($course_subscribe_allowed) {
$html .= return_register_button($course, $stok, $code, $search_term);
$html .= $subscribeButton;
}
}
}
@ -318,7 +331,7 @@ function returnThumbnail($course)
$html .= '<div class="author-card">';
$count = 0;
foreach ($teachers as $value) {
if ($count>2) {
if ($count > 2) {
break;
}
$name = $value['firstname'].' ' . $value['lastname'];
@ -329,7 +342,10 @@ function returnThumbnail($course)
. $name . '</a></h5></div>';
$count ++;
}
$html .= '</div></div></div>';
$html .= '</div></div>';
$html .= '<div class="user-actions">';
$html .= return_description_button($course);
$html .= '</div></div>';
return $html;
}
@ -338,6 +354,7 @@ function returnThumbnail($course)
/**
* Display the title of a course in course catalog
* @param $course
* @return string HTML string
*/
function return_title($course)
{
@ -355,9 +372,9 @@ function return_title($course)
/**
* Display the description button of a course in the course catalog
* @param $course
* @param $icon_title
* @return string HTML string
*/
function return_description_button($course, $icon_title)
function return_description_button($course)
{
$title = $course['title'];
$html = '';
@ -372,6 +389,7 @@ function return_description_button($course, $icon_title)
/**
* Display the goto course button of a course in the course catalog
* @param $course
* @return string HTML string
*/
function return_goto_button($course)
{
@ -384,17 +402,21 @@ function return_goto_button($course)
/**
* Display the already registerd text in a course in the course catalog
* @param $in_status
* @return string HTML string
*/
function return_already_registered_label($in_status)
{
$icon = Display::return_icon('teacher.png', get_lang('Teacher'), null, ICON_SIZE_TINY);
$icon = '<em class="fa fa-suitcase"></em>';
$title = get_lang("YouAreATeacherOfThisCourse");
if ($in_status == 'student') {
$icon = Display::return_icon('user.png', get_lang('Student'), null, ICON_SIZE_TINY);
$icon = '<em class="fa fa-graduation-cap"></em>';
$title = get_lang("AlreadyRegisteredToCourse");
}
$html = Display::tag(
'button',
$icon,
array('id' => 'register', 'class' => 'btn btn-default btn-sm', 'title' => get_lang("AlreadyRegisteredToCourse"))
array('id' => 'register', 'class' => 'btn btn-default btn-sm', 'title' => $title)
);
return $html;
@ -406,6 +428,7 @@ function return_already_registered_label($in_status)
* @param $stok
* @param $code
* @param $search_term
* @return html
*/
function return_register_button($course, $stok, $code, $search_term)
{
@ -420,6 +443,7 @@ function return_register_button($course, $stok, $code, $search_term)
* @param $stok
* @param $search_term
* @param $code
* @return html
*/
function return_unregister_button($course, $stok, $search_term, $code)
{

@ -9,7 +9,7 @@
<div class="cribbon"></div>
{% endif %}
<div class="black-shadow">
<div class="author-card">
<div class="author-card">
{% for teacher in item.teachers %}
{% set counter = counter + 1 %}
{% if counter <= 3 %}
@ -36,10 +36,16 @@
<div class="ranking">
{{ item.rating_html }}
</div>
{% if item.price %}
{{ item.price }}
{% else %}
<div class="separator">&nbsp;</div>
{% endif %}
<div class="toolbar">
<div class="btn-group" role="group">
{{ item.register_button }}
{{ item.unsubscribe_button }}
{{ item.already_register_as }}
</div>
</div>
</div>

@ -7,6 +7,7 @@ $strings['include_sessions'] = "Incluir sessões";
$strings['paypal_enable'] = "Ativar PayPal";
$strings['transfer_enable'] = "Permitir transferência bancária";
$strings['unregistered_users_enable'] = "Permitir que usuários anônimos";
$strings['Free'] = "GRÁTIS";
$strings['banktransfer'] = "Transferência Bancária";
$strings['SaleStatusPending'] = "Venda pendente";

@ -8,6 +8,7 @@ $strings['paypal_enable'] = "Enable PayPal";
$strings['commissions_enable'] = "Enable Commissions";
$strings['transfer_enable'] = "Enable bank transfer";
$strings['unregistered_users_enable'] = "Allow anonymous users";
$strings['Free'] = "FREE";
$strings['PaypalPayoutCommissions'] = "Paypal Payout Commissions";
$strings['MyPayouts'] = "My payments";

@ -8,6 +8,7 @@ $strings['paypal_enable'] = "Activer PayPal";
$strings['commissions_enable'] = "Activer commissions";
$strings['transfer_enable'] = "Activer les transferts bancaires";
$strings['unregistered_users_enable'] = "Permettre l'accès aux utilisateurs non enregistrés sur la plateforme";
$strings['Free'] = "GRAIUIT";
$strings['PaypalPayoutCommissions'] = "Commissions PayPal Payouts";
$strings['MyPayouts'] = "Mes paiements";

@ -8,6 +8,7 @@ $strings['paypal_enable'] = "Habilitar PayPal";
$strings['commissions_enable'] = "Habilitar Comisiones";
$strings['transfer_enable'] = "Habilitar transferencia";
$strings['unregistered_users_enable'] = "Permitir usuarios sin registro en la plataforma";
$strings['Free'] = "GRATIS";
$strings['PaypalPayoutCommissions'] = "Pagar comisiones por Paypal";
$strings['MyPayouts'] = "Mis Pagos";

@ -114,6 +114,55 @@ class BuyCoursesPlugin extends Plugin
$this->manageTab(false);
}
/**
* This function verify if the plugin is enable and return the price info for a course in the new grid catalog
* for 1.11.x , the main purpose is to show if a course is in sale it shows in the main platform course catalog
* so the old buycourses plugin catalog can be deprecated.
* @param Array $course course info
* @return mixed bool|string html
*/
public function buyCoursesForGridCatalogVerificator($course) {
$return = [];
$paypal = $this->get('paypal_enable') === 'true';
$transfer = $this->get('transfer_enable') === 'true';
if ($paypal || $transfer) {
$item = $this->getItemByProduct(intval($course['real_id']), self::PRODUCT_TYPE_COURSE);
$return['html'] = '<div class="buycourses-price">';
if ($item) {
$return['html'] .= '<span class="label label-primary"><b>'. $item['iso_code'] .' ' . $item['price'] . '</b></span>';
$return['verificator'] = true;
} else {
$return['html'] .= '<span class="label label-primary"><b>'. $this->get_lang('Free'). '</b></span>';
$return['verificator'] = false;
}
$return['html'] .= '</div>';
} else {
return false;
}
return $return;
}
/**
* Return the buyCourses plugin button to buy the course
* @param array $course course info
* @return string $html
*/
public function returnBuyCourseButton($course) {
$url = api_get_path(WEB_PLUGIN_PATH) .
'buycourses/src/process.php?i=' .
intval($course['real_id']) .
'&t=' .
self::PRODUCT_TYPE_COURSE
;
$html = ' <a class="btn btn-success btn-sm" title="' . $this->get_lang('Buy') . '" href="' . $url . '">' .
Display::returnFontAwesomeIcon('fa fa-shopping-cart') . '</a>';
return $html;
}
/**
* Get the currency for sales
* @return array The selected currency. Otherwise return false

@ -21,8 +21,12 @@ $includeSession = $plugin->get('include_sessions') === 'true';
$paypalEnabled = $plugin->get('paypal_enable') === 'true';
$transferEnabled = $plugin->get('transfer_enable') === 'true';
if (!$paypalEnabled && !$transferEnabled) {
api_not_allowed(true);
}
if (!isset($_REQUEST['t'], $_REQUEST['i'])) {
die;
api_not_allowed(true);
}
$buyingCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_COURSE;

Loading…
Cancel
Save