original_string: public static function get_default_completion($course, $module, $flatten = true) {
          global $DB, $CFG;
          if ($data = $DB->get_record('course_completion_defaults', ['course' => $course->id, 'module' => $module->id],
              'completion, completionview, completionexpected, completionusegrade, customrules')) {
              if ($data->customrules && ($customrules = @json_decode($data->customrules, true))) {
                  if ($flatten) {
                      foreach ($customrules as $key => $value) {
                          $data->$key = $value;
                      }
                  } else {
                      $data->customdata['customcompletionrules'] = $customrules;
                  }
              }
              unset($data->customrules);
          } else {
              $data = new stdClass();
              $data->completion = COMPLETION_TRACKING_NONE;
              if ($CFG->completiondefault) {
                  $completion = new \completion_info(get_fast_modinfo($course->id)->get_course());
                  if ($completion->is_enabled() && plugin_supports('mod', $module->name, FEATURE_MODEDIT_DEFAULT_COMPLETION, true)) {
                      $data->completion = COMPLETION_TRACKING_MANUAL;
                      $data->completionview = 1;
                  }
              }
          }
          return $data;
      }
code: public static function get_default_completion($course, $module, $flatten = true) {
          global $DB, $CFG;
          if ($data = $DB->get_record('course_completion_defaults', ['course' => $course->id, 'module' => $module->id],
              'completion, completionview, completionexpected, completionusegrade, customrules')) {
              if ($data->customrules && ($customrules = @json_decode($data->customrules, true))) {
                  if ($flatten) {
                      foreach ($customrules as $key => $value) {
                          $data->$key = $value;
                      }
                  } else {
                      $data->customdata['customcompletionrules'] = $customrules;
                  }
              }
              unset($data->customrules);
          } else {
              $data = new stdClass();
              $data->completion = COMPLETION_TRACKING_NONE;
              if ($CFG->completiondefault) {
                  $completion = new \completion_info(get_fast_modinfo($course->id)->get_course());
                  if ($completion->is_enabled() && plugin_supports('mod', $module->name, FEATURE_MODEDIT_DEFAULT_COMPLETION, true)) {
                      $data->completion = COMPLETION_TRACKING_MANUAL;
                      $data->completionview = 1;
                  }
              }
          }
          return $data;
      }
code_tokens: public static function get_default_completion ( $ course , $ module , $ flatten = true ) { global $ DB , $ CFG ; if ( $ data = $ DB -> get_record ( 'course_completion_defaults' , [ 'course' => $ course -> id , 'module' => $ module -> id ] , 'completion, completionview, completionexpected, completionusegrade, customrules' ) ) { if ( $ data -> customrules && ( $ customrules = @ json_decode ( $ data -> customrules , true ) ) ) { if ( $ flatten ) { foreach ( $ customrules as $ key => $ value ) { $ data -> $ key = $ value ; } } else { $ data -> customdata [ 'customcompletionrules' ] = $ customrules ; } } unset ( $ data -> customrules ) ; } else { $ data = new stdClass ( ) ; $ data -> completion = COMPLETION_TRACKING_NONE ; if ( $ CFG -> completiondefault ) { $ completion = new \ completion_info ( get_fast_modinfo ( $ course -> id ) -> get_course ( ) ) ; if ( $ completion -> is_enabled ( ) && plugin_supports ( 'mod' , $ module -> name , FEATURE_MODEDIT_DEFAULT_COMPLETION , true ) ) { $ data -> completion = COMPLETION_TRACKING_MANUAL ; $ data -> completionview = 1 ; } } } return $ data ; }
docstring: Returns default completion rules for given module type in the given course
  
  @param stdClass $course
  @param stdClass $module
  @param bool $flatten if true all module custom completion rules become properties of the same object,
  otherwise they can be found as array in ->customdata['customcompletionrules']
  @return stdClass
docstring_tokens: Returns default completion rules for given module type in the given course