<?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.

/**
 * Télécharge le modèle CSV d'import des compétences pour une session CAPP,
 * au même format que l'import CSV pour permettre un aller-retour direct.
 *
 * @package local_kid
 */

require(__DIR__ . '/../../../config.php');

use local_kid\local\access_helper;
use local_kid\local\capp_repository;
use local_kid\local\csv_import_service;

require_login();
$context = context_system::instance();
access_helper::require_capability_or_teacher('local/kid:evaluate_capp', $context);

$sessionid = required_param('sessionid', PARAM_INT);
$session = capp_repository::get_session($sessionid);
if (!$session) {
    throw new \moodle_exception('invalidrecord', 'error');
}

$content = capp_repository::build_csv_template_competences($session);
$filename = clean_param('capp_' . $session->code . '_competences.csv', PARAM_FILE);
csv_import_service::send($content, $filename);
