<?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');

class local_kid_stage_form extends moodleform {

    protected function definition() {
        $mform = $this->_form;
        $competencyoptions = $this->_customdata['competencyoptions'];
        $isediting = !empty($this->_customdata['isediting']);

        $mform->addElement('hidden', 'id');
        $mform->setType('id', PARAM_INT);
        $mform->addElement('hidden', 'promotionid');
        $mform->setType('promotionid', PARAM_INT);

        $mform->addElement('text', 'libelle', get_string('stage_libelle', 'local_kid'), ['maxlength' => 255, 'size' => 60]);
        $mform->setType('libelle', PARAM_TEXT);
        $mform->addRule('libelle', get_string('required'), 'required', null, 'client');

        $mform->addElement('date_selector', 'datedebut', get_string('stage_datedebut', 'local_kid'), ['optional' => true]);
        $mform->addElement('date_selector', 'datefin', get_string('stage_datefin', 'local_kid'), ['optional' => true]);

        $mform->addElement('select', 'competencyscope', get_string('stage_competencyscope', 'local_kid'), [
            'all' => get_string('stage_competencyscope_all', 'local_kid'),
            'custom' => get_string('stage_competencyscope_custom', 'local_kid'),
        ]);

        $mform->addElement('select', 'competencyids', get_string('eval_competencies', 'local_kid'), $competencyoptions,
            ['multiple' => 'multiple', 'size' => min(10, max(4, count($competencyoptions)))]);
        $mform->hideIf('competencyids', 'competencyscope', 'eq', 'all');

        if ($isediting) {
            $mform->addElement('advcheckbox', 'active', get_string('competency_active', 'local_kid'));
            $mform->setDefault('active', 1);
        }

        $this->add_action_buttons();
    }
}
