Ejemplo n.º 1
0
 /**
  * Renders a table containing information about calendar subscriptions.
  *
  * @param int $courseid
  * @param array $subscriptions
  * @param string $importresults
  * @return string
  */
 public function subscription_details($courseid, $subscriptions, $importresults = '')
 {
     $table = new html_table();
     $table->head = array(get_string('colcalendar', 'calendar'), get_string('collastupdated', 'calendar'), get_string('eventkind', 'calendar'), get_string('colpoll', 'calendar'), get_string('colactions', 'calendar'));
     $table->align = array('left', 'left', 'left', 'center');
     $table->width = '100%';
     $table->data = array();
     if (empty($subscriptions)) {
         $cell = new html_table_cell(get_string('nocalendarsubscriptions', 'calendar'));
         $cell->colspan = 4;
         $table->data[] = new html_table_row(array($cell));
     }
     $strnever = new lang_string('never', 'calendar');
     foreach ($subscriptions as $sub) {
         $label = $sub->name;
         if (!empty($sub->url)) {
             $label = html_writer::link($sub->url, $label);
         }
         if (empty($sub->lastupdated)) {
             $lastupdated = $strnever->out();
         } else {
             $lastupdated = userdate($sub->lastupdated, get_string('strftimedatetimeshort', 'langconfig'));
         }
         $cell = new html_table_cell($this->subscription_action_form($sub, $courseid));
         $cell->colspan = 2;
         $type = $sub->eventtype . 'events';
         $table->data[] = new html_table_row(array(new html_table_cell($label), new html_table_cell($lastupdated), new html_table_cell(get_string($type, 'calendar')), $cell));
     }
     $out = $this->output->box_start('generalbox calendarsubs');
     $out .= $importresults;
     $out .= html_writer::table($table);
     $out .= $this->output->box_end();
     return $out;
 }
Ejemplo n.º 2
0
 /**
  * Returns the string
  *
  * @param string $lang The langauge to use when processing the string
  * @return string
  */
 public function out($lang = null)
 {
     if ($lang !== null && $lang != $this->lang && ($this->lang == null && $lang != current_language())) {
         if ($this->forcedstring) {
             debugging('lang_string objects that have been used cannot be printed in another language. (' . $this->lang . ' used)', DEBUG_DEVELOPER);
             return $this->get_string();
         }
         $translatedstring = new lang_string($this->identifier, $this->component, $this->a, $lang);
         return $translatedstring->out();
     }
     return $this->get_string();
 }
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Conditions: Don't let them set dates which make no sense
     if (array_key_exists('availablefrom', $data) && $data['availablefrom'] && $data['availableuntil'] && $data['availablefrom'] >= $data['availableuntil']) {
         $errors['availablefrom'] = get_string('badavailabledates', 'condition');
     }
     // Conditions: Verify that the grade conditions are numbers, and make sense.
     if (array_key_exists('conditiongradegroup', $data)) {
         foreach ($data['conditiongradegroup'] as $i => $gradedata) {
             if ($gradedata['conditiongrademin'] !== '' && !is_numeric(unformat_float($gradedata['conditiongrademin']))) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
                 continue;
             }
             if ($gradedata['conditiongrademax'] !== '' && !is_numeric(unformat_float($gradedata['conditiongrademax']))) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
                 continue;
             }
             if ($gradedata['conditiongrademin'] !== '' && $gradedata['conditiongrademax'] !== '' && unformat_float($gradedata['conditiongrademax']) <= unformat_float($gradedata['conditiongrademin'])) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('badgradelimits', 'condition');
                 continue;
             }
             if ($gradedata['conditiongrademin'] === '' && $gradedata['conditiongrademax'] === '' && $gradedata['conditiongradeitemid']) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('gradeitembutnolimits', 'condition');
                 continue;
             }
             if (($gradedata['conditiongrademin'] !== '' || $gradedata['conditiongrademax'] !== '') && !$gradedata['conditiongradeitemid']) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('gradelimitsbutnoitem', 'condition');
                 continue;
             }
         }
     }
     // Conditions: Verify that the user profile field has not been declared more than once
     if (array_key_exists('conditionfieldgroup', $data)) {
         // Array to store the existing fields
         $arrcurrentfields = array();
         // Error message displayed if any condition is declared more than once. We use lang string because
         // this way we don't actually generate the string unless there is an error.
         $stralreadydeclaredwarning = new lang_string('fielddeclaredmultipletimes', 'condition');
         foreach ($data['conditionfieldgroup'] as $i => $fielddata) {
             if ($fielddata['conditionfield'] == 0) {
                 // Don't need to bother if none is selected
                 continue;
             }
             if (in_array($fielddata['conditionfield'], $arrcurrentfields)) {
                 $errors["conditionfieldgroup[{$i}]"] = $stralreadydeclaredwarning->out();
             }
             // Add the field to the array
             $arrcurrentfields[] = $fielddata['conditionfield'];
         }
     }
     return $errors;
 }
Ejemplo n.º 4
0
 function validation($data, $files)
 {
     global $COURSE, $DB;
     $errors = parent::validation($data, $files);
     $mform =& $this->_form;
     $errors = array();
     if ($mform->elementExists('name')) {
         $name = trim($data['name']);
         if ($name == '') {
             $errors['name'] = get_string('required');
         }
     }
     $grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $data['modulename'], 'iteminstance' => $data['instance'], 'itemnumber' => 0, 'courseid' => $COURSE->id));
     if ($data['coursemodule']) {
         $cm = $DB->get_record('course_modules', array('id' => $data['coursemodule']));
     } else {
         $cm = null;
     }
     if ($mform->elementExists('cmidnumber')) {
         // verify the idnumber
         if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $grade_item, $cm)) {
             $errors['cmidnumber'] = get_string('idnumbertaken');
         }
     }
     // Completion: Don't let them choose automatic completion without turning
     // on some conditions
     if (array_key_exists('completion', $data) && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC) {
         if (empty($data['completionview']) && empty($data['completionusegrade']) && !$this->completion_rule_enabled($data)) {
             $errors['completion'] = get_string('badautocompletion', 'completion');
         }
     }
     // Conditions: Don't let them set dates which make no sense
     if (array_key_exists('availablefrom', $data) && $data['availablefrom'] && $data['availableuntil'] && $data['availablefrom'] >= $data['availableuntil']) {
         $errors['availablefrom'] = get_string('badavailabledates', 'condition');
     }
     // Conditions: Verify that the grade conditions are numbers, and make sense.
     if (array_key_exists('conditiongradegroup', $data)) {
         foreach ($data['conditiongradegroup'] as $i => $gradedata) {
             if ($gradedata['conditiongrademin'] !== '' && !is_numeric(unformat_float($gradedata['conditiongrademin']))) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
                 continue;
             }
             if ($gradedata['conditiongrademax'] !== '' && !is_numeric(unformat_float($gradedata['conditiongrademax']))) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
                 continue;
             }
             if ($gradedata['conditiongrademin'] !== '' && $gradedata['conditiongrademax'] !== '' && unformat_float($gradedata['conditiongrademax']) <= unformat_float($gradedata['conditiongrademin'])) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('badgradelimits', 'condition');
                 continue;
             }
             if ($gradedata['conditiongrademin'] === '' && $gradedata['conditiongrademax'] === '' && $gradedata['conditiongradeitemid']) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('gradeitembutnolimits', 'condition');
                 continue;
             }
             if (($gradedata['conditiongrademin'] !== '' || $gradedata['conditiongrademax'] !== '') && !$gradedata['conditiongradeitemid']) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('gradelimitsbutnoitem', 'condition');
                 continue;
             }
         }
     }
     // Conditions: Verify that the user profile field has not been declared more than once
     if (array_key_exists('conditionfieldgroup', $data)) {
         // Array to store the existing fields
         $arrcurrentfields = array();
         // Error message displayed if any condition is declared more than once. We use lang string because
         // this way we don't actually generate the string unless there is an error.
         $stralreadydeclaredwarning = new lang_string('fielddeclaredmultipletimes', 'condition');
         foreach ($data['conditionfieldgroup'] as $i => $fielddata) {
             if ($fielddata['conditionfield'] == 0) {
                 // Don't need to bother if none is selected
                 continue;
             }
             if (in_array($fielddata['conditionfield'], $arrcurrentfields)) {
                 $errors["conditionfieldgroup[{$i}]"] = $stralreadydeclaredwarning->out();
             }
             // Add the field to the array
             $arrcurrentfields[] = $fielddata['conditionfield'];
         }
     }
     return $errors;
 }
Ejemplo n.º 5
0
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Conditions: Don't let them set dates which make no sense
     if (array_key_exists('availablefrom', $data) && $data['availablefrom'] && $data['availableuntil'] && $data['availablefrom'] > $data['availableuntil']) {
         $errors['availablefrom'] = get_string('badavailabledates', 'condition');
     }
     // Conditions: Verify that the user profile field has not been declared more than once
     if (array_key_exists('conditionfieldgroup', $data)) {
         // Array to store the existing fields
         $arrcurrentfields = array();
         // Error message displayed if any condition is declared more than once. We use lang string because
         // this way we don't actually generate the string unless there is an error.
         $stralreadydeclaredwarning = new lang_string('fielddeclaredmultipletimes', 'condition');
         foreach ($data['conditionfieldgroup'] as $i => $fielddata) {
             if ($fielddata['conditionfield'] == 0) {
                 // Don't need to bother if none is selected
                 continue;
             }
             if (in_array($fielddata['conditionfield'], $arrcurrentfields)) {
                 $errors["conditionfieldgroup[{$i}]"] = $stralreadydeclaredwarning->out();
             }
             // Add the field to the array
             $arrcurrentfields[] = $fielddata['conditionfield'];
         }
     }
     return $errors;
 }