• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP grade_category类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_event

 /**
  * Test the event.
  */
 public function test_event()
 {
     global $CFG;
     require_once "{$CFG->libdir}/gradelib.php";
     $this->resetAfterTest();
     $course = $this->getDataGenerator()->create_course();
     $user = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($user->id, $course->id);
     $grade_category = grade_category::fetch_course_category($course->id);
     $grade_category->load_grade_item();
     $grade_item = $grade_category->grade_item;
     $grade_item->update_final_grade($user->id, 10, 'gradebook');
     $grade_grade = new grade_grade(array('userid' => $user->id, 'itemid' => $grade_item->id), true);
     $grade_grade->grade_item = $grade_item;
     $event = \core\event\user_graded::create_from_grade($grade_grade);
     $this->assertEventLegacyLogData(array($course->id, 'grade', 'update', '/report/grader/index.php?id=' . $course->id, $grade_item->itemname . ': ' . fullname($user)), $event);
     $this->assertEquals(context_course::instance($course->id), $event->get_context());
     $this->assertSame($event->objecttable, 'grade_grades');
     $this->assertEquals($event->objectid, $grade_grade->id);
     $this->assertEquals($event->other['itemid'], $grade_item->id);
     $this->assertTrue($event->other['overridden']);
     $this->assertEquals(10, $event->other['finalgrade']);
     // Trigger the events.
     $sink = $this->redirectEvents();
     $event->trigger();
     $result = $sink->get_events();
     $sink->close();
     $this->assertCount(1, $result);
     $event = reset($result);
     $this->assertEventContextNotUsed($event);
     $grade = $event->get_grade();
     $this->assertInstanceOf('grade_grade', $grade);
     $this->assertEquals($grade_grade->id, $grade->id);
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:37,代码来源:event_user_graded_test.php


示例2: execute

 /**
  * Adds a grade category and moves the specified item into it.
  * Uses locks to prevent race conditions (see MDL-37055).
  */
 public function execute()
 {
     $customdata = $this->get_custom_data();
     // Get lock timeout.
     $timeout = 5;
     // A namespace for the locks.
     $locktype = 'block_mhaairs_add_category';
     // Resource key - course id and category name.
     $resource = "course: {$customdata->courseid}; catname: {$customdata->catname}";
     // Get an instance of the currently configured lock_factory.
     $lockfactory = \core\lock\lock_config::get_lock_factory($locktype);
     // Open a lock.
     $lock = $lockfactory->get_lock($resource, $timeout);
     // Add the category.
     $catparams = array('fullname' => $customdata->catname, 'courseid' => $customdata->courseid);
     if (!($category = \grade_category::fetch($catparams))) {
         // If the category does not exist we create it.
         $gradeaggregation = get_config('core', 'grade_aggregation');
         if ($gradeaggregation === false) {
             $gradeaggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2;
         }
         // Parent category is automatically added(created) during insert.
         $catparams['hidden'] = false;
         $catparams['aggregation'] = $gradeaggregation;
         try {
             $category = new \grade_category($catparams, false);
             $category->id = $category->insert();
         } catch (Exception $e) {
             // Must release the locks.
             $lock->release();
             // Rethrow to reschedule task.
             throw $e;
         }
     }
     // Release locks.
     $lock->release();
     // Add the item to the category.
     $gitem = \grade_item::fetch(array('id' => $customdata->itemid));
     $gitem->categoryid = $category->id;
     $gitem->update();
 }
开发者ID:itamart,项目名称:moodle-block_mhaairs,代码行数:45,代码来源:add_grade_category_task.php


示例3: cleanup

 public function cleanup()
 {
     // cleanup any clickers before the test
     $user_id = iclicker_service::require_user();
     $results = iclicker_service::get_registrations_by_user($user_id);
     if ($results) {
         echo "cleanup registrations for user: {$user_id}  " . PHP_EOL;
         foreach ($results as $reg) {
             if ($reg->clicker_id == $this->clicker_id) {
                 iclicker_service::remove_registration($reg->id);
                 echo "cleanup: {$reg->id} " . PHP_EOL;
             }
         }
     }
     // cleanup the test grades
     $def_grade_cats = grade_category::fetch_all(array('courseid' => $this->courseid, 'fullname' => iclicker_service::GRADE_CATEGORY_NAME));
     $stuff_grade_cats = grade_category::fetch_all(array('courseid' => $this->courseid, 'fullname' => 'stuff'));
     $grade_cats = $def_grade_cats;
     if (is_array($def_grade_cats) && is_array($stuff_grade_cats)) {
         $grade_cats = array_merge($def_grade_cats, $stuff_grade_cats);
     } else {
         if (is_array($stuff_grade_cats)) {
             $grade_cats = $stuff_grade_cats;
         }
     }
     if ($grade_cats) {
         foreach ($grade_cats as $cat) {
             $grade_items = grade_item::fetch_all(array('courseid' => $this->courseid, 'categoryid' => $cat->id));
             if ($grade_items) {
                 foreach ($grade_items as $item) {
                     $grades = grade_grade::fetch_all(array('itemid' => $item->id));
                     if ($grades) {
                         foreach ($grades as $grade) {
                             $grade->delete("cleanup");
                         }
                     }
                     $item->delete("cleanup");
                 }
             }
             $cat->delete("cleanup");
         }
     }
 }
开发者ID:dirkcgrunwald,项目名称:iclicker-moodle2-integrate,代码行数:43,代码来源:test_iclicker_service.php


示例4: restore_create_gradebook

/**
 * This function creates all the gradebook data from xml
 */
function restore_create_gradebook($restore, $xml_file)
{
    global $CFG;
    $status = true;
    //Check it exists
    if (!file_exists($xml_file)) {
        return false;
    }
    // Get info from xml
    // info will contain the number of record to process
    $info = restore_read_xml_gradebook($restore, $xml_file);
    // If we have info, then process
    if (empty($info)) {
        return $status;
    }
    if (empty($CFG->disablegradehistory) and isset($info->gradebook_histories) and $info->gradebook_histories == "true") {
        $restore_histories = true;
    } else {
        $restore_histories = false;
    }
    // make sure top course category exists
    $course_category = grade_category::fetch_course_category($restore->course_id);
    $course_category->load_grade_item();
    // we need to know if all grade items that were backed up are being restored
    // if that is not the case, we do not restore grade categories nor gradeitems of category type or course type
    // i.e. the aggregated grades of that category
    $restoreall = true;
    // set to false if any grade_item is not selected/restored or already exist
    $importing = !empty($SESSION->restore->importing);
    if ($importing) {
        $restoreall = false;
    } else {
        $prev_grade_items = grade_item::fetch_all(array('courseid' => $restore->course_id));
        $prev_grade_cats = grade_category::fetch_all(array('courseid' => $restore->course_id));
        // if any categories already present, skip restore of categories from backup - course item or category already exist
        if (count($prev_grade_items) > 1 or count($prev_grade_cats) > 1) {
            $restoreall = false;
        }
        unset($prev_grade_items);
        unset($prev_grade_cats);
        if ($restoreall) {
            if ($recs = get_records_select("backup_ids", "table_name = 'grade_items' AND backup_code = {$restore->backup_unique_code}", "", "old_id")) {
                foreach ($recs as $rec) {
                    if ($data = backup_getid($restore->backup_unique_code, 'grade_items', $rec->old_id)) {
                        $info = $data->info;
                        // do not restore if this grade_item is a mod, and
                        $itemtype = backup_todb($info['GRADE_ITEM']['#']['ITEMTYPE']['0']['#']);
                        if ($itemtype == 'mod') {
                            $olditeminstance = backup_todb($info['GRADE_ITEM']['#']['ITEMINSTANCE']['0']['#']);
                            $itemmodule = backup_todb($info['GRADE_ITEM']['#']['ITEMMODULE']['0']['#']);
                            if (empty($restore->mods[$itemmodule]->granular)) {
                                continue;
                            } else {
                                if (!empty($restore->mods[$itemmodule]->instances[$olditeminstance]->restore)) {
                                    continue;
                                }
                            }
                            // at least one activity should not be restored - do not restore categories and manual items at all
                            $restoreall = false;
                            break;
                        }
                    }
                }
            }
        }
    }
    // Start ul
    if (!defined('RESTORE_SILENTLY')) {
        echo '<ul>';
    }
    // array of restored categories - speedup ;-)
    $cached_categories = array();
    $outcomes = array();
    /// Process letters
    $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
    // respect current grade letters if defined
    if ($status and $restoreall and !record_exists('grade_letters', 'contextid', $context->id)) {
        if (!defined('RESTORE_SILENTLY')) {
            echo '<li>' . get_string('gradeletters', 'grades') . '</li>';
        }
        // Fetch recordset_size records in each iteration
        $recs = get_records_select("backup_ids", "table_name = 'grade_letters' AND backup_code = {$restore->backup_unique_code}", "", "old_id");
        if ($recs) {
            foreach ($recs as $rec) {
                // Get the full record from backup_ids
                $data = backup_getid($restore->backup_unique_code, 'grade_letters', $rec->old_id);
                if ($data) {
                    $info = $data->info;
                    $dbrec = new object();
                    $dbrec->contextid = $context->id;
                    $dbrec->lowerboundary = backup_todb($info['GRADE_LETTER']['#']['LOWERBOUNDARY']['0']['#']);
                    $dbrec->letter = backup_todb($info['GRADE_LETTER']['#']['LETTER']['0']['#']);
                    insert_record('grade_letters', $dbrec);
                }
            }
        }
    }
//.........这里部分代码省略.........
开发者ID:kai707,项目名称:ITSA-backup,代码行数:101,代码来源:restorelib.php


示例5: can_output_item

 /**
  * Determines whether the grade tree item can be displayed.
  * This is particularly targeted for grade categories that have no total (None) when rendering the grade tree.
  * It checks if the grade tree item is of type 'category', and makes sure that the category, or at least one of children,
  * can be output.
  *
  * @param array $element The grade category element.
  * @return bool True if the grade tree item can be displayed. False, otherwise.
  */
 public static function can_output_item($element)
 {
     $canoutput = true;
     if ($element['type'] === 'category') {
         $object = $element['object'];
         $category = grade_category::fetch(array('id' => $object->id));
         // Category has total, we can output this.
         if ($category->get_grade_item()->gradetype != GRADE_TYPE_NONE) {
             return true;
         }
         // Category has no total and has no children, no need to output this.
         if (empty($element['children'])) {
             return false;
         }
         $canoutput = false;
         // Loop over children and make sure at least one child can be output.
         foreach ($element['children'] as $child) {
             $canoutput = self::can_output_item($child);
             if ($canoutput) {
                 break;
             }
         }
     }
     return $canoutput;
 }
开发者ID:jeffthestampede,项目名称:excelsior,代码行数:34,代码来源:lib.php


示例6: process_grade_item

 protected function process_grade_item($data)
 {
     global $DB;
     $data = (object) $data;
     $oldid = $data->id;
     // We'll need these later
     $oldparentid = $data->categoryid;
     $courseid = $this->get_courseid();
     // make sure top course category exists, all grade items will be associated
     // to it. Later, if restoring the whole gradebook, categories will be introduced
     $coursecat = grade_category::fetch_course_category($courseid);
     $coursecatid = $coursecat->id;
     // Get the categoryid to be used
     $idnumber = null;
     if (!empty($data->idnumber)) {
         // Don't get any idnumber from course module. Keep them as they are in grade_item->idnumber
         // Reason: it's not clear what happens with outcomes->idnumber or activities with multiple items (workshop)
         // so the best is to keep the ones already in the gradebook
         // Potential problem: duplicates if same items are restored more than once. :-(
         // This needs to be fixed in some way (outcomes & activities with multiple items)
         // $data->idnumber     = get_coursemodule_from_instance($data->itemmodule, $data->iteminstance)->idnumber;
         // In any case, verify always for uniqueness
         $sql = "SELECT cm.id\n                      FROM {course_modules} cm\n                     WHERE cm.course = :courseid AND\n                           cm.idnumber = :idnumber AND\n                           cm.id <> :cmid";
         $params = array('courseid' => $courseid, 'idnumber' => $data->idnumber, 'cmid' => $this->task->get_moduleid());
         if (!$DB->record_exists_sql($sql, $params) && !$DB->record_exists('grade_items', array('courseid' => $courseid, 'idnumber' => $data->idnumber))) {
             $idnumber = $data->idnumber;
         }
     }
     unset($data->id);
     $data->categoryid = $coursecatid;
     $data->courseid = $this->get_courseid();
     $data->iteminstance = $this->task->get_activityid();
     $data->idnumber = $idnumber;
     $data->scaleid = $this->get_mappingid('scale', $data->scaleid);
     $data->outcomeid = $this->get_mappingid('outcome', $data->outcomeid);
     $data->timecreated = $this->apply_date_offset($data->timecreated);
     $data->timemodified = $this->apply_date_offset($data->timemodified);
     $gradeitem = new grade_item($data, false);
     $gradeitem->insert('restore');
     //sortorder is automatically assigned when inserting. Re-instate the previous sortorder
     $gradeitem->sortorder = $data->sortorder;
     $gradeitem->update('restore');
     // Set mapping, saving the original category id into parentitemid
     // gradebook restore (final task) will need it to reorganise items
     $this->set_mapping('grade_item', $oldid, $gradeitem->id, false, null, $oldparentid);
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:46,代码来源:restore_stepslib.php


示例7: grade_tree

 /**
  * Constructor, retrieves and stores a hierarchical array of all grade_category and grade_item
  * objects for the given courseid. Full objects are instantiated. Ordering sequence is fixed if needed.
  *
  * @param int   $courseid The Course ID
  * @param bool  $fillers include fillers and colspans, make the levels var "rectangular"
  * @param bool  $category_grade_last category grade item is the last child
  * @param array $collapsed array of collapsed categories
  * @param bool  $nooutcomes Whether or not outcomes should be included
  */
 public function grade_tree($courseid, $fillers = true, $category_grade_last = false, $collapsed = null, $nooutcomes = false)
 {
     global $USER, $CFG, $COURSE, $DB;
     $this->courseid = $courseid;
     $this->levels = array();
     $this->context = context_course::instance($courseid);
     if (!empty($COURSE->id) && $COURSE->id == $this->courseid) {
         $course = $COURSE;
     } else {
         $course = $DB->get_record('course', array('id' => $this->courseid));
     }
     $this->modinfo = get_fast_modinfo($course);
     // get course grade tree
     $this->top_element = grade_category::fetch_course_tree($courseid, true);
     // collapse the categories if requested
     if (!empty($collapsed)) {
         grade_tree::category_collapse($this->top_element, $collapsed);
     }
     // no otucomes if requested
     if (!empty($nooutcomes)) {
         grade_tree::no_outcomes($this->top_element);
     }
     // move category item to last position in category
     if ($category_grade_last) {
         grade_tree::category_grade_last($this->top_element);
     }
     if ($fillers) {
         // inject fake categories == fillers
         grade_tree::inject_fillers($this->top_element, 0);
         // add colspans to categories and fillers
         grade_tree::inject_colspans($this->top_element);
     }
     grade_tree::fill_levels($this->levels, $this->top_element, 0);
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:44,代码来源:lib.php


示例8: sub_test_grade_item_set_parent

 protected function sub_test_grade_item_set_parent()
 {
     $grade_item = new grade_item($this->grade_items[0], false);
     $this->assertTrue(method_exists($grade_item, 'set_parent'));
     $old = $grade_item->get_parent_category();
     $new = new grade_category($this->grade_categories[3], false);
     $new_item = $new->get_grade_item();
     $this->assertTrue($grade_item->set_parent($new->id));
     $new_item->update_from_db();
     $grade_item->update_from_db();
     $this->assertEquals($grade_item->categoryid, $new->id);
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:12,代码来源:grade_item_test.php


示例9: edit_module_post_actions

/**
 * Common create/update module module actions that need to be processed as soon as a module is created/updaded.
 * For example:create grade parent category, add outcomes, rebuild caches, regrade, save plagiarism settings...
 * Please note this api does not trigger events as of MOODLE 2.6. Please trigger events before calling this api.
 *
 * @param object $moduleinfo the module info
 * @param object $course the course of the module
 *
 * @return object moduleinfo update with grading management info
 */
function edit_module_post_actions($moduleinfo, $course)
{
    global $CFG;
    require_once $CFG->libdir . '/gradelib.php';
    $modcontext = context_module::instance($moduleinfo->coursemodule);
    $hasgrades = plugin_supports('mod', $moduleinfo->modulename, FEATURE_GRADE_HAS_GRADE, false);
    $hasoutcomes = plugin_supports('mod', $moduleinfo->modulename, FEATURE_GRADE_OUTCOMES, true);
    // Sync idnumber with grade_item.
    if ($hasgrades && ($grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'itemnumber' => 0, 'courseid' => $course->id)))) {
        if ($grade_item->idnumber != $moduleinfo->cmidnumber) {
            $grade_item->idnumber = $moduleinfo->cmidnumber;
            $grade_item->update();
        }
    }
    if ($hasgrades) {
        $items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'courseid' => $course->id));
    } else {
        $items = array();
    }
    // Create parent category if requested and move to correct parent category.
    if ($items and isset($moduleinfo->gradecat)) {
        if ($moduleinfo->gradecat == -1) {
            $grade_category = new grade_category();
            $grade_category->courseid = $course->id;
            $grade_category->fullname = $moduleinfo->name;
            $grade_category->insert();
            if ($grade_item) {
                $parent = $grade_item->get_parent_category();
                $grade_category->set_parent($parent->id);
            }
            $moduleinfo->gradecat = $grade_category->id;
        }
        $gradecategory = $grade_item->get_parent_category();
        foreach ($items as $itemid => $unused) {
            $items[$itemid]->set_parent($moduleinfo->gradecat);
            if ($itemid == $grade_item->id) {
                // Use updated grade_item.
                $grade_item = $items[$itemid];
            }
            if (!empty($moduleinfo->add)) {
                if (grade_category::aggregation_uses_aggregationcoef($gradecategory->aggregation)) {
                    if ($gradecategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
                        $grade_item->aggregationcoef = 1;
                    } else {
                        $grade_item->aggregationcoef = 0;
                    }
                    $grade_item->update();
                }
            }
        }
    }
    require_once $CFG->libdir . '/grade/grade_outcome.php';
    // Add outcomes if requested.
    if ($hasoutcomes && ($outcomes = grade_outcome::fetch_all_available($course->id))) {
        $grade_items = array();
        // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes.
        $max_itemnumber = 999;
        if ($items) {
            foreach ($items as $item) {
                if ($item->itemnumber > $max_itemnumber) {
                    $max_itemnumber = $item->itemnumber;
                }
            }
        }
        foreach ($outcomes as $outcome) {
            $elname = 'outcome_' . $outcome->id;
            if (property_exists($moduleinfo, $elname) and $moduleinfo->{$elname}) {
                // So we have a request for new outcome grade item?
                if ($items) {
                    $outcomeexists = false;
                    foreach ($items as $item) {
                        if ($item->outcomeid == $outcome->id) {
                            $outcomeexists = true;
                            break;
                        }
                    }
                    if ($outcomeexists) {
                        continue;
                    }
                }
                $max_itemnumber++;
                $outcome_item = new grade_item();
                $outcome_item->courseid = $course->id;
                $outcome_item->itemtype = 'mod';
                $outcome_item->itemmodule = $moduleinfo->modulename;
                $outcome_item->iteminstance = $moduleinfo->instance;
                $outcome_item->itemnumber = $max_itemnumber;
                $outcome_item->itemname = $outcome->fullname;
                $outcome_item->outcomeid = $outcome->id;
                $outcome_item->gradetype = GRADE_TYPE_SCALE;
//.........这里部分代码省略.........
开发者ID:abhilash1994,项目名称:moodle,代码行数:101,代码来源:modlib.php


示例10: set_hidden

 /**
  * Sets the grade_item's hidden variable and updates the grade_item.
  * Method named after grade_item::set_hidden().
  * @param int $hidden 0, 1 or a timestamp int(10) after which date the item will be hidden.
  * @param boolean $cascade apply to child objects too
  * @return void
  */
 function set_hidden($hidden, $cascade = false)
 {
     $this->load_grade_item();
     $this->grade_item->set_hidden($hidden);
     if ($cascade) {
         if ($children = grade_item::fetch_all(array('categoryid' => $this->id))) {
             foreach ($children as $child) {
                 $child->set_hidden($hidden, $cascade);
             }
         }
         if ($children = grade_category::fetch_all(array('parent' => $this->id))) {
             foreach ($children as $child) {
                 $child->set_hidden($hidden, $cascade);
             }
         }
     }
 }
开发者ID:r007,项目名称:PMoodle,代码行数:24,代码来源:grade_category.php


示例11: format_float

}
if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
    $item->aggregationcoef2 = format_float($item->aggregationcoef2 * 100.0);
}
$item->cancontrolvisibility = $grade_item->can_control_visibility();
$mform = new edit_item_form(null, array('current' => $item, 'gpr' => $gpr));
if ($mform->is_cancelled()) {
    redirect($returnurl);
} else {
    if ($data = $mform->get_data(false)) {
        // This is a new item, and the category chosen is different than the default category.
        if (empty($grade_item->id) && isset($data->parentcategory) && $parent_category->id != $data->parentcategory) {
            $parent_category = grade_category::fetch(array('id' => $data->parentcategory));
        }
        // If unset, give the aggregation values a default based on parent aggregation method.
        $defaults = grade_category::get_default_aggregation_coefficient_values($parent_category->aggregation);
        if (!isset($data->aggregationcoef) || $data->aggregationcoef == '') {
            $data->aggregationcoef = $defaults['aggregationcoef'];
        }
        if (!isset($data->weightoverride)) {
            $data->weightoverride = $defaults['weightoverride'];
        }
        if (!isset($data->gradepass) || $data->gradepass == '') {
            $data->gradepass = 0;
        }
        if (!isset($data->grademin) || $data->grademin == '') {
            $data->grademin = 0;
        }
        $hidden = empty($data->hidden) ? 0 : $data->hidden;
        $hiddenuntil = empty($data->hiddenuntil) ? 0 : $data->hiddenuntil;
        unset($data->hidden);
开发者ID:alanaipe2015,项目名称:moodle,代码行数:31,代码来源:item.php


示例12: workshopplus_grade_item_category_update

/**
 * Update the grade items categories if they are changed via mod_form.php
 *
 * We must do it manually here in the workshopplus module because modedit supports only
 * single grade item while we use two.
 *
 * @param stdClass $workshopplus An object from the form in mod_form.php
 */
function workshopplus_grade_item_category_update($workshopplus)
{
    $gradeitems = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => 'workshopplus', 'iteminstance' => $workshopplus->id, 'courseid' => $workshopplus->course));
    if (!empty($gradeitems)) {
        foreach ($gradeitems as $gradeitem) {
            if ($gradeitem->itemnumber == 0) {
                if ($gradeitem->categoryid != $workshopplus->gradecategory) {
                    $gradeitem->set_parent($workshopplus->gradecategory);
                }
            } else {
                if ($gradeitem->itemnumber == 1) {
                    if ($gradeitem->categoryid != $workshopplus->gradinggradecategory) {
                        $gradeitem->set_parent($workshopplus->gradinggradecategory);
                    }
                }
            }
            if (!empty($workshopplus->add)) {
                $gradecategory = $gradeitem->get_parent_category();
                if (grade_category::aggregation_uses_aggregationcoef($gradecategory->aggregation)) {
                    if ($gradecategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
                        $gradeitem->aggregationcoef = 1;
                    } else {
                        $gradeitem->aggregationcoef = 0;
                    }
                    $gradeitem->update();
                }
            }
        }
    }
}
开发者ID:mortezaaa,项目名称:moodle-activity_workshopplus,代码行数:38,代码来源:lib.php


示例13: load_grade_items

 /**
  * Load grade_item data into the database, and adds the corresponding objects to this class' variable.
  */
 function load_grade_items()
 {
     global $DB;
     $course_category = grade_category::fetch_course_category($this->courseid);
     // id = 0
     $grade_item = new stdClass();
     $grade_item->courseid = $this->courseid;
     $grade_item->categoryid = $this->grade_categories[1]->id;
     $grade_item->itemname = 'unittestgradeitem1';
     $grade_item->itemtype = 'mod';
     $grade_item->itemmodule = 'quiz';
     $grade_item->iteminstance = 1;
     $grade_item->gradetype = GRADE_TYPE_VALUE;
     $grade_item->grademin = 30;
     $grade_item->grademax = 110;
     $grade_item->itemnumber = 1;
     $grade_item->idnumber = 'item id 0';
     $grade_item->iteminfo = 'Grade item 0 used for unit testing';
     $grade_item->timecreated = mktime();
     $grade_item->timemodified = mktime();
     $grade_item->sortorder = 3;
     $grade_item->id = $DB->insert_record('grade_items', $grade_item);
     $this->grade_items[0] = $grade_item;
     // id = 1
     $grade_item = new stdClass();
     $grade_item->courseid = $this->courseid;
     $grade_item->categoryid = $this->grade_categories[1]->id;
     $grade_item->itemname = 'unittestgradeitem2';
     $grade_item->itemtype = 'import';
     $grade_item->itemmodule = 'assignment';
     $grade_item->calculation = '= ##gi' . $this->grade_items[0]->id . '## + 30 + [[item id 0]] - [[item id 0]]';
     $grade_item->gradetype = GRADE_TYPE_VALUE;
     $grade_item->iteminstance = 2;
     $grade_item->itemnumber = null;
     $grade_item->grademin = 0;
     $grade_item->grademax = 100;
     $grade_item->iteminfo = 'Grade item 1 used for unit testing';
     $grade_item->timecreated = mktime();
     $grade_item->timemodified = mktime();
     $grade_item->sortorder = 4;
     $grade_item->id = $DB->insert_record('grade_items', $grade_item);
     $this->grade_items[1] = $grade_item;
     // id = 2
     $grade_item = new stdClass();
     $grade_item->courseid = $this->courseid;
     $grade_item->categoryid = $this->grade_categories[2]->id;
     $grade_item->itemname = 'unittestgradeitem3';
     $grade_item->itemtype = 'mod';
     $grade_item->itemmodule = 'forum';
     $grade_item->iteminstance = 3;
     $grade_item->gradetype = GRADE_TYPE_SCALE;
     $grade_item->scaleid = $this->scale[0]->id;
     $grade_item->grademin = 0;
     $grade_item->grademax = $this->scalemax[0];
     $grade_item->iteminfo = 'Grade item 2 used for unit testing';
     $grade_item->timecreated = mktime();
     $grade_item->timemodified = mktime();
     $grade_item->sortorder = 6;
     $grade_item->id = $DB->insert_record('grade_items', $grade_item);
     $this->grade_items[2] = $grade_item;
     // Load grade_items associated with the 3 categories
     // id = 3
     $grade_item = new stdClass();
     $grade_item->courseid = $this->courseid;
     $grade_item->iteminstance = $this->grade_categories[0]->id;
     $grade_item->itemname = 'unittestgradeitemcategory1';
     $grade_item->needsupdate = 0;
     $grade_item->itemtype = 'category';
     $grade_item->gradetype = GRADE_TYPE_VALUE;
     $grade_item->grademin = 0;
     $grade_item->grademax = 100;
     $grade_item->iteminfo = 'Grade item 3 used for unit testing';
     $grade_item->timecreated = mktime();
     $grade_item->timemodified = mktime();
     $grade_item->sortorder = 1;
     $grade_item->id = $DB->insert_record('grade_items', $grade_item);
     $this->grade_items[3] = $grade_item;
     // id = 4
     $grade_item = new stdClass();
     $grade_item->courseid = $this->courseid;
     $grade_item->iteminstance = $this->grade_categories[1]->id;
     $grade_item->itemname = 'unittestgradeitemcategory2';
     $grade_item->itemtype = 'category';
     $grade_item->gradetype = GRADE_TYPE_VALUE;
     $grade_item->needsupdate = 0;
     $grade_item->grademin = 0;
     $grade_item->grademax = 100;
     $grade_item->iteminfo = 'Grade item 4 used for unit testing';
     $grade_item->timecreated = mktime();
     $grade_item->timemodified = mktime();
     $grade_item->sortorder = 2;
     $grade_item->id = $DB->insert_record('grade_items', $grade_item);
     $this->grade_items[4] = $grade_item;
     // id = 5
     $grade_item = new stdClass();
     $grade_item->courseid = $this->courseid;
     $grade_item->iteminstance = $this->grade_categories[2]->id;
//.........这里部分代码省略.........
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:101,代码来源:gradetest.php


示例14: test_upgrade_calculated_grade_items_regrade

 function test_upgrade_calculated_grade_items_regrade()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     // Create a user.
     $user = $this->getDataGenerator()->create_user();
     // Create a course.
     $course = $this->getDataGenerator()->create_course();
     // Enrol the user in the course.
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $maninstance1 = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $manual = enrol_get_plugin('manual');
     $manual->enrol_user($maninstance1, $user->id, $studentrole->id);
     set_config('upgrade_calculatedgradeitemsonlyregrade', 1);
     // Creating a category for a grade item.
     $gradecategory = new grade_category();
     $gradecategory->fullname = 'calculated grade category';
     $gradecategory->courseid = $course->id;
     $gradecategory->insert();
     $gradecategoryid = $gradecategory->id;
     // This is a manual grade item.
     $gradeitem = new grade_item();
     $gradeitem->itemname = 'grade item one';
     $gradeitem->itemtype = 'manual';
     $gradeitem->categoryid = $gradecategoryid;
     $gradeitem->courseid = $course->id;
     $gradeitem->idnumber = 'gi1';
     $gradeitem->insert();
     // Changing the category into a calculated grade category.
     $gradecategoryitem = grade_item::fetch(array('iteminstance' => $gradecategory->id));
     $gradecategoryitem->calculation = '=##gi' . $gradeitem->id . '##/2';
     $gradecategoryitem->grademax = 50;
     $gradecategoryitem->grademin = 15;
     $gradecategoryitem->update();
     // Setting a grade for the student.
     $grade = $gradeitem->get_grade($user->id, true);
     $grade->finalgrade = 50;
     $grade->update();
     grade_regrade_final_grades($course->id);
     $grade = grade_grade::fetch(array('itemid' => $gradecategoryitem->id, 'userid' => $user->id));
     $grade->rawgrademax = 100;
     $grade->rawgrademin = 0;
     $grade->update();
     $this->assertNotEquals($gradecategoryitem->grademax, $grade->rawgrademax);
     $this->assertNotEquals($gradecategoryitem->grademin, $grade->rawgrademin);
     // This is the function that we are testing. If we comment out this line, then the test fails because the grade items
     // are not flagged for regrading.
     upgrade_calculated_grade_items();
     grade_regrade_final_grades($course->id);
     $grade = grade_grade::fetch(array('itemid' => $gradecategoryitem->id, 'userid' => $user->id));
     $this->assertEquals($gradecategoryitem->grademax, $grade->rawgrademax);
     $this->assertEquals($gradecategoryitem->grademin, $grade->rawgrademin);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:53,代码来源:upgradelib_test.php


示例15: test_update_item_multiple_categories

 /**
  * Tests the gradebookservice update grade function for adding an item in a category,
  * where multiple categories with the same name already exist. The item should be assigned
  * to the oldest category. When moved to a category with a different name, the item should
  * be assigned to the new category. No tasks should be created and no locking should be triggered.
  *
  * @return void
  */
 public function test_update_item_multiple_categories()
 {
     global $DB, $CFG;
     $this->set_user('admin');
     // No tasks.
     $this->assertEquals(0, $DB->count_records('task_adhoc'));
     $catname = 'testcat';
     $catname1 = 'testcat1';
     $catparams = array('fullname' => $catname, 'courseid' => $this->course->id, 'hidden' => false);
     // Create category.
     $category = new \grade_category($catparams, false);
     $categoryid1 = $category->insert();
     // Create second category with the same name.
     $category = new \grade_category($catparams, false);
     $categoryid2 = $category->insert();
     // Create another category with the different name.
     $catparams['fullname'] = $catname1;
     $category = new \grade_category($catparams, false);
     $categoryid3 = $category->insert();
     // Add item 101 to $catname.
     $this->add_grade_item('101', $catname);
     // No tasks.
     $this->assertEquals(0, $DB->count_records('task_adhoc'));
     // The items should be assigned to category 1.
     $params = array('iteminstance' => '101', 'categoryid' => $categoryid1, 'courseid' => $this->course->id);
     $this->assertEquals(1, $DB->count_records('grade_items', $params));
     // Add item 102 to $catname.
     $this->add_grade_item('102', $catname);
     // No tasks.
     $this->assertEquals(0, $DB->count_records('task_adhoc'));
     // The item should be assigned to the category 1.
     $params = array('iteminstance' => '102', 'categoryid' => $categoryid1, 'courseid' => $this->course->id);
     $this->assertEquals(1, $DB->count_records('grade_items', $params));
     // Add item 103 to $catname1.
     $this->add_grade_item('103', $catname1);
     // No tasks.
     $this->assertEquals(0, $DB->count_records('task_adhoc'));
     // The item should be assigned to the category 3.
     $params = array('iteminstance' => '103', 'categoryid' => $categoryid3, 'courseid' => $this->course->id);
     $this->assertEquals(1, $DB->count_records('grade_items', $params));
     // Move item 102 to $catname1.
     $this->add_grade_item('102', $catname1);
     // No tasks.
     $this->assertEquals(0, $DB->count_records('task_adhoc'));
     // There should be two items assigned to the category 3.
     $params = array('categoryid' => $categoryid3, 'courseid' => $this->course->id);
     $this->assertEquals(2, $DB->count_records('grade_items', $params));
     // The item should be assigned to the category 3.
     $params['iteminstance'] = '102';
     $this->assertEquals(1, $DB->count_records('grade_items', $params));
 }
开发者ID:itamart,项目名称:moodle-block_mhaairs,代码行数:59,代码来源:gradebookservice_update_item_category_test.php


示例16: create_grade_category

 /**
  * Create a grade_category.
  *
  * @param array|stdClass $record
  * @return stdClass the grade category record
  */
 public function create_grade_category($record = null)
 {
     global $CFG;
     $this->gradecategorycounter++;
     $i = $this->gradecategorycounter;
     $record = (array) $record;
     if (empty($record['courseid'])) {
         throw new coding_exception('courseid must be present in testing::create_grade_category() $record');
     }
     if (!isset($record['fullname'])) {
         $record['fullname'] = 'Grade category ' . $i;
     }
     // For gradelib classes.
     require_once $CFG->libdir . '/gradelib.php';
     // Create new grading category in this course.
     $gradecategory = new grade_category(array('courseid' => $record['courseid']), false);
     $gradecategory->apply_default_settings();
     grade_category::set_properties($gradecategory, $record);
     $gradecategory->apply_forced_settings();
     $gradecategory->insert();
     // This creates a default grade item for the category
     $gradeitem = $gradecategory->load_grade_item();
     $gradecategory->update_from_db();
     return $gradecategory->get_record_data();
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:31,代码来源:data_generator.php


示例17: backup_gradebook_info

function backup_gradebook_info($bf, $preferences)
{
    global $CFG;
    require_once $CFG->libdir . '/gradelib.php';
    //first make sure items are properly sorted and everything is ok
    grade_category::fetch_course_tree($preferences->backup_course, true);
    grade_regrade_final_grades($preferences->backup_course);
    $status = true;
    // see if ALL grade items of type mod of this course are being backed up
    // if not, we do not need to backup grade category and associated grade items/grades
    $backupall = true;
    if ($grade_items = get_records_sql("SELECT *\n                                              FROM {$CFG->prefix}grade_items\n                                             WHERE courseid = {$preferences->backup_course}\n                                                   AND itemtype = 'mod'")) {
        foreach ($grade_items as $grade_item) {
            // get module information
            // if some activities not selected, we do not backup categories at all
            if (!backup_mod_selected($preferences, $grade_item->itemmodule, $grade_item->iteminstance)) {
                $backupall = false;
                break;
            }
        }
        unset($grade_items);
        //free memory
    }
    //Gradebook header
    fwrite($bf, start_tag("GRADEBOOK", 2, true));
    $status = backup_gradebook_outcomes_info($bf, $preferences);
    $status = backup_gradebook_grade_letters_info($bf, $preferences);
    // Now backup grade_item (inside grade_category)
    if ( 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP grade_grade类代码示例发布时间:2022-05-23
下一篇:
PHP gpPlugin类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap