original_string: public function submissions_open($userid = 0,
                                       $skipenrolled = false,
                                       $submission = false,
                                       $flags = false,
                                       $gradinginfo = false) {
          global $USER;
  
          if (!$userid) {
              $userid = $USER->id;
          }
  
          $time = time();
          $dateopen = true;
          $finaldate = false;
          if ($this->get_instance()->cutoffdate) {
              $finaldate = $this->get_instance()->cutoffdate;
          }
  
          if ($flags === false) {
              $flags = $this->get_user_flags($userid, false);
          }
          if ($flags && $flags->locked) {
              return false;
          }
  
          // User extensions.
          if ($finaldate) {
              if ($flags && $flags->extensionduedate) {
                  // Extension can be before cut off date.
                  if ($flags->extensionduedate > $finaldate) {
                      $finaldate = $flags->extensionduedate;
                  }
              }
          }
  
          if ($finaldate) {
              $dateopen = ($this->get_instance()->allowsubmissionsfromdate <= $time && $time <= $finaldate);
          } else {
              $dateopen = ($this->get_instance()->allowsubmissionsfromdate <= $time);
          }
  
          if (!$dateopen) {
              return false;
          }
  
          // Now check if this user has already submitted etc.
          if (!$skipenrolled && !is_enrolled($this->get_course_context(), $userid)) {
              return false;
          }
          // Note you can pass null for submission and it will not be fetched.
          if ($submission === false) {
              if ($this->get_instance()->teamsubmission) {
                  $submission = $this->get_group_submission($userid, 0, false);
              } else {
                  $submission = $this->get_user_submission($userid, false);
              }
          }
          if ($submission) {
  
              if ($this->get_instance()->submissiondrafts && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
                  // Drafts are tracked and the student has submitted the assignment.
                  return false;
              }
          }
  
          // See if this user grade is locked in the gradebook.
          if ($gradinginfo === false) {
              $gradinginfo = grade_get_grades($this->get_course()->id,
                                              'mod',
                                              'assign',
                                              $this->get_instance()->id,
                                              array($userid));
          }
          if ($gradinginfo &&
                  isset($gradinginfo->items[0]->grades[$userid]) &&
                  $gradinginfo->items[0]->grades[$userid]->locked) {
              return false;
          }
  
          return true;
      }
code: public function submissions_open($userid = 0,
                                       $skipenrolled = false,
                                       $submission = false,
                                       $flags = false,
                                       $gradinginfo = false) {
          global $USER;
  
          if (!$userid) {
              $userid = $USER->id;
          }
  
          $time = time();
          $dateopen = true;
          $finaldate = false;
          if ($this->get_instance()->cutoffdate) {
              $finaldate = $this->get_instance()->cutoffdate;
          }
  
          if ($flags === false) {
              $flags = $this->get_user_flags($userid, false);
          }
          if ($flags && $flags->locked) {
              return false;
          }
  
          // User extensions.
          if ($finaldate) {
              if ($flags && $flags->extensionduedate) {
                  // Extension can be before cut off date.
                  if ($flags->extensionduedate > $finaldate) {
                      $finaldate = $flags->extensionduedate;
                  }
              }
          }
  
          if ($finaldate) {
              $dateopen = ($this->get_instance()->allowsubmissionsfromdate <= $time && $time <= $finaldate);
          } else {
              $dateopen = ($this->get_instance()->allowsubmissionsfromdate <= $time);
          }
  
          if (!$dateopen) {
              return false;
          }
  
          // Now check if this user has already submitted etc.
          if (!$skipenrolled && !is_enrolled($this->get_course_context(), $userid)) {
              return false;
          }
          // Note you can pass null for submission and it will not be fetched.
          if ($submission === false) {
              if ($this->get_instance()->teamsubmission) {
                  $submission = $this->get_group_submission($userid, 0, false);
              } else {
                  $submission = $this->get_user_submission($userid, false);
              }
          }
          if ($submission) {
  
              if ($this->get_instance()->submissiondrafts && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
                  // Drafts are tracked and the student has submitted the assignment.
                  return false;
              }
          }
  
          // See if this user grade is locked in the gradebook.
          if ($gradinginfo === false) {
              $gradinginfo = grade_get_grades($this->get_course()->id,
                                              'mod',
                                              'assign',
                                              $this->get_instance()->id,
                                              array($userid));
          }
          if ($gradinginfo &&
                  isset($gradinginfo->items[0]->grades[$userid]) &&
                  $gradinginfo->items[0]->grades[$userid]->locked) {
              return false;
          }
  
          return true;
      }
code_tokens: public function submissions_open ( $ userid = 0 , $ skipenrolled = false , $ submission = false , $ flags = false , $ gradinginfo = false ) { global $ USER ; if ( ! $ userid ) { $ userid = $ USER -> id ; } $ time = time ( ) ; $ dateopen = true ; $ finaldate = false ; if ( $ this -> get_instance ( ) -> cutoffdate ) { $ finaldate = $ this -> get_instance ( ) -> cutoffdate ; } if ( $ flags === false ) { $ flags = $ this -> get_user_flags ( $ userid , false ) ; } if ( $ flags && $ flags -> locked ) { return false ; } // User extensions. if ( $ finaldate ) { if ( $ flags && $ flags -> extensionduedate ) { // Extension can be before cut off date. if ( $ flags -> extensionduedate > $ finaldate ) { $ finaldate = $ flags -> extensionduedate ; } } } if ( $ finaldate ) { $ dateopen = ( $ this -> get_instance ( ) -> allowsubmissionsfromdate <= $ time && $ time <= $ finaldate ) ; } else { $ dateopen = ( $ this -> get_instance ( ) -> allowsubmissionsfromdate <= $ time ) ; } if ( ! $ dateopen ) { return false ; } // Now check if this user has already submitted etc. if ( ! $ skipenrolled && ! is_enrolled ( $ this -> get_course_context ( ) , $ userid ) ) { return false ; } // Note you can pass null for submission and it will not be fetched. if ( $ submission === false ) { if ( $ this -> get_instance ( ) -> teamsubmission ) { $ submission = $ this -> get_group_submission ( $ userid , 0 , false ) ; } else { $ submission = $ this -> get_user_submission ( $ userid , false ) ; } } if ( $ submission ) { if ( $ this -> get_instance ( ) -> submissiondrafts && $ submission -> status == ASSIGN_SUBMISSION_STATUS_SUBMITTED ) { // Drafts are tracked and the student has submitted the assignment. return false ; } } // See if this user grade is locked in the gradebook. if ( $ gradinginfo === false ) { $ gradinginfo = grade_get_grades ( $ this -> get_course ( ) -> id , 'mod' , 'assign' , $ this -> get_instance ( ) -> id , array ( $ userid ) ) ; } if ( $ gradinginfo && isset ( $ gradinginfo -> items [ 0 ] -> grades [ $ userid ] ) && $ gradinginfo -> items [ 0 ] -> grades [ $ userid ] -> locked ) { return false ; } return true ; }
docstring: Is this assignment open for submissions?
  
  Check the due date,
  prevent late submissions,
  has this person already submitted,
  is the assignment locked?
  
  @param int $userid - Optional userid so we can see if a different user can submit
  @param bool $skipenrolled - Skip enrollment checks (because they have been done already)
  @param stdClass $submission - Pre-fetched submission record (or false to fetch it)
  @param stdClass $flags - Pre-fetched user flags record (or false to fetch it)
  @param stdClass $gradinginfo - Pre-fetched user gradinginfo record (or false to fetch it)
  @return bool
docstring_tokens: Is this assignment open for submissions?