Added buyCourse plugin integration to the new sessions grid catalog

pull/2487/head
José Loguercio 10 years ago
parent fbaea0cb0a
commit 923d872edc
  1. 6
      main/auth/courses_controller.php
  2. 4
      main/inc/lib/course.lib.php
  3. 4
      main/template/default/auth/courses_categories.php
  4. 20
      plugin/buycourses/src/buy_course_plugin.class.php
  5. 20
      src/Chamilo/CoreBundle/Entity/Session.php

@ -806,6 +806,9 @@ class CoursesController
if (api_is_platform_admin()) {
$actions = api_get_path(WEB_CODE_PATH) .'session/resume_session.php?id_session='.$session->getId();
}
$isThisSessionOnSale = $session->getBuyCoursePluginPrice();
$sessionsBlock = array(
'id' => $session->getId(),
'name' => $session->getName(),
@ -819,7 +822,8 @@ class CoursesController
'is_subscribed' => SessionManager::isUserSubscribedAsStudent($session->getId(), $userId),
'icon' => $this->getSessionIcon($session->getName()),
'date' => $sessionDates['display'],
'subscribe_button' => $this->getRegisteredInSessionButton(
'price' => $isThisSessionOnSale['html'],
'subscribe_button' => $isThisSessionOnSale['buy_button'] ? $isThisSessionOnSale['buy_button'] : $this->getRegisteredInSessionButton(
$session->getId(),
$session->getName(),
$hasRequirements

@ -4747,13 +4747,13 @@ class CourseManager
// 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);
$isThisCourseInSale = $plugin->buyCoursesForGridCatalogVerificator($course_info['real_id'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
if ($isThisCourseInSale) {
// set the price label
$my_course['price'] = $isThisCourseInSale['html'];
// set the Buy button instead register.
if ($isThisCourseInSale['verificator'] && !empty($my_course['register_button'])) {
$my_course['register_button'] = $plugin->returnBuyCourseButton($course_info);
$my_course['register_button'] = $plugin->returnBuyCourseButton($course_info['real_id'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
}
}
// end buycourse validation

@ -228,14 +228,14 @@ if ($showCourses && $action != 'display_sessions') {
// 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);
$isThisCourseInSale = $plugin->buyCoursesForGridCatalogVerificator($course['real_id'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
if ($isThisCourseInSale) {
// set the Price label
$separator = $isThisCourseInSale['html'];
// set the Buy button instead register.
if ($isThisCourseInSale['verificator']) {
$subscribeButton = $plugin->returnBuyCourseButton($course);
$subscribeButton = $plugin->returnBuyCourseButton($course['real_id'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
}
}
// end buycourse validation

@ -119,19 +119,20 @@ class BuyCoursesPlugin extends Plugin
}
/**
* 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
* This function verify if the plugin is enable and return the price info for a course or session in the new grid catalog
* for 1.11.x , the main purpose is to show if a course or session 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
* @param int $productId course or session id
* @param int $productType course or session type
* @return mixed bool|string html
*/
public function buyCoursesForGridCatalogVerificator($course) {
public function buyCoursesForGridCatalogVerificator($productId, $productType) {
$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);
$item = $this->getItemByProduct(intval($productId), $productType);
$return['html'] = '<div class="buycourses-price">';
if ($item) {
$return['html'] .= '<span class="label label-primary"><b>'. $item['iso_code'] .' ' . $item['price'] . '</b></span>';
@ -150,15 +151,16 @@ class BuyCoursesPlugin extends Plugin
/**
* Return the buyCourses plugin button to buy the course
* @param array $course course info
* @param int $productId
* @param int $productType
* @return string $html
*/
public function returnBuyCourseButton($course) {
public function returnBuyCourseButton($productId, $productType) {
$url = api_get_path(WEB_PLUGIN_PATH) .
'buycourses/src/process.php?i=' .
intval($course['real_id']) .
intval($productId) .
'&t=' .
self::PRODUCT_TYPE_COURSE
$productType
;
$html = ' <a class="btn btn-success btn-sm" title="' . $this->get_lang('Buy') . '" href="' . $url . '">' .

@ -1006,4 +1006,24 @@ class Session
return $this->userCourseSubscriptions->matching($criteria);
}
public function getBuyCoursePluginPrice()
{
// 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($this->id, \BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
$return = [];
if ($isThisCourseInSale) {
// set the Price label
$return['html'] = $isThisCourseInSale['html'];
// set the Buy button instead register.
if ($isThisCourseInSale['verificator']) {
$return['buy_button'] = $plugin->returnBuyCourseButton($this->id, \BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
}
}
// end buycourse validation
return $return;
}
}

Loading…
Cancel
Save