original_string: public function validation($data, $files) {
          global $CFG, $DB, $USER;
  
          $errors = parent::validation($data, $files);
  
          // Validate course association.
          if (!empty($data['courseassoc'])) {
              $coursecontext = context::instance_by_id($data['courseassoc']);
  
              if ($coursecontext->contextlevel != CONTEXT_COURSE) {
                  $errors['courseassoc'] = get_string('error');
              }
          }
  
          // Validate mod association.
          if (!empty($data['modassoc'])) {
              $modcontextid = $data['modassoc'];
              $modcontext = context::instance_by_id($modcontextid);
  
              if ($modcontext->contextlevel == CONTEXT_MODULE) {
                  // Get context of the mod's course.
                  $coursecontext = $modcontext->get_course_context(true);
  
                  // Ensure only one course is associated.
                  if (!empty($data['courseassoc'])) {
                      if ($data['courseassoc'] != $coursecontext->id) {
                          $errors['modassoc'] = get_string('onlyassociateonecourse', 'blog');
                      }
                  } else {
                      $data['courseassoc'] = $coursecontext->id;
                  }
              } else {
                  $errors['modassoc'] = get_string('error');
              }
          }
  
          if ($errors) {
              return $errors;
          }
          return true;
      }
code: public function validation($data, $files) {
          global $CFG, $DB, $USER;
  
          $errors = parent::validation($data, $files);
  
          // Validate course association.
          if (!empty($data['courseassoc'])) {
              $coursecontext = context::instance_by_id($data['courseassoc']);
  
              if ($coursecontext->contextlevel != CONTEXT_COURSE) {
                  $errors['courseassoc'] = get_string('error');
              }
          }
  
          // Validate mod association.
          if (!empty($data['modassoc'])) {
              $modcontextid = $data['modassoc'];
              $modcontext = context::instance_by_id($modcontextid);
  
              if ($modcontext->contextlevel == CONTEXT_MODULE) {
                  // Get context of the mod's course.
                  $coursecontext = $modcontext->get_course_context(true);
  
                  // Ensure only one course is associated.
                  if (!empty($data['courseassoc'])) {
                      if ($data['courseassoc'] != $coursecontext->id) {
                          $errors['modassoc'] = get_string('onlyassociateonecourse', 'blog');
                      }
                  } else {
                      $data['courseassoc'] = $coursecontext->id;
                  }
              } else {
                  $errors['modassoc'] = get_string('error');
              }
          }
  
          if ($errors) {
              return $errors;
          }
          return true;
      }
code_tokens: public function validation ( $ data , $ files ) { global $ CFG , $ DB , $ USER ; $ errors = parent :: validation ( $ data , $ files ) ; // Validate course association. if ( ! empty ( $ data [ 'courseassoc' ] ) ) { $ coursecontext = context :: instance_by_id ( $ data [ 'courseassoc' ] ) ; if ( $ coursecontext -> contextlevel != CONTEXT_COURSE ) { $ errors [ 'courseassoc' ] = get_string ( 'error' ) ; } } // Validate mod association. if ( ! empty ( $ data [ 'modassoc' ] ) ) { $ modcontextid = $ data [ 'modassoc' ] ; $ modcontext = context :: instance_by_id ( $ modcontextid ) ; if ( $ modcontext -> contextlevel == CONTEXT_MODULE ) { // Get context of the mod's course. $ coursecontext = $ modcontext -> get_course_context ( true ) ; // Ensure only one course is associated. if ( ! empty ( $ data [ 'courseassoc' ] ) ) { if ( $ data [ 'courseassoc' ] != $ coursecontext -> id ) { $ errors [ 'modassoc' ] = get_string ( 'onlyassociateonecourse' , 'blog' ) ; } } else { $ data [ 'courseassoc' ] = $ coursecontext -> id ; } } else { $ errors [ 'modassoc' ] = get_string ( 'error' ) ; } } if ( $ errors ) { return $ errors ; } return true ; }
docstring: Validate the blog form data.
  @param array $data Data to be validated
  @param array $files unused
  @return array|bool
docstring_tokens: Validate the blog form data .