/** * addAreaField() (adds an area field if it is not already created) * @return void */ private function addAreaField() { $extraField = new ExtraField('user'); $extraFieldHandler = $extraField->get_handler_field_info_by_field_variable('area'); $areaExists = $extraFieldHandler !== false; if (!$areaExists) { $extraField = new ExtraField('user'); $extraField->save(array('field_type' => 1, 'variable' => 'area', 'display_text' => get_plugin_lang('Area', 'AdvancedSubscriptionPlugin'), 'default_value' => null, 'field_order' => null, 'visible' => 1, 'changeable' => 1, 'filter' => null)); } }
/** * @param HookAdminBlockEventInterface $hook * @return int */ public function hookAdminBlock(HookAdminBlockEventInterface $hook) { $data = $hook->getEventData(); if ($data['type'] === HOOK_EVENT_TYPE_PRE) { // Nothing to do } elseif ($data['type'] === HOOK_EVENT_TYPE_POST) { if (isset($data['blocks'])) { $data['blocks']['sessions']['items'][] = array('url' => '../../plugin/advanced_subscription/src/admin_view.php', 'label' => get_plugin_lang('plugin_title', 'AdvancedSubscriptionPlugin')); } } else { // Hook type is not valid // Nothing to do } return $data; }
/** * Limit session resubscription when a Chamilo user is resubscribed to a session * @param HookCreateUserEventInterface $hook The hook */ public function hookResubscribe(HookResubscribeEventInterface $hook) { $data = $hook->getEventData(); if ($data['type'] === HOOK_EVENT_TYPE_PRE) { $resubscriptionLimit = Resubscription::create()->get('resubscription_limit'); // Initialize variables as a calendar year by default $limitDateFormat = 'Y-01-01'; $limitDate = gmdate($limitDateFormat); $resubscriptionOffset = "1 year"; // No need to use a 'switch' with only two options so an 'if' is enough. // However this could change if the number of options increases if ($resubscriptionLimit === 'natural_year') { $limitDateFormat = 'Y-m-d'; $limitDate = gmdate($limitDateFormat); $limitDate = gmdate($limitDateFormat, strtotime("{$limitDate} -{$resubscriptionOffset}")); } $join = " INNER JOIN " . Database::get_main_table(TABLE_MAIN_SESSION) . "ON id = session_id"; // User sessions and courses $userSessions = Database::select('session_id, date_end', Database::get_main_table(TABLE_MAIN_SESSION_USER) . $join, array('where' => array('user_id = ? AND date_end >= ?' => array(api_get_user_id(), $limitDate)), 'order' => 'date_end DESC')); $userSessionCourses = array(); foreach ($userSessions as $userSession) { $userSessionCourseResult = Database::select('c_id', Database::get_main_table(TABLE_MAIN_SESSION_COURSE), array('where' => array('session_id = ?' => array($userSession['session_id'])))); foreach ($userSessionCourseResult as $userSessionCourse) { if (!isset($userSessionCourses[$userSessionCourse['c_id']])) { $userSessionCourses[$userSessionCourse['c_id']] = $userSession['date_end']; } } } // Current session and courses $currentSessionCourseResult = Database::select('c_id', Database::get_main_table(TABLE_MAIN_SESSION_COURSE), array('where' => array('session_id = ?' => array($data['session_id'])))); // Check if current course code matches with one of the users foreach ($currentSessionCourseResult as $currentSessionCourse) { if (isset($userSessionCourses[$currentSessionCourse['c_id']])) { $endDate = $userSessionCourses[$currentSessionCourse['c_id']]; $resubscriptionDate = gmdate($limitDateFormat, strtotime($endDate . " +{$resubscriptionOffset}")); $icon = Display::return_icon('students.gif', get_lang('Student')); $canResubscribeFrom = sprintf(get_plugin_lang('CanResubscribeFromX', 'resubscription'), $resubscriptionDate); throw new Exception(Display::label($icon . ' ' . $canResubscribeFrom, "info")); } } } }
$totalPayout = 0; $payouts = isset($_POST['payouts']) ? $_POST['payouts'] : ''; if (!$payouts) { echo Display::return_message(get_plugin_lang("SelectOptionToProceed", "BuyCoursesPlugin"), 'error', false); break; } foreach ($payouts as $index => $id) { $allPayouts[] = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING, $id); } $currentCurrency = $plugin->getSelectedCurrency(); $isoCode = $currentCurrency['iso_code']; $result = MassPayment($allPayouts, $isoCode); if ($result['ACK'] === 'Success') { foreach ($allPayouts as $payout) { $plugin->setStatusPayouts($payout['id'], BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED); } echo Display::return_message(get_plugin_lang("PayoutSuccess", "BuyCoursesPlugin"), 'success', false); } else { echo Display::return_message('<b>' . $result['L_SEVERITYCODE0'] . ' ' . $result['L_ERRORCODE0'] . '</b> - ' . $result['L_SHORTMESSAGE0'] . '</br><ul><li>' . $result['L_LONGMESSAGE0'] . '</li></ul>', 'error', false); } break; case 'cancelPayout': if (api_is_anonymous()) { break; } $payoutId = isset($_POST['id']) ? $_POST['id'] : ''; $plugin->setStatusPayouts($payoutId, BuyCoursesPlugin::PAYOUT_STATUS_CANCELED); echo ''; break; } exit;
/** * Return an icon representing the visibility of the course * @param int $option The course visibility * @return string HTML string of the visibility icon */ function getCourseVisibilityIcon($option) { $style = 'margin-bottom:-5px;margin-right:5px;'; switch ($option) { case 0: return Display::return_icon('bullet_red.gif', get_plugin_lang('CourseVisibilityClosed', 'BuyCoursesPlugin'), array('style' => $style)); break; case 1: return Display::return_icon('bullet_orange.gif', get_plugin_lang('Private', 'BuyCoursesPlugin'), array('style' => $style)); break; case 2: return Display::return_icon('bullet_green.gif', get_plugin_lang('OpenToThePlatform', 'BuyCoursesPlugin'), array('style' => $style)); break; case 3: return Display::return_icon('bullet_blue.gif', get_plugin_lang('OpenToTheWorld', 'BuyCoursesPlugin'), array('style' => $style)); break; default: return Display::return_icon('bullet_grey.gif', get_plugin_lang('CourseVisibilityHidden', 'BuyCoursesPlugin'), array('style' => $style)); } }
/** * Create the drupal_user_id when it not exists */ private function createExtraField() { $extraFieldExists = $this->getExtraFieldInfo() !== false; if (!$extraFieldExists) { $extraField = new ExtraField('user'); $extraField->save(['field_type' => ExtraField::FIELD_TYPE_INTEGER, 'variable' => self::EXTRAFIELD_VARIABLE_NAME, 'display_text' => get_plugin_lang('DrupalUserId', 'CreateDrupalUser'), 'default_value' => null, 'field_order' => null, 'visible' => false, 'changeable' => false, 'filter' => null]); } }
$form->addText('product_type', $plugin->get_lang('ProductType'), false); $form->addText('name', get_lang('Name'), false); $visibleCheckbox = $form->addCheckBox('visible', $plugin->get_lang('VisibleInCatalog'), $plugin->get_lang('ShowOnCourseCatalog')); $form->addElement('number', 'price', [$plugin->get_lang('Price'), null, $currencyIso], ['step' => 0.01]); $beneficiariesSelect = $form->addSelect('beneficiaries', $plugin->get_lang('Beneficiaries'), null, ['multiple' => 'multiple', 'id' => 'selectBox']); if ($editingCourse) { $teachersOptions = api_unique_multidim_array($teachersOptions, 'value'); $beneficiariesSelect->addOptGroup($teachersOptions, get_lang('Teachers')); } elseif ($editingSession) { $courseCoachesOptions = api_unique_multidim_array($courseCoachesOptions, 'value'); $beneficiariesSelect->addOptGroup([$generalCoachOption], get_lang('SessionGeneralCoach')); $beneficiariesSelect->addOptGroup($courseCoachesOptions, get_lang('SessionCourseCoach')); } if ($commissionsEnable === 'true') { $platformCommission = $plugin->getPlatformCommission(); $form->addHtml('' . '<div class="form-group">' . '<label for="sliders" class="col-sm-2 control-label">' . get_plugin_lang('Commissions', 'BuyCoursesPlugin') . '</label>' . '<div class="col-sm-8">' . Display::return_message(sprintf($plugin->get_lang('TheActualPlatformCommissionIsX'), $platformCommission['commission'] . '%'), 'info', false) . '<div class="" id="panelSliders"></div>' . '</div>' . '</div>'); $form->addHidden('commissions', ''); } $form->addHidden('t', null); $form->addHidden('i', null); $form->addButtonSave(get_lang('Save')); $form->freeze(['product_type', '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;