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: {
|
||||
content: content,
|
||||
format: "application/json",
|
||||
context_id: contextid,
|
||||
},
|
||||
}])[0].done(function(response){
|
||||
if(response.success){
|
||||
|
|
|
@ -262,10 +262,12 @@ class gradegenerator {
|
|||
}
|
||||
|
||||
public function toFile(string $filename){
|
||||
$filename = self::expand_tilde($filename);
|
||||
file_put_contents($filename,$this->serialize());
|
||||
}
|
||||
|
||||
public function fromFile(string $filename){
|
||||
$filename = self::expand_tilde($filename);
|
||||
if(file_exists($filename)){
|
||||
try{
|
||||
$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;
|
||||
$list = [];
|
||||
|
||||
if($contextid <= 1){
|
||||
$contextid = 1;
|
||||
$where = "context_id <= :contextid OR context_id IS NULL";
|
||||
} else {
|
||||
$where = "context_id = :contextid";
|
||||
|
||||
if($contextid <= 0){
|
||||
$ids = $DB->get_fieldset_select(self::TABLE,"id","");
|
||||
}
|
||||
|
||||
$ids = $DB->get_fieldset_select(self::TABLE,"id",$where,["contextid" => $contextid]);
|
||||
else{
|
||||
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)
|
||||
{
|
||||
$list[] = studyplan::findById($id);
|
||||
|
@ -638,7 +643,7 @@ class studyplan {
|
|||
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;}
|
||||
|
||||
|
@ -648,6 +653,8 @@ class studyplan {
|
|||
// Make sure the aggregation_config is re-encoded as json text
|
||||
$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"]);
|
||||
return $plan->import_studylines_model($content["studyplan"]["studylines"]);
|
||||
|
||||
|
|
|
@ -1005,7 +1005,7 @@ class studyplanservice extends \external_api
|
|||
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{
|
||||
|
@ -1013,7 +1013,7 @@ class studyplanservice extends \external_api
|
|||
$context = webservicehelper::find_context($context_id);
|
||||
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();
|
||||
}
|
||||
catch(\webservice_access_exception $x) {
|
||||
|
|
|
@ -46,7 +46,7 @@ if (empty($options['studyplan']) && empty($options["all"])) {
|
|||
}
|
||||
|
||||
if(!empty($options["all"])){
|
||||
$plans = studyplan::find_all();
|
||||
$plans = studyplan::find_all();
|
||||
} else {
|
||||
$plans = studyplan::find_by_shortname($options["studyplan"]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user