<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir . '/formslib.php');

/**
 * Reused on every screen scoped to "the" currently displayed promotion
 * (admin Compétences/Niveaux-less-so/Stages/Évaluations/CAPP, dashboard).
 * Submits GET so the resulting URL is bookmarkable/shareable.
 */
class local_kid_promotion_switch_form extends moodleform {

    public function __construct($action, array $customdata) {
        parent::__construct($action, $customdata, 'get');
    }

    protected function definition() {
        $mform = $this->_form;
        $mform->disable_form_change_checker();

        foreach ($this->_customdata['hidden'] ?? [] as $name => $value) {
            $mform->addElement('hidden', $name, $value);
            $mform->setType($name, PARAM_ALPHANUMEXT);
        }

        $promotions = $this->_customdata['promotions'];
        $mform->addElement('select', 'promotionid', get_string('promotion_switch', 'local_kid'), $promotions);

        $mform->addElement('submit', 'switchsubmit', get_string('promotion_switch_go', 'local_kid'));
    }
}
