Added span editability
This commit is contained in:
		
							parent
							
								
									0a9f6318c8
								
							
						
					
					
						commit
						7b36ee3284
					
				
					 2 changed files with 9 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -191,7 +191,7 @@ class studyitem {
 | 
			
		|||
    public static function add($fields,$import=false)
 | 
			
		||||
    {
 | 
			
		||||
        global $DB;
 | 
			
		||||
        $addable = ['line_id','type','layer','conditions','slot','competency_id','course_id','badge_id','continuation_id'];
 | 
			
		||||
        $addable = ['line_id','type','layer','conditions','slot','competency_id','course_id','badge_id','continuation_id','span'];
 | 
			
		||||
        $info = [ 'layer' => 0, ];
 | 
			
		||||
        foreach($addable as $f){
 | 
			
		||||
            if(array_key_exists($f,$fields)){
 | 
			
		||||
| 
						 | 
				
			
			@ -210,7 +210,7 @@ class studyitem {
 | 
			
		|||
    public function edit($fields)
 | 
			
		||||
    {
 | 
			
		||||
        global $DB;
 | 
			
		||||
        $editable = ['conditions','course_id','continuation_id'];
 | 
			
		||||
        $editable = ['conditions','course_id','continuation_id','span'];
 | 
			
		||||
 | 
			
		||||
        $info = ['id' => $this->id,];
 | 
			
		||||
        foreach($editable as $f){
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -658,7 +658,6 @@ class studyplanservice extends \external_api
 | 
			
		|||
 
 | 
			
		||||
    public static function include_grade($grade_id,$item_id,$include,$required=false)
 | 
			
		||||
    {
 | 
			
		||||
        // TODO: DEPRECATE THIS WHEN IMPLEMENTING THE CORE COMPLETION STRATEGY
 | 
			
		||||
        global $USER;
 | 
			
		||||
 | 
			
		||||
        // find related course and course context
 | 
			
		||||
| 
						 | 
				
			
			@ -1192,6 +1191,7 @@ class studyplanservice extends \external_api
 | 
			
		|||
             "page_id" => new \external_value(PARAM_INT, 'Studyplan page id'),
 | 
			
		||||
             "period" => new \external_value(PARAM_INT, 'Period number within page'),
 | 
			
		||||
             "course_id"=> new \external_value(PARAM_INT, 'Id of course to adjust dates for'),
 | 
			
		||||
             "span"=> new \external_value(PARAM_INT, 'Period span (default 1)',VALUE_DEFAULT),
 | 
			
		||||
         ]);
 | 
			
		||||
     }
 | 
			
		||||
 
 | 
			
		||||
| 
						 | 
				
			
			@ -1199,17 +1199,21 @@ class studyplanservice extends \external_api
 | 
			
		|||
     {
 | 
			
		||||
         return success::structure();
 | 
			
		||||
     }
 | 
			
		||||
     public static function course_period_timing($page_id, $period, $course_id){
 | 
			
		||||
     
 | 
			
		||||
     public static function course_period_timing($page_id, $period, $course_id, $span=1){
 | 
			
		||||
        $course = \get_course($course_id);
 | 
			
		||||
        $coursecontext = \context_course::instance($course_id);
 | 
			
		||||
        $page = studyplanpage::findById($page_id);
 | 
			
		||||
        // Check for studyplan edit permissions
 | 
			
		||||
        webservicehelper::require_capabilities(self::CAP_EDIT,$page->studyplan()->context());
 | 
			
		||||
 | 
			
		||||
        // Determine end period number
 | 
			
		||||
        $endperiod = $period + ($span -1);
 | 
			
		||||
        // Get the proper list of periods for this page
 | 
			
		||||
        $periods = period::findForPage($page);
 | 
			
		||||
        if(array_key_exists($period,$periods)){
 | 
			
		||||
            $pstart = $periods[$period];
 | 
			
		||||
            $pend = $periods[$period];
 | 
			
		||||
            $pend = $periods[$endperiod];
 | 
			
		||||
 | 
			
		||||
            if(webservicehelper::has_capabilities("moodle/course:update",$coursecontext)){
 | 
			
		||||
                // Actually perform the timing changes, while also updating the module times
 | 
			
		||||
| 
						 | 
				
			
			@ -1223,8 +1227,6 @@ class studyplanservice extends \external_api
 | 
			
		|||
            
 | 
			
		||||
                ]);
 | 
			
		||||
 | 
			
		||||
                // TODO: parse status
 | 
			
		||||
 | 
			
		||||
                return success::success()->model();
 | 
			
		||||
            } else {
 | 
			
		||||
                // probably should return a nice message
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue