Plans are imported in correct context now
This commit is contained in:
parent
1023576b34
commit
cc6101194f
|
@ -230,6 +230,7 @@ export function init(contextid,categoryid) {
|
||||||
args: {
|
args: {
|
||||||
content: content,
|
content: content,
|
||||||
format: "application/json",
|
format: "application/json",
|
||||||
|
context_id: contextid,
|
||||||
},
|
},
|
||||||
}])[0].done(function(response){
|
}])[0].done(function(response){
|
||||||
if(response.success){
|
if(response.success){
|
||||||
|
|
|
@ -262,10 +262,12 @@ class gradegenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toFile(string $filename){
|
public function toFile(string $filename){
|
||||||
|
$filename = self::expand_tilde($filename);
|
||||||
file_put_contents($filename,$this->serialize());
|
file_put_contents($filename,$this->serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromFile(string $filename){
|
public function fromFile(string $filename){
|
||||||
|
$filename = self::expand_tilde($filename);
|
||||||
if(file_exists($filename)){
|
if(file_exists($filename)){
|
||||||
try{
|
try{
|
||||||
$json = file_get_contents($filename);
|
$json = file_get_contents($filename);
|
||||||
|
@ -277,4 +279,15 @@ class gradegenerator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function expand_tilde($path)
|
||||||
|
{
|
||||||
|
if (function_exists('posix_getuid') && strpos($path, '~') !== false) {
|
||||||
|
$info = posix_getpwuid(posix_getuid());
|
||||||
|
$path = str_replace('~', $info['dir'], $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,18 +242,23 @@ class studyplan {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function find_all($contextid=1){
|
public static function find_all($contextid=-1){
|
||||||
global $DB, $USER;
|
global $DB, $USER;
|
||||||
$list = [];
|
$list = [];
|
||||||
|
|
||||||
if($contextid <= 1){
|
if($contextid <= 0){
|
||||||
$contextid = 1;
|
$ids = $DB->get_fieldset_select(self::TABLE,"id","");
|
||||||
$where = "context_id <= :contextid OR context_id IS NULL";
|
|
||||||
} else {
|
|
||||||
$where = "context_id = :contextid";
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
$ids = $DB->get_fieldset_select(self::TABLE,"id",$where,["contextid" => $contextid]);
|
if($contextid == 1){
|
||||||
|
$contextid = 1;
|
||||||
|
$where = "context_id <= :contextid OR context_id IS NULL";
|
||||||
|
} else {
|
||||||
|
$where = "context_id = :contextid";
|
||||||
|
}
|
||||||
|
$ids = $DB->get_fieldset_select(self::TABLE,"id",$where,["contextid" => $contextid]);
|
||||||
|
}
|
||||||
|
|
||||||
foreach($ids as $id)
|
foreach($ids as $id)
|
||||||
{
|
{
|
||||||
$list[] = studyplan::findById($id);
|
$list[] = studyplan::findById($id);
|
||||||
|
@ -638,7 +643,7 @@ class studyplan {
|
||||||
return $lines;
|
return $lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function import_studyplan($content,$format="application/json")
|
public static function import_studyplan($content,$format="application/json",$context_id=1)
|
||||||
{
|
{
|
||||||
if($format != "application/json") { return false;}
|
if($format != "application/json") { return false;}
|
||||||
|
|
||||||
|
@ -648,6 +653,8 @@ class studyplan {
|
||||||
// Make sure the aggregation_config is re-encoded as json text
|
// Make sure the aggregation_config is re-encoded as json text
|
||||||
$content["studyplan"]["aggregation_config"] = json_encode($content["studyplan"]["aggregation_config"]);
|
$content["studyplan"]["aggregation_config"] = json_encode($content["studyplan"]["aggregation_config"]);
|
||||||
|
|
||||||
|
// And make sure the context_id is set to the
|
||||||
|
$content["studyplan"]["context_id"] = $context_id;
|
||||||
$plan = self::add($content["studyplan"]);
|
$plan = self::add($content["studyplan"]);
|
||||||
return $plan->import_studylines_model($content["studyplan"]["studylines"]);
|
return $plan->import_studylines_model($content["studyplan"]["studylines"]);
|
||||||
|
|
||||||
|
|
|
@ -1005,7 +1005,7 @@ class studyplanservice extends \external_api
|
||||||
return success::structure();
|
return success::structure();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function import_plan($content,$format="application/json",$context_id=0)
|
public static function import_plan($content,$format="application/json",$context_id=1)
|
||||||
{
|
{
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
@ -1013,7 +1013,7 @@ class studyplanservice extends \external_api
|
||||||
$context = webservicehelper::find_context($context_id);
|
$context = webservicehelper::find_context($context_id);
|
||||||
webservicehelper::require_capabilities(self::CAP_EDIT,$context);
|
webservicehelper::require_capabilities(self::CAP_EDIT,$context);
|
||||||
|
|
||||||
$result = studyplan::import_studyplan($content,$format);
|
$result = studyplan::import_studyplan($content,$format,$context_id);
|
||||||
return (new success($result, "During study plan import"))->model();
|
return (new success($result, "During study plan import"))->model();
|
||||||
}
|
}
|
||||||
catch(\webservice_access_exception $x) {
|
catch(\webservice_access_exception $x) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ if (empty($options['studyplan']) && empty($options["all"])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($options["all"])){
|
if(!empty($options["all"])){
|
||||||
$plans = studyplan::find_all();
|
$plans = studyplan::find_all();
|
||||||
} else {
|
} else {
|
||||||
$plans = studyplan::find_by_shortname($options["studyplan"]);
|
$plans = studyplan::find_by_shortname($options["studyplan"]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user