| Línea 99... | Línea 99... | 
          
            | 99 |     public function get_moduleid() {
 | 99 |     public function get_moduleid() {
 | 
          
            | 100 |         return $this->moduleid;
 | 100 |         return $this->moduleid;
 | 
          
            | 101 |     }
 | 101 |     }
 | 
          
            | Línea 102... | Línea 102... | 
          
            | 102 |  
 | 102 |  
 | 
          
            | - |   | 103 |     /**
 | 
          
            | - |   | 104 |      * Return if the activity is inside a subsection.
 | 
          
            | - |   | 105 |      *
 | 
          
            | - |   | 106 |      * @return bool
 | 
          
            | - |   | 107 |      */
 | 
          
            | - |   | 108 |     public function is_in_subsection(): bool {
 | 
          
            | - |   | 109 |         return !empty($this->info->insubsection);
 | 
          
            | - |   | 110 |     }
 | 
          
            | - |   | 111 |  
 | 
          
            | 103 |     /**
 | 112 |     /**
 | 
          
            | 104 |      * Returns the old course module id (cmid of activity which will be restored)
 | 113 |      * Returns the old course module id (cmid of activity which will be restored)
 | 
          
            | 105 |      *
 | 114 |      *
 | 
          
            | 106 |      * @return int
 | 115 |      * @return int
 | 
          
            | 107 |      */
 | 116 |      */
 | 
          
            | Línea 286... | Línea 295... | 
          
            | 286 |  
 | 295 |  
 | 
          
            | 287 |     /**
 | 296 |     /**
 | 
          
            | 288 |      * Define the common setting that any restore activity will have
 | 297 |      * Define the common setting that any restore activity will have
 | 
          
            | 289 |      */
 | 298 |      */
 | 
          
            | 290 |     protected function define_settings() {
 | - |   | 
          
            | 291 |  
 | 299 |     protected function define_settings() {
 | 
          
            | 292 |         // All the settings related to this activity will include this prefix
 | 300 |         // All the settings related to this activity will include this prefix
 | 
          
            | Línea 293... | Línea 301... | 
          
            | 293 |         $settingprefix = $this->info->modulename . '_' . $this->info->moduleid . '_';
 | 301 |         $settingprefix = $this->info->modulename . '_' . $this->info->moduleid . '_';
 | 
          
            | - |   | 302 |  
 | 
          
            | - |   | 303 |         // All these are common settings to be shared by all activities
 | 
          
            | - |   | 304 |         $activityincluded = $this->add_activity_included_setting($settingprefix);
 | 
          
            | - |   | 305 |         $this->add_activity_userinfo_setting($settingprefix, $activityincluded);
 | 
          
            | - |   | 306 |  
 | 
          
            | - |   | 307 |         // End of common activity settings, let's add the particular ones.
 | 
          
            | Línea -... | Línea 308... | 
          
            | - |   | 308 |         $this->define_my_settings();
 | 
          
            | - |   | 309 |     }
 | 
          
            | - |   | 310 |  
 | 
          
            | - |   | 311 |     /**
 | 
          
            | - |   | 312 |      * Add the activity included setting to the task.
 | 
          
            | - |   | 313 |      *
 | 
          
            | - |   | 314 |      * @param string $settingprefix the identifier of the setting
 | 
          
            | 294 |  
 | 315 |      * @return activity_backup_setting the setting added
 | 
          
            | 295 |         // All these are common settings to be shared by all activities
 | 316 |      */
 | 
          
            | 296 |  
 | 317 |     protected function add_activity_included_setting(string $settingprefix): activity_backup_setting {
 | 
          
            | 297 |         // Define activity_include (to decide if the whole task must be really executed)
 | 318 |         // Define activity_included (to decide if the whole task must be really executed)
 | 
          
            | 298 |         // Dependent of:
 | 319 |         // Dependent of:
 | 
          
            | - |   | 320 |         // - activities root setting.
 | 
          
            | - |   | 321 |         // - sectionincluded setting (if exists).
 | 
          
            | - |   | 322 |         $settingname = $settingprefix . 'included';
 | 
          
            | - |   | 323 |  
 | 
          
            | 299 |         // - activities root setting
 | 324 |         if ($this->is_in_subsection()) {
 | 
          
            | - |   | 325 |             $activityincluded = new restore_subactivity_generic_setting($settingname, base_setting::IS_BOOLEAN, true);
 | 
          
            | - |   | 326 |         } else {
 | 
          
            | 300 |         // - section_included setting (if exists)
 | 327 |             $activityincluded = new restore_activity_generic_setting($settingname, base_setting::IS_BOOLEAN, true);
 | 
          
            | 301 |         $settingname = $settingprefix . 'included';
 | 328 |         }
 | 
          
            | 302 |         $activity_included = new restore_activity_generic_setting($settingname, base_setting::IS_BOOLEAN, true);
 | 329 |  
 | 
          
            | 303 |         $activity_included->get_ui()->set_icon(new image_icon('monologo', get_string('pluginname', $this->modulename),
 | 330 |         $activityincluded->get_ui()->set_icon(new image_icon('monologo', get_string('pluginname', $this->modulename),
 | 
          
            | 304 |             $this->modulename, array('class' => 'iconlarge icon-post ml-1')));
 | 331 |             $this->modulename, ['class' => 'ms-1']));
 | 
          
            | 305 |         $this->add_setting($activity_included);
 | 332 |         $this->add_setting($activityincluded);
 | 
          
            | 306 |         // Look for "activities" root setting
 | 333 |         // Look for "activities" root setting.
 | 
          
            | 307 |         $activities = $this->plan->get_setting('activities');
 | 334 |         $activities = $this->plan->get_setting('activities');
 | 
          
            | 308 |         $activities->add_dependency($activity_included);
 | 335 |         $activities->add_dependency($activityincluded);
 | 
          
            | 309 |         // Look for "section_included" section setting (if exists)
 | 336 |         // Look for "sectionincluded" section setting (if exists).
 | 
          
            | 310 |         $settingname = 'section_' . $this->info->sectionid . '_included';
 | 337 |         $settingname = 'section_' . $this->info->sectionid . '_included';
 | 
          
            | 311 |         if ($this->plan->setting_exists($settingname)) {
 | 338 |         if ($this->plan->setting_exists($settingname)) {
 | 
          
            | Línea -... | Línea 339... | 
          
            | - |   | 339 |             $sectionincluded = $this->plan->get_setting($settingname);
 | 
          
            | - |   | 340 |             $sectionincluded->add_dependency($activityincluded);
 | 
          
            | - |   | 341 |         }
 | 
          
            | - |   | 342 |  
 | 
          
            | - |   | 343 |         return $activityincluded;
 | 
          
            | - |   | 344 |     }
 | 
          
            | - |   | 345 |  
 | 
          
            | - |   | 346 |     /**
 | 
          
            | - |   | 347 |      * Add the activity userinfo setting to the task.
 | 
          
            | - |   | 348 |      *
 | 
          
            | - |   | 349 |      * @param string $settingprefix the identifier of the setting
 | 
          
            | - |   | 350 |      * @param activity_backup_setting $includefield the activity included setting
 | 
          
            | - |   | 351 |      * @return activity_backup_setting the setting added
 | 
          
            | - |   | 352 |      */
 | 
          
            | 312 |             $section_included = $this->plan->get_setting($settingname);
 | 353 |     protected function add_activity_userinfo_setting(
 | 
          
            | 313 |             $section_included->add_dependency($activity_included);
 | 354 |         string $settingprefix,
 | 
          
            | 314 |         }
 | 355 |         activity_backup_setting $includefield
 | 
          
            | 315 |  
 | 356 |     ): activity_backup_setting {
 | 
          
            | 316 |         // Define activity_userinfo. Dependent of:
 | 357 |         // Define activityuserinfo. Dependent of:
 | 
          
            | 317 |         // - users root setting
 | 358 |         // - users root setting.
 | 
          
            | 318 |         // - section_userinfo setting (if exists)
 | 359 |         // - sectionuserinfo setting (if exists).
 | 
          
            | 319 |         // - activity_included setting.
 | 360 |         // - activity included setting.
 | 
          
            | 320 |         $settingname = $settingprefix . 'userinfo';
 | 361 |         $settingname = $settingprefix . 'userinfo';
 | 
          
            | Línea -... | Línea 362... | 
          
            | - |   | 362 |         $defaultvalue = false;
 | 
          
            | - |   | 363 |         if (isset($this->info->settings[$settingname]) && $this->info->settings[$settingname]) { // Only enabled when available
 | 
          
            | - |   | 364 |             $defaultvalue = true;
 | 
          
            | 321 |         $defaultvalue = false;
 | 365 |         }
 | 
          
            | - |   | 366 |  
 | 
          
            | - |   | 367 |         if ($this->is_in_subsection()) {
 | 
          
            | 322 |         if (isset($this->info->settings[$settingname]) && $this->info->settings[$settingname]) { // Only enabled when available
 | 368 |             $activityuserinfo = new restore_subactivity_userinfo_setting($settingname, base_setting::IS_BOOLEAN, $defaultvalue);
 | 
          
            | 323 |             $defaultvalue = true;
 | 369 |         } else {
 | 
          
            | 324 |         }
 | 370 |             $activityuserinfo = new restore_activity_userinfo_setting($settingname, base_setting::IS_BOOLEAN, $defaultvalue);
 | 
          
            | 325 |  
 | 371 |         }
 | 
          
            | 326 |         $activity_userinfo = new restore_activity_userinfo_setting($settingname, base_setting::IS_BOOLEAN, $defaultvalue);
 | 372 |  
 | 
          
            | 327 |         if (!$defaultvalue) {
 | 373 |         if (!$defaultvalue) {
 | 
          
            | 328 |             // This is a bit hacky, but if there is no user data to restore, then
 | 374 |             // This is a bit hacky, but if there is no user data to restore, then
 | 
          
            | 329 |             // we replace the standard check-box with a select menu with the
 | 375 |             // we replace the standard check-box with a select menu with the
 | 
          
            | 330 |             // single choice 'No', and the select menu is clever enough that if
 | 376 |             // single choice 'No', and the select menu is clever enough that if
 | 
          
            | - |   | 377 |             // there is only one choice, it just displays a static string.
 | 
          
            | 331 |             // there is only one choice, it just displays a static string.
 | 378 |             //
 | 
          
            | - |   | 379 |             // It would probably be better design to have a special UI class
 | 
          
            | - |   | 380 |             // setting_ui_checkbox_or_no, rather than this hack, but I am not
 | 
          
            | 332 |             //
 | 381 |             // going to do that today.
 | 
          
            | - |   | 382 |             $activityuserinfo->set_ui(
 | 
          
            | - |   | 383 |                 new backup_setting_ui_select(
 | 
          
            | 333 |             // It would probably be better design to have a special UI class
 | 384 |                     $activityuserinfo,
 | 
          
            | 334 |             // setting_ui_checkbox_or_no, rather than this hack, but I am not
 | 385 |                     '-',
 | 
          
            | 335 |             // going to do that today.
 | 386 |                     [0 => get_string('no')]
 | 
          
            | Línea 336... | Línea 387... | 
          
            | 336 |             $activity_userinfo->set_ui(new backup_setting_ui_select($activity_userinfo, '-',
 | 387 |                 )
 | 
          
            | Línea 337... | Línea 388... | 
          
            | 337 |                     array(0 => get_string('no'))));
 | 388 |             );
 | 
          
            | 338 |         } else {
 | 389 |         } else {
 | 
          
            | 339 |             $activity_userinfo->get_ui()->set_label('-');
 | 390 |             $activityuserinfo->get_ui()->set_label('-');
 | 
          
            | Línea 340... | Línea 391... | 
          
            | 340 |         }
 | 391 |         }
 | 
          
            | 341 |  
 | 392 |  
 | 
          
            | 342 |         $this->add_setting($activity_userinfo);
 | 393 |         $this->add_setting($activityuserinfo);
 | 
          
            | 343 |  
 | 394 |  
 | 
          
            | 344 |         // Look for "users" root setting
 | 395 |         // Look for "users" root setting.
 | 
          
            | 345 |         $users = $this->plan->get_setting('users');
 | 396 |         $users = $this->plan->get_setting('users');
 | 
          
            | Línea 346... | Línea 397... | 
          
            | 346 |         $users->add_dependency($activity_userinfo);
 | 397 |         $users->add_dependency($activityuserinfo);
 | 
          
            | 347 |  
 | 398 |  
 | 
          
            | Línea 348... | Línea -... | 
          
            | 348 |         // Look for "section_userinfo" section setting (if exists)
 | - |   | 
          
            | 349 |         $settingname = 'section_' . $this->info->sectionid . '_userinfo';
 | 399 |         // Look for "sectionuserinfo" section setting (if exists).
 | 
          
            | 350 |         if ($this->plan->setting_exists($settingname)) {
 | 400 |         $settingname = 'section_' . $this->info->sectionid . '_userinfo';
 | 
          
            | Línea 351... | Línea 401... | 
          
            | 351 |             $section_userinfo = $this->plan->get_setting($settingname);
 | 401 |         if ($this->plan->setting_exists($settingname)) {
 | 
          
            | 352 |             $section_userinfo->add_dependency($activity_userinfo);
 | 402 |             $sectionuserinfo = $this->plan->get_setting($settingname);
 | 
          
            | 353 |         }
 | 403 |             $sectionuserinfo->add_dependency($activityuserinfo);
 |