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


PHP grade_item::force_regrading方法代码示例

本文整理汇总了PHP中grade_item::force_regrading方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_item::force_regrading方法的具体用法?PHP grade_item::force_regrading怎么用?PHP grade_item::force_regrading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grade_item的用法示例。


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

示例1: save_grade_item


//.........这里部分代码省略.........
     // now save the related scores
     if (isset($grade_item->scores) && !empty($grade_item->scores)) {
         // get the existing scores
         $current_scores = array();
         $existing_grades = grade_grade::fetch_all(array('itemid' => $grade_item_id));
         if ($existing_grades) {
             foreach ($existing_grades as $grade) {
                 $current_scores[$grade->userid] = $grade;
             }
         }
         // run through the scores in the gradeitem and try to save them
         $errors_count = 0;
         $processed_scores = array();
         foreach ($grade_item->scores as $score) {
             $user = self::get_users($score->user_id);
             if (!$user) {
                 $score->error = self::USER_DOES_NOT_EXIST_ERROR;
                 $processed_scores[] = $score;
                 $errors_count++;
                 continue;
             }
             $user_id = $user->id;
             // null/blank scores are not allowed
             if (!isset($score->score)) {
                 $score->error = 'NO_SCORE_ERROR';
                 $processed_scores[] = $score;
                 $errors_count++;
                 continue;
             }
             if (!is_numeric($score->score)) {
                 $score->error = 'SCORE_INVALID';
                 $processed_scores[] = $score;
                 $errors_count++;
                 continue;
             }
             $score->score = floatval($score->score);
             // Student Score should not be greater than the total points possible
             if ($score->score > $grade_item_pp) {
                 $score->error = self::POINTS_POSSIBLE_UPDATE_ERRORS;
                 $processed_scores[] = $score;
                 $errors_count++;
                 continue;
             }
             try {
                 $grade_tosave = null;
                 if (isset($current_scores[$user_id])) {
                     // existing score
                     $grade_tosave = $current_scores[$user_id];
                     // check against existing score
                     if ($score->score < $grade_tosave->rawgrade) {
                         $score->error = self::SCORE_UPDATE_ERRORS;
                         $processed_scores[] = $score;
                         $errors_count++;
                         continue;
                     }
                     $grade_tosave->finalgrade = $score->score;
                     $grade_tosave->rawgrade = $score->score;
                     $grade_tosave->timemodified = time();
                     /** @noinspection PhpUndefinedMethodInspection */
                     $grade_tosave->update(self::GRADE_LOCATION_STR);
                 } else {
                     // new score
                     $grade_tosave = new grade_grade();
                     $grade_tosave->itemid = $grade_item_id;
                     $grade_tosave->userid = $user_id;
                     $grade_tosave->finalgrade = $score->score;
                     $grade_tosave->rawgrade = $score->score;
                     $grade_tosave->rawgrademax = $grade_item_pp;
                     $now = time();
                     $grade_tosave->timecreated = $now;
                     $grade_tosave->timemodified = $now;
                     $grade_tosave->insert(self::GRADE_LOCATION_STR);
                 }
                 /** @noinspection PhpUndefinedFieldInspection */
                 $grade_tosave->user_id = $score->user_id;
                 $processed_scores[] = $grade_tosave;
             } catch (Exception $e) {
                 // General errors, caused while performing updates (Tag: generalerrors)
                 $score->error = self::GENERAL_ERRORS;
                 $processed_scores[] = $score;
                 $errors_count++;
             }
         }
         /** @noinspection PhpUndefinedFieldInspection */
         $grade_item_tosave->scores = $processed_scores;
         // put the errors in the item
         if ($errors_count > 0) {
             $errors = array();
             foreach ($processed_scores as $score) {
                 if (isset($score->error)) {
                     $errors[$score->user_id] = $score->error;
                 }
             }
             /** @noinspection PhpUndefinedFieldInspection */
             $grade_item_tosave->errors = $errors;
         }
         $grade_item_tosave->force_regrading();
     }
     return $grade_item_tosave;
 }
开发者ID:dirkcgrunwald,项目名称:iclicker-moodle2-integrate,代码行数:101,代码来源:iclicker_service.php


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