当前位置: 首页>>代码示例>>PHP>>正文


PHP make_menu_from_list函数代码示例

本文整理汇总了PHP中make_menu_from_list函数的典型用法代码示例。如果您正苦于以下问题:PHP make_menu_from_list函数的具体用法?PHP make_menu_from_list怎么用?PHP make_menu_from_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了make_menu_from_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validation

    /**
     * Perform minimal validation on the grade form
     * @param array $data
     * @param array $files
     */
    function validation($data, $files) {
        global $DB;
        $errors = parent::validation($data, $files);
        // advanced grading
        if (!array_key_exists('grade', $data)) {
            return $errors;
        }

        if ($this->assignment->get_instance()->grade > 0) {
            if (unformat_float($data['grade']) === null && (!empty($data['grade']))) {
                $errors['grade'] = get_string('invalidfloatforgrade', 'assign', $data['grade']);
            } else if (unformat_float($data['grade']) > $this->assignment->get_instance()->grade) {
                $errors['grade'] = get_string('gradeabovemaximum', 'assign', $this->assignment->get_instance()->grade);
            } else if (unformat_float($data['grade']) < 0) {
                $errors['grade'] = get_string('gradebelowzero', 'assign');
            }
        } else {
            // this is a scale
            if ($scale = $DB->get_record('scale', array('id'=>-($this->assignment->get_instance()->grade)))) {
                $scaleoptions = make_menu_from_list($scale->scale);
                if (!array_key_exists((int)$data['grade'], $scaleoptions)) {
                    $errors['grade'] = get_string('invalidgradeforscale', 'assign');
                }
            }
        }
        return $errors;
    }
开发者ID:JP-Git,项目名称:moodle,代码行数:32,代码来源:gradeform.php

示例2: get_scale_selection

 protected function get_scale_selection()
 {
     global $DB;
     $vplinstance = $this->vpl->get_instance();
     $scaleid = $this->vpl->get_grade();
     $options = array();
     $options[-1] = get_string('nograde');
     if ($scaleid > 0) {
         for ($i = 0; $i <= $scaleid; $i++) {
             $options[$i] = $i . ' / ' . $scaleid;
         }
     } elseif ($scaleid < 0) {
         $scaleid = -$scaleid;
         if ($scale = $DB->get_record('scale', array('id' => $scaleid))) {
             $options = $options + make_menu_from_list($scale->scale);
         }
     }
     return $options;
 }
开发者ID:go38,项目名称:moodle-mod_vpl,代码行数:19,代码来源:grade_form.php

示例3: journal_grades

function journal_grades($journalid)
{
    /// Must return an array of grades, indexed by user, and a max grade.
    if (!($journal = get_record("journal", "id", $journalid))) {
        return NULL;
    }
    $grades = get_records_menu("journal_entries", "journal", $journal->id, "", "userid,rating");
    if ($journal->assessed > 0) {
        $return->grades = $grades;
        $return->maxgrade = $journal->assessed;
    } else {
        if ($journal->assessed == 0) {
            return NULL;
        } else {
            if ($scale = get_record("scale", "id", -$journal->assessed)) {
                $scalegrades = make_menu_from_list($scale->scale);
                if ($grades) {
                    foreach ($grades as $key => $grade) {
                        $grades[$key] = $scalegrades[$grade];
                    }
                }
            }
            $return->grades = $grades;
            $return->maxgrade = "";
        }
    }
    return $return;
}
开发者ID:r007,项目名称:PMoodle,代码行数:28,代码来源:lib.php

示例4: definition

 /**
  * Create this grade import form
  */
 public function definition()
 {
     global $CFG, $PAGE, $DB;
     $mform = $this->_form;
     $params = $this->_customdata;
     $renderer = $PAGE->get_renderer('assign');
     // Visible elements.
     $assignment = $params['assignment'];
     $csvdata = $params['csvdata'];
     $gradeimporter = $params['gradeimporter'];
     $update = false;
     $ignoremodified = $params['ignoremodified'];
     $draftid = $params['draftid'];
     if (!$gradeimporter) {
         print_error('invalidarguments');
         return;
     }
     if ($csvdata) {
         $gradeimporter->parsecsv($csvdata);
     }
     $scaleoptions = null;
     if ($assignment->get_instance()->grade < 0) {
         if ($scale = $DB->get_record('scale', array('id' => -$assignment->get_instance()->grade))) {
             $scaleoptions = make_menu_from_list($scale->scale);
         }
     }
     if (!$gradeimporter->init()) {
         $thisurl = new moodle_url('/mod/assign/view.php', array('action' => 'viewpluginpage', 'pluginsubtype' => 'assignfeedback', 'plugin' => 'offline', 'pluginaction' => 'uploadgrades', 'id' => $assignment->get_course_module()->id));
         print_error('invalidgradeimport', 'assignfeedback_offline', $thisurl);
         return;
     }
     $mform->addElement('header', 'importgrades', get_string('importgrades', 'assignfeedback_offline'));
     $updates = array();
     while ($record = $gradeimporter->next()) {
         $user = $record->user;
         $grade = $record->grade;
         $modified = $record->modified;
         $userdesc = fullname($user);
         if ($assignment->is_blind_marking()) {
             $userdesc = get_string('hiddenuser', 'assign') . $assignment->get_uniqueid_for_user($user->id);
         }
         $usergrade = $assignment->get_user_grade($user->id, false);
         // Note: we lose the seconds when converting to user date format - so must not count seconds in comparision.
         $skip = false;
         $stalemodificationdate = $usergrade && $usergrade->timemodified > $modified + 60;
         if (!empty($scaleoptions)) {
             // This is a scale - we need to convert any grades to indexes in the scale.
             $scaleindex = array_search($grade, $scaleoptions);
             if ($scaleindex !== false) {
                 $grade = $scaleindex;
             } else {
                 $grade = '';
             }
         } else {
             $grade = unformat_float($grade);
         }
         if ($usergrade && $usergrade->grade == $grade) {
             // Skip - grade not modified.
             $skip = true;
         } else {
             if (!isset($grade) || $grade === '' || $grade < 0) {
                 // Skip - grade has no value.
                 $skip = true;
             } else {
                 if (!$ignoremodified && $stalemodificationdate) {
                     // Skip - grade has been modified.
                     $skip = true;
                 } else {
                     if ($assignment->grading_disabled($user->id)) {
                         // Skip grade is locked.
                         $skip = true;
                     } else {
                         if ($assignment->get_instance()->grade > -1 && ($grade < 0 || $grade > $assignment->get_instance()->grade)) {
                             // Out of range.
                             $skip = true;
                         }
                     }
                 }
             }
         }
         if (!$skip) {
             $update = true;
             if (!empty($scaleoptions)) {
                 $formattedgrade = $scaleoptions[$grade];
             } else {
                 $formattedgrade = format_float($grade, 2);
             }
             $updates[] = get_string('gradeupdate', 'assignfeedback_offline', array('grade' => $formattedgrade, 'student' => $userdesc));
         }
         if ($ignoremodified || !$stalemodificationdate) {
             foreach ($record->feedback as $feedback) {
                 $plugin = $feedback['plugin'];
                 $field = $feedback['field'];
                 $newvalue = $feedback['value'];
                 $description = $feedback['description'];
                 $oldvalue = '';
                 if ($usergrade) {
//.........这里部分代码省略.........
开发者ID:gabrielrosset,项目名称:moodle,代码行数:101,代码来源:importgradesform.php

示例5: get_records_sql

 } else {
     if ($subaction == 'grades') {
         $sql = "\n           SELECT \n             a.id,\n             a.studentid,\n             a.grade,\n             a.appointmentnote,\n             u.lastname,\n             u.firstname\n           FROM \n                {$CFG->prefix}user AS u,\n                {$CFG->prefix}scheduler_slots AS s,\n                {$CFG->prefix}scheduler_appointment AS a\n           WHERE\n                u.id = a.studentid AND\n                a.slotid = s.id AND\n                s.schedulerid = {$scheduler->id} AND\n                a.attended = 1\n           ORDER BY\n                u.lastname,u.firstname,s.teacherid\n        ";
         $grades = get_records_sql($sql);
         foreach ($grades as $grade) {
             if ($scheduler->scale > 0) {
                 // numeric scales
                 $finals[$grade->studentid]->sum = @$finals[$grade->studentid]->sum + $grade->grade;
                 $finals[$grade->studentid]->count = @$finals[$grade->studentid]->count + 1;
                 $finals[$grade->studentid]->max = @$finals[$grade->studentid]->max < $grade->grade ? $grade->grade : @$finals[$studentid]->max;
             } else {
                 if ($scheduler->scale < 0) {
                     // non numeric scales
                     $scaleid = -$scheduler->scale;
                     if ($scale = get_record('scale', 'id', $scaleid)) {
                         $scalegrades = make_menu_from_list($scale->scale);
                         foreach ($grades as $aGrade) {
                             $finals[$aGrade->studentid]->sum = @$finals[$aGrade->studentid]->sum + $scalegrades[$aGgrade->grade];
                             $finals[$aGrade->studentid]->count = @$finals[$aGrade->studentid]->count + 1;
                             $finals[$aGrade->studentid]->max = @$finals[$aGrade->studentid]->max < $aGrade ? $scalegrades[$aGgrade->grade] : @$finals[$aGrade->studentid]->max;
                         }
                     }
                 }
             }
             $finals[$grade->studentid]->lastname = $grade->lastname;
             $finals[$grade->studentid]->firstname = $grade->firstname;
             $finals[$grade->studentid]->appointmentnote = @$finals[$grade->studentid]->appointmentnote . ' | ' . $grade->appointmentnote;
         }
         /// Making title line
         $stream .= get_string('student', 'scheduler') . $csvfieldseparator;
         $stream .= get_string('grades') . $csvfieldseparator;
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:31,代码来源:downloads.php

示例6: text_to_html

        echo $OUTPUT->heading($scale->name);
        echo "<center>";
        echo $OUTPUT->select(html_select::make($scalemenu));
        echo "</center>";
        echo text_to_html($scale->description);
        echo $OUTPUT->box_end();
        echo "<hr />";
    }
} else {
    if (has_capability('moodle/course:managescales', $context)) {
        echo "<p align=\"center\">(";
        print_string("scalestip");
        echo ")</p>";
    }
}
if ($scales = $DB->get_records("scale", array("courseid" => 0), "name ASC")) {
    echo $OUTPUT->heading($strstandardscales);
    foreach ($scales as $scale) {
        $scalemenu = make_menu_from_list($scale->scale);
        echo $OUTPUT->box_start();
        echo $OUTPUT->heading($scale->name);
        echo "<center>";
        echo $OUTPUT->select(html_select::make($scalemenu, ''));
        echo "</center>";
        echo text_to_html($scale->description);
        echo $OUTPUT->box_end();
        echo "<hr />";
    }
}
echo $OUTPUT->close_window_button();
echo $OUTPUT->footer();
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:scales.php

示例7: display_grade

    /**
     *  Return a grade in user-friendly form, whether it's a scale or not
     *
     * @global object
     * @param mixed $grade
     * @return string User-friendly representation of grade
     */
    function display_grade($grade) {
        global $DB;

        static $scalegrades = array();   // Cache scales for each assignment - they might have different scales!!

        if ($this->assignment->grade >= 0) {    // Normal number
            if ($grade == -1) {
                return '-';
            } else {
                return $grade.' / '.$this->assignment->grade;
            }

        } else {                                // Scale
            if (empty($scalegrades[$this->assignment->id])) {
                if ($scale = $DB->get_record('scale', array('id'=>-($this->assignment->grade)))) {
                    $scalegrades[$this->assignment->id] = make_menu_from_list($scale->scale);
                } else {
                    return '-';
                }
            }
            if (isset($scalegrades[$this->assignment->id][$grade])) {
                return $scalegrades[$this->assignment->id][$grade];
            }
            return '-';
        }
    }
开发者ID:nuckey,项目名称:moodle,代码行数:33,代码来源:lib.php

示例8: make_grading_menu

/**
* A small utility function for making scale menus
*
*/
function make_grading_menu(&$brainstorm, $id, $selected = '', $return = false)
{
    if (!$brainstorm->scale) {
        return '';
    }
    if ($brainstorm->scale > 0) {
        for ($i = 0; $i <= $brainstorm->scale; $i++) {
            $scalegrades[$i] = $i;
        }
    } else {
        $scaleid = -$brainstorm->scale;
        if ($scale = get_record('scale', 'id', $scaleid)) {
            $scalegrades = make_menu_from_list($scale->scale);
        }
    }
    return choose_from_menu($scalegrades, $id, $selected, 'choose', '', '', $return);
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:21,代码来源:locallib.php

示例9: process_import_grades

 /**
  * Loop through uploaded grades and update the grades for this assignment
  *
  * @param int $draftid - The unique draft item id for this import
  * @param int $importid - The unique import ID for this csv import operation
  * @param bool $ignoremodified - Ignore the last modified date when checking fields
  * @return string - The html response
  */
 public function process_import_grades($draftid, $importid, $ignoremodified)
 {
     global $USER, $DB;
     require_sesskey();
     require_capability('mod/assign:grade', $this->assignment->get_context());
     $gradeimporter = new assignfeedback_offline_grade_importer($importid, $this->assignment);
     $context = context_user::instance($USER->id);
     $fs = get_file_storage();
     if (!($files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false))) {
         redirect(new moodle_url('view.php', array('id' => $this->assignment->get_course_module()->id, 'action' => 'grading')));
         return;
     }
     $file = reset($files);
     $csvdata = $file->get_content();
     if ($csvdata) {
         $gradeimporter->parsecsv($csvdata);
     }
     if (!$gradeimporter->init()) {
         $thisurl = new moodle_url('/mod/assign/view.php', array('action' => 'viewpluginpage', 'pluginsubtype' => 'assignfeedback', 'plugin' => 'offline', 'pluginaction' => 'uploadgrades', 'id' => $assignment->get_course_module()->id));
         print_error('invalidgradeimport', 'assignfeedback_offline', $thisurl);
         return;
     }
     // Does this assignment use a scale?
     $scaleoptions = null;
     if ($this->assignment->get_instance()->grade < 0) {
         if ($scale = $DB->get_record('scale', array('id' => -$this->assignment->get_instance()->grade))) {
             $scaleoptions = make_menu_from_list($scale->scale);
         }
     }
     // We may need to upgrade the gradebook comments after this update.
     $adminconfig = $this->assignment->get_admin_config();
     $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
     $updatecount = 0;
     while ($record = $gradeimporter->next()) {
         $user = $record->user;
         $modified = $record->modified;
         $userdesc = fullname($user);
         $usergrade = $this->assignment->get_user_grade($user->id, false);
         if (!empty($scaleoptions)) {
             // This is a scale - we need to convert any grades to indexes in the scale.
             $scaleindex = array_search($record->grade, $scaleoptions);
             if ($scaleindex !== false) {
                 $record->grade = $scaleindex;
             } else {
                 $record->grade = '';
             }
         } else {
             $record->grade = unformat_float($record->grade);
         }
         // Note: Do not count the seconds when comparing modified dates.
         $skip = false;
         $stalemodificationdate = $usergrade && $usergrade->timemodified > $modified + 60;
         if ($usergrade && $usergrade->grade == $record->grade) {
             // Skip - grade not modified.
             $skip = true;
         } else {
             if (!isset($record->grade) || $record->grade === '' || $record->grade < 0) {
                 // Skip - grade has no value.
                 $skip = true;
             } else {
                 if (!$ignoremodified && $stalemodificationdate) {
                     // Skip - grade has been modified.
                     $skip = true;
                 } else {
                     if ($this->assignment->grading_disabled($record->user->id)) {
                         // Skip grade is locked.
                         $skip = true;
                     } else {
                         if ($this->assignment->get_instance()->grade > -1 && ($record->grade < 0 || $record->grade > $this->assignment->get_instance()->grade)) {
                             // Out of range.
                             $skip = true;
                         }
                     }
                 }
             }
         }
         if (!$skip) {
             $grade = $this->assignment->get_user_grade($record->user->id, true);
             $grade->grade = $record->grade;
             $grade->grader = $USER->id;
             if ($this->assignment->update_grade($grade)) {
                 $this->assignment->notify_grade_modified($grade);
                 $updatecount += 1;
             }
         }
         if ($ignoremodified || !$stalemodificationdate) {
             foreach ($record->feedback as $feedback) {
                 $plugin = $feedback['plugin'];
                 $field = $feedback['field'];
                 $newvalue = $feedback['value'];
                 $description = $feedback['description'];
                 $oldvalue = '';
//.........这里部分代码省略.........
开发者ID:pzhu2004,项目名称:moodle,代码行数:101,代码来源:locallib.php

示例10: scheduler_make_grading_menu

/**
* a utility function for making grading lists
* @param reference $scheduler
* @param string $id the form field id
* @param string $selected the selected value
* @param boolean $return if true, prints the list to output elsewhere returns the HTML string.
* @return the output of the choose_from_menu production
*/
function scheduler_make_grading_menu(&$scheduler, $id, $selected = '', $return = false)
{
    if ($scheduler->scale > 0) {
        for ($i = 0; $i <= $scheduler->scale; $i++) {
            $scalegrades[$i] = $i;
        }
    } else {
        $scaleid = -$scheduler->scale;
        if ($scale = get_record('scale', 'id', $scaleid)) {
            $scalegrades = make_menu_from_list($scale->scale);
        }
    }
    return choose_from_menu($scalegrades, $id, $selected, 'choose', '', '', $return);
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:22,代码来源:locallib.php

示例11: update_grade

 /**
  * Update a grade in the grade table for the setaskment and in the gradebook.
  *
  * @param stdClass $grade a grade record keyed on id
  * @param bool $reopenattempt If the attempt reopen method is manual, allow another attempt at this setaskment.
  * @return bool true for success
  */
 public function update_grade($grade, $reopenattempt = false)
 {
     global $DB;
     $grade->timemodified = time();
     if (!empty($grade->workflowstate)) {
         $validstates = $this->get_marking_workflow_states_for_current_user();
         if (!array_key_exists($grade->workflowstate, $validstates)) {
             return false;
         }
     }
     if ($grade->grade && $grade->grade != -1) {
         if ($this->get_instance()->grade > 0) {
             if (!is_numeric($grade->grade)) {
                 return false;
             } else {
                 if ($grade->grade > $this->get_instance()->grade) {
                     return false;
                 } else {
                     if ($grade->grade < 0) {
                         return false;
                     }
                 }
             }
         } else {
             // This is a scale.
             if ($scale = $DB->get_record('scale', array('id' => -$this->get_instance()->grade))) {
                 $scaleoptions = make_menu_from_list($scale->scale);
                 if (!array_key_exists((int) $grade->grade, $scaleoptions)) {
                     return false;
                 }
             }
         }
     }
     if (empty($grade->attemptnumber)) {
         // Set it to the default.
         $grade->attemptnumber = 0;
     }
     $DB->update_record('setask_grades', $grade);
     $submission = null;
     if ($this->get_instance()->teamsubmission) {
         $submission = $this->get_group_submission($grade->userid, 0, false);
     } else {
         $submission = $this->get_user_submission($grade->userid, false);
     }
     // Only push to gradebook if the update is for the latest attempt.
     // Not the latest attempt.
     if ($submission && $submission->attemptnumber != $grade->attemptnumber) {
         return true;
     }
     if ($this->gradebook_item_update(null, $grade)) {
         \mod_setask\event\submission_graded::create_from_grade($this, $grade)->trigger();
     }
     // If the conditions are met, allow another attempt.
     if ($submission) {
         $this->reopen_submission_if_required($grade->userid, $submission, $reopenattempt);
     }
     return true;
 }
开发者ID:krzpassrl,项目名称:SRL_Moodle_db,代码行数:65,代码来源:locallib.php

示例12: scheduler_grades

/**
* Must return an array of grades for a given instance of this module, 
* indexed by user. It also returns a maximum allowed grade.
* @param int $schedulerid the id of the activity module
* @return array an array of grades
*/
function scheduler_grades($cmid)
{
    global $CFG;
    if (!($module = get_record('course_modules', 'id', $cmid))) {
        return NULL;
    }
    if (!($scheduler = get_record('scheduler', 'id', $module->instance))) {
        return NULL;
    }
    if ($scheduler->scale == 0) {
        // No grading
        return NULL;
    }
    $query = "\n       SELECT\n          a.id,\n          a.studentid,\n          a.grade\n       FROM\n          {$CFG->prefix}scheduler_slots AS s \n       LEFT JOIN\n          {$CFG->prefix}scheduler_appointment AS a\n       ON\n          s.id = a.slotid\n       WHERE\n          s.schedulerid = {$scheduler->id} AND \n          a.grade IS NOT NULL\n    ";
    // echo $query ;
    $grades = get_records_sql($query);
    if ($grades) {
        if ($scheduler->scale > 0) {
            // Grading numerically
            $finalgrades = array();
            foreach ($grades as $aGrade) {
                $finals[$aGrade->studentid]->sum = @$finals[$aGrade->studentid]->sum + $aGrade->grade;
                $finals[$aGrade->studentid]->count = @$finals[$aGrade->studentid]->count + 1;
                $finals[$aGrade->studentid]->max = @$finals[$aGrade->studentid]->max < $aGrade->grade ? $aGrade->grade : @$finalgrades[$aGrade->studentid]->max;
            }
            /// compute the adequate strategy
            foreach ($finals as $student => $aGradeSet) {
                switch ($scheduler->gradingstrategy) {
                    case MAX_GRADE:
                        $finalgrades[$student] = $aGradeSet->max;
                        break;
                    case MEAN_GRADE:
                        $finalgrades[$student] = $aGradeSet->sum / $aGradeSet->count;
                        break;
                }
            }
            $return->grades = $finalgrades;
            $return->maxgrade = $scheduler->scale;
        } else {
            // Scales
            $finalgrades = array();
            $scaleid = -$scheduler->scale;
            $maxgrade = '';
            if ($scale = get_record('scale', 'id', $scaleid)) {
                $scalegrades = make_menu_from_list($scale->scale);
                foreach ($grades as $aGrade) {
                    $finals[$aGrade->studentid]->sum = @$finals[$aGrade->studentid]->sum + $scalegrades[$aGgrade->grade];
                    $finals[$aGrade->studentid]->count = @$finals[$aGrade->studentid]->count + 1;
                    $finals[$aGrade->studentid]->max = @$finals[$aGrade->studentid]->max < $aGrade ? $scalegrades[$aGgrade->grade] : @$finals[$aGrade->studentid]->max;
                }
                $maxgrade = $scale->name;
            }
            /// compute the adequate strategy
            foreach ($finals as $student => $aGradeSet) {
                switch ($scheduler->gradingstrategy) {
                    case MAX_GRADE:
                        $finalgrades[$student] = $aGradeSet->max;
                        break;
                    case MEAN_GRADE:
                        $finalgrades[$student] = $aGradeSet->sum / $aGradeSet->count;
                        break;
                }
            }
            $return->grades = $finalgrades;
            $return->maxgrade = $maxgrade;
        }
        return $return;
    }
    return NULL;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:76,代码来源:lib.php

示例13: validation

 /**
  * Perform minimal validation on the grade form
  * @param array $data
  * @param array $files
  */
 public function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $instance = $this->seplment->get_instance();
     if ($instance->markingworkflow && !empty($data['sendstudentnotifications']) && $data['workflowstate'] != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
         $errors['sendstudentnotifications'] = get_string('studentnotificationworkflowstateerror', 'sepl');
     }
     // Advanced grading.
     if (!array_key_exists('grade', $data)) {
         return $errors;
     }
     if ($instance->grade > 0) {
         if (unformat_float($data['grade'], true) === false && !empty($data['grade'])) {
             $errors['grade'] = get_string('invalidfloatforgrade', 'sepl', $data['grade']);
         } else {
             if (unformat_float($data['grade']) > $instance->grade) {
                 $errors['grade'] = get_string('gradeabovemaximum', 'sepl', $instance->grade);
             } else {
                 if (unformat_float($data['grade']) < 0) {
                     $errors['grade'] = get_string('gradebelowzero', 'sepl');
                 }
             }
         }
     } else {
         // This is a scale.
         if ($scale = $DB->get_record('scale', array('id' => -$instance->grade))) {
             $scaleoptions = make_menu_from_list($scale->scale);
             if ((int) $data['grade'] !== -1 && !array_key_exists((int) $data['grade'], $scaleoptions)) {
                 $errors['grade'] = get_string('invalidgradeforscale', 'sepl');
             }
         }
     }
     return $errors;
 }
开发者ID:krzpassrl,项目名称:SRL_Moodle_Baseline,代码行数:40,代码来源:gradeform.php

示例14: mumiemodule_grades

/**
 * Must return an array of grades for a given instance of this module, 
 * indexed by user.  It also returns a maximum allowed grade.
 * 
 * Example:
 *    $return->grades = array of grades;
 *    $return->maxgrade = maximum allowed grade;
 *
 *    return $return;
 *
 * @param int $mumiemoduleID of an instance of this module
 * @return mixed Null or object with an array of grades and with the maximum grade
 **/
function mumiemodule_grades($mumiemoduleid)
{
    if (!($mumiemodule = get_record('mumiemodule', 'id', $mumiemoduleid))) {
        return NULL;
    }
    if ($mumiemodule->grade == 0) {
        // No grading
        return NULL;
    }
    $grades = get_records_menu('mumiemodule_students', 'mumiemodule', $mumiemodule > id, '', 'userid, grade');
    $return = new object();
    if ($mumiemodule->grade > 0) {
        if ($grades) {
            foreach ($grades as $userid => $grade) {
                if ($grade == -1) {
                    $grades[$userid] = '-';
                }
            }
        }
        $return->grades = $grades;
        $return->maxgrade = (int) $mumiemodule->grade;
    } else {
        // Scale
        if ($grades) {
            $scaleid = -$mumiemodule->grade;
            $maxgrade = "";
            if ($scale = get_record('scale', 'id', $scaleid)) {
                $scalegrades = make_menu_from_list($scale->scale);
                foreach ($grades as $userid => $grade) {
                    if (empty($scalegrades[$grade])) {
                        $grades[$userid] = '-';
                    } else {
                        $grades[$userid] = $scalegrades[$grade];
                    }
                }
                $maxgrade = $scale->name;
            }
        }
        $return->grades = $grades;
        $return->maxgrade = $maxgrade;
    }
    return $return;
}
开发者ID:TU-Berlin,项目名称:Mumie,代码行数:56,代码来源:lib.php

示例15: get_user_grades

 /**
  * Return grade for given user or all users.
  *
  * @param int $schedulerid id of scheduler
  * @param int $userid optional user id, 0 means all users
  * @return array array of grades, false if none
  */
 public function get_user_grades($userid = 0)
 {
     global $CFG, $DB;
     if ($this->scale == 0) {
         return false;
     }
     $usersql = '';
     $params = array();
     if ($userid) {
         $usersql = ' AND a.studentid = :userid';
         $params['userid'] = $userid;
     }
     $params['sid'] = $this->id;
     $sql = 'SELECT a.id, a.studentid, a.grade ' . 'FROM {scheduler_slots} s JOIN {scheduler_appointment} a ON s.id = a.slotid ' . 'WHERE s.schedulerid = :sid AND a.grade IS NOT NULL' . $usersql;
     $grades = $DB->get_records_sql($sql, $params);
     $finalgrades = array();
     $gradesums = array();
     foreach ($grades as $grade) {
         $gradesums[$grade->studentid] = new stdClass();
         $finalgrades[$grade->studentid] = new stdClass();
         $finalgrades[$grade->studentid]->userid = $grade->studentid;
     }
     if ($this->scale > 0) {
         // Grading numerically.
         foreach ($grades as $grade) {
             $gradesums[$grade->studentid]->sum = @$gradesums[$grade->studentid]->sum + $grade->grade;
             $gradesums[$grade->studentid]->count = @$gradesums[$grade->studentid]->count + 1;
             $gradesums[$grade->studentid]->max = @$gradesums[$grade->studentid]->max < $grade->grade ? $grade->grade : @$gradesums[$grade->studentid]->max;
         }
         // Retrieve the adequate strategy.
         foreach ($gradesums as $student => $gradeset) {
             switch ($this->gradingstrategy) {
                 case SCHEDULER_MAX_GRADE:
                     $finalgrades[$student]->rawgrade = $gradeset->max;
                     break;
                 case SCHEDULER_MEAN_GRADE:
                     $finalgrades[$student]->rawgrade = $gradeset->sum / $gradeset->count;
                     break;
             }
         }
     } else {
         // Grading on scales.
         $scaleid = -$this->scale;
         $maxgrade = '';
         if ($scale = $DB->get_record('scale', array('id' => $scaleid))) {
             $scalegrades = make_menu_from_list($scale->scale);
             foreach ($grades as $grade) {
                 $gradesums[$grade->studentid]->sum = @$gradesums[$grade->studentid]->sum + $grade->grade;
                 $gradesums[$grade->studentid]->count = @$gradesums[$grade->studentid]->count + 1;
                 $gradesums[$grade->studentid]->max = @$gradesums[$grade->studentid]->max < $grade ? $grade->grade : @$gradesums[$grade->studentid]->max;
             }
             $maxgrade = $scale->name;
         }
         // Retrieve the adequate strategy.
         foreach ($gradesums as $student => $gradeset) {
             switch ($this->gradingstrategy) {
                 case SCHEDULER_MAX_GRADE:
                     $finalgrades[$student]->rawgrade = $gradeset->max;
                     break;
                 case SCHEDULER_MEAN_GRADE:
                     $finalgrades[$student]->rawgrade = $gradeset->sum / $gradeset->count;
                     break;
             }
         }
     }
     // Include any empty grades.
     if ($userid > 0) {
         if (!array_key_exists($userid, $finalgrades)) {
             $finalgrades[$userid] = new stdClass();
             $finalgrades[$userid]->userid = $userid;
             $finalgrades[$userid]->rawgrade = null;
         }
     } else {
         $gui = new graded_users_iterator($this->get_courserec());
         $gui->init();
         while ($userdata = $gui->next_user()) {
             $uid = $userdata->user->id;
             if (!array_key_exists($uid, $finalgrades)) {
                 $finalgrades[$uid] = new stdClass();
                 $finalgrades[$uid]->userid = $uid;
                 $finalgrades[$uid]->rawgrade = null;
             }
         }
     }
     return $finalgrades;
 }
开发者ID:ninelanterns,项目名称:moodle-mod_scheduler,代码行数:93,代码来源:scheduler_instance.php


注:本文中的make_menu_from_list函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。