"Buy/sell courses" plugin fixes

- Changed buyCoursesForGridCatalogVerificator to buyCoursesForGridCatalogValidator
- New function isEnabled
- Fix fatal error in session/about.php
- Fix typos and english
- Update docs
pull/2487/head
jmontoyaa 9 years ago
parent 039dae6f98
commit ce37836102
  1. 5
      main/inc/lib/course.lib.php
  2. 2
      main/lp/lp_final_item.php
  3. 17
      main/session/about.php
  4. 2
      main/template/default/auth/courses_categories.php
  5. 88
      plugin/buycourses/src/buy_course_plugin.class.php
  6. 2
      src/Chamilo/CoreBundle/Entity/Session.php

@ -4793,7 +4793,10 @@ class CourseManager
// start buycourse validation // start buycourse validation
// display the course price and buy button if the buycourses plugin is enabled and this course is configured // display the course price and buy button if the buycourses plugin is enabled and this course is configured
$plugin = BuyCoursesPlugin::create(); $plugin = BuyCoursesPlugin::create();
$isThisCourseInSale = $plugin->buyCoursesForGridCatalogVerificator($course_info['real_id'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE); $isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator(
$course_info['real_id'],
BuyCoursesPlugin::PRODUCT_TYPE_COURSE
);
if ($isThisCourseInSale) { if ($isThisCourseInSale) {
// set the price label // set the price label
$my_course['price'] = $isThisCourseInSale['html']; $my_course['price'] = $isThisCourseInSale['html'];

@ -31,7 +31,7 @@ if (!$id && !$lpId) {
// Certificate and Skills Premium with Service check // Certificate and Skills Premium with Service check
$plugin = BuyCoursesPlugin::create(); $plugin = BuyCoursesPlugin::create();
$checker = ($plugin->get('paypal_enable') || $plugin->get('transfer_enable') || $plugin->get('culqi_enable')) && $plugin->get('include_services'); $checker = $plugin->isEnabled() && $plugin->get('include_services');
if ($checker) { if ($checker) {
$userServiceSale = $plugin->getServiceSale( $userServiceSale = $plugin->getServiceSale(

@ -195,12 +195,17 @@ $template->assign(
); );
$plugin = BuyCoursesPlugin::create(); $plugin = BuyCoursesPlugin::create();
$checker = $plugin->get('paypal_enable') || $plugin->get('transfer_enable') || $plugin->get('culqi_enable'); $checker = $plugin->isEnabled();
$sessionIsPremium = $plugin->getItemByProduct($sessionId, BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
if ($checker) {
if ($checker && $sessionIsPremium) { $sessionIsPremium = $plugin->getItemByProduct(
Session::write('SessionIsPremium', true); $sessionId,
Session::write('sessionId', $sessionId); BuyCoursesPlugin::PRODUCT_TYPE_SESSION
);
if ($sessionIsPremium) {
Session::write('SessionIsPremium', true);
Session::write('sessionId', $sessionId);
}
} }
$redirectToSession = api_get_configuration_value('allow_redirect_to_session_after_inscription_about'); $redirectToSession = api_get_configuration_value('allow_redirect_to_session_after_inscription_about');

@ -189,7 +189,7 @@ if ($showCourses && $action != 'display_sessions') {
// start buycourse validation // start buycourse validation
// display the course price and buy button if the buycourses plugin is enabled and this course is configured // display the course price and buy button if the buycourses plugin is enabled and this course is configured
$plugin = BuyCoursesPlugin::create(); $plugin = BuyCoursesPlugin::create();
$isThisCourseInSale = $plugin->buyCoursesForGridCatalogVerificator( $isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator(
$course['real_id'], $course['real_id'],
BuyCoursesPlugin::PRODUCT_TYPE_COURSE BuyCoursesPlugin::PRODUCT_TYPE_COURSE
); );

@ -12,6 +12,7 @@ use Chamilo\CoreBundle\Entity\Course;
* @author Alex Aragón <alex.aragon@beeznest.com> * @author Alex Aragón <alex.aragon@beeznest.com>
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com> * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @author José Loguercio Silva <jose.loguercio@beeznest.com> * @author José Loguercio Silva <jose.loguercio@beeznest.com>
* @author Julio Montoya
*/ */
class BuyCoursesPlugin extends Plugin class BuyCoursesPlugin extends Plugin
{ {
@ -49,16 +50,18 @@ class BuyCoursesPlugin extends Plugin
const CULQI_PRODUCTION_TYPE = 'PRODUC'; const CULQI_PRODUCTION_TYPE = 'PRODUC';
/** /**
* * @return BuyCoursesPlugin
* @return StaticPlugin
*/ */
static function create() public static function create()
{ {
static $result = null; static $result = null;
return $result ? $result : $result = new self(); return $result ? $result : $result = new self();
} }
protected function __construct() /**
* BuyCoursesPlugin constructor.
*/
public function __construct()
{ {
parent::__construct( parent::__construct(
'1.0', '1.0',
@ -69,6 +72,7 @@ class BuyCoursesPlugin extends Plugin
Imanol Losada - BeezNest (introduction of sessions purchase) <br/> Imanol Losada - BeezNest (introduction of sessions purchase) <br/>
Angel Fernando Quiroz Campos - BeezNest (cleanup and new reports) <br/> Angel Fernando Quiroz Campos - BeezNest (cleanup and new reports) <br/>
José Loguercio Silva - BeezNest (Payouts and buy Services) José Loguercio Silva - BeezNest (Payouts and buy Services)
Julio Montoya
", ",
array( array(
'show_main_menu_tab' => 'boolean', 'show_main_menu_tab' => 'boolean',
@ -83,10 +87,19 @@ class BuyCoursesPlugin extends Plugin
); );
} }
/**
* Check if plugin is enabled
* @return bool
*/
public function isEnabled()
{
return $this->get('paypal_enable') || $this->get('transfer_enable') || $this->get('culqi_enable');
}
/** /**
* This method creates the tables required to this plugin * This method creates the tables required to this plugin
*/ */
function install() public function install()
{ {
$tablesToBeCompared = array( $tablesToBeCompared = array(
self::TABLE_PAYPAL, self::TABLE_PAYPAL,
@ -117,7 +130,7 @@ class BuyCoursesPlugin extends Plugin
/** /**
* This method drops the plugin tables * This method drops the plugin tables
*/ */
function uninstall() public function uninstall()
{ {
$tablesToBeDeleted = array( $tablesToBeDeleted = array(
self::TABLE_PAYPAL, self::TABLE_PAYPAL,
@ -150,7 +163,8 @@ class BuyCoursesPlugin extends Plugin
* @param int $productType course or session type * @param int $productType course or session type
* @return mixed bool|string html * @return mixed bool|string html
*/ */
public function buyCoursesForGridCatalogVerificator($productId, $productType) { public function buyCoursesForGridCatalogValidator($productId, $productType)
{
$return = []; $return = [];
$paypal = $this->get('paypal_enable') === 'true'; $paypal = $this->get('paypal_enable') === 'true';
$transfer = $this->get('transfer_enable') === 'true'; $transfer = $this->get('transfer_enable') === 'true';
@ -179,7 +193,8 @@ class BuyCoursesPlugin extends Plugin
* @param int $productType * @param int $productType
* @return string $html * @return string $html
*/ */
public function returnBuyCourseButton($productId, $productType) { public function returnBuyCourseButton($productId, $productType)
{
$url = api_get_path(WEB_PLUGIN_PATH) . $url = api_get_path(WEB_PLUGIN_PATH) .
'buycourses/src/process.php?i=' . 'buycourses/src/process.php?i=' .
intval($productId) . intval($productId) .
@ -406,11 +421,8 @@ class BuyCoursesPlugin extends Plugin
{ {
$auth = new Auth(); $auth = new Auth();
$sessions = $auth->browseSessions(); $sessions = $auth->browseSessions();
$currency = $this->getSelectedCurrency(); $currency = $this->getSelectedCurrency();
$items = []; $items = [];
foreach ($sessions as $session) { foreach ($sessions as $session) {
$items[] = $this->getSessionForConfiguration($session, $currency); $items[] = $this->getSessionForConfiguration($session, $currency);
} }
@ -537,7 +549,6 @@ class BuyCoursesPlugin extends Plugin
private function getUserStatusForCourse($userId, Course $course) private function getUserStatusForCourse($userId, Course $course)
{ {
if (empty($userId)) { if (empty($userId)) {
return 'NO'; return 'NO';
} }
@ -598,7 +609,10 @@ class BuyCoursesPlugin extends Plugin
$courseCatalog = []; $courseCatalog = [];
foreach ($courses as $course) { foreach ($courses as $course) {
$item = $this->getItemByProduct($course->getId(), self::PRODUCT_TYPE_COURSE); $item = $this->getItemByProduct(
$course->getId(),
self::PRODUCT_TYPE_COURSE
);
if (empty($item)) { if (empty($item)) {
continue; continue;
@ -793,7 +807,6 @@ class BuyCoursesPlugin extends Plugin
} }
$entityManager = Database::getManager(); $entityManager = Database::getManager();
$item = $this->getItem($itemId); $item = $this->getItem($itemId);
if (empty($item)) { if (empty($item)) {
@ -933,7 +946,6 @@ class BuyCoursesPlugin extends Plugin
switch ($sale['product_type']) { switch ($sale['product_type']) {
case self::PRODUCT_TYPE_COURSE: case self::PRODUCT_TYPE_COURSE:
$course = api_get_course_info_by_id($sale['product_id']); $course = api_get_course_info_by_id($sale['product_id']);
$saleIsCompleted = CourseManager::subscribe_user($sale['user_id'], $course['code']); $saleIsCompleted = CourseManager::subscribe_user($sale['user_id'], $course['code']);
break; break;
case self::PRODUCT_TYPE_SESSION: case self::PRODUCT_TYPE_SESSION:
@ -1158,7 +1170,6 @@ class BuyCoursesPlugin extends Plugin
} }
$courses = []; $courses = [];
foreach ($courseIds as $courseId) { foreach ($courseIds as $courseId) {
$courses[] = Database::getManager()->find('ChamiloCoreBundle:Course', $courseId); $courses[] = Database::getManager()->find('ChamiloCoreBundle:Course', $courseId);
} }
@ -1179,8 +1190,7 @@ class BuyCoursesPlugin extends Plugin
$lowercase = true, $lowercase = true,
$uppercase = true, $uppercase = true,
$numbers = true $numbers = true
) ) {
{
$salt = $lowercase ? 'abchefghknpqrstuvwxyz' : ''; $salt = $lowercase ? 'abchefghknpqrstuvwxyz' : '';
$salt .= $uppercase ? 'ACDEFHKNPRSTUVWXYZ' : ''; $salt .= $uppercase ? 'ACDEFHKNPRSTUVWXYZ' : '';
$salt .= $numbers ? (strlen($salt) ? '2345679' : '0123456789') : ''; $salt .= $numbers ? (strlen($salt) ? '2345679' : '0123456789') : '';
@ -1259,7 +1269,6 @@ class BuyCoursesPlugin extends Plugin
*/ */
public function getSaleListByUserId($id) public function getSaleListByUserId($id)
{ {
if (empty($id)) { if (empty($id)) {
return []; return [];
} }
@ -1387,7 +1396,7 @@ class BuyCoursesPlugin extends Plugin
/** /**
* Get all beneficiaries for a item * Get all beneficiaries for a item
* @param int $itemId The item ID * @param int $itemId The item ID
* @return array The beneficiries. Otherwise return false * @return array The beneficiaries. Otherwise return false
*/ */
public function getItemBeneficiaries($itemId) public function getItemBeneficiaries($itemId)
{ {
@ -1410,7 +1419,6 @@ class BuyCoursesPlugin extends Plugin
public function deleteItem($itemId) public function deleteItem($itemId)
{ {
$itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM); $itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM);
$affectedRows = Database::delete( $affectedRows = Database::delete(
$itemTable, $itemTable,
['id = ?' => intval($itemId)] ['id = ?' => intval($itemId)]
@ -1519,21 +1527,18 @@ class BuyCoursesPlugin extends Plugin
*/ */
public function getBeneficiariesBySale($saleId) public function getBeneficiariesBySale($saleId)
{ {
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$beneficiaries = [];
$sale = $this->getSale($saleId); $sale = $this->getSale($saleId);
$item = $this->getItemByProduct($sale['product_id'], $sale['product_type']); $item = $this->getItemByProduct($sale['product_id'], $sale['product_type']);
$itemBeneficiaries = $this->getItemBeneficiaries($item['id']); $itemBeneficiaries = $this->getItemBeneficiaries($item['id']);
return $itemBeneficiaries;
return $itemBeneficiaries;
} }
/** /**
* gets all payouts * gets all payouts
* @param int $status - default 0 - pending * @param int $status - default 0 - pending
* @param int $payoutId - for get an individual payout if want all then false * @param int $payoutId - for get an individual payout if want all then false
* @param int $userId
* @return array * @return array
*/ */
public function getPayouts($status = self::PAYOUT_STATUS_PENDING, $payoutId = false, $userId = false) public function getPayouts($status = self::PAYOUT_STATUS_PENDING, $payoutId = false, $userId = false)
@ -1605,7 +1610,6 @@ class BuyCoursesPlugin extends Plugin
} }
$paypalFieldId = $paypalExtraField['id']; $paypalFieldId = $paypalExtraField['id'];
$paypalAccount = Database::select( $paypalAccount = Database::select(
"value", "value",
$extraFieldValues, $extraFieldValues,
@ -1671,7 +1675,6 @@ class BuyCoursesPlugin extends Plugin
['status' => intval($status)], ['status' => intval($status)],
['id = ?' => intval($payoutId)] ['id = ?' => intval($payoutId)]
); );
} }
/** /**
@ -1704,8 +1707,9 @@ class BuyCoursesPlugin extends Plugin
} }
/** /**
* Register addicional service * Register additional service
* @param array params $service * @param array $service params
*
* @return mixed response * @return mixed response
*/ */
public function storeService($service) public function storeService($service)
@ -1728,7 +1732,9 @@ class BuyCoursesPlugin extends Plugin
] ]
); );
if ($return && !empty($service['picture_crop_image_base_64']) && !empty($service['picture_crop_result'])) { if ($return && !empty($service['picture_crop_image_base_64'])
&& !empty($service['picture_crop_result'])
) {
$img = str_replace('data:image/png;base64,', '', $service['picture_crop_image_base_64']); $img = str_replace('data:image/png;base64,', '', $service['picture_crop_image_base_64']);
$img = str_replace(' ', '+', $img); $img = str_replace(' ', '+', $img);
$data = base64_decode($img); $data = base64_decode($img);
@ -1799,7 +1805,7 @@ class BuyCoursesPlugin extends Plugin
} }
/** /**
* List adicional services * List additional services
* @param integer $id service id * @param integer $id service id
* @return array * @return array
*/ */
@ -1888,8 +1894,14 @@ class BuyCoursesPlugin extends Plugin
* @param boolean $hot enable hot services * @param boolean $hot enable hot services
* @return array * @return array
*/ */
public function getServiceSale($id = null, $buyerId = null, $status = null, $nodeType = null, $nodeId = null, $hot = false) public function getServiceSale(
{ $id = null,
$buyerId = null,
$status = null,
$nodeType = null,
$nodeId = null,
$hot = false
) {
$servicesTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SERVICES); $servicesTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SERVICES);
$servicesSaleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SERVICES_SALE); $servicesSaleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SERVICES_SALE);
@ -1942,7 +1954,6 @@ class BuyCoursesPlugin extends Plugin
$servicesSale = []; $servicesSale = [];
if ($id) { if ($id) {
$owner = api_get_user_info($return['owner_id']); $owner = api_get_user_info($return['owner_id']);
$buyer = api_get_user_info($return['buyer_id']); $buyer = api_get_user_info($return['buyer_id']);
@ -1976,9 +1987,7 @@ class BuyCoursesPlugin extends Plugin
return $servicesSale; return $servicesSale;
} }
foreach ($return as $index => $service) { foreach ($return as $index => $service) {
$owner = api_get_user_info($service['owner_id']); $owner = api_get_user_info($service['owner_id']);
$buyer = api_get_user_info($service['buyer_id']); $buyer = api_get_user_info($service['buyer_id']);
@ -2020,6 +2029,7 @@ class BuyCoursesPlugin extends Plugin
public function cancelServiceSale($serviceSaleId) public function cancelServiceSale($serviceSaleId)
{ {
$this->updateServiceSaleStatus($serviceSaleId, self::SERVICE_STATUS_CANCELLED); $this->updateServiceSaleStatus($serviceSaleId, self::SERVICE_STATUS_CANCELLED);
return true; return true;
} }
@ -2031,7 +2041,6 @@ class BuyCoursesPlugin extends Plugin
public function completeServiceSale($serviceSaleId) public function completeServiceSale($serviceSaleId)
{ {
$serviceSale = $this->getServiceSale($serviceSaleId); $serviceSale = $this->getServiceSale($serviceSaleId);
if ($serviceSale['status'] == self::SERVICE_STATUS_COMPLETED) { if ($serviceSale['status'] == self::SERVICE_STATUS_COMPLETED) {
return true; return true;
} }
@ -2102,7 +2111,6 @@ class BuyCoursesPlugin extends Plugin
} }
return $services; return $services;
} }
/** /**
@ -2137,7 +2145,6 @@ class BuyCoursesPlugin extends Plugin
} }
$userId = api_get_user_id(); $userId = api_get_user_id();
$service = $this->getServices($serviceId); $service = $this->getServices($serviceId);
if (empty($service)) { if (empty($service)) {
@ -2254,5 +2261,4 @@ class BuyCoursesPlugin extends Plugin
return $paths[$var]; return $paths[$var];
} }
} }

@ -1019,7 +1019,7 @@ class Session
// start buycourse validation // start buycourse validation
// display the course price and buy button if the buycourses plugin is enabled and this course is configured // display the course price and buy button if the buycourses plugin is enabled and this course is configured
$plugin = \BuyCoursesPlugin::create(); $plugin = \BuyCoursesPlugin::create();
$isThisCourseInSale = $plugin->buyCoursesForGridCatalogVerificator($this->id, \BuyCoursesPlugin::PRODUCT_TYPE_SESSION); $isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator($this->id, \BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
$return = []; $return = [];
if ($isThisCourseInSale) { if ($isThisCourseInSale) {

Loading…
Cancel
Save