|
3 | 3 |
|
4 | 4 | /** |
5 | 5 | * Configuration script for the Buy Courses plugin. |
| 6 | + * |
| 7 | + * @package chamilo.plugin.buycourses |
6 | 8 | */ |
7 | 9 |
|
8 | 10 | use Chamilo\CoreBundle\Entity\Course; |
|
42 | 44 | Display::addFlash( |
43 | 45 | Display::return_message($plugin->get_lang('CurrencyIsNotConfigured'), 'error') |
44 | 46 | ); |
| 47 | + $currency = null; |
45 | 48 | } |
46 | 49 |
|
47 | 50 | $currencyIso = null; |
|
71 | 74 | $defaultBeneficiaries[] = $teacher->getId(); |
72 | 75 | } |
73 | 76 |
|
74 | | - $currentBeneficiaries = $plugin->getItemBeneficiaries($courseItem['item_id']); |
75 | | - if (!empty($currentBeneficiaries)) { |
76 | | - $defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id'); |
77 | | - if ('true' === $commissionsEnable) { |
78 | | - $defaultCommissions = array_column($currentBeneficiaries, 'commissions'); |
79 | | - foreach ($defaultCommissions as $defaultCommission) { |
80 | | - $commissions .= $defaultCommission.','; |
| 77 | + if (!empty($courseItem['item_id'])) { |
| 78 | + $currentBeneficiaries = $plugin->getItemBeneficiaries($courseItem['course_id']); |
| 79 | + |
| 80 | + if (!empty($currentBeneficiaries)) { |
| 81 | + $defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id'); |
| 82 | + |
| 83 | + if ('true' === $commissionsEnable) { |
| 84 | + $defaultCommissions = array_column($currentBeneficiaries, 'commissions'); |
| 85 | + |
| 86 | + foreach ($defaultCommissions as $defaultCommission) { |
| 87 | + $commissions .= $defaultCommission.','; |
| 88 | + } |
| 89 | + |
| 90 | + $commissions = substr($commissions, 0, -1); |
81 | 91 | } |
82 | | - $commissions = substr($commissions, 0, -1); |
83 | 92 | } |
84 | | - } |
85 | 93 |
|
86 | | - $currencyIso = $courseItem['currency']; |
87 | | - $formDefaults = [ |
88 | | - 'product_type' => get_lang('Course'), |
89 | | - 'id' => $courseItem['course_id'], |
90 | | - 'type' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE, |
91 | | - 'name' => $courseItem['course_title'], |
92 | | - 'visible' => $courseItem['visible'], |
93 | | - 'price' => $courseItem['price'], |
94 | | - 'tax_perc' => $courseItem['tax_perc'], |
95 | | - 'beneficiaries' => $defaultBeneficiaries, |
96 | | - 'true' == $commissionsEnable ? 'commissions' : '' => 'true' == $commissionsEnable ? $commissions : '', |
97 | | - ]; |
| 94 | + $currencyIso = $courseItem['currency']; |
| 95 | + $formDefaults = [ |
| 96 | + 'product_type' => get_lang('Course'), |
| 97 | + 'id' => $courseItem['course_id'], |
| 98 | + 'type' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE, |
| 99 | + 'name' => $courseItem['course_title'], |
| 100 | + 'visible' => $courseItem['visible'], |
| 101 | + 'price' => $courseItem['price'], |
| 102 | + 'tax_perc' => $courseItem['tax_perc'], |
| 103 | + 'beneficiaries' => $defaultBeneficiaries, |
| 104 | + ]; |
| 105 | + |
| 106 | + if ('true' == $commissionsEnable) { |
| 107 | + $formDefaults['commissions'] = $commissions; |
| 108 | + } |
| 109 | + } else { |
| 110 | + $formDefaults = [ |
| 111 | + 'product_type' => get_lang('Course'), |
| 112 | + 'id' => $courseItem['course_id'], |
| 113 | + 'type' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE, |
| 114 | + 'name' => $courseItem['course_title'], |
| 115 | + 'visible' => false, |
| 116 | + 'price' => 0, |
| 117 | + 'tax_perc' => 0, |
| 118 | + 'beneficiaries' => [], |
| 119 | + ]; |
| 120 | + |
| 121 | + if ('true' == $commissionsEnable) { |
| 122 | + $formDefaults['commissions'] = $commissions; |
| 123 | + } |
| 124 | + } |
98 | 125 | } elseif ($editingSession) { |
99 | 126 | if (!$includeSession) { |
100 | 127 | api_not_allowed(true); |
|
137 | 164 | } |
138 | 165 | } |
139 | 166 |
|
140 | | - $currentBeneficiaries = $plugin->getItemBeneficiaries($sessionItem['item_id']); |
| 167 | + if ($sessionItem['item_id']) { |
| 168 | + $currentBeneficiaries = $plugin->getItemBeneficiaries($sessionItem['item_id']); |
| 169 | + } |
141 | 170 |
|
142 | 171 | if (!empty($currentBeneficiaries)) { |
143 | 172 | $defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id'); |
|
163 | 192 | 'price' => $sessionItem['price'], |
164 | 193 | 'tax_perc' => $sessionItem['tax_perc'], |
165 | 194 | 'beneficiaries' => $defaultBeneficiaries, |
166 | | - 'true' == $commissionsEnable ? 'commissions' : '' => 'true' == $commissionsEnable ? $commissions : '', |
167 | 195 | ]; |
| 196 | + |
| 197 | + if ('true' == $commissionsEnable) { |
| 198 | + $formDefaults['commissions'] = $commissions; |
| 199 | + } |
168 | 200 | } else { |
169 | 201 | api_not_allowed(true); |
170 | 202 | } |
|
296 | 328 | $plugin->deleteItemBeneficiaries($productItem['id']); |
297 | 329 |
|
298 | 330 | if (isset($formValues['beneficiaries'])) { |
299 | | - if ('true' === $commissionsEnable) { |
| 331 | + if ($commissionsEnable === 'true') { |
300 | 332 | $usersId = $formValues['beneficiaries']; |
301 | 333 | $commissions = explode(',', $formValues['commissions']); |
302 | 334 | $commissions = (count($usersId) != count($commissions)) |
|
310 | 342 | } |
311 | 343 | $plugin->registerItemBeneficiaries($productItem['id'], $beneficiaries); |
312 | 344 | } |
313 | | - } else { |
| 345 | + } elseif (!empty($productItem['id'])) { |
314 | 346 | $plugin->deleteItem($productItem['id']); |
315 | 347 | } |
316 | 348 |
|
317 | | - header('Location: '.api_get_path(WEB_PLUGIN_PATH).'BuyCourses/src/list.php'); |
| 349 | + $url = 'list.php'; |
| 350 | + |
| 351 | + if ($type == 2) { |
| 352 | + $url = 'list_session.php'; |
| 353 | + } |
| 354 | + header('Location: '.api_get_path(WEB_PLUGIN_PATH).'BuyCourses/src/'.$url); |
318 | 355 | exit; |
319 | 356 | } |
320 | 357 |
|
321 | 358 | $form->setDefaults($formDefaults); |
322 | 359 |
|
323 | | -$templateName = $plugin->get_lang('AvailableCourse'); |
324 | | - |
| 360 | +$templateName = ''; |
325 | 361 | $interbreadcrumb[] = [ |
326 | 362 | 'url' => 'paymentsetup.php', |
327 | 363 | 'name' => get_lang('Configuration'), |
328 | 364 | ]; |
329 | | -$interbreadcrumb[] = [ |
330 | | - 'url' => 'list.php', |
331 | | - 'name' => $plugin->get_lang('AvailableCourses'), |
332 | | -]; |
| 365 | +switch ($type) { |
| 366 | + case 2: |
| 367 | + $interbreadcrumb[] = [ |
| 368 | + 'url' => 'list_session.php', |
| 369 | + 'name' => $plugin->get_lang('Sessions'), |
| 370 | + ]; |
| 371 | + $templateName = $plugin->get_lang('Sessions'); |
| 372 | + break; |
| 373 | + default: |
| 374 | + $interbreadcrumb[] = [ |
| 375 | + 'url' => 'list.php', |
| 376 | + 'name' => $plugin->get_lang('Available Courses'), |
| 377 | + ]; |
| 378 | + $templateName = $plugin->get_lang('Available course'); |
| 379 | +} |
333 | 380 |
|
334 | 381 | $template = new Template($templateName); |
335 | 382 | $template->assign('header', $templateName); |
|
0 commit comments