81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?php
|
|
namespace local_treestudyplan;
|
|
|
|
use \local_treestudyplan\local\gradegenerator;
|
|
|
|
define('CLI_SCRIPT', true);
|
|
require(__DIR__ . '/../../../config.php');
|
|
require_once($CFG->libdir . '/clilib.php');
|
|
|
|
$usage = "Prime the generator with random stats for all relevant students
|
|
Usage:
|
|
# php prime_students.php --studyplan=<shortname> [--file|-f=userfile]
|
|
# php prime_students.php --all|-a [--file|-f=userfile]
|
|
# php prime_students.php --help|-h
|
|
|
|
Options:
|
|
-h --help Print this help.
|
|
--file=<value> Specify file name to store generated user specs in.
|
|
";
|
|
|
|
list($options, $unrecognised) = cli_get_params([
|
|
'help' => false,
|
|
'studyplan' => null,
|
|
'all' => false,
|
|
'file' => "/tmp/generategrades.json"
|
|
], [
|
|
'h' => 'help',
|
|
's' => 'studyplan',
|
|
'a' => 'all',
|
|
'f' => 'file',
|
|
]);
|
|
|
|
if ($unrecognised) {
|
|
$unrecognised = implode(PHP_EOL . ' ', $unrecognised);
|
|
cli_error(get_string('cliunknowoption', 'core_admin', $unrecognised));
|
|
}
|
|
|
|
if ($options['help']) {
|
|
cli_writeln($usage);
|
|
exit(2);
|
|
}
|
|
//cli_writeln(print_r($options,true));
|
|
|
|
if (empty($options['studyplan']) && empty($options["all"])) {
|
|
cli_error('Missing mandatory argument studyplan.', 2);
|
|
}
|
|
|
|
if(!empty($options["all"])){
|
|
$plans = studyplan::find_all();
|
|
} else {
|
|
$plans = studyplan::find_by_shortname($options["studyplan"]);
|
|
}
|
|
|
|
|
|
$generator = new gradegenerator();
|
|
$generator->fromFile($options["file"]);
|
|
|
|
cli_writeln(count($plans)." studyplans found:");
|
|
foreach($plans as $plan){
|
|
cli_heading($plan->name());
|
|
$users = $plan->find_linked_users();
|
|
foreach($users as $u){
|
|
$generator->addstudent($u->username);
|
|
$generator->addUserNameInfo($u->username,$u->firstname,$u->lastname);
|
|
cli_writeln(" - {$u->firstname} {$u->lastname} / {$u->username}");
|
|
}
|
|
|
|
foreach($plan->pages() as $page){
|
|
$lines = studyline::find_page_children($page);
|
|
foreach($lines as $line){
|
|
cli_writeln(" ** {$line->name()} **");
|
|
$items = studyitem::find_studyline_children($line);
|
|
foreach($users as $u){
|
|
$generator->addskill($u->username,$line->shortname());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$generator->toFile($options["file"]);
|