Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Settings for the Fee enrolment plugin
  19   *
  20   * @package    enrol_fee
  21   * @copyright  2019 Shamim Rezaie <shamim@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  if ($ADMIN->fulltree) {
  28  
  29      $currencies = enrol_get_plugin('fee')->get_possible_currencies();
  30  
  31      if (empty($currencies)) {
  32          $notify = new \core\output\notification(
  33              get_string('nocurrencysupported', 'core_payment'),
  34              \core\output\notification::NOTIFY_WARNING
  35          );
  36          $settings->add(new admin_setting_heading('enrol_fee_nocurrency', '', $OUTPUT->render($notify)));
  37      }
  38  
  39      $settings->add(new admin_setting_heading('enrol_fee_settings', '', get_string('pluginname_desc', 'enrol_fee')));
  40  
  41      // Note: let's reuse the ext sync constants and strings here, internally it is very similar,
  42      // it describes what should happen when users are not supposed to be enrolled any more.
  43      $options = array(
  44          ENROL_EXT_REMOVED_KEEP           => get_string('extremovedkeep', 'enrol'),
  45          ENROL_EXT_REMOVED_SUSPENDNOROLES => get_string('extremovedsuspendnoroles', 'enrol'),
  46          ENROL_EXT_REMOVED_UNENROL        => get_string('extremovedunenrol', 'enrol'),
  47      );
  48      $settings->add(new admin_setting_configselect(
  49          'enrol_fee/expiredaction',
  50          get_string('expiredaction', 'enrol_fee'),
  51          get_string('expiredaction_help', 'enrol_fee'),
  52          ENROL_EXT_REMOVED_SUSPENDNOROLES,
  53          $options));
  54  
  55      $settings->add(new admin_setting_heading('enrol_fee_defaults',
  56          get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin')));
  57  
  58      $options = array(ENROL_INSTANCE_ENABLED  => get_string('yes'),
  59                       ENROL_INSTANCE_DISABLED => get_string('no'));
  60      $settings->add(new admin_setting_configselect('enrol_fee/status',
  61          get_string('status', 'enrol_fee'), get_string('status_desc', 'enrol_fee'), ENROL_INSTANCE_DISABLED, $options));
  62  
  63      if (!empty($currencies)) {
  64          $settings->add(new admin_setting_configtext('enrol_fee/cost', get_string('cost', 'enrol_fee'), '', 0, PARAM_FLOAT, 4));
  65          $settings->add(new admin_setting_configselect('enrol_fee/currency', get_string('currency', 'enrol_fee'), '', 'USD',
  66              $currencies));
  67      }
  68  
  69      if (!during_initial_install()) {
  70          $options = get_default_enrol_roles(context_system::instance());
  71          $student = get_archetype_roles('student');
  72          $student = reset($student);
  73          $settings->add(new admin_setting_configselect('enrol_fee/roleid',
  74              get_string('defaultrole', 'enrol_fee'), get_string('defaultrole_desc', 'enrol_fee'), $student->id ?? null, $options));
  75      }
  76  
  77      $settings->add(new admin_setting_configduration('enrol_fee/enrolperiod',
  78          get_string('enrolperiod', 'enrol_fee'), get_string('enrolperiod_desc', 'enrol_fee'), 0));
  79  }