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


PHP unformat_float函数代码示例

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


在下文中一共展示了unformat_float函数的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: update_config

 /**
  * Update the criteria information stored in the database
  *
  * @param stdClass $data Form data
  */
 public function update_config(&$data)
 {
     if (!empty($data->criteria_grade)) {
         $formatedgrade = unformat_float($data->criteria_grade_value);
         // TODO validation
         if (!empty($formatedgrade) && is_numeric($formatedgrade)) {
             $this->course = $data->id;
             $this->gradepass = $formatedgrade;
             $this->insert();
         }
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:17,代码来源:completion_criteria_grade.php

示例3: get_data

 public function get_data()
 {
     if (!($item = parent::get_data())) {
         return false;
     }
     $num1 = unformat_float($item->rangefrom, true);
     if ($num1 === false || $num1 === null) {
         $num1 = '-';
     }
     $num2 = unformat_float($item->rangeto, true);
     if ($num2 === false || $num2 === null) {
         $num2 = '-';
     }
     if ($num1 === '-' or $num2 === '-') {
         $item->presentation = $num1 . '|' . $num2;
         return $item;
     }
     if ($num1 > $num2) {
         $item->presentation = $num2 . '|' . $num1;
     } else {
         $item->presentation = $num1 . '|' . $num2;
     }
     return $item;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:24,代码来源:numeric_form.php

示例4: count

        $numpages = count($pagebreakpositions);
        // Ensure the target page number is in range.
        for ($i = $moveselectedonpage; $i > $numpages; $i--) {
            $questions[] = 0;
            $pagebreakpositions[] = count($questions) - 1;
        }
        $moveselectedpos = $pagebreakpositions[$moveselectedonpage - 1];
        // Do the move.
        array_splice($questions, $moveselectedpos, 0, $selectedquestionids);
        $quiz->questions = implode(',', $questions);
        // Update the database.
        $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
        $deletepreviews = true;
    }
    // If rescaling is required save the new maximum.
    $maxgrade = unformat_float(optional_param('maxgrade', -1, PARAM_RAW));
    if ($maxgrade >= 0) {
        quiz_set_grade($maxgrade, $quiz);
    }
    if ($deletepreviews) {
        quiz_delete_previews($quiz);
    }
    if ($recomputesummarks) {
        quiz_update_sumgrades($quiz);
        quiz_update_all_attempt_sumgrades($quiz);
        quiz_update_all_final_grades($quiz);
        quiz_update_grades($quiz, 0, true);
    }
    redirect($afteractionurl);
}
$questionbank->process_actions($thispageurl, $cm);
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:31,代码来源:edit.php

示例5: test_unformat_float

 /**
  * Test localised float unformatting.
  */
 public function test_unformat_float()
 {
     // Tests without the localised decimal separator.
     // Special case for null, empty or white spaces only strings.
     $this->assertEquals(null, unformat_float(null));
     $this->assertEquals(null, unformat_float(''));
     $this->assertEquals(null, unformat_float('    '));
     // Regular use.
     $this->assertEquals(5.4, unformat_float('5.4'));
     $this->assertEquals(5.4, unformat_float('5.4', true));
     // No decimal.
     $this->assertEquals(5.0, unformat_float('5'));
     // Custom number of decimal.
     $this->assertEquals(5.43267, unformat_float('5.43267'));
     // Empty decimal.
     $this->assertEquals(100.0, unformat_float('100.00'));
     // With the thousand separator.
     $this->assertEquals(1000.0, unformat_float('1 000'));
     $this->assertEquals(1000.32, unformat_float('1 000.32'));
     // Negative number.
     $this->assertEquals(-100.0, unformat_float('-100'));
     // Wrong value.
     $this->assertEquals(0.0, unformat_float('Wrong value'));
     // Wrong value in strict mode.
     $this->assertFalse(unformat_float('Wrong value', true));
     // Combining options.
     $this->assertEquals(-1023.862567, unformat_float('   -1 023.862567     '));
     // Bad decimal separator (should crop the decimal).
     $this->assertEquals(50.0, unformat_float('50,57'));
     // Bad decimal separator in strict mode (should return false).
     $this->assertFalse(unformat_float('50,57', true));
     // Tests with a localised decimal separator.
     $this->define_local_decimal_separator();
     // We repeat the tests above but with the current decimal separator.
     // Regular use without and with the localised separator.
     $this->assertEquals(5.4, unformat_float('5.4'));
     $this->assertEquals(5.4, unformat_float('5X4'));
     // Custom number of decimal.
     $this->assertEquals(5.43267, unformat_float('5X43267'));
     // Empty decimal.
     $this->assertEquals(100.0, unformat_float('100X00'));
     // With the thousand separator.
     $this->assertEquals(1000.32, unformat_float('1 000X32'));
     // Bad different separator (should crop the decimal).
     $this->assertEquals(50.0, unformat_float('50Y57'));
     // Bad different separator in strict mode (should return false).
     $this->assertFalse(unformat_float('50Y57', true));
     // Combining options.
     $this->assertEquals(-1023.862567, unformat_float('   -1 023X862567     '));
     // Combining options in strict mode.
     $this->assertEquals(-1023.862567, unformat_float('   -1 023X862567     ', true));
 }
开发者ID:miguelangelUvirtual,项目名称:uEducon,代码行数:55,代码来源:moodlelib_test.php

示例6: unformat_float

        }
        $grade_item->outcomeid = null;
        // update hiding flag
        if ($hiddenuntil) {
            $grade_item->set_hidden($hiddenuntil, false);
        } else {
            $grade_item->set_hidden($hidden, false);
        }
        $grade_item->set_locktime($locktime);
        // locktime first - it might be removed when unlocking
        $grade_item->set_locked($locked, false, true);
        $grade_item->update();
        // We don't need to insert it, it's already created when the category is created
        // set parent if needed
        if (isset($data->parentcategory)) {
            $grade_category->set_parent($data->parentcategory, 'gradebook');
        }
        // update agg coef if needed
        if (isset($data->aggregationcoef)) {
            $data->aggregationcoef = unformat_float($data->aggregationcoef);
            $grade_item = $grade_category->load_grade_item();
            $grade_item->aggregationcoef = $data->aggregationcoef;
            $grade_item->update();
        }
        redirect($returnurl);
    }
}
print_grade_page_head($courseid, 'edittree', null, $heading);
$mform->display();
print_footer($course);
die;
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:31,代码来源:category.php

示例7: import_cleanup

             echo "<br/>grade is {$value}";
             $status = false;
             import_cleanup($importcode);
             echo $OUTPUT->notification(get_string('badgrade', 'grades'));
             break 3;
         }
         $value = $key;
     }
     $newgrade->finalgrade = $value;
 } else {
     if ($value === '' or $value == '-') {
         $value = null;
         // No grade.
     } else {
         // If the value has a local decimal or can correctly be unformatted, do it.
         $validvalue = unformat_float($value, true);
         if ($validvalue !== false) {
             $value = $validvalue;
         } else {
             // Non numeric grade value supplied, possibly mapped wrong column.
             echo "<br/>t0 is {$t0}";
             echo "<br/>grade is {$value}";
             $status = false;
             import_cleanup($importcode);
             echo $OUTPUT->notification(get_string('badgrade', 'grades'));
             break 3;
         }
     }
     $newgrade->finalgrade = $value;
 }
 $newgrades[] = $newgrade;
开发者ID:covex-nn,项目名称:moodle,代码行数:31,代码来源:index.php

示例8: apply_grade_to_user

   /**
     * Apply a grade from a grading form to a user (may be called multiple times for a group submission)
     *
     * @param stdClass $formdata - the data from the form
     * @param int $userid - the user to apply the grade to
     * @return void
     */
    private function apply_grade_to_user($formdata, $userid) {
        global $USER, $CFG, $DB;

        $grade = $this->get_user_grade($userid, true);
        $gradingdisabled = $this->grading_disabled($userid);
        $gradinginstance = $this->get_grading_instance($userid, $gradingdisabled);
        if (!$gradingdisabled) {
            if ($gradinginstance) {
                $grade->grade = $gradinginstance->submit_and_get_grade($formdata->advancedgrading, $grade->id);
            } else {
                // Handle the case when grade is set to No Grade.
                if (isset($formdata->grade)) {
                    $grade->grade= grade_floatval(unformat_float($formdata->grade));
                }
            }
        }
        $grade->grader= $USER->id;

        $adminconfig = $this->get_admin_config();
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;

        // Call save in plugins.
        foreach ($this->feedbackplugins as $plugin) {
            if ($plugin->is_enabled() && $plugin->is_visible()) {
                if (!$plugin->save($grade, $formdata)) {
                    $result = false;
                    print_error($plugin->get_error());
                }
                if (('assignfeedback_' . $plugin->get_type()) == $gradebookplugin) {
                    // This is the feedback plugin chose to push comments to the gradebook.
                    $grade->feedbacktext = $plugin->text_for_gradebook($grade);
                    $grade->feedbackformat = $plugin->format_for_gradebook($grade);
                }
            }
        }
        $this->update_grade($grade);
        $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);

        $this->add_to_log('grade submission', $this->format_grade_for_log($grade));
    }
开发者ID:netspotau,项目名称:moodle-mod_assign,代码行数:47,代码来源:locallib.php

示例9: validation

 /**
  * Validates the form input
  *
  * @param array $data submitted data
  * @param array $files submitted files
  * @return array eventual errors indexed by the field name
  */
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Validate lists of allowed extensions.
     foreach (array('submissionfiletypes', 'overallfeedbackfiletypes') as $fieldname) {
         if (isset($data[$fieldname])) {
             $invalidextensions = workshop::invalid_file_extensions($data[$fieldname], array_keys(core_filetypes::get_types()));
             if ($invalidextensions) {
                 $errors[$fieldname] = get_string('err_unknownfileextension', 'mod_workshop', workshop::clean_file_extensions($invalidextensions));
             }
         }
     }
     // check the phases borders are valid
     if ($data['submissionstart'] > 0 and $data['submissionend'] > 0 and $data['submissionstart'] >= $data['submissionend']) {
         $errors['submissionend'] = get_string('submissionendbeforestart', 'mod_workshop');
     }
     if ($data['assessmentstart'] > 0 and $data['assessmentend'] > 0 and $data['assessmentstart'] >= $data['assessmentend']) {
         $errors['assessmentend'] = get_string('assessmentendbeforestart', 'mod_workshop');
     }
     // check the phases do not overlap
     if (max($data['submissionstart'], $data['submissionend']) > 0 and max($data['assessmentstart'], $data['assessmentend']) > 0) {
         $phasesubmissionend = max($data['submissionstart'], $data['submissionend']);
         $phaseassessmentstart = min($data['assessmentstart'], $data['assessmentend']);
         if ($phaseassessmentstart == 0) {
             $phaseassessmentstart = max($data['assessmentstart'], $data['assessmentend']);
         }
         if ($phasesubmissionend > 0 and $phaseassessmentstart > 0 and $phaseassessmentstart < $phasesubmissionend) {
             foreach (array('submissionend', 'submissionstart', 'assessmentstart', 'assessmentend') as $f) {
                 if ($data[$f] > 0) {
                     $errors[$f] = get_string('phasesoverlap', 'mod_workshop');
                     break;
                 }
             }
         }
     }
     // Check that the submission grade pass is a valid number.
     if (!empty($data['submissiongradepass'])) {
         $submissiongradefloat = unformat_float($data['submissiongradepass'], true);
         if ($submissiongradefloat === false) {
             $errors['submissiongradepass'] = get_string('err_numeric', 'form');
         } else {
             if ($submissiongradefloat > $data['grade']) {
                 $errors['submissiongradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['grade']);
             }
         }
     }
     // Check that the grade pass is a valid number.
     if (!empty($data['gradinggradepass'])) {
         $gradepassfloat = unformat_float($data['gradinggradepass'], true);
         if ($gradepassfloat === false) {
             $errors['gradinggradepass'] = get_string('err_numeric', 'form');
         } else {
             if ($gradepassfloat > $data['gradinggrade']) {
                 $errors['gradinggradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['gradinggrade']);
             }
         }
     }
     return $errors;
 }
开发者ID:sirromas,项目名称:lms,代码行数:66,代码来源:mod_form.php

示例10: apply_grade_to_user

    /**
     * Apply a grade from a grading form to a user (may be called multiple times for a group submission).
     *
     * @param stdClass $formdata - the data from the form
     * @param int $userid - the user to apply the grade to
     * @param int attemptnumber - The attempt number to apply the grade to.
     * @return void
     */
    protected function apply_grade_to_user($formdata, $userid, $attemptnumber) {
        global $USER, $CFG, $DB;

        $grade = $this->get_user_grade($userid, true, $attemptnumber);
        $gradingdisabled = $this->grading_disabled($userid);
        $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled);
        if (!$gradingdisabled) {
            if ($gradinginstance) {
                $grade->grade = $gradinginstance->submit_and_get_grade($formdata->advancedgrading,
                                                                       $grade->id);
            } else {
                // Handle the case when grade is set to No Grade.
                if (isset($formdata->grade)) {
                    $grade->grade = grade_floatval(unformat_float($formdata->grade));
                }
            }
        }
        $grade->grader= $USER->id;

        $adminconfig = $this->get_admin_config();
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;

        // Call save in plugins.
        foreach ($this->feedbackplugins as $plugin) {
            if ($plugin->is_enabled() && $plugin->is_visible()) {
                if (!$plugin->save($grade, $formdata)) {
                    $result = false;
                    print_error($plugin->get_error());
                }
                if (('assignfeedback_' . $plugin->get_type()) == $gradebookplugin) {
                    // This is the feedback plugin chose to push comments to the gradebook.
                    $grade->feedbacktext = $plugin->text_for_gradebook($grade);
                    $grade->feedbackformat = $plugin->format_for_gradebook($grade);
                }
            }
        }
        $this->update_grade($grade);
        // Note the default if not provided for this option is true (e.g. webservices).
        // This is for backwards compatibility.
        if (!isset($formdata->sendstudentnotifications) || $formdata->sendstudentnotifications) {
            $this->notify_grade_modified($grade);
        }

        $this->add_to_log('grade submission', $this->format_grade_for_log($grade));
    }
开发者ID:verbazend,项目名称:AWFA,代码行数:53,代码来源:locallib.php

示例11: validation

    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. Ignore this check when completion settings are
        // locked, as the options are then disabled.
        if (array_key_exists('completion', $data) &&
                $data['completion'] == COMPLETION_TRACKING_AUTOMATIC &&
                !empty($data['completionunlocked'])) {
            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;
                }
            }
        }

        return $errors;
    }
开发者ID:ncsu-delta,项目名称:moodle,代码行数:82,代码来源:moodleform_mod.php

示例12: validation

    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;
                }
            }
        }

        return $errors;
    }
开发者ID:ncsu-delta,项目名称:moodle,代码行数:42,代码来源:editsection_form.php

示例13: update_from_form

 /**
  * Utility function that resets grade/completion conditions in table based
  * in data from editing form.
  *
  * @param condition_info_base $ci Condition info
  * @param object $fromform Data from form
  * @param bool $wipefirst If true, wipes existing conditions
  */
 protected static function update_from_form(condition_info_base $ci, $fromform, $wipefirst)
 {
     if ($wipefirst) {
         $ci->wipe_conditions();
     }
     foreach ($fromform->conditiongradegroup as $record) {
         if ($record['conditiongradeitemid']) {
             $ci->add_grade_condition($record['conditiongradeitemid'], unformat_float($record['conditiongrademin']), unformat_float($record['conditiongrademax']));
         }
     }
     foreach ($fromform->conditionfieldgroup as $record) {
         if ($record['conditionfield']) {
             $ci->add_user_field_condition($record['conditionfield'], $record['conditionfieldoperator'], $record['conditionfieldvalue']);
         }
     }
     if (isset($fromform->conditioncompletiongroup)) {
         foreach ($fromform->conditioncompletiongroup as $record) {
             if ($record['conditionsourcecmid']) {
                 $ci->add_completion_condition($record['conditionsourcecmid'], $record['conditionrequiredcompletion']);
             }
         }
     }
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:31,代码来源:conditionlib.php

示例14: update_slot_maxmark

 /**
  * Change the max mark for a slot.
  *
  * Saves changes to the question grades in the offlinequiz_group_questions table and any
  * corresponding question_attempts.
  *
  * @param \stdClass $slot row from the offlinequiz_group_questions table.
  * @param float $maxmark the new maxmark.
  * @return bool true if the new grade is different from the old one.
  */
 public function update_slot_maxmark($slot, $maxmark)
 {
     global $DB;
     $maxmark = unformat_float($maxmark);
     if (abs($maxmark - $slot->maxmark) < 1.0E-7) {
         // Grade has not changed. Nothing to do.
         return false;
     }
     $trans = $DB->start_delegated_transaction();
     $slot->maxmark = $maxmark;
     $DB->update_record('offlinequiz_group_questions', $slot);
     // We also need to update the maxmark for this question in other offlinequiz groups.
     $offlinequiz = $this->offlinequizobj->get_offlinequiz();
     $currentgroupid = $offlinequiz->groupid;
     $groupids = $DB->get_fieldset_select('offlinequiz_groups', 'id', 'offlinequizid = :offlinequizid AND id <> :currentid', array('offlinequizid' => $offlinequiz->id, 'currentid' => $currentgroupid));
     $params = array();
     if ($groupids) {
         list($gsql, $params) = $DB->get_in_or_equal($groupids, SQL_PARAMS_NAMED, 'grp');
         $sql = "SELECT *\n                      FROM {offlinequiz_group_questions}\n                     WHERE offlinequizid = :offlinequizid\n                       AND offlinegroupid {$gsql}\n                       AND questionid = :questionid ";
         $params['offlinequizid'] = $offlinequiz->id;
         $params['questionid'] = $slot->questionid;
         $otherslots = $DB->get_records_sql($sql, $params);
         foreach ($otherslots as $otherslot) {
             $otherslot->maxmark = $maxmark;
             $DB->update_record('offlinequiz_group_questions', $otherslot);
         }
     }
     // Now look at the maxmark of attemps.
     // We do this already in offlinequiz_update_question_instance.
     //         \question_engine::set_max_mark_in_attempts(new \result_qubaids_for_offlinequiz($slot->offlinequizid, $slot->offlinegroupid),
     //                 $slot->slot, $maxmark);
     $trans->allow_commit();
     return true;
 }
开发者ID:frankkoch,项目名称:moodle-mod_offlinequiz,代码行数:44,代码来源:structure.php

示例15: 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


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