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


PHP grade_floatval函数代码示例

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


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

示例1: process_legacy_element

    /**
     * Converts <ELEMENT> into <workshopform_numerrors_dimension> and stores it for later writing
     *
     * @return array to be written to workshop.xml
     */
    public function process_legacy_element($data, $raw) {

        $workshop = $this->parenthandler->get_current_workshop();

        $mapping = array();
        $mapping['id'] = $data['id'];
        $mapping['nonegative'] = $data['elementno'];
        if ($workshop['grade'] == 0 or $data['maxscore'] == 0) {
            $mapping['grade'] = 0;
        } else {
            $mapping['grade'] = grade_floatval($data['maxscore'] / $workshop['grade'] * 100);
        }
        $this->mappings[] = $mapping;

        $converted = null;

        if (trim($data['description']) and $data['description'] <> '@@ GRADE_MAPPING_ELEMENT @@') {
            // prepare a fake record and re-use the upgrade logic
            $fakerecord = (object)$data;
            $converted = (array)workshopform_numerrors_upgrade_element($fakerecord, 12345678);
            unset($converted['workshopid']);

            $converted['id'] = $data['id'];
            $this->dimensions[] = $converted;
        }

        return $converted;
    }
开发者ID:nigeli,项目名称:moodle,代码行数:33,代码来源:lib.php

示例2: errors_to_grade

 /**
  * Returns a grade 0.00000 to 100.00000 for the given number of errors
  *
  * This is where we use the mapping table defined by the teacher. If a grade for the given
  * number of errors (negative assertions) is not defined, the most recently defined one is used.
  * Example of the defined mapping:
  * Number of errors | Grade
  *                0 | 100%  (always)
  *                1 | -     (not defined)
  *                2 | 80%
  *                3 | 60%
  *                4 | -
  *                5 | 30%
  *                6 | 0%
  * With this mapping, one error is mapped to 100% grade and 4 errors is mapped to 60%.
  *
  * @param mixed $numerrors Number of errors
  * @return float          Raw grade (0.00000 to 100.00000) for the given number of negative assertions
  */
 protected function errors_to_grade($numerrors) {
     $grade = 100.00000;
     for ($i = 1; $i <= $numerrors; $i++) {
         if (isset($this->mappings[$i])) {
             $grade = $this->mappings[$i]->grade;
         }
     }
     if ($grade > 100.00000) {
         $grade = 100.00000;
     }
     if ($grade < 0.00000) {
         $grade = 0.00000;
     }
     return grade_floatval($grade);
 }
开发者ID:nuckey,项目名称:moodle,代码行数:34,代码来源:lib.php

示例3: calculate_peer_grade

 /**
  * Calculates the aggregated grade given by the reviewer
  *
  * @param array $grades Grade records as returned by {@link get_current_assessment_data}
  * @uses $this->dimensions
  * @return float|null   Raw grade (from 0.00000 to 100.00000) for submission as suggested by the peer
  */
 protected function calculate_peer_grade(array $grades)
 {
     if (empty($grades)) {
         return null;
     }
     // summarize the grades given in rubrics
     $sumgrades = 0;
     foreach ($grades as $grade) {
         $sumgrades += $grade->grade;
     }
     // get the minimal and maximal possible grade (sum of minimal/maximal grades across all dimensions)
     $mingrade = 0;
     $maxgrade = 0;
     foreach ($this->dimensions as $dimension) {
         $mindimensiongrade = null;
         $maxdimensiongrade = null;
         foreach ($dimension->levels as $level) {
             if (is_null($mindimensiongrade) or $level->grade < $mindimensiongrade) {
                 $mindimensiongrade = $level->grade;
             }
             if (is_null($maxdimensiongrade) or $level->grade > $maxdimensiongrade) {
                 $maxdimensiongrade = $level->grade;
             }
         }
         $mingrade += $mindimensiongrade;
         $maxgrade += $maxdimensiongrade;
     }
     if ($maxgrade - $mingrade > 0) {
         return grade_floatval(100 * ($sumgrades - $mingrade) / ($maxgrade - $mingrade));
     } else {
         return null;
     }
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:40,代码来源:lib.php

示例4: 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));
             }
         }
         if (isset($formdata->workflowstate) || isset($formdata->allocatedmarker)) {
             $flags = $this->get_user_flags($userid, true);
             $flags->workflowstate = isset($formdata->workflowstate) ? $formdata->workflowstate : $flags->workflowstate;
             $flags->allocatedmarker = isset($formdata->allocatedmarker) ? $formdata->allocatedmarker : $flags->allocatedmarker;
             $this->update_user_flags($flags);
         }
     }
     $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);
     $this->notify_grade_modified($grade);
     $addtolog = $this->add_to_log('grade submission', $this->format_grade_for_log($grade), '', true);
     $params = array('context' => $this->context, 'objectid' => $grade->id, 'relateduserid' => $userid);
     $event = \mod_assign\event\submission_graded::create($params);
     $event->set_legacy_logdata($addtolog);
     $event->trigger();
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:55,代码来源:locallib.php

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

示例6: calculate_peer_grade

 /**
  * Calculates the aggregated grade given by the reviewer
  *
  * @param array $grades Grade records as returned by {@link get_current_assessment_data}
  * @uses $this->dimensions
  * @return float|null   Raw grade (from 0.00000 to 100.00000) for submission as suggested by the peer
  */
 protected function calculate_peer_grade(array $grades)
 {
     if (empty($grades)) {
         return null;
     }
     $sumgrades = 0;
     $sumweights = 0;
     foreach ($grades as $grade) {
         $dimension = $this->dimensions[$grade->dimensionid];
         if ($dimension->weight < 0) {
             throw new coding_exception('Negative weights are not supported any more. Something is wrong with your data');
         }
         if (grade_floats_equal($dimension->weight, 0) or grade_floats_equal($dimension->grade, 0)) {
             // does not influence the final grade
             continue;
         }
         if ($dimension->grade < 0) {
             // this is a scale
             $scaleid = -$dimension->grade;
             $sumgrades += $this->scale_to_grade($scaleid, $grade->grade) * $dimension->weight * 100;
             $sumweights += $dimension->weight;
         } else {
             // regular grade
             $sumgrades += $grade->grade / $dimension->grade * $dimension->weight * 100;
             $sumweights += $dimension->weight;
         }
     }
     if ($sumweights === 0) {
         return 0;
     }
     return grade_floatval($sumgrades / $sumweights);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:39,代码来源:lib.php

示例7: grade_floats_different

/**
 * Compare two float numbers safely. Uses 5 decimals php precision. Nulls accepted too.
 * Used for skipping of db updates
 * @param float $f1
 * @param float $f2
 * @return true if different
 */
function grade_floats_different($f1, $f2)
{
    // note: db rounding for 10,5 is different from php round() function
    return grade_floatval($f1) !== grade_floatval($f2);
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:12,代码来源:gradelib.php

示例8: update

 /**
  * In addition to update() as defined in grade_object, handle the grade_outcome and grade_scale objects.
  * Force regrading if necessary, rounds the float numbers using php function,
  * the reason is we need to compare the db value with computed number to skip regrading if possible.
  * @param string $source from where was the object inserted (mod/forum, manual, etc.)
  * @return boolean success
  */
 function update($source = null)
 {
     // reset caches
     $this->dependson_cache = null;
     // Retrieve scale and infer grademax/min from it if needed
     $this->load_scale();
     // make sure there is not 0 in outcomeid
     if (empty($this->outcomeid)) {
         $this->outcomeid = null;
     }
     if ($this->qualifies_for_regrading()) {
         $this->force_regrading();
     }
     $this->timemodified = time();
     $this->grademin = grade_floatval($this->grademin);
     $this->grademax = grade_floatval($this->grademax);
     $this->multfactor = grade_floatval($this->multfactor);
     $this->plusfactor = grade_floatval($this->plusfactor);
     $this->aggregationcoef = grade_floatval($this->aggregationcoef);
     return parent::update($source);
 }
开发者ID:r007,项目名称:PMoodle,代码行数:28,代码来源:grade_item.php

示例9: auto_update_weights


//.........这里部分代码省略.........
         }
     }
     // Initialise this variable (used to keep track of the weight override total).
     $normalisetotal = 0;
     // Keep a record of how much the override total is to see if it is above 100. It it is then we need to set the
     // other weights to zero and normalise the others.
     $overriddentotal = 0;
     // If the overridden weight total is higher than 1 then set the other untouched weights to zero.
     $setotherweightstozero = false;
     // Total up all of the weights.
     foreach ($overridearray as $gradeitemdetail) {
         // If the grade item has extra credit, then don't add it to the normalisetotal.
         if (!$gradeitemdetail['extracredit']) {
             $normalisetotal += $gradeitemdetail['weight'];
         }
         // The overridden total comprises of items that are set as overridden, that aren't extra credit and have a value
         // greater than zero.
         if ($gradeitemdetail['weightoverride'] && !$gradeitemdetail['extracredit'] && $gradeitemdetail['weight'] > 0) {
             // Add overriden weights up to see if they are greater than 1.
             $overriddentotal += $gradeitemdetail['weight'];
         }
     }
     if ($overriddentotal > 1) {
         // Make sure that this catergory of weights gets normalised.
         $requiresnormalising = true;
         // The normalised weights are only the overridden weights, so we just use the total of those.
         $normalisetotal = $overriddentotal;
     }
     $totalnonoverriddengrademax = $totalgrademax - $totaloverriddengrademax;
     // This setting indicates if we should use algorithm prior to MDL-49257 fix for calculating extra credit weights.
     // Even though old algorith has bugs in it, we need to preserve existing grades.
     $gradebookcalculationfreeze = (int) get_config('core', 'gradebook_calculations_freeze_' . $this->courseid);
     $oldextracreditcalculation = $gradebookcalculationfreeze && $gradebookcalculationfreeze <= 20150619;
     reset($children);
     foreach ($children as $sortorder => $child) {
         $gradeitem = null;
         if ($child['type'] == 'item') {
             $gradeitem = $child['object'];
         } else {
             if ($child['type'] == 'category') {
                 $gradeitem = $child['object']->load_grade_item();
             }
         }
         if ($gradeitem->gradetype == GRADE_TYPE_NONE || $gradeitem->gradetype == GRADE_TYPE_TEXT) {
             // Text items and none items do not have a weight, no need to set their weight to
             // zero as they must never be used during aggregation.
             continue;
         } else {
             if (!$this->aggregateoutcomes && $gradeitem->is_outcome_item()) {
                 // We will not aggregate outcome items, so we can ignore updating their weights.
                 continue;
             } else {
                 if (empty($CFG->grade_includescalesinaggregation) && $gradeitem->gradetype == GRADE_TYPE_SCALE) {
                     // We will not aggregate the scales, so we can ignore upating their weights.
                     continue;
                 } else {
                     if (!$oldextracreditcalculation && $gradeitem->aggregationcoef > 0 && $gradeitem->weightoverride) {
                         // For an item with extra credit ignore other weigths and overrides but do not change anything at all
                         // if it's weight was already overridden.
                         continue;
                     }
                 }
             }
         }
         // Store the previous value here, no need to update if it is the same value.
         $prevaggregationcoef2 = $gradeitem->aggregationcoef2;
         if (!$oldextracreditcalculation && $gradeitem->aggregationcoef > 0 && !$gradeitem->weightoverride) {
             // For an item with extra credit ignore other weigths and overrides.
             $gradeitem->aggregationcoef2 = $totalgrademax ? $gradeitem->grademax / $totalgrademax : 0;
         } else {
             if (!$gradeitem->weightoverride) {
                 // Calculations with a grade maximum of zero will cause problems. Just set the weight to zero.
                 if ($totaloverriddenweight >= 1 || $totalnonoverriddengrademax == 0 || $gradeitem->grademax == 0) {
                     // There is no more weight to distribute.
                     $gradeitem->aggregationcoef2 = 0;
                 } else {
                     // Calculate this item's weight as a percentage of the non-overridden total grade maxes
                     // then convert it to a proportion of the available non-overriden weight.
                     $gradeitem->aggregationcoef2 = $gradeitem->grademax / $totalnonoverriddengrademax * (1 - $totaloverriddenweight);
                 }
             } else {
                 if (!$automaticgradeitemspresent && $normalisetotal != 1 || $requiresnormalising || $overridearray[$gradeitem->id]['weight'] < 0) {
                     // Just divide the overriden weight for this item against the total weight override of all
                     // items in this category.
                     if ($normalisetotal == 0 || $overridearray[$gradeitem->id]['weight'] < 0) {
                         // If the normalised total equals zero, or the weight value is less than zero,
                         // set the weight for the grade item to zero.
                         $gradeitem->aggregationcoef2 = 0;
                     } else {
                         $gradeitem->aggregationcoef2 = $overridearray[$gradeitem->id]['weight'] / $normalisetotal;
                     }
                 }
             }
         }
         if (grade_floatval($prevaggregationcoef2) !== grade_floatval($gradeitem->aggregationcoef2)) {
             // Update the grade item to reflect these changes.
             $gradeitem->update();
         }
     }
 }
开发者ID:rushi963,项目名称:moodle,代码行数:101,代码来源:grade_category.php

示例10: test_calculate_peer_grade_two_scales_weighted

 public function test_calculate_peer_grade_two_scales_weighted()
 {
     global $DB;
     // fixture set-up
     $mockscale13 = 'Poor,Good,Excellent';
     $mockscale17 = '-,*,**,***,****,*****,******';
     $this->strategy->dimensions[1012] = (object) array('grade' => '-13', 'weight' => 2);
     $this->strategy->dimensions[1019] = (object) array('grade' => '-17', 'weight' => 3);
     $grades[] = (object) array('dimensionid' => 1012, 'grade' => '2.00000');
     // "Good"
     $grades[] = (object) array('dimensionid' => 1019, 'grade' => '5.00000');
     // "****"
     $DB->expectAt(0, 'get_field', array('scale', 'scale', array('id' => 13), MUST_EXIST));
     $DB->setReturnValueAt(0, 'get_field', $mockscale13);
     $DB->expectAt(1, 'get_field', array('scale', 'scale', array('id' => 17), MUST_EXIST));
     $DB->setReturnValueAt(1, 'get_field', $mockscale17);
     // exercise SUT
     $suggested = $this->strategy->calculate_peer_grade($grades);
     // validate
     $this->assertEqual(grade_floatval((1 / 2 * 2 + 4 / 6 * 3) / 5 * 100), $suggested);
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:21,代码来源:testlib.php

示例11: workshopform_numerrors_upgrade_legacy

/**
 * Check if there are some legacy workshop 1.x data to be migrated and upgrade them
 *
 * This must be called after workshop core migration has finished so that
 * all assessments are already upgraded and tables are correctly renamed.
 */
function workshopform_numerrors_upgrade_legacy() {
    global $CFG, $DB, $OUTPUT;
    require_once($CFG->dirroot . '/mod/workshop/db/upgradelib.php');

    if (!workshopform_numerrors_upgrade_legacy_needed()) {
        return;
    }

    // get the list of all legacy workshops using this grading strategy
    if ($legacyworkshops = $DB->get_records('workshop_old', array('gradingstrategy' => 2), 'course,id', 'id')) {
        echo $OUTPUT->notification('Copying assessment forms elements and grade mappings', 'notifysuccess');
        $legacyworkshops = array_keys($legacyworkshops);
        // get some needed info about the workshops
        $workshopinfos = $DB->get_records_list('workshop_old', 'id', $legacyworkshops, 'id', 'id,grade');
        // get the list of all form elements
        list($workshopids, $params) = $DB->get_in_or_equal($legacyworkshops, SQL_PARAMS_NAMED);
        $sql = "SELECT *
                  FROM {workshop_elements_old}
                 WHERE workshopid $workshopids
                       AND newid IS NULL";
        $rs = $DB->get_recordset_sql($sql, $params);
        foreach ($rs as $old) {
            // process the information about mapping
            $newmapping = new stdclass();
            $newmapping->workshopid = $old->workshopid;
            $newmapping->nonegative = $old->elementno;
            $newmapping->grade = $old->maxscore;
            if ($old->maxscore > 0) {
                $newmapping->grade = grade_floatval($old->maxscore / $workshopinfos[$old->workshopid]->grade * 100);
            } else {
                $newmapping->grade = 0;
            }
            $DB->delete_records('workshopform_numerrors_map',
                                array('workshopid' => $newmapping->workshopid, 'nonegative' => $newmapping->nonegative));
            $DB->insert_record('workshopform_numerrors_map', $newmapping);
            // process the information about the element itself
            if (trim($old->description) and $old->description <> '@@ GRADE_MAPPING_ELEMENT @@') {
                $new = workshopform_numerrors_upgrade_element($old, $old->workshopid);
                $newid = $DB->insert_record('workshopform_numerrors', $new);
            } else {
                $newid = 0;
            }
            $DB->set_field('workshop_elements_old', 'newplugin', 'numerrors', array('id' => $old->id));
            $DB->set_field('workshop_elements_old', 'newid', $newid, array('id' => $old->id));
        }
        $rs->close();

        // now we need to reload the legacy ids. Although we have them in $newelements after the first run, we must
        // refetch them from DB so that this function can be called during recovery
        $newelementids = workshop_upgrade_element_id_mappings('numerrors');

        // migrate all grades for these elements (it est the values that reviewers put into forms)
        echo $OUTPUT->notification('Copying assessment form grades', 'notifysuccess');
        $sql = "SELECT *
                  FROM {workshop_grades_old}
                 WHERE workshopid $workshopids
                       AND newid IS NULL";
        $rs = $DB->get_recordset_sql($sql, $params);
        $newassessmentids = workshop_upgrade_assessment_id_mappings();
        foreach ($rs as $old) {
            if (!isset($newassessmentids[$old->assessmentid])) {
                // orphaned grade - the assessment was removed but the grade remained
                continue;
            }
            if (!isset($newelementids[$old->workshopid]) or !isset($newelementids[$old->workshopid][$old->elementno])) {
                // orphaned grade - the assessment form element has been removed after the grade was recorded
                continue;
            }
            $newelementinfo = $newelementids[$old->workshopid][$old->elementno];
            if ($newelementinfo->newid == 0 or $old->feedback == '@@ GRADE_ADJUSTMENT @@') {
                // this is not a real grade - it was used just for mapping purposes
                $DB->set_field('workshop_grades_old', 'newplugin', 'numerrors_map', array('id' => $old->id));
                $DB->set_field('workshop_grades_old', 'newid', 0, array('id' => $old->id));
                continue;
            }
            $new = workshopform_numerrors_upgrade_grade($old, $newassessmentids[$old->assessmentid],
                                                         $newelementids[$old->workshopid][$old->elementno]);
            $newid = $DB->insert_record('workshop_grades', $new);
            $DB->set_field('workshop_grades_old', 'newplugin', 'numerrors', array('id' => $old->id));
            $DB->set_field('workshop_grades_old', 'newid', $newid, array('id' => $old->id));
        }
        $rs->close();
    }
}
开发者ID:nuckey,项目名称:moodle,代码行数:90,代码来源:upgradelib.php

示例12: normalize_grade

 private function normalize_grade($dim,$grade) {
     //todo: weight? is weight a factor here? probably should be...
     $dimmin = $dim->min;
     $dimmax = $dim->max;
     if ($dimmin == $dimmax) {
         return grade_floatval($dimmax);
     } else {
         return grade_floatval(($grade - $dimmin) / ($dimmax - $dimmin) * 100);
     }
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:10,代码来源:lib.php

示例13: workshop_update_grades

/**
 * Update workshop grades in the gradebook
 *
 * Needed by grade_update_mod_grades() in lib/gradelib.php
 *
 * @category grade
 * @param stdClass $workshop instance object with extra cmidnumber and modname property
 * @param int $userid        update grade of specific user only, 0 means all participants
 * @return void
 */
function workshop_update_grades(stdclass $workshop, $userid=0) {
    global $CFG, $DB;
    require_once($CFG->libdir.'/gradelib.php');

    //todo: this ignores userid
    if($workshop->teammode) {
        //this is necessary because we need data like the grouping id
        $course     = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
        $cm         = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
        $whereuser  = '';
        if ($userid) {
            $groups = groups_get_all_groups($cm->course, $userid, $cm->groupingid);
            if(count($groups) ==  1) $group = $groups[0];
            $whereuser = $DB->get_in_or_equal(array_keys(groups_get_members($group,'u.id','')));
        } else {
            $allgroups = groups_get_all_groups($cm->course, 0, $cm->groupingid);
            //todo: on duplicate key error out
            $groupmembers = $DB->get_records_list('groups_members','groupid',array_keys($allgroups),'','userid,groupid');
            //invert this array for use later
            $membergroups = array();
            foreach($groupmembers as $i) {
                $membergroups[$i->groupid][] = $i->userid;
            }
        }
        
        $params = array('workshopid' => $workshop->id, 'userid' => $userid);
        $sql = 'SELECT authorid, grade, gradeover, gradeoverby, feedbackauthor, feedbackauthorformat, timemodified, timegraded
                  FROM {workshop_submissions}
                 WHERE workshopid = :workshopid AND example=0' . $whereuser . ' ORDER BY timemodified DESC';

        $records = $DB->get_records_sql($sql, $params);
        $submissions = array();
        
        //this hinges on ORDER BY timemodified DESC
        if ( isset($allgroups) ) {
            foreach($records as $r) {
                $grp = $groupmembers[$r->authorid]->groupid;
                if (isset($submissions[$grp])) continue;
                $submissions[$grp] = $r;
            }
        }
        
//        print_r($submissions);
        
        
        foreach($submissions as $grp => $s) {
            $members = $membergroups[$grp];
            foreach($members as $m) {
                $grade = new stdclass();
                $grade->userid = $m;
                if (!is_null($s->gradeover)) {
                    $grade->rawgrade = grade_floatval($workshop->grade * $s->gradeover / 100);
                    $grade->usermodified = $s->gradeoverby;
                } else {
                    $grade->rawgrade = grade_floatval($workshop->grade * $s->grade / 100);
                }
                $grade->feedback = $s->feedbackauthor;
                $grade->feedbackformat = $s->feedbackauthorformat;
                $grade->datesubmitted = $s->timemodified;
                $grade->dategraded = $s->timegraded;
                $submissiongrades[$m] = $grade;
            }
        }
    } else {
        $whereuser = $userid ? ' AND authorid = :userid' : '';
        $params = array('workshopid' => $workshop->id, 'userid' => $userid);
        $sql = 'SELECT authorid, grade, gradeover, gradeoverby, feedbackauthor, feedbackauthorformat, timemodified, timegraded
                  FROM {workshop_submissions}
                 WHERE workshopid = :workshopid AND example=0' . $whereuser;
        $records = $DB->get_records_sql($sql, $params);
        $submissiongrades = array();
        foreach ($records as $record) {
            $grade = new stdclass();
            $grade->userid = $record->authorid;
            if (!is_null($record->gradeover)) {
                $grade->rawgrade = grade_floatval($workshop->grade * $record->gradeover / 100);
                $grade->usermodified = $record->gradeoverby;
            } else {
                $grade->rawgrade = grade_floatval($workshop->grade * $record->grade / 100);
            }
            $grade->feedback = $record->feedbackauthor;
            $grade->feedbackformat = $record->feedbackauthorformat;
            $grade->datesubmitted = $record->timemodified;
            $grade->dategraded = $record->timegraded;
            $submissiongrades[$record->authorid] = $grade;
        }
    }

    $whereuser = $userid ? ' AND userid = :userid' : '';
    $params = array('workshopid' => $workshop->id, 'userid' => $userid);
//.........这里部分代码省略.........
开发者ID:JP-Git,项目名称:moodle,代码行数:101,代码来源:lib.php

示例14: update

 /**
  * In addition to update() as defined in grade_object rounds the float numbers using php function,
  * the reason is we need to compare the db value with computed number to skip updates if possible.
  *
  * @param string $source from where was the object inserted (mod/forum, manual, etc.)
  * @return bool success
  */
 public function update($source = null)
 {
     $this->rawgrade = grade_floatval($this->rawgrade);
     $this->finalgrade = grade_floatval($this->finalgrade);
     $this->rawgrademin = grade_floatval($this->rawgrademin);
     $this->rawgrademax = grade_floatval($this->rawgrademax);
     return parent::update($source);
 }
开发者ID:sriysk,项目名称:moodle-integration,代码行数:15,代码来源:grade_grade.php

示例15: test_average_assessment_different_weights

 public function test_average_assessment_different_weights()
 {
     // fixture set-up
     $assessments = array();
     $assessments[11] = (object) array('weight' => 1, 'dimgrades' => array(3 => 10.0, 4 => 13.4, 5 => 95.0));
     $assessments[13] = (object) array('weight' => 3, 'dimgrades' => array(3 => 11.0, 4 => 10.1, 5 => 92.0));
     $assessments[17] = (object) array('weight' => 1, 'dimgrades' => array(3 => 11.0, 4 => 8.1, 5 => 88.0));
     // exercise SUT
     $average = $this->evaluator->average_assessment($assessments);
     // validate
     $this->assertEquals(gettype($average->dimgrades), 'array');
     $this->assertEquals(grade_floatval($average->dimgrades[3]), grade_floatval((10.0 + 11.0 * 3 + 11.0) / 5));
     $this->assertEquals(grade_floatval($average->dimgrades[4]), grade_floatval((13.4 + 10.1 * 3 + 8.1) / 5));
     $this->assertEquals(grade_floatval($average->dimgrades[5]), grade_floatval((95.0 + 92.0 * 3 + 88.0) / 5));
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:15,代码来源:lib_test.php


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