From 339b29033a43c763e5aadf8473c7ad1eb712f9c9 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 21 Sep 2015 15:00:28 -0500 Subject: [PATCH 01/17] Fix and improve HTML code on Buy Courses index - refs #7768 --- plugin/buycourses/src/index.buycourses.php | 1 - plugin/buycourses/view/index.tpl | 135 ++++++++++----------- 2 files changed, 65 insertions(+), 71 deletions(-) diff --git a/plugin/buycourses/src/index.buycourses.php b/plugin/buycourses/src/index.buycourses.php index 8a65c2049c..96f6ebee2d 100644 --- a/plugin/buycourses/src/index.buycourses.php +++ b/plugin/buycourses/src/index.buycourses.php @@ -21,7 +21,6 @@ if ($guess_enable == "true" || isset($_SESSION['_user'])) { $content = $tpl->fetch('buycourses/view/index.tpl'); - $tpl->assign('header', $plugin->get_lang('plugin_title')); $tpl->assign('content', $content); $tpl->display_one_col_template(); diff --git a/plugin/buycourses/view/index.tpl b/plugin/buycourses/view/index.tpl index 03370ffaae..9d2e91dbcb 100644 --- a/plugin/buycourses/view/index.tpl +++ b/plugin/buycourses/view/index.tpl @@ -1,80 +1,75 @@ +{% if _u.is_admin %} +
+
+
+

{{ 'TitlePlugin'|get_plugin_lang('BuyCoursesPlugin') }}

+

{{ 'PluginPresentation'|get_plugin_lang('BuyCoursesPlugin') }}

+
    +
  • + {{ 'Instructions'|get_plugin_lang('BuyCoursesPlugin') }} +
      +
    • {{ 'InstructionsStepOne'|get_plugin_lang('BuyCoursesPlugin') }}
    • +
    • {{ 'InstructionsStepTwo'|get_plugin_lang('BuyCoursesPlugin') }}
    • +
    • {{ 'InstructionsStepThree'|get_plugin_lang('BuyCoursesPlugin') }}
    • +
    +
  • +
+
+
+
+{% endif %} +
-
- {% if _u.is_admin %} -
-
-
-
-
-

{{ 'TitlePlugin'|get_plugin_lang('BuyCoursesPlugin') }}

-

{{ 'PluginPresentation'|get_plugin_lang('BuyCoursesPlugin') }}

-

 

-
-
-
-
-
-
- {{ 'Instructions'|get_plugin_lang('BuyCoursesPlugin') }} -
-
-
    -
  • {{ 'InstructionsStepOne'|get_plugin_lang('BuyCoursesPlugin') }}
  • -
  • {{ 'InstructionsStepTwo'|get_plugin_lang('BuyCoursesPlugin') }}
  • -
  • {{ 'InstructionsStepThree'|get_plugin_lang('BuyCoursesPlugin') }}
  • -
-
-
-
-
+ -
-
-
- - - - + {% if _u.is_admin %} + From edf83bdc0d778d347dcf3e37425369eaaecb1335 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 22 Sep 2015 09:19:57 -0500 Subject: [PATCH 02/17] Add filter by user on sales report - refs #7768 --- .../src/buy_course_plugin.class.php | 36 +++++++++++++++++++ plugin/buycourses/src/sales_report.php | 34 ++++++++++++++++-- plugin/buycourses/view/sales_report.tpl | 20 ++++++++--- 3 files changed, 84 insertions(+), 6 deletions(-) diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index 5f2d48c41d..5cfd538fdc 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -1127,4 +1127,40 @@ class BuyCoursesPlugin extends Plugin ); } + /** + * Get a list of sales by the user + * @param string $term The search term + * @return array The sale list. Otherwise return false + */ + public function getSaleListByUser($term) + { + $term = trim($term); + + if (empty($term)) { + return []; + } + + $saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE); + $currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY); + $userTable = Database::get_main_table(TABLE_MAIN_USER); + + $innerJoins = " + INNER JOIN $currencyTable c ON s.currency_id = c.id + INNER JOIN $userTable u ON s.user_id = u.id + "; + + return Database::select( + ['c.iso_code', 'u.firstname', 'u.lastname', 's.*'], + "$saleTable s $innerJoins", + [ + 'where' => [ + 'u.username LIKE %?% OR ' => $term, + 'u.lastname LIKE %?% OR ' => $term, + 'u.firstname LIKE %?%' => $term + ], + 'order' => 'id DESC' + ] + ); + } + } diff --git a/plugin/buycourses/src/sales_report.php b/plugin/buycourses/src/sales_report.php index 3aa02b040e..0854d5bfcf 100644 --- a/plugin/buycourses/src/sales_report.php +++ b/plugin/buycourses/src/sales_report.php @@ -61,24 +61,54 @@ if (isset($_GET['order'])) { $productTypes = $plugin->getProductTypes(); $saleStatuses = $plugin->getSaleStatuses(); + +$selectedFilterType = '0'; $selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::SALE_STATUS_PENDING; $selectedSale = isset($_GET['sale']) ? intval($_GET['sale']) : 0; +$searchTerm = ''; $form = new FormValidator('search', 'get'); if ($form->validate()) { + $selectedFilterType = $form->getSubmitValue('filter_type'); $selectedStatus = $form->getSubmitValue('status'); + $searchTerm = $form->getSubmitValue('user'); if ($selectedStatus === false) { $selectedStatus = BuyCoursesPlugin::SALE_STATUS_PENDING; } + + if ($selectedFilterType === false) { + $selectedFilterType = '0'; + } } +$form->addRadio( + 'filter_type', + get_lang('FilterBy'), + [$plugin->get_lang('ByStatus'), $plugin->get_lang('ByUser')] +); +$form->addHtml('
'); $form->addSelect('status', $plugin->get_lang('OrderStatus'), $saleStatuses); +$form->addHtml('
'); +$form->addHtml('
'); +$form->addText('user', get_lang('UserName'), false); +$form->addHtml('
'); $form->addButtonFilter($plugin->get_lang('SearchByStatus')); -$form->setDefaults(['status' => $selectedStatus]); +$form->setDefaults([ + 'filter_type' => $selectedFilterType, + 'status' => $selectedStatus +]); + +switch ($selectedFilterType) { + case '0': + $sales = $plugin->getSaleListByStatus($selectedStatus); + break; + case '1': + $sales = $plugin->getSaleListByUser($searchTerm); + break; +} -$sales = $plugin->getSaleListByStatus($selectedStatus); $saleList = []; foreach ($sales as $sale) { diff --git a/plugin/buycourses/view/sales_report.tpl b/plugin/buycourses/view/sales_report.tpl index 565646cfcb..780588362a 100644 --- a/plugin/buycourses/view/sales_report.tpl +++ b/plugin/buycourses/view/sales_report.tpl @@ -11,9 +11,7 @@ {{ 'ProductType'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Name'|get_lang }} {{ 'UserName'|get_lang }} - {% if selected_status == sale_status_pending %} {{ 'Options'|get_lang }} - {% endif %} @@ -34,7 +32,6 @@ {{ sale.product_type }} {{ sale.product_name }} {{ sale.complete_user_name }} - {% if selected_status == sale_status_pending %} {% if sale.status == sale_status_pending %} @@ -45,9 +42,24 @@ {% endif %} - {% endif %} {% endfor %}
+ + From 1ebec60d96d611eb7a47a322274dfe4dfeb4583b Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 22 Sep 2015 09:53:34 -0500 Subject: [PATCH 03/17] Minor - Format code and PHP Doc - refs #7768 --- .../src/buy_course_plugin.class.php | 16 +++++--------- plugin/buycourses/src/sales_report.php | 5 +++-- plugin/buycourses/view/catalog.tpl | 8 +++---- plugin/buycourses/view/sales_report.tpl | 22 +++++++++---------- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index 5cfd538fdc..ed55c6afa8 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -44,7 +44,7 @@ class BuyCoursesPlugin extends Plugin Jose Angel Ruiz - NoSoloRed (original author), Francis Gonzales and Yannick Warnier - BeezNest (integration), Alex Aragón - BeezNest (Design icons and css styles), - Imanol Losada - BeezNest (introduction of sessions purchase) + Imanol Losada - BeezNest (introduction of sessions purchase), Angel Fernando Quiroz Campos - BeezNest ", array( @@ -540,10 +540,6 @@ class BuyCoursesPlugin extends Plugin return 'NO'; } - /** - * Lists current user course details - * @return array - */ /** * Lists current user course details * @param string $name Optional. The name filter @@ -915,8 +911,8 @@ class BuyCoursesPlugin extends Plugin /** * Get a list of sales by the status - * @param type $status - * @return type + * @param int $status The status to filter + * @return array The sale list. Otherwise return false */ public function getSaleListByStatus($status = self::SALE_STATUS_PENDING) { @@ -925,10 +921,8 @@ class BuyCoursesPlugin extends Plugin $userTable = Database::get_main_table(TABLE_MAIN_USER); $innerJoins = " - INNER JOIN $currencyTable c - ON s.currency_id = c.id - INNER JOIN $userTable u - ON s.user_id = u.id + INNER JOIN $currencyTable c ON s.currency_id = c.id + INNER JOIN $userTable u ON s.user_id = u.id "; return Database::select( diff --git a/plugin/buycourses/src/sales_report.php b/plugin/buycourses/src/sales_report.php index 0854d5bfcf..448fc8f79f 100644 --- a/plugin/buycourses/src/sales_report.php +++ b/plugin/buycourses/src/sales_report.php @@ -1,4 +1,5 @@ BuyCoursesPlugin::SALE_STATUS_COMPLETED, - 'sale' => $sale['id'] + 'sale' => $sale['id'] ]); break; case 'cancel': @@ -50,7 +51,7 @@ if (isset($_GET['order'])) { $urlToRedirect .= http_build_query([ 'status' => BuyCoursesPlugin::SALE_STATUS_CANCELED, - 'sale' => $sale['id'] + 'sale' => $sale['id'] ]); break; } diff --git a/plugin/buycourses/view/catalog.tpl b/plugin/buycourses/view/catalog.tpl index 772748e5d0..1bea2bce23 100644 --- a/plugin/buycourses/view/catalog.tpl +++ b/plugin/buycourses/view/catalog.tpl @@ -23,7 +23,7 @@ {% if showing_courses %} {% for course in courses %}
-
+
{{ course.title }}
{% set course_description_url = _p.web_ajax ~ 'course_home.ajax.php?' ~ {'code': course.code, 'a': 'show_course_information'}|url_encode() %} @@ -53,7 +53,7 @@
{{ 'WaitingToReceiveThePayment'|get_plugin_lang('BuyCoursesPlugin') }}
{% endif %}
-
+
{% endfor %} {% endif %} @@ -61,7 +61,7 @@ {% if showing_sessions %} {% for session in sessions %}
-
+
{{ session.name }}

@@ -100,7 +100,7 @@
{{ 'WaitingToReceiveThePayment'|get_plugin_lang('BuyCoursesPlugin') }}
{% endif %}

-
+
{% endfor %} {% endif %} diff --git a/plugin/buycourses/view/sales_report.tpl b/plugin/buycourses/view/sales_report.tpl index 780588362a..1cfe4a994b 100644 --- a/plugin/buycourses/view/sales_report.tpl +++ b/plugin/buycourses/view/sales_report.tpl @@ -11,7 +11,7 @@ {{ 'ProductType'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Name'|get_lang }} {{ 'UserName'|get_lang }} - {{ 'Options'|get_lang }} + {{ 'Options'|get_lang }} @@ -32,16 +32,16 @@ {{ sale.product_type }} {{ sale.product_name }} {{ sale.complete_user_name }} - - {% if sale.status == sale_status_pending %} - - {{ 'SubscribeUser'|get_plugin_lang('BuyCoursesPlugin') }} - - - {{ 'DeleteOrder'|get_plugin_lang('BuyCoursesPlugin') }} - - {% endif %} - + + {% if sale.status == sale_status_pending %} + + {{ 'SubscribeUser'|get_plugin_lang('BuyCoursesPlugin') }} + + + {{ 'DeleteOrder'|get_plugin_lang('BuyCoursesPlugin') }} + + {% endif %} + {% endfor %} From 5b26584ff2b2db0b5a33a5c642a431b80ecb2c5b Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 22 Sep 2015 10:12:25 -0500 Subject: [PATCH 04/17] Display payment method on sale report - refs #7768 --- plugin/buycourses/src/sales_report.php | 4 +++- plugin/buycourses/view/sales_report.tpl | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin/buycourses/src/sales_report.php b/plugin/buycourses/src/sales_report.php index 448fc8f79f..a368b676fe 100644 --- a/plugin/buycourses/src/sales_report.php +++ b/plugin/buycourses/src/sales_report.php @@ -62,6 +62,7 @@ if (isset($_GET['order'])) { $productTypes = $plugin->getProductTypes(); $saleStatuses = $plugin->getSaleStatuses(); +$paymentTypes = $plugin->getPaymentTypes(); $selectedFilterType = '0'; $selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::SALE_STATUS_PENDING; @@ -122,7 +123,8 @@ foreach ($sales as $sale) { 'price' => $sale['price'], 'product_name' => $sale['product_name'], 'product_type' => $productTypes[$sale['product_type']], - 'complete_user_name' => api_get_person_name($sale['firstname'], $sale['lastname']) + 'complete_user_name' => api_get_person_name($sale['firstname'], $sale['lastname']), + 'payment_type' => $paymentTypes[$sale['payment_type']] ]; } diff --git a/plugin/buycourses/view/sales_report.tpl b/plugin/buycourses/view/sales_report.tpl index 1cfe4a994b..9496bfcc91 100644 --- a/plugin/buycourses/view/sales_report.tpl +++ b/plugin/buycourses/view/sales_report.tpl @@ -7,6 +7,7 @@ {{ 'OrderReference'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'OrderStatus'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'OrderDate'|get_plugin_lang('BuyCoursesPlugin') }} + {{ 'PaymentMethod'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'ProductType'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Name'|get_lang }} @@ -28,6 +29,7 @@ {% endif %} {{ sale.date }} + {{ sale.payment_type }} {{ sale.currency ~ ' ' ~ sale.price }} {{ sale.product_type }} {{ sale.product_name }} From df5a2eb3ad28465b4fbf94263aa088b136f8dcff Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 22 Sep 2015 10:19:04 -0500 Subject: [PATCH 05/17] Register datetime of sales - refs #7768 --- plugin/buycourses/database.php | 2 +- plugin/buycourses/src/sales_report.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/buycourses/database.php b/plugin/buycourses/database.php index c4f135f38a..5b4ffb9aba 100644 --- a/plugin/buycourses/database.php +++ b/plugin/buycourses/database.php @@ -104,7 +104,7 @@ $saleTable->addColumn( ['autoincrement' => true, 'unsigned' => true] ); $saleTable->addColumn('reference', \Doctrine\DBAL\Types\Type::STRING); -$saleTable->addColumn('date', \Doctrine\DBAL\Types\Type::DATE); +$saleTable->addColumn('date', \Doctrine\DBAL\Types\Type::DATETIME); $saleTable->addColumn( 'user_id', \Doctrine\DBAL\Types\Type::INTEGER, diff --git a/plugin/buycourses/src/sales_report.php b/plugin/buycourses/src/sales_report.php index a368b676fe..e325916252 100644 --- a/plugin/buycourses/src/sales_report.php +++ b/plugin/buycourses/src/sales_report.php @@ -118,7 +118,7 @@ foreach ($sales as $sale) { 'id' => $sale['id'], 'reference' => $sale['reference'], 'status' => $sale['status'], - 'date' => api_format_date($sale['date'], DATE_FORMAT_LONG_NO_DAY), + 'date' => api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H), 'currency' => $sale['iso_code'], 'price' => $sale['price'], 'product_name' => $sale['product_name'], From 8f67cf686f428278470e131fcd05df1257c4cbfd Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Thu, 24 Sep 2015 14:42:40 -0500 Subject: [PATCH 06/17] Allow register beneficiaries with the sales of items - refs #7768 --- plugin/buycourses/database.php | 24 ++ .../src/buy_course_plugin.class.php | 299 +++++++++++++----- plugin/buycourses/src/configuration.php | 2 + plugin/buycourses/src/configure_course.php | 198 ++++++++++++ plugin/buycourses/src/function.php | 47 +-- plugin/buycourses/view/configuration.tpl | 8 +- 6 files changed, 470 insertions(+), 108 deletions(-) create mode 100644 plugin/buycourses/src/configure_course.php diff --git a/plugin/buycourses/database.php b/plugin/buycourses/database.php index 5b4ffb9aba..e3dddb98c9 100644 --- a/plugin/buycourses/database.php +++ b/plugin/buycourses/database.php @@ -97,6 +97,30 @@ $itemTable->addForeignKeyConstraint( ['onDelete' => 'CASCADE'] ); +$itemBeneficiary = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_ITEM_BENEFICIARY); +$itemBeneficiary->addColumn( + 'id', + \Doctrine\DBAL\Types\Type::INTEGER, + ['autoincrement' => true, 'unsigned' => true] +); +$itemBeneficiary->addColumn( + 'item_id', + \Doctrine\DBAL\Types\Type::INTEGER, + ['unsigned' => true] +); +$itemBeneficiary->addColumn( + 'user_id', + \Doctrine\DBAL\Types\Type::INTEGER, + ['unsigned' => true] +); +$itemBeneficiary->setPrimaryKey(['id']); +$itemBeneficiary->addForeignKeyConstraint( + $itemTable, + ['item_id'], + ['id'], + ['onDelete' => 'CASCADE'] +); + $saleTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_SALE); $saleTable->addColumn( 'id', diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index ed55c6afa8..954ae85b0e 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -16,6 +16,7 @@ class BuyCoursesPlugin extends Plugin const TABLE_PAYPAL = 'plugin_buycourses_paypal_account'; const TABLE_CURRENCY = 'plugin_buycourses_currency'; const TABLE_ITEM = 'plugin_buycourses_item'; + const TABLE_ITEM_BENEFICIARY = 'plugin_buycourses_item_rel_beneficiary'; const TABLE_SALE = 'plugin_buycourses_sale'; const TABLE_TRANSFER = 'plugin_buycourses_transfer'; const PRODUCT_TYPE_COURSE = 1; @@ -75,7 +76,8 @@ class BuyCoursesPlugin extends Plugin self::TABLE_TRANSFER, self::TABLE_ITEM, self::TABLE_SALE, - self::TABLE_CURRENCY + self::TABLE_CURRENCY, + self::TABLE_ITEM_BENEFICIARY ); foreach ($tablesToBeDeleted as $tableToBeDeleted) { @@ -285,26 +287,7 @@ class BuyCoursesPlugin extends Plugin $currency = $this->getSelectedCurrency(); foreach ($courses as $course) { - $courseItem = [ - 'course_id' => $course->getId(), - 'course_visual_code' => $course->getVisualCode(), - 'course_code' => $course->getCode(), - 'course_title' => $course->getTitle(), - 'course_visibility' => $course->getVisibility(), - 'visible' => false, - 'currency' => empty($currency) ? null : $currency['iso_code'], - 'price' => 0.00 - ]; - - $item = $this->getItemByProduct($course->getId(), self::PRODUCT_TYPE_COURSE); - - if ($item !== false) { - $courseItem['visible'] = true; - $courseItem['currency'] = $item['iso_code']; - $courseItem['price'] = $item['price']; - } - - $configurationCourses[] = $courseItem; + $configurationCourses[] = $this->getCourseForConfiguration($course, $currency); } return $configurationCourses; @@ -316,9 +299,6 @@ class BuyCoursesPlugin extends Plugin */ public function getSessionsForConfiguration() { - $buyItemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM); - $buyCurrencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY); - $auth = new Auth(); $sessions = $auth->browseSessions(); @@ -326,55 +306,8 @@ class BuyCoursesPlugin extends Plugin $items = []; - $fakeItemFrom = " - $buyItemTable i - INNER JOIN $buyCurrencyTable c - ON i.currency_id = c.id - "; - foreach ($sessions as $session) { - $sessionItem = [ - 'session_id' => $session->getId(), - 'session_name' => $session->getName(), - 'session_visibility' => $session->getVisibility(), - 'session_display_start_date' => null, - 'session_display_end_date' => null, - 'visible' => false, - 'currency' => empty($currency) ? null : $currency['iso_code'], - 'price' => 0.00 - ]; - - if (!empty($session->getDisplayStartDate())) { - $sessionItem['session_display_start_date'] = api_format_date( - $session->getDisplayStartDate()->format('Y-m-d h:i:s') - ); - } - - if (!empty($session->getDisplayEndDate())) { - $sessionItem['session_display_end_date'] = api_format_date( - $session->getDisplayEndDate()->format('Y-m-d h:i:s') - ); - } - - $item = Database::select( - ['i.*', 'c.iso_code'], - $fakeItemFrom, - [ - 'where' => [ - 'i.product_id = ? AND ' => $session->getId(), - 'i.product_type = ?' => self::PRODUCT_TYPE_SESSION - ] - ], - 'first' - ); - - if ($item !== false) { - $sessionItem['visible'] = true; - $sessionItem['currency'] = $item['iso_code']; - $sessionItem['price'] = $item['price']; - } - - $items[] = $sessionItem; + $items[] = $this->getSessionForConfiguration($session, $currency); } return $items; @@ -1157,4 +1090,226 @@ class BuyCoursesPlugin extends Plugin ); } + /** + * Convert the course info to array with necessary course data for save item + * @param \Chamilo\CoreBundle\Entity\Course $course + * @param array $defaultCurrency Optional. Currency data + * @return array + */ + public function getCourseForConfiguration(\Chamilo\CoreBundle\Entity\Course $course, $defaultCurrency = null) + { + $courseItem = [ + 'item_id' => null, + 'course_id' => $course->getId(), + 'course_visual_code' => $course->getVisualCode(), + 'course_code' => $course->getCode(), + 'course_title' => $course->getTitle(), + 'course_visibility' => $course->getVisibility(), + 'visible' => false, + 'currency' => empty($defaultCurrency) ? null : $defaultCurrency['iso_code'], + 'price' => 0.00 + ]; + + $item = $this->getItemByProduct($course->getId(), self::PRODUCT_TYPE_COURSE); + + if ($item !== false) { + $courseItem['item_id'] = $item['id']; + $courseItem['visible'] = true; + $courseItem['currency'] = $item['iso_code']; + $courseItem['price'] = $item['price']; + } + + return $courseItem; + } + + /** + * Convert the session info to array with necessary session data for save item + * @param Chamilo\CoreBundle\Entity\Session $session The session data + * @param array $defaultCurrency Optional. Currency data + * @return array + */ + public function getSessionForConfiguration(Chamilo\CoreBundle\Entity\Session $session, $defaultCurrency = null) + { + $buyItemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM); + $buyCurrencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY); + + $fakeItemFrom = " + $buyItemTable i + INNER JOIN $buyCurrencyTable c ON i.currency_id = c.id + "; + + $sessionItem = [ + 'item_id' => null, + 'session_id' => $session->getId(), + 'session_name' => $session->getName(), + 'session_visibility' => $session->getVisibility(), + 'session_display_start_date' => null, + 'session_display_end_date' => null, + 'visible' => false, + 'currency' => empty($defaultCurrency) ? null : $defaultCurrency['iso_code'], + 'price' => 0.00 + ]; + + if (!empty($session->getDisplayStartDate())) { + $sessionItem['session_display_start_date'] = api_format_date( + $session->getDisplayStartDate()->format('Y-m-d h:i:s') + ); + } + + if (!empty($session->getDisplayEndDate())) { + $sessionItem['session_display_end_date'] = api_format_date( + $session->getDisplayEndDate()->format('Y-m-d h:i:s'), + DATE_TIME_FORMAT_LONG_24H + ); + } + + $item = Database::select( + ['i.*', 'c.iso_code'], + $fakeItemFrom, + [ + 'where' => [ + 'i.product_id = ? AND ' => $session->getId(), + 'i.product_type = ?' => self::PRODUCT_TYPE_SESSION + ] + ], + 'first' + ); + + if ($item !== false) { + $sessionItem['item_id'] = $item['id']; + $sessionItem['visible'] = true; + $sessionItem['currency'] = $item['iso_code']; + $sessionItem['price'] = $item['price']; + } + + return $sessionItem; + } + + /** + * Get all beneficiaries for a item + * @param int $itemId The item ID + * @return array The beneficiries. Otherwise return false + */ + public function getItemBeneficiaries($itemId) + { + $beneficiaryTable = Database::get_main_table(self::TABLE_ITEM_BENEFICIARY); + + return Database::select( + '*', + $beneficiaryTable, + ['where' => [ + 'item_id = ?' => intval($itemId) + ]] + ); + } + + /** + * Delete a item with its beneficiaries + * @param int $itemId The item ID + * @return int The number of affected rows. Otherwise return false + */ + public function deleteItem($itemId) + { + $itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM); + + $affectedRows = Database::delete( + $itemTable, + ['id = ?' => intval($itemId)] + ); + + if (!$affectedRows) { + return false; + } + + return $this->deleteItemBeneficiaries($itemId); + } + + /** + * Register a item + * @param array $itemData The item data + * @return int The item ID. Otherwise return false + */ + public function registerItem(array $itemData) + { + $itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM); + + return Database::insert($itemTable, $itemData); + } + + /** + * Update the item data by product + * @param array $itemData The item data to be updated + * @param int $productId The product ID + * @param int $productType The type of product + * @return int The number of affected rows. Otherwise return false + */ + public function updateItem(array $itemData, $productId, $productType) + { + $itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM); + + return Database::update( + $itemTable, + $itemData, + [ + 'product_id = ? AND ' => intval($productId), + 'product_type' => $productType + ] + ); + } + + /** + * Remove all beneficiaries for a item + * @param int $itemId The user ID + * @return int The number of affected rows. Otherwise return false + */ + public function deleteItemBeneficiaries($itemId) + { + $beneficiaryTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM_BENEFICIARY); + + return Database::delete( + $beneficiaryTable, + ['item_id = ?' => intval($itemId)] + ); + } + + /** + * Register the beneficiaries users with the sale of item + * @param int $itemId The item ID + * @param array $userIds The beneficiary user ID + */ + public function registerItemBeneficiaries($itemId, array $userIds) + { + $beneficiaryTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM_BENEFICIARY); + + $this->deleteItemBeneficiaries($itemId); + + foreach ($userIds as $userId) { + Database::insert( + $beneficiaryTable, + [ + 'item_id' => intval($itemId), + 'user_id' => intval($userId) + ] + ); + } + } + + /** + * Check if a course is valid for sale + * @param Chamilo\CoreBundle\Entity\Course $course The course + * @return boolean + */ + public function isValidCourse(Chamilo\CoreBundle\Entity\Course $course) + { + $courses = $this->getCourses(); + + foreach ($courses as $_c) { + if ($_c->getCode() === $course->getCode()) { + return true; + } + } + + return false; + } + } diff --git a/plugin/buycourses/src/configuration.php b/plugin/buycourses/src/configuration.php index ceb4106250..7a49bee247 100644 --- a/plugin/buycourses/src/configuration.php +++ b/plugin/buycourses/src/configuration.php @@ -30,6 +30,8 @@ $interbreadcrumb[] = [ $templateName = $plugin->get_lang('AvailableCourses'); $tpl = new Template($templateName); +$tpl->assign('product_type_course', BuyCoursesPlugin::PRODUCT_TYPE_COURSE); +$tpl->assign('product_type_session', BuyCoursesPlugin::PRODUCT_TYPE_SESSION); $tpl->assign('courses', $courses); $tpl->assign('sessions_are_included', $includeSession); diff --git a/plugin/buycourses/src/configure_course.php b/plugin/buycourses/src/configure_course.php new file mode 100644 index 0000000000..73c7ef5ee0 --- /dev/null +++ b/plugin/buycourses/src/configure_course.php @@ -0,0 +1,198 @@ +get('include_sessions') === 'true'; + +$editingCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_COURSE; +$editingSession = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_SESSION; + +$entityManager = Database::getManager(); +$userRepo = $entityManager->getRepository('ChamiloUserBundle:User'); + +$currency = $plugin->getSelectedCurrency(); +$currencyIso = null; + +if ($editingCourse) { + $course = $entityManager->find('ChamiloCoreBundle:Course', $_REQUEST['i']); + + if (!$course) { + api_not_allowed(true); + } + + if (!$plugin->isValidCourse($course)) { + api_not_allowed(true); + } + + $courseItem = $plugin->getCourseForConfiguration($course, $currency); + + $teachers = $course->getTeachers(); + $teachersOptions = []; + + foreach ($teachers as $courseTeacher) { + $teacher = $courseTeacher->getUser(); + + $teachersOptions[] = [ + 'text' => $teacher->getCompleteName(), + 'value' => $teacher->getId() + ]; + } + + $beneficiaries = $plugin->getItemBeneficiaries($courseItem['item_id']); + $currencyIso = $courseItem['currency']; + $formDefaults = [ + 'i' => $courseItem['course_id'], + 't' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE, + 'name' => $courseItem['course_title'], + 'visible' => $courseItem['visible'], + 'price' => $courseItem['price'], + 'beneficiaries' => array_column($beneficiaries, 'user_id') + ]; +} elseif ($editingSession) { + if (!$includeSession) { + api_not_allowed(true); + } + + $session = $entityManager->find('ChamiloCoreBundle:Session', $_REQUEST['i']); + + if (!$session) { + api_not_allowed(true); + } + + $sessionItem = $plugin->getSessionForConfiguration($session, $currency); + $generalCoach = $session->getGeneralCoach(); + $generalCoachOption = [ + 'text' => $generalCoach->getCompleteName(), + 'value' => $generalCoach->getId() + ]; + $courseCoachesOptions = []; + $sessionCourses = $session->getCourses(); + + foreach ($sessionCourses as $sessionCourse) { + $courseCoaches = $userRepo->getCoachesForSessionCourse($session, $sessionCourse->getCourse()); + + foreach ($courseCoaches as $courseCoach) { + if ($generalCoach->getId() === $courseCoach->getId()) { + continue; + } + + $courseCoachesOptions[] = [ + 'text' => $courseCoach->getCompleteName(), + 'value' => $courseCoach->getId() + ]; + } + } + + $beneficiaries = $plugin->getItemBeneficiaries($sessionItem['item_id']); + + $currencyIso = $sessionItem['currency']; + $formDefaults = [ + 'i' => $session->getId(), + 't' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION, + 'name' => $sessionItem['session_name'], + 'visible' => $sessionItem['visible'], + 'price' => $sessionItem['price'], + 'beneficiaries' => array_column($beneficiaries, 'user_id') + ]; +} else { + api_not_allowed(true); +} + +$form = new FormValidator('beneficiaries'); +$form->addText('name', get_lang('Name'), false); +$visibleCheckbox = $form->addCheckBox('visible', get_lang('Visible'), 'Mostrar en el catálogo de cursos'); +$form->addElement( + 'number', + 'price', + [$plugin->get_lang('Price'), null, $currencyIso], + ['step' => 0.01] +); +$beneficiariesSelect = $form->addSelect( + 'beneficiaries', + get_lang('Beneficiaries'), + null, + ['multiple' => 'multiple'] +); + +if ($editingCourse) { + $beneficiariesSelect->addOptGroup($teachersOptions, get_lang('Teachers')); +} elseif ($editingSession) { + $beneficiariesSelect->addOptGroup([$generalCoachOption], get_lang('SessionGeneralCoach')); + $beneficiariesSelect->addOptGroup($courseCoachesOptions, get_lang('SessionCourseCoach')); +} + +$form->addHidden('t', null); +$form->addHidden('i', null); +$form->addButtonSave(get_lang('Save')); +$form->freeze(['name']); + +if ($form->validate()) { + $formValues = $form->exportValues(); + $productItem = $plugin->getItemByProduct($formValues['i'], $formValues['t']); + + if (isset($formValues['visible'])) { + if (!empty($productItem)) { + $plugin->updateItem( + ['price' => floatval($formValues['price'])], + $formValues['i'], + $formValues['t'] + ); + } else { + $itemId = $plugin->registerItem([ + 'currency_id' => $currency['id'], + 'product_type' => $formValues['t'], + 'product_id' => intval($formValues['i']), + 'price' => floatval($_POST['price']) + ]); + $productItem['id'] = $itemId; + } + + $plugin->deleteItemBeneficiaries($productItem['id']); + + if (isset($formValues['beneficiaries'])) { + $plugin->registerItemBeneficiaries($productItem['id'], $formValues['beneficiaries']); + } + } else { + $plugin->deleteItem($productItem['id']); + } + + header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/configuration.php'); + exit; +} + +$form->setDefaults($formDefaults); + +//View +$templateName = $plugin->get_lang('AvailableCourse'); + +$interbreadcrumb[] = [ + 'url' => 'paymentsetup.php', + 'name' => get_lang('Configuration') +]; +$interbreadcrumb[] = [ + 'url' => 'configuration.php', + 'name' => $plugin->get_lang('AvailableCourses') +]; + +$template = new Template($templateName); +$template->assign('header', $templateName); +$template->assign('content', $form->returnForm()); +$template->display_one_col_template(); diff --git a/plugin/buycourses/src/function.php b/plugin/buycourses/src/function.php index 5dca375fef..79a4a5b336 100644 --- a/plugin/buycourses/src/function.php +++ b/plugin/buycourses/src/function.php @@ -24,48 +24,25 @@ if ($_REQUEST['tab'] == 'save_mod') { } $affectedRows = false; + $item = $plugin->getItemByProduct($productId, $productType); if ($_POST['visible'] == 1) { - $item = Database::select( - 'COUNT(1) AS qty', - $itemTable, - [ - 'where' => [ - 'product_id = ? AND ' => intval($productId), - 'product_type = ?' => $productType - ] - ], - 'first' - ); - - if ($item['qty'] > 0) { - $affectedRows = Database::update( - $itemTable, + if (!empty($item)) { + $affectedRows = $plugin->updateItem( ['price' => floatval($_POST['price'])], - [ - 'product_id = ? AND ' => intval($productId), - 'product_type' => $productType - ] + $productId, + $productType ); } else { - $affectedRows = Database::insert( - $itemTable, - [ - 'currency_id' => $currency['id'], - 'product_type' => $productType, - 'product_id' => intval($productId), - 'price' => floatval($_POST['price']) - ] - ); + $affectedRows = $plugin->registerItem([ + 'currency_id' => $currency['id'], + 'product_type' => $productType, + 'product_id' => intval($productId), + 'price' => floatval($_POST['price']) + ]); } } else { - $affectedRows = Database::delete( - $itemTable, - [ - 'product_id = ? AND ' => intval($productId), - 'product_type = ?' => $productType - ] - ); + $affectedRows = $plugin->deleteItem($item['id']); } if ($affectedRows > 0) { diff --git a/plugin/buycourses/view/configuration.tpl b/plugin/buycourses/view/configuration.tpl index 9609b62b1c..24bbb84302 100644 --- a/plugin/buycourses/view/configuration.tpl +++ b/plugin/buycourses/view/configuration.tpl @@ -67,6 +67,9 @@ {% endif %} + + {{ 'Configure'|get_lang }} + @@ -133,7 +136,10 @@ {% endif %} - + + + {{ 'Configure'|get_lang }} + From 30bc15bd0aa0eabe8e7c4915c5a563a62e4ec020 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 25 Sep 2015 09:27:30 -0500 Subject: [PATCH 07/17] Only show courses details on configuration of available courses - refs #7768 --- plugin/buycourses/js/buycourses.js | 36 -------------- plugin/buycourses/src/function.php | 62 ------------------------ plugin/buycourses/view/configuration.tpl | 46 +++++------------- 3 files changed, 13 insertions(+), 131 deletions(-) delete mode 100644 plugin/buycourses/js/buycourses.js delete mode 100644 plugin/buycourses/src/function.php diff --git a/plugin/buycourses/js/buycourses.js b/plugin/buycourses/js/buycourses.js deleted file mode 100644 index 25c1927ade..0000000000 --- a/plugin/buycourses/js/buycourses.js +++ /dev/null @@ -1,36 +0,0 @@ -/* For licensing terms, see /license.txt */ -/** - * JS library for the Chamilo buy-courses plugin - * @package chamilo.plugin.buycourses - */ -$(document).ready(function () { - $(".bc-button-save").click(function () { - var currentRow = $(this).closest("tr"); - var courseOrSessionObject = { - tab: "save_mod", - visible: currentRow.find("[name='visible']").is(':checked') ? 1 : 0, - price: currentRow.find("[name='price']").val() - }; - - var itemField = currentRow.data('type') + '_id'; - - courseOrSessionObject[itemField] = currentRow.data('item') || 0; - - $.post( - "function.php", - courseOrSessionObject, - function (data) { - if (!data.status) { - return; - } - - currentRow.addClass('success'); - - window.setTimeout(function () { - currentRow.removeClass('success'); - }, 3000); - }, - "json" - ); - }); -}); diff --git a/plugin/buycourses/src/function.php b/plugin/buycourses/src/function.php deleted file mode 100644 index 79a4a5b336..0000000000 --- a/plugin/buycourses/src/function.php +++ /dev/null @@ -1,62 +0,0 @@ -getSelectedCurrency(); - -if ($_REQUEST['tab'] == 'save_mod') { - if (isset($_REQUEST['course_id'])) { - $productId = $_REQUEST['course_id']; - $productType = BuyCoursesPlugin::PRODUCT_TYPE_COURSE; - } else { - $productId = $_REQUEST['session_id']; - $productType = BuyCoursesPlugin::PRODUCT_TYPE_SESSION; - } - - $affectedRows = false; - $item = $plugin->getItemByProduct($productId, $productType); - - if ($_POST['visible'] == 1) { - if (!empty($item)) { - $affectedRows = $plugin->updateItem( - ['price' => floatval($_POST['price'])], - $productId, - $productType - ); - } else { - $affectedRows = $plugin->registerItem([ - 'currency_id' => $currency['id'], - 'product_type' => $productType, - 'product_id' => intval($productId), - 'price' => floatval($_POST['price']) - ]); - } - } else { - $affectedRows = $plugin->deleteItem($item['id']); - } - - if ($affectedRows > 0) { - $jsonResult = [ - "status" => true, - "itemId" => $productId - ]; - } else { - $jsonResult = [ - "status" => false, - "content" => $plugin->get_lang('ItemNotSaved') - ]; - } - - echo json_encode($jsonResult); - exit; -} diff --git a/plugin/buycourses/view/configuration.tpl b/plugin/buycourses/view/configuration.tpl index 24bbb84302..3d1c4f7d62 100644 --- a/plugin/buycourses/view/configuration.tpl +++ b/plugin/buycourses/view/configuration.tpl @@ -21,9 +21,9 @@ {{ 'Title'|get_lang }} {{ 'OfficialCode'|get_lang }} - {{ 'Visible'|get_lang }} + {{ 'VisibleInCatalog'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }} - {{ 'Option'|get_lang }} + {{ 'Options '|get_lang }} @@ -50,29 +50,19 @@ {{ item.course_code }} - {% if item.visible == 1 %} - + {% if item.visible %} + {% else %} - + {% endif %} - - {% if item.currency %} -
- {{ item.currency }} - -
- {% else %} - - {% endif %} + + {{ "#{item.price} #{tem.currency ?: item.currency}" }} {{ 'Configure'|get_lang }} - {% endfor %} @@ -90,9 +80,9 @@ {{ 'Title'|get_lang }} {{ 'StartDate'|get_lang }} {{ 'EndDate'|get_lang }} - {{ 'Visible'|get_lang }} + {{ 'VisibleInCatalog'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }} - {{ 'Option'|get_lang }} + {{ 'Options'|get_lang }} @@ -121,28 +111,18 @@ {% if item.visible %} - + {% else %} - + {% endif %} - {% if item.currency %} -
- {{ item.currency }} - -
- {% else %} - - {% endif %} + {{ "#{item.price} #{tem.currency ?: item.currency}" }} - + {{ 'Configure'|get_lang }} - {% endfor %} From e159a227e347aba15a1cdb1244083005cbd383a9 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 25 Sep 2015 09:37:28 -0500 Subject: [PATCH 08/17] Minor - Update changelog and plugin description - refs #7768 --- plugin/buycourses/CHANGELOG.md | 2 ++ plugin/buycourses/lang/english.php | 2 +- plugin/buycourses/lang/french.php | 2 +- plugin/buycourses/lang/spanish.php | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plugin/buycourses/CHANGELOG.md b/plugin/buycourses/CHANGELOG.md index 6576068e46..06b5a2daf1 100644 --- a/plugin/buycourses/CHANGELOG.md +++ b/plugin/buycourses/CHANGELOG.md @@ -12,6 +12,7 @@ in a currency other than the others courses or sessions Allowing filter the sales by its status - The plugin Registration page was removed. Instead the Chamilo LMS registrarion page is used. +- Added the ability to record beneficiaries with the sale of courses/sessions ##Changes in database structure @@ -40,6 +41,7 @@ The __new database__ structure is formed for the tables: - `plugin_buycourses_currency` The list of countries with their currencies - `plugin_buycourses_item` The registered courses and sessions in the platform +- `plugin_buycourses_item_re_beneficiary` The beneficiaries users with the sale of courses - `plugin_buycourses_paypal_account` The PayPal account info - `plugin_buycourses_sale` The sales of courses and sessions that were made - `plugin_buycourses_transfer` The bank accounts for transfers diff --git a/plugin/buycourses/lang/english.php b/plugin/buycourses/lang/english.php index f8ff35d464..4e846fc32a 100644 --- a/plugin/buycourses/lang/english.php +++ b/plugin/buycourses/lang/english.php @@ -1,6 +1,6 @@ Date: Fri, 25 Sep 2015 09:51:46 -0500 Subject: [PATCH 09/17] Set all course teachers or all session course coaches as beneficiaries by default - refs #7768 --- plugin/buycourses/src/configure_course.php | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/plugin/buycourses/src/configure_course.php b/plugin/buycourses/src/configure_course.php index 73c7ef5ee0..ae8e4a9eb5 100644 --- a/plugin/buycourses/src/configure_course.php +++ b/plugin/buycourses/src/configure_course.php @@ -43,7 +43,7 @@ if ($editingCourse) { } $courseItem = $plugin->getCourseForConfiguration($course, $currency); - + $defaultBeneficiaries = []; $teachers = $course->getTeachers(); $teachersOptions = []; @@ -54,9 +54,16 @@ if ($editingCourse) { 'text' => $teacher->getCompleteName(), 'value' => $teacher->getId() ]; + + $defaultBeneficiaries[] = $teacher->getId(); + } + + $currentBeneficiaries = $plugin->getItemBeneficiaries($courseItem['item_id']); + + if (!empty($currentBeneficiaries)) { + $defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id'); } - $beneficiaries = $plugin->getItemBeneficiaries($courseItem['item_id']); $currencyIso = $courseItem['currency']; $formDefaults = [ 'i' => $courseItem['course_id'], @@ -64,7 +71,7 @@ if ($editingCourse) { 'name' => $courseItem['course_title'], 'visible' => $courseItem['visible'], 'price' => $courseItem['price'], - 'beneficiaries' => array_column($beneficiaries, 'user_id') + 'beneficiaries' => $defaultBeneficiaries ]; } elseif ($editingSession) { if (!$includeSession) { @@ -83,6 +90,9 @@ if ($editingCourse) { 'text' => $generalCoach->getCompleteName(), 'value' => $generalCoach->getId() ]; + $defaultBeneficiaries = [ + $generalCoach->getId() + ]; $courseCoachesOptions = []; $sessionCourses = $session->getCourses(); @@ -98,10 +108,15 @@ if ($editingCourse) { 'text' => $courseCoach->getCompleteName(), 'value' => $courseCoach->getId() ]; + $defaultBeneficiaries[] = $courseCoach->getId(); } } - $beneficiaries = $plugin->getItemBeneficiaries($sessionItem['item_id']); + $currentBeneficiaries = $plugin->getItemBeneficiaries($sessionItem['item_id']); + + if (!empty($currentBeneficiaries)) { + $defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id'); + } $currencyIso = $sessionItem['currency']; $formDefaults = [ @@ -110,7 +125,7 @@ if ($editingCourse) { 'name' => $sessionItem['session_name'], 'visible' => $sessionItem['visible'], 'price' => $sessionItem['price'], - 'beneficiaries' => array_column($beneficiaries, 'user_id') + 'beneficiaries' => $defaultBeneficiaries ]; } else { api_not_allowed(true); From 583415069cc52d83dbdcc70a19af7ead17436013 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 25 Sep 2015 10:01:55 -0500 Subject: [PATCH 10/17] Fix the removal process of tables in the database - refs #7768 --- plugin/buycourses/src/buy_course_plugin.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index 954ae85b0e..a41a6d9d34 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -74,10 +74,10 @@ class BuyCoursesPlugin extends Plugin $tablesToBeDeleted = array( self::TABLE_PAYPAL, self::TABLE_TRANSFER, + self::TABLE_ITEM_BENEFICIARY, self::TABLE_ITEM, self::TABLE_SALE, - self::TABLE_CURRENCY, - self::TABLE_ITEM_BENEFICIARY + self::TABLE_CURRENCY ); foreach ($tablesToBeDeleted as $tableToBeDeleted) { From 4ceba14286a3db338eae38e9d13282d1ddf15ea3 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 25 Sep 2015 10:09:53 -0500 Subject: [PATCH 11/17] Minor - Update language files - refs #7768 --- plugin/buycourses/lang/english.php | 4 ++++ plugin/buycourses/lang/french.php | 6 +++++- plugin/buycourses/lang/spanish.php | 4 ++++ plugin/buycourses/src/configure_course.php | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugin/buycourses/lang/english.php b/plugin/buycourses/lang/english.php index 4e846fc32a..4513468153 100644 --- a/plugin/buycourses/lang/english.php +++ b/plugin/buycourses/lang/english.php @@ -84,3 +84,7 @@ $strings['InfoApiStepOne'] = "Go to your PayPal account, SummaryAPI d\'accès, cloquer sur l\'option Mettre à jour"; $strings['InfoApiStepThree'] = "Dans l\'option 2 de Configuration des données et permissions API, cliquer sur Voir signature API. Copier ces donées dans le formulaire de configuration de ce plugin"; $strings['ErrorOccurred'] = "Une erreur est survenue. Code: %s. Message: %s. Veuillez contacter l'administrateur de la plateforme"; +$strings['VisibleInCatalog'] = "Visible dans le catalogue"; +$strings['Beneficiaries'] = "Bénéficiaires"; +$strings['AvailableCourse'] = "Cours disponibles"; +$strings['ShowOnCourseCatalog'] = "Afficher sur le catalogue des cours"; diff --git a/plugin/buycourses/lang/spanish.php b/plugin/buycourses/lang/spanish.php index 6fda0428b3..f53ee22d93 100644 --- a/plugin/buycourses/lang/spanish.php +++ b/plugin/buycourses/lang/spanish.php @@ -84,3 +84,7 @@ $strings['InfoApiStepOne'] = "Ir a la opción de Perfil de PayPaladdElement( ); $beneficiariesSelect = $form->addSelect( 'beneficiaries', - get_lang('Beneficiaries'), + $plugin->get_lang('Beneficiaries'), null, ['multiple' => 'multiple'] ); From dc970620c7a42462f5de726eb2236b955677a7be Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 25 Sep 2015 10:23:11 -0500 Subject: [PATCH 12/17] Show product type on configuration course - refs #7768 --- plugin/buycourses/src/configure_course.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugin/buycourses/src/configure_course.php b/plugin/buycourses/src/configure_course.php index 5a9045a15d..594bc2d162 100644 --- a/plugin/buycourses/src/configure_course.php +++ b/plugin/buycourses/src/configure_course.php @@ -66,6 +66,7 @@ if ($editingCourse) { $currencyIso = $courseItem['currency']; $formDefaults = [ + 'product_type' => get_lang('Course'), 'i' => $courseItem['course_id'], 't' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE, 'name' => $courseItem['course_title'], @@ -120,6 +121,7 @@ if ($editingCourse) { $currencyIso = $sessionItem['currency']; $formDefaults = [ + 'product_type' => get_lang('Session'), 'i' => $session->getId(), 't' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION, 'name' => $sessionItem['session_name'], @@ -132,8 +134,13 @@ if ($editingCourse) { } $form = new FormValidator('beneficiaries'); +$form->addText('product_type', $plugin->get_lang('ProductType'), false); $form->addText('name', get_lang('Name'), false); -$visibleCheckbox = $form->addCheckBox('visible', get_lang('Visible'), 'Mostrar en el catálogo de cursos'); +$visibleCheckbox = $form->addCheckBox( + 'visible', + $plugin->get_lang('VisibleInCatalog'), + $plugin->get_lang('ShowOnCourseCatalog') +); $form->addElement( 'number', 'price', @@ -157,7 +164,7 @@ if ($editingCourse) { $form->addHidden('t', null); $form->addHidden('i', null); $form->addButtonSave(get_lang('Save')); -$form->freeze(['name']); +$form->freeze(['product_type', 'name']); if ($form->validate()) { $formValues = $form->exportValues(); From e406e2ee8cfb597951ccac4f1ec2b77875b1f77d Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 25 Sep 2015 10:50:59 -0500 Subject: [PATCH 13/17] Fix install process to avoid re-install plugin - refs #7768 --- plugin/buycourses/src/buy_course_plugin.class.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index a41a6d9d34..28b417d03a 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -63,6 +63,13 @@ class BuyCoursesPlugin extends Plugin */ function install() { + $appPlugin = new AppPlugin(); + $installedPlugins = $appPlugin->get_installed_plugins(); + + if (in_array($this->get_name(), $installedPlugins)) { + return false; + } + require_once api_get_path(SYS_PLUGIN_PATH) . 'buycourses/database.php'; } From 2dc814909c1f115043c42a7226c1587393d18865 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 25 Sep 2015 14:05:13 -0500 Subject: [PATCH 14/17] Change location for videos on WebRTC Video chat - refs #7558 --- main/template/default/chat/video.tpl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/main/template/default/chat/video.tpl b/main/template/default/chat/video.tpl index 542fa454a1..746d3048c3 100644 --- a/main/template/default/chat/video.tpl +++ b/main/template/default/chat/video.tpl @@ -9,7 +9,15 @@

-
+
+
+
+
+

{{ "ChatWithXUser"|get_lang|format(chat_user.complete_name) }}

+
+
+
+
@@ -36,14 +44,6 @@
-
-
-
-
-

{{ "ChatWithXUser"|get_lang|format(chat_user.complete_name) }}

-
-
-