Ejemplo n.º 1
0
function certificate_grade_condition()
{
    global $certificate, $course;
    $restrict_errors = '';
    if ($linked_acts = certificate_get_linked_activities($certificate->id)) {
        if (!certificate_is_available_time($linked_acts, $course->id)) {
            $restrict_errors[] = get_string('errorlocktime', 'certificate');
        }
        if (!certificate_is_available_mod($linked_acts, $course->id)) {
            $restrict_errors[] = get_string('errorlockmod', 'certificate');
        }
    }
    if ($certificate->lockgrade == 1) {
        $coursegrade = certificate_print_course_grade($course);
        if ($certificate->requiredgrade > $coursegrade->points) {
            $a->current = $coursegrade->points;
            $a->needed = $certificate->requiredgrade;
            $restrict_errors[] = get_string('errorlockgradecourse', 'certificate', $a);
        }
    }
    return $restrict_errors;
}
Ejemplo n.º 2
0
 /**
  * Add the linked activities portion only after the entire form has been created. That way,
  * we can act on previous added values that haven't been committed to the database.
  * Check for an 'addlink' button. If the linked activities fields are all full, add an empty one.
  */
 function definition_after_data()
 {
     global $form;
     /// This gets called more than once, and there's no way to tell which time this is, so set a
     /// variable to make it as called so we only do this processing once.
     if (!empty($this->def_after_data_done)) {
         return;
     }
     $this->def_after_data_done = true;
     $mform =& $this->_form;
     $fdata = $mform->getSubmitValues();
     /// Get the existing linked activities from the database, unless this form has resubmitted itself, in
     /// which case they will be in the form already.
     $linkids = array();
     $linkgrade = array();
     $linkentry = array();
     if (empty($fdata)) {
         if ($linkedacts = certificate_get_linked_activities($form->instance)) {
             foreach ($linkedacts as $idx => $linkedact) {
                 if ($idx != CERTCOURSETIMEID) {
                     $linkids[] = $linkedact->linkid;
                     $linkgrades[] = $linkedact->linkgrade;
                     $linkentry[] = $linkedact->id;
                 }
             }
         }
     } else {
         foreach ($fdata['linkid'] as $idx => $linkid) {
             $linkids[$idx] = $linkid;
             $linkgrades[$idx] = $fdata['linkgrade'][$idx];
             if (!empty($fdata['linkentry'][$idx])) {
                 $linkentry[$idx] = $fdata['linkentry'][$idx];
             }
         }
     }
     foreach ($linkids as $idx => $linkid) {
         $formgroup = array();
         $formgroup[] =& $mform->createElement('select', 'linkid[' . $idx . ']', '', $this->activities);
         $mform->setDefault('linkid[' . $idx . ']', $linkid);
         $formgroup[] =& $mform->createElement('select', 'linkgrade[' . $idx . ']', '', $this->restrictoptions);
         $mform->setDefault('linkgrade[' . $idx . ']', $linkgrades[$idx]);
         $group =& $mform->createElement('group', 'actlab' . $idx, $idx + 1, $formgroup, array(' '), false);
         $mform->insertElementBefore($group, 'addlink');
         if (!empty($linkentry[$idx])) {
             $mform->addElement('hidden', 'linkentry[' . $idx . ']', $linkentry[$idx]);
         }
     }
     $numlacts = count($linkids);
     $formgroup = array();
     $formgroup[] =& $mform->createElement('select', 'linkid[' . $numlacts . ']', '', $this->activities);
     $mform->setDefault('linkid[' . $numlacts . ']', 0);
     $formgroup[] =& $mform->createElement('select', 'linkgrade[' . $numlacts . ']', '', $this->restrictoptions);
     $mform->setDefault('linkgrade[' . $numlacts . ']', '');
     $group =& $mform->createElement('group', 'actlab' . $numlacts, $numlacts + 1, $formgroup, array(' '), false);
     $mform->insertElementBefore($group, 'addlink');
 }