Breaking database changes to support periods and studyplan pages.
This commit is contained in:
parent
c9e25b765d
commit
ff321e21c5
|
@ -125,9 +125,9 @@ class badgeinfo {
|
|||
|
||||
if($issued) {
|
||||
$issueinfo = $DB->get_record('badge_issued', array('badgeid' => $this->badge->id, 'userid' => $userid));
|
||||
$badge['dateissued'] = userdate($issueinfo->dateissued,"%e %b %G");
|
||||
$badge['dateissued'] = date("Y-m-d",$issueinfo->dateissued);
|
||||
if($issueinfo->expiredate){
|
||||
$badge['dateexpire'] = userdate($issueinfo->dateexpire,"%e %b %G");
|
||||
$badge['dateexpire'] = date("Y-m-d",$issueinfo->dateexpire);
|
||||
}
|
||||
$badge['uniquehash'] = $issueinfo->uniquehash;
|
||||
$badge['issuedlink'] = (new \moodle_url('/badges/badge.php', ['hash' => $issueinfo->uniquehash]))->out(false);
|
||||
|
|
|
@ -179,7 +179,7 @@ class corecompletioninfo {
|
|||
$details = [
|
||||
"type" => get_string('datepassed', 'completion'),
|
||||
"criteria" => get_string('remainingenroleduntildate', 'completion'),
|
||||
"requirement" => userdate($criteria->timeend, '%d %B %Y'),
|
||||
"requirement" => date("Y-m-d",$criteria->timeend),
|
||||
"status" => "",
|
||||
];
|
||||
}
|
||||
|
|
|
@ -197,8 +197,8 @@ class courseinfo {
|
|||
'context' => $contextinfo->model(),
|
||||
'ctxid' => $this->coursecontext->id,
|
||||
'timing' => $timing,
|
||||
'startdate' => userdate($this->course->startdate,"%e %b %G"),
|
||||
'enddate' => userdate($this->course->enddate, "%e %b %G"),
|
||||
'startdate' => date("Y-m-d",$this->course->startdate,),
|
||||
'enddate' => date("Y-m-d",$this->course->enddate),
|
||||
'amteacher' => $this->amTeacher(),
|
||||
'canselectgradables' => $this->iCanSelectGradables(),
|
||||
'tag' => "Editormodel",
|
||||
|
@ -250,12 +250,11 @@ class courseinfo {
|
|||
'context' => $contextinfo->model(),
|
||||
'ctxid' => $this->coursecontext->id,
|
||||
'timing' => $timing,
|
||||
'startdate' => userdate($this->course->startdate,"%e %b %G"),
|
||||
'enddate' => userdate($this->course->enddate, "%e %b %G"),
|
||||
'startdate' => date("Y-m-d",$this->course->startdate),
|
||||
'enddate' => date("Y-m-d",$this->course->enddate),
|
||||
'grades' => [],
|
||||
];
|
||||
|
||||
|
||||
if(!$usecorecompletioninfo){
|
||||
$gradables = gradeinfo::list_studyitem_gradables($this->studyitem);
|
||||
foreach($gradables as $gi) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="local/treestudyplan/db" VERSION="20230718" COMMENT="XMLDB file for Moodle local/treestudyplan"
|
||||
<XMLDB PATH="local/treestudyplan/db" VERSION="20230719" COMMENT="XMLDB file for Moodle local/treestudyplan"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
|
@ -65,6 +65,7 @@
|
|||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="studyplan_id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="page_id" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="name" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="shortname" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="color" TYPE="char" LENGTH="12" NOTNULL="false" SEQUENCE="false"/>
|
||||
|
@ -72,7 +73,7 @@
|
|||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="studyplan_id-id" TYPE="foreign" FIELDS="studyplan_id" REFTABLE="local_treestudyplan" REFFIELDS="id"/>
|
||||
<KEY NAME="page_id-id" TYPE="foreign" FIELDS="page_id" REFTABLE="local_treestudyplan_page" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="local_treestudyplan_item" COMMENT="Table">
|
||||
|
@ -149,14 +150,30 @@
|
|||
</TABLE>
|
||||
<TABLE NAME="local_treestudyplan_period" COMMENT="Stores timing information about the different periods in a study plan page">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="studyplan_id" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="page_id" TYPE="int" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="period" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="starttime" TYPE="int" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="endtime" TYPE="int" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="startdate" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="enddate" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="shortname" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="fullname" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="page_id-id" TYPE="foreign" FIELDS="page_id" REFTABLE="local_treestudyplan_page" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="local_treestudyplan_page" COMMENT="Single page in a studyplan">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="studyplan_id" TYPE="int" LENGTH="20" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="periods" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="fullname" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="shortname" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="startdate" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="enddate" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
|
|
161
db/upgrade.php
161
db/upgrade.php
|
@ -219,31 +219,178 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
|
|||
// Treestudyplan savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2023063002, 'local', 'treestudyplan');
|
||||
}
|
||||
if ($oldversion < 2023071801) {
|
||||
if ($oldversion < 2023071900) {
|
||||
|
||||
/******
|
||||
* Prepare the studyline table to hold links to pages insted of study plans
|
||||
* And drop the foreign key constraint for the studyplan_id-id relation
|
||||
*/
|
||||
// Define field page_id to be added to local_treestudyplan_line.
|
||||
$table = new xmldb_table('local_treestudyplan_line');
|
||||
$field = new xmldb_field('page_id', XMLDB_TYPE_INTEGER, '20', null, null, null, null, 'studyplan_id');
|
||||
|
||||
// Conditionally launch add field page_id.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Define key studyplan_id-id (foreign) to be dropped form local_treestudyplan_line.
|
||||
$table = new xmldb_table('local_treestudyplan_line');
|
||||
$key = new xmldb_key('studyplan_id-id', XMLDB_KEY_FOREIGN, ['studyplan_id'], 'local_treestudyplan', ['id']);
|
||||
|
||||
// Launch drop key studyplan_id-id.
|
||||
$dbman->drop_key($table, $key);
|
||||
|
||||
|
||||
/******
|
||||
* Create the page table and copy data from treestudyplan there
|
||||
* Also re-link the studylines to the newly created page instead of the studyplan
|
||||
*/
|
||||
// Define table local_treestudyplan_page to be created.
|
||||
$table = new xmldb_table('local_treestudyplan_page');
|
||||
|
||||
// Adding fields to table local_treestudyplan_page.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('studyplan_id', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('periods', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('fullname', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('shortname', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('startdate', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('enddate', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
|
||||
// Adding keys to table local_treestudyplan_page.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
|
||||
// Conditionally launch create table for local_treestudyplan_page.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
|
||||
// Create a page 0 with it's data copied
|
||||
$plans = $DB->get_recordset("local_treestudyplan");
|
||||
foreach($plans as $p){
|
||||
$o = [ "studyplan_id" => $p->id,
|
||||
"periods" => $p->slots,
|
||||
"fullname" => $p->name,
|
||||
"shortname" => $p->shortname,
|
||||
"description" => $p->description,
|
||||
"startdate" => $p->startdate,
|
||||
"enddate" => $p->enddate,
|
||||
];
|
||||
$pageid = $DB->insert_record("local_treestudyplan_page",$o);
|
||||
|
||||
// Now find all studyline references to the studyplan
|
||||
// And update their record to reference the page instead of the plan
|
||||
$lines = $DB->get_recordset("local_treestudyplan_line",["studyplan_id" => $p->id]);
|
||||
foreach($lines as $l){
|
||||
$lo = [
|
||||
"id" => $l->id,
|
||||
"page_id"=> $pageid,
|
||||
];
|
||||
$DB->update_record("local_treestudyplan_line",$lo);
|
||||
}
|
||||
$lines->close();
|
||||
}
|
||||
$plans->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize studyline table to drop studyplan_id field and have page id be a non-nullable and foreign key
|
||||
*/
|
||||
|
||||
// Changing nullability of field page_id on table local_treestudyplan_line to not null.
|
||||
$table = new xmldb_table('local_treestudyplan_line');
|
||||
$field = new xmldb_field('page_id', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null, 'studyplan_id');
|
||||
|
||||
// Launch change of nullability for field page_id.
|
||||
$dbman->change_field_notnull($table, $field);
|
||||
|
||||
// Define field studyplan_id to be dropped from local_treestudyplan_line.
|
||||
$table = new xmldb_table('local_treestudyplan_line');
|
||||
$field = new xmldb_field('studyplan_id');
|
||||
|
||||
// Conditionally launch drop field studyplan_id.
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$dbman->drop_field($table, $field);
|
||||
}
|
||||
|
||||
// Define key page_id-id (foreign) to be added to local_treestudyplan_line.
|
||||
$table = new xmldb_table('local_treestudyplan_line');
|
||||
$key = new xmldb_key('page_id-id', XMLDB_KEY_FOREIGN, ['page_id'], 'local_treestudyplan_page', ['id']);
|
||||
|
||||
// Launch add key page_id-id.
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
|
||||
/***
|
||||
* Create Period table and make a period record for all studyplan periods
|
||||
*/
|
||||
|
||||
// Define table local_treestudyplan_period to be created.
|
||||
$table = new xmldb_table('local_treestudyplan_period');
|
||||
|
||||
// Adding fields to table local_treestudyplan_period.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('studyplan_id', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('page_id', XMLDB_TYPE_INTEGER, '20', null, null, null, null);
|
||||
$table->add_field('period', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
|
||||
$table->add_field('starttime', XMLDB_TYPE_INTEGER, '20', null, null, null, null);
|
||||
$table->add_field('endtime', XMLDB_TYPE_INTEGER, '20', null, null, null, null);
|
||||
$table->add_field('startdate', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('enddate', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('shortname', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('fullname', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
|
||||
// Adding keys to table local_treestudyplan_period.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
$table->add_key('page_id-id', XMLDB_KEY_FOREIGN, ['page_id'], 'local_treestudyplan_page', ['id']);
|
||||
|
||||
|
||||
// Conditionally launch create table for local_treestudyplan_period.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
|
||||
// Create a period page for all slots in the study
|
||||
$recordset = $DB->get_recordset("local_treestudyplan_page");
|
||||
foreach($recordset as $r){
|
||||
|
||||
// Make a best guess for the periods based on the specified period for the plan and the
|
||||
$pcount = $r->periods;
|
||||
$ystart = strtotime($r->startdate)+0;
|
||||
$yend = strtotime($r->enddate)+0;
|
||||
if($yend < $ystart){
|
||||
// If no end time is given, assume a year duration for period calculations
|
||||
$ydelta = (365*24*60*60)/$pcount;
|
||||
}
|
||||
|
||||
// Treestudyplan savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2023071801, 'local', 'treestudyplan');
|
||||
$ydelta = $yend - $ystart;
|
||||
$ptime = $ydelta / $pcount;
|
||||
|
||||
for($i=0; $i < $pcount; $i++){
|
||||
$pnum = $i+1;
|
||||
$pstart = $ystart + ($i*$ptime);
|
||||
$pend = $pstart + $ptime;
|
||||
|
||||
$o = [ "page_id" => $r->id,
|
||||
"period" => $pnum,
|
||||
"fullname" => "Period {$pnum}",
|
||||
"shortname" => "P{$pnum}",
|
||||
"startdate" => date("Y-m-d",$pstart),
|
||||
"enddate" => date("Y-m-d",$pend)
|
||||
];
|
||||
$DB->insert_record("local_treestudyplan_period",$o);
|
||||
}
|
||||
}
|
||||
$recordset->close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Treestudyplan savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2023071900, 'local', 'treestudyplan');
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494)
|
||||
$plugin->version = 2023071801; // YYYYMMDDHH (year, month, day, iteration)
|
||||
$plugin->version = 2023071900; // YYYYMMDDHH (year, month, day, iteration)
|
||||
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11)
|
||||
|
||||
$plugin->dependencies = [
|
||||
|
|
Loading…
Reference in New Issue
Block a user