diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 077a3c7fe4..430feaa554 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -4793,7 +4793,10 @@ 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['real_id'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE); + $isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator( + $course_info['real_id'], + BuyCoursesPlugin::PRODUCT_TYPE_COURSE + ); if ($isThisCourseInSale) { // set the price label $my_course['price'] = $isThisCourseInSale['html']; diff --git a/main/lp/lp_final_item.php b/main/lp/lp_final_item.php index 237563429e..c6c8e8baa5 100644 --- a/main/lp/lp_final_item.php +++ b/main/lp/lp_final_item.php @@ -31,7 +31,7 @@ if (!$id && !$lpId) { // Certificate and Skills Premium with Service check $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) { $userServiceSale = $plugin->getServiceSale( diff --git a/main/session/about.php b/main/session/about.php index ac4951b61f..162aa5a287 100644 --- a/main/session/about.php +++ b/main/session/about.php @@ -195,12 +195,17 @@ $template->assign( ); $plugin = BuyCoursesPlugin::create(); -$checker = $plugin->get('paypal_enable') || $plugin->get('transfer_enable') || $plugin->get('culqi_enable'); -$sessionIsPremium = $plugin->getItemByProduct($sessionId, BuyCoursesPlugin::PRODUCT_TYPE_SESSION); - -if ($checker && $sessionIsPremium) { - Session::write('SessionIsPremium', true); - Session::write('sessionId', $sessionId); +$checker = $plugin->isEnabled(); + +if ($checker) { + $sessionIsPremium = $plugin->getItemByProduct( + $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'); diff --git a/main/template/default/auth/courses_categories.php b/main/template/default/auth/courses_categories.php index 4631306053..35a07320ec 100755 --- a/main/template/default/auth/courses_categories.php +++ b/main/template/default/auth/courses_categories.php @@ -189,7 +189,7 @@ 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( + $isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator( $course['real_id'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE ); diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index 1b7b7a5d97..3392502699 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -12,6 +12,7 @@ use Chamilo\CoreBundle\Entity\Course; * @author Alex Aragón * @author Angel Fernando Quiroz Campos * @author José Loguercio Silva + * @author Julio Montoya */ class BuyCoursesPlugin extends Plugin { @@ -49,16 +50,18 @@ class BuyCoursesPlugin extends Plugin const CULQI_PRODUCTION_TYPE = 'PRODUC'; /** - * - * @return StaticPlugin + * @return BuyCoursesPlugin */ - static function create() + public static function create() { static $result = null; return $result ? $result : $result = new self(); } - protected function __construct() + /** + * BuyCoursesPlugin constructor. + */ + public function __construct() { parent::__construct( '1.0', @@ -69,6 +72,7 @@ class BuyCoursesPlugin extends Plugin Imanol Losada - BeezNest (introduction of sessions purchase)
Angel Fernando Quiroz Campos - BeezNest (cleanup and new reports)
José Loguercio Silva - BeezNest (Payouts and buy Services) + Julio Montoya ", array( '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 */ - function install() + public function install() { $tablesToBeCompared = array( self::TABLE_PAYPAL, @@ -117,7 +130,7 @@ class BuyCoursesPlugin extends Plugin /** * This method drops the plugin tables */ - function uninstall() + public function uninstall() { $tablesToBeDeleted = array( self::TABLE_PAYPAL, @@ -150,7 +163,8 @@ class BuyCoursesPlugin extends Plugin * @param int $productType course or session type * @return mixed bool|string html */ - public function buyCoursesForGridCatalogVerificator($productId, $productType) { + public function buyCoursesForGridCatalogValidator($productId, $productType) + { $return = []; $paypal = $this->get('paypal_enable') === 'true'; $transfer = $this->get('transfer_enable') === 'true'; @@ -179,7 +193,8 @@ class BuyCoursesPlugin extends Plugin * @param int $productType * @return string $html */ - public function returnBuyCourseButton($productId, $productType) { + public function returnBuyCourseButton($productId, $productType) + { $url = api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/process.php?i=' . intval($productId) . @@ -406,11 +421,8 @@ class BuyCoursesPlugin extends Plugin { $auth = new Auth(); $sessions = $auth->browseSessions(); - $currency = $this->getSelectedCurrency(); - $items = []; - foreach ($sessions as $session) { $items[] = $this->getSessionForConfiguration($session, $currency); } @@ -537,7 +549,6 @@ class BuyCoursesPlugin extends Plugin private function getUserStatusForCourse($userId, Course $course) { if (empty($userId)) { - return 'NO'; } @@ -598,7 +609,10 @@ class BuyCoursesPlugin extends Plugin $courseCatalog = []; 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)) { continue; @@ -793,7 +807,6 @@ class BuyCoursesPlugin extends Plugin } $entityManager = Database::getManager(); - $item = $this->getItem($itemId); if (empty($item)) { @@ -933,7 +946,6 @@ class BuyCoursesPlugin extends Plugin switch ($sale['product_type']) { case self::PRODUCT_TYPE_COURSE: $course = api_get_course_info_by_id($sale['product_id']); - $saleIsCompleted = CourseManager::subscribe_user($sale['user_id'], $course['code']); break; case self::PRODUCT_TYPE_SESSION: @@ -1158,7 +1170,6 @@ class BuyCoursesPlugin extends Plugin } $courses = []; - foreach ($courseIds as $courseId) { $courses[] = Database::getManager()->find('ChamiloCoreBundle:Course', $courseId); } @@ -1179,8 +1190,7 @@ class BuyCoursesPlugin extends Plugin $lowercase = true, $uppercase = true, $numbers = true - ) - { + ) { $salt = $lowercase ? 'abchefghknpqrstuvwxyz' : ''; $salt .= $uppercase ? 'ACDEFHKNPRSTUVWXYZ' : ''; $salt .= $numbers ? (strlen($salt) ? '2345679' : '0123456789') : ''; @@ -1259,7 +1269,6 @@ class BuyCoursesPlugin extends Plugin */ public function getSaleListByUserId($id) { - if (empty($id)) { return []; } @@ -1387,7 +1396,7 @@ class BuyCoursesPlugin extends Plugin /** * Get all beneficiaries for a item * @param int $itemId The item ID - * @return array The beneficiries. Otherwise return false + * @return array The beneficiaries. Otherwise return false */ public function getItemBeneficiaries($itemId) { @@ -1410,7 +1419,6 @@ class BuyCoursesPlugin extends Plugin public function deleteItem($itemId) { $itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM); - $affectedRows = Database::delete( $itemTable, ['id = ?' => intval($itemId)] @@ -1519,21 +1527,18 @@ class BuyCoursesPlugin extends Plugin */ public function getBeneficiariesBySale($saleId) { - - $userTable = Database::get_main_table(TABLE_MAIN_USER); - - $beneficiaries = []; $sale = $this->getSale($saleId); $item = $this->getItemByProduct($sale['product_id'], $sale['product_type']); $itemBeneficiaries = $this->getItemBeneficiaries($item['id']); - return $itemBeneficiaries; + return $itemBeneficiaries; } /** * gets all payouts * @param int $status - default 0 - pending * @param int $payoutId - for get an individual payout if want all then false + * @param int $userId * @return array */ public function getPayouts($status = self::PAYOUT_STATUS_PENDING, $payoutId = false, $userId = false) @@ -1605,7 +1610,6 @@ class BuyCoursesPlugin extends Plugin } $paypalFieldId = $paypalExtraField['id']; - $paypalAccount = Database::select( "value", $extraFieldValues, @@ -1671,7 +1675,6 @@ class BuyCoursesPlugin extends Plugin ['status' => intval($status)], ['id = ?' => intval($payoutId)] ); - } /** @@ -1704,8 +1707,9 @@ class BuyCoursesPlugin extends Plugin } /** - * Register addicional service - * @param array params $service + * Register additional service + * @param array $service params + * * @return mixed response */ 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(' ', '+', $img); $data = base64_decode($img); @@ -1799,7 +1805,7 @@ class BuyCoursesPlugin extends Plugin } /** - * List adicional services + * List additional services * @param integer $id service id * @return array */ @@ -1888,8 +1894,14 @@ class BuyCoursesPlugin extends Plugin * @param boolean $hot enable hot services * @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); $servicesSaleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SERVICES_SALE); @@ -1942,7 +1954,6 @@ class BuyCoursesPlugin extends Plugin $servicesSale = []; if ($id) { - $owner = api_get_user_info($return['owner_id']); $buyer = api_get_user_info($return['buyer_id']); @@ -1976,9 +1987,7 @@ class BuyCoursesPlugin extends Plugin return $servicesSale; } - foreach ($return as $index => $service) { - $owner = api_get_user_info($service['owner_id']); $buyer = api_get_user_info($service['buyer_id']); @@ -2020,6 +2029,7 @@ class BuyCoursesPlugin extends Plugin public function cancelServiceSale($serviceSaleId) { $this->updateServiceSaleStatus($serviceSaleId, self::SERVICE_STATUS_CANCELLED); + return true; } @@ -2031,7 +2041,6 @@ class BuyCoursesPlugin extends Plugin public function completeServiceSale($serviceSaleId) { $serviceSale = $this->getServiceSale($serviceSaleId); - if ($serviceSale['status'] == self::SERVICE_STATUS_COMPLETED) { return true; } @@ -2102,7 +2111,6 @@ class BuyCoursesPlugin extends Plugin } return $services; - } /** @@ -2137,7 +2145,6 @@ class BuyCoursesPlugin extends Plugin } $userId = api_get_user_id(); - $service = $this->getServices($serviceId); if (empty($service)) { @@ -2254,5 +2261,4 @@ class BuyCoursesPlugin extends Plugin return $paths[$var]; } - } diff --git a/src/Chamilo/CoreBundle/Entity/Session.php b/src/Chamilo/CoreBundle/Entity/Session.php index e8788794bc..b68bffca63 100644 --- a/src/Chamilo/CoreBundle/Entity/Session.php +++ b/src/Chamilo/CoreBundle/Entity/Session.php @@ -1019,7 +1019,7 @@ class Session // 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); + $isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator($this->id, \BuyCoursesPlugin::PRODUCT_TYPE_SESSION); $return = []; if ($isThisCourseInSale) {