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


PHP grade_category::fetch_all方法代码示例

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


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

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

示例2: definition

 function definition()
 {
     global $COURSE, $CFG, $DB;
     $mform =& $this->_form;
     $item = $this->_customdata['current'];
     /// visible elements
     $mform->addElement('header', 'general', get_string('gradeitem', 'grades'));
     $mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
     $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades'));
     $mform->setHelpButton('iteminfo', array('iteminfo', get_string('iteminfo', 'grades'), 'grade'), true);
     $mform->addElement('text', 'idnumber', get_string('idnumbermod'));
     $mform->setHelpButton('idnumber', array('idnumber', get_string('idnumber', 'grades'), 'grade'), true);
     $options = array(GRADE_TYPE_NONE => get_string('typenone', 'grades'), GRADE_TYPE_VALUE => get_string('typevalue', 'grades'), GRADE_TYPE_SCALE => get_string('typescale', 'grades'), GRADE_TYPE_TEXT => get_string('typetext', 'grades'));
     $mform->addElement('select', 'gradetype', get_string('gradetype', 'grades'), $options);
     $mform->setHelpButton('gradetype', array('gradetype', get_string('gradetype', 'grades'), 'grade'), true);
     $mform->setDefault('gradetype', GRADE_TYPE_VALUE);
     //$mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $options = array(0 => get_string('usenoscale', 'grades'));
     if ($scales = grade_scale::fetch_all_local($COURSE->id)) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     if ($scales = grade_scale::fetch_all_global()) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     // ugly BC hack - it was possbile to use custom scale from other courses :-(
     if (!empty($item->scaleid) and !isset($options[$item->scaleid])) {
         if ($scale = grade_scale::fetch(array('id' => $item->scaleid))) {
             $options[$scale->id] = $scale->get_name() . get_string('incorrectcustomscale', 'grades');
         }
     }
     $mform->addElement('select', 'scaleid', get_string('scale'), $options);
     $mform->setHelpButton('scaleid', array('scaleid', get_string('scaleid', 'grades'), 'grade'), true);
     $mform->disabledIf('scaleid', 'gradetype', 'noteq', GRADE_TYPE_SCALE);
     $mform->addElement('text', 'grademax', get_string('grademax', 'grades'));
     $mform->setHelpButton('grademax', array('grademax', get_string('grademax', 'grades'), 'grade'), true);
     $mform->disabledIf('grademax', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->addElement('text', 'grademin', get_string('grademin', 'grades'));
     $mform->setHelpButton('grademin', array('grademin', get_string('grademin', 'grades'), 'grade'), true);
     $mform->disabledIf('grademin', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->addElement('text', 'gradepass', get_string('gradepass', 'grades'));
     $mform->setHelpButton('gradepass', array('gradepass', get_string('gradepass', 'grades'), 'grade'), true);
     $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     $mform->addElement('text', 'multfactor', get_string('multfactor', 'grades'));
     $mform->setHelpButton('multfactor', array('multfactor', get_string('multfactor', 'grades'), 'grade'), true);
     $mform->setAdvanced('multfactor');
     $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     $mform->addElement('text', 'plusfactor', get_string('plusfactor', 'grades'));
     $mform->setHelpButton('plusfactor', array('plusfactor', get_string('plusfactor', 'grades'), 'grade'), true);
     $mform->setAdvanced('plusfactor');
     $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     /// grade display prefs
     $default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype);
     $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'), GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'), GRADE_DISPLAY_TYPE_REAL_PERCENTAGE => get_string('realpercentage', 'grades'), GRADE_DISPLAY_TYPE_REAL_LETTER => get_string('realletter', 'grades'), GRADE_DISPLAY_TYPE_LETTER_REAL => get_string('letterreal', 'grades'), GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE => get_string('letterpercentage', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER => get_string('percentageletter', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_REAL => get_string('percentagereal', 'grades'));
     asort($options);
     foreach ($options as $key => $option) {
         if ($key == $default_gradedisplaytype) {
             $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
             break;
         }
     }
     $mform->addElement('select', 'display', get_string('gradedisplaytype', 'grades'), $options);
     $mform->setHelpButton('display', array('gradedisplaytype', get_string('gradedisplaytype', 'grades'), 'grade'), true);
     $default_gradedecimals = grade_get_setting($COURSE->id, 'decimalpoints', $CFG->grade_decimalpoints);
     $options = array(-1 => get_string('defaultprev', 'grades', $default_gradedecimals), 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5);
     $mform->addElement('select', 'decimals', get_string('decimalpoints', 'grades'), $options);
     $mform->setHelpButton('decimals', array('decimalpoints', get_string('decimalpoints', 'grades'), 'grade'), true);
     $mform->setDefault('decimals', -1);
     $mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
     if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
         $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
     }
     /// hiding
     // advcheckbox is not compatible with disabledIf!
     $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
     $mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade'));
     $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true));
     $mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade'));
     $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked');
     /// locking
     $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
     $mform->setHelpButton('locked', array('locked', get_string('locked', 'grades'), 'grade'));
     $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional' => true));
     $mform->setHelpButton('locktime', array('lockedafter', get_string('locktime', 'grades'), 'grade'));
     $mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
     /// parent category related settings
     $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
     $options = array();
     $coefstring = '';
     $categories = grade_category::fetch_all(array('courseid' => $COURSE->id));
     foreach ($categories as $cat) {
         $cat->apply_forced_settings();
//.........这里部分代码省略.........
开发者ID:ajv,项目名称:Offline-Caching,代码行数:101,代码来源:item_form.php

示例3: certificate_get_grade_categories

/**
 * Fetch all grade categories from the specified course.
 *
 * @param int $courseid the course id
 * @return array
 */
function certificate_get_grade_categories($courseid)
{
    $grade_category_options = array();
    if ($grade_categories = grade_category::fetch_all(array('courseid' => $courseid))) {
        foreach ($grade_categories as $grade_category) {
            if (!$grade_category->is_course_category()) {
                $grade_category_options[-$grade_category->id] = get_string('category') . ' : ' . $grade_category->get_name();
            }
        }
    }
    return $grade_category_options;
}
开发者ID:ccle,项目名称:moodle-mod_certificate,代码行数:18,代码来源:locallib.php

示例4: sub_test_grade_category_fetch_all

 protected function sub_test_grade_category_fetch_all()
 {
     $grade_category = new grade_category();
     $this->assertTrue(method_exists($grade_category, 'fetch_all'));
     $grade_categories = grade_category::fetch_all(array('courseid' => $this->courseid));
     $this->assertEquals(count($this->grade_categories), count($grade_categories) - 1);
 }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:7,代码来源:grade_category_test.php

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

示例6: set_hidden

 /**
  * Set the hidden status of grade_item and all grades, 0 mean visible, 1 always hidden, number means date to hide until.
  * @param int $hidden new hidden status
  * @param boolean $cascade apply to child objects too
  * @return void
  */
 function set_hidden($hidden, $cascade = false)
 {
     $this->hidden = $hidden;
     $this->update();
     if ($cascade) {
         if ($grades = grade_grade::fetch_all(array('itemid' => $this->id))) {
             foreach ($grades as $grade) {
                 $grade->grade_item =& $this;
                 $grade->set_hidden($hidden, $cascade);
             }
         }
     }
     //if marking item visible make sure category is visible MDL-21367
     if (!$hidden) {
         $category_array = grade_category::fetch_all(array('id' => $this->categoryid));
         if ($category_array && array_key_exists($this->categoryid, $category_array)) {
             $category = $category_array[$this->categoryid];
             //call set_hidden on the category regardless of whether it is hidden as its parent might be hidden
             //if($category->is_hidden()) {
             $category->set_hidden($hidden, false);
             //}
         }
     }
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:30,代码来源:grade_item.php

示例7: update_grade_item_category

 /**
  * Adds the grade item to the category specified by fullname.
  * If the category does not it is first created. This may create a performance hit
  * as the service call locks the database table until it completes adding the category.
  * Adding the category is delegated to an ad-hoc task.
  * If desired the code can be adjusted to queue the task for cron instead of executing
  * it here. This can consist of a mode switch by a config setting and when in background
  * mode, calling \core\task\manager::queue_adhoc_task($addcat) to queue the task.
  *
  * @param \grade_item $gitem
  * @param string $catnam
  * @return void.
  */
 protected static function update_grade_item_category($gitem, $catname)
 {
     $courseid = $gitem->courseid;
     // Fetch the grade category item that matches the target grade category by fullname.
     // There could be more than one grade category with the same name, so fetch all and
     // sort by id so that we always use the oldest one.
     $fetchparams = array('fullname' => $catname, 'courseid' => $courseid);
     if ($categories = \grade_category::fetch_all($fetchparams)) {
         // Categories found.
         if (count($categories) > 1) {
             // Sort by key which is the category id,
             // to put the oldest first.
             ksort($categories);
         }
         // Take the first.
         $category = reset($categories);
         if ($gitem->categoryid != $category->id) {
             // Item needs update.
             $gitem->categoryid = $category->id;
             $gitem->update();
         }
     } else {
         // Category not found so we task it.
         $addcat = new \block_mhaairs\task\add_grade_category_task();
         // We don't set blocking by set_blocking(true).
         // We add custom data.
         $addcat->set_custom_data(array('catname' => $catname, 'courseid' => $courseid, 'itemid' => $gitem->id));
         // We execute the task.
         // This will throw an exception if fails to create the category.
         $addcat->execute();
     }
 }
开发者ID:itamart,项目名称:moodle-block_mhaairs,代码行数:45,代码来源:externallib.php

示例8: set_hidden

 /**
  * Sets the grade_item's hidden variable and updates the grade_item.
  *
  * Overrides grade_item::set_hidden() to add cascading of the hidden value to grade items in this grade category
  *
  * @param int $hidden 0 mean always visible, 1 means always hidden and a number > 1 is a timestamp to hide until
  * @param bool $cascade apply to child objects too
  */
 public function set_hidden($hidden, $cascade = false)
 {
     $this->load_grade_item();
     //this hides the associated grade item (the course total)
     $this->grade_item->set_hidden($hidden, $cascade);
     //this hides the category itself and everything it contains
     parent::set_hidden($hidden, $cascade);
     if ($cascade) {
         if ($children = grade_item::fetch_all(array('categoryid' => $this->id))) {
             foreach ($children as $child) {
                 if ($child->can_control_visibility()) {
                     $child->set_hidden($hidden, $cascade);
                 }
             }
         }
         if ($children = grade_category::fetch_all(array('parent' => $this->id))) {
             foreach ($children as $child) {
                 $child->set_hidden($hidden, $cascade);
             }
         }
     }
     //if marking category visible make sure parent category is visible MDL-21367
     if (!$hidden) {
         $category_array = grade_category::fetch_all(array('id' => $this->parent));
         if ($category_array && array_key_exists($this->parent, $category_array)) {
             $category = $category_array[$this->parent];
             //call set_hidden on the category regardless of whether it is hidden as its parent might be hidden
             //if($category->is_hidden()) {
             $category->set_hidden($hidden, false);
             //}
         }
     }
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:41,代码来源:grade_category.php

示例9: definition

 function definition()
 {
     global $CFG, $COURSE, $DB;
     $mform =& $this->_form;
     $category = $this->_customdata['current'];
     $this->aggregation_options = array(GRADE_AGGREGATE_MEAN => get_string('aggregatemean', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN => get_string('aggregateweightedmean', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN2 => get_string('aggregateweightedmean2', 'grades'), GRADE_AGGREGATE_EXTRACREDIT_MEAN => get_string('aggregateextracreditmean', 'grades'), GRADE_AGGREGATE_MEDIAN => get_string('aggregatemedian', 'grades'), GRADE_AGGREGATE_MIN => get_string('aggregatemin', 'grades'), GRADE_AGGREGATE_MAX => get_string('aggregatemax', 'grades'), GRADE_AGGREGATE_MODE => get_string('aggregatemode', 'grades'), GRADE_AGGREGATE_SUM => get_string('aggregatesum', 'grades'));
     // visible elements
     $mform->addElement('header', 'headercategory', get_string('gradecategory', 'grades'));
     $mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
     $mform->addRule('fullname', null, 'required', null, 'client');
     $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_options);
     $mform->addHelpButton('aggregation', 'aggregation', 'grades');
     if ((int) $CFG->grade_aggregation_flag & 2) {
         $mform->setAdvanced('aggregation');
     }
     $mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
     $mform->addHelpButton('aggregateonlygraded', 'aggregateonlygraded', 'grades');
     $mform->disabledIf('aggregateonlygraded', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     if ((int) $CFG->grade_aggregateonlygraded_flag & 2) {
         $mform->setAdvanced('aggregateonlygraded');
     }
     if (empty($CFG->enableoutcomes)) {
         $mform->addElement('hidden', 'aggregateoutcomes');
         $mform->setType('aggregateoutcomes', PARAM_INT);
     } else {
         $mform->addElement('checkbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
         $mform->addHelpButton('aggregateoutcomes', 'aggregateoutcomes', 'grades');
         if ((int) $CFG->grade_aggregateoutcomes_flag & 2) {
             $mform->setAdvanced('aggregateoutcomes');
         }
     }
     $mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades'));
     $mform->addHelpButton('aggregatesubcats', 'aggregatesubcats', 'grades');
     if ((int) $CFG->grade_aggregatesubcats_flag & 2) {
         $mform->setAdvanced('aggregatesubcats');
     }
     $options = array(0 => get_string('none'));
     for ($i = 1; $i <= 20; $i++) {
         $options[$i] = $i;
     }
     $mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $options);
     $mform->addHelpButton('keephigh', 'keephigh', 'grades');
     if ((int) $CFG->grade_keephigh_flag & 2) {
         $mform->setAdvanced('keephigh');
     }
     $mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options);
     $mform->addHelpButton('droplow', 'droplow', 'grades');
     $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
     if ((int) $CFG->grade_droplow_flag & 2) {
         $mform->setAdvanced('droplow');
     }
     $mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
     $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
     // Grade item settings
     // Displayed as Category total to avoid confusion between grade items requiring marking and category totals
     $mform->addElement('header', 'general', get_string('categorytotal', 'grades'));
     $mform->addElement('text', 'grade_item_itemname', get_string('categorytotalname', 'grades'));
     $mform->setAdvanced('grade_item_itemname');
     $mform->addElement('text', 'grade_item_iteminfo', get_string('iteminfo', 'grades'));
     $mform->addHelpButton('grade_item_iteminfo', 'iteminfo', 'grades');
     $mform->addElement('text', 'grade_item_idnumber', get_string('idnumbermod'));
     $mform->addHelpButton('grade_item_idnumber', 'idnumbermod');
     $options = array(GRADE_TYPE_NONE => get_string('typenone', 'grades'), GRADE_TYPE_VALUE => get_string('typevalue', 'grades'), GRADE_TYPE_SCALE => get_string('typescale', 'grades'), GRADE_TYPE_TEXT => get_string('typetext', 'grades'));
     $mform->addElement('select', 'grade_item_gradetype', get_string('gradetype', 'grades'), $options);
     $mform->addHelpButton('grade_item_gradetype', 'gradetype', 'grades');
     $mform->setDefault('grade_item_gradetype', GRADE_TYPE_VALUE);
     $mform->disabledIf('grade_item_gradetype', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     //$mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $options = array(0 => get_string('usenoscale', 'grades'));
     if ($scales = grade_scale::fetch_all_local($COURSE->id)) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     if ($scales = grade_scale::fetch_all_global()) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     // ugly BC hack - it was possible to use custom scale from other courses :-(
     if (!empty($category->grade_item_scaleid) and !isset($options[$category->grade_item_scaleid])) {
         if ($scale = grade_scale::fetch(array('id' => $category->grade_item_scaleid))) {
             $options[$scale->id] = $scale->get_name() . ' ' . get_string('incorrectcustomscale', 'grades');
         }
     }
     $mform->addElement('select', 'grade_item_scaleid', get_string('scale'), $options);
     $mform->addHelpButton('grade_item_scaleid', 'typescale', 'grades');
     $mform->disabledIf('grade_item_scaleid', 'grade_item_gradetype', 'noteq', GRADE_TYPE_SCALE);
     $mform->disabledIf('grade_item_scaleid', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     $mform->addElement('text', 'grade_item_grademax', get_string('grademax', 'grades'));
     $mform->addHelpButton('grade_item_grademax', 'grademax', 'grades');
     $mform->disabledIf('grade_item_grademax', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->disabledIf('grade_item_grademax', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     $mform->addElement('text', 'grade_item_grademin', get_string('grademin', 'grades'));
     $mform->addHelpButton('grade_item_grademin', 'grademin', 'grades');
     $mform->disabledIf('grade_item_grademin', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->disabledIf('grade_item_grademin', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     $mform->addElement('text', 'grade_item_gradepass', get_string('gradepass', 'grades'));
//.........这里部分代码省略.........
开发者ID:nmicha,项目名称:moodle,代码行数:101,代码来源:category_form.php

示例10: grade_regrade_final_grades

/**
 * Updates all final grades in course.
 *
 * @param int $courseid The course ID
 * @param int $userid If specified try to do a quick regrading of the grades of this user only
 * @param object $updated_item Optional grade item to be marked for regrading
 * @return bool true if ok, array of errors if problems found. Grade item id => error message
 */
function grade_regrade_final_grades($courseid, $userid = null, $updated_item = null)
{
    // This may take a very long time.
    \core_php_time_limit::raise();
    $course_item = grade_item::fetch_course_item($courseid);
    if ($userid) {
        // one raw grade updated for one user
        if (empty($updated_item)) {
            print_error("cannotbenull", 'debug', '', "updated_item");
        }
        if ($course_item->needsupdate) {
            $updated_item->force_regrading();
            return array($course_item->id => 'Can not do fast regrading after updating of raw grades');
        }
    } else {
        if (!$course_item->needsupdate) {
            // nothing to do :-)
            return true;
        }
    }
    // Categories might have to run some processing before we fetch the grade items.
    // This gives them a final opportunity to update and mark their children to be updated.
    // We need to work on the children categories up to the parent ones, so that, for instance,
    // if a category total is updated it will be reflected in the parent category.
    $cats = grade_category::fetch_all(array('courseid' => $courseid));
    $flatcattree = array();
    foreach ($cats as $cat) {
        if (!isset($flatcattree[$cat->depth])) {
            $flatcattree[$cat->depth] = array();
        }
        $flatcattree[$cat->depth][] = $cat;
    }
    krsort($flatcattree);
    foreach ($flatcattree as $depth => $cats) {
        foreach ($cats as $cat) {
            $cat->pre_regrade_final_grades();
        }
    }
    $grade_items = grade_item::fetch_all(array('courseid' => $courseid));
    $depends_on = array();
    // first mark all category and calculated items as needing regrading
    // this is slower, but 100% accurate
    foreach ($grade_items as $gid => $gitem) {
        if (!empty($updated_item) and $updated_item->id == $gid) {
            $grade_items[$gid]->needsupdate = 1;
        } else {
            if ($gitem->is_course_item() or $gitem->is_category_item() or $gitem->is_calculated()) {
                $grade_items[$gid]->needsupdate = 1;
            }
        }
        // construct depends_on lookup array
        $depends_on[$gid] = $grade_items[$gid]->depends_on();
    }
    $errors = array();
    $finalids = array();
    $gids = array_keys($grade_items);
    $failed = 0;
    while (count($finalids) < count($gids)) {
        // work until all grades are final or error found
        $count = 0;
        foreach ($gids as $gid) {
            if (in_array($gid, $finalids)) {
                continue;
                // already final
            }
            if (!$grade_items[$gid]->needsupdate) {
                $finalids[] = $gid;
                // we can make it final - does not need update
                continue;
            }
            $doupdate = true;
            foreach ($depends_on[$gid] as $did) {
                if (!in_array($did, $finalids)) {
                    $doupdate = false;
                    continue;
                    // this item depends on something that is not yet in finals array
                }
            }
            //oki - let's update, calculate or aggregate :-)
            if ($doupdate) {
                $result = $grade_items[$gid]->regrade_final_grades($userid);
                if ($result === true) {
                    $grade_items[$gid]->regrading_finished();
                    $grade_items[$gid]->check_locktime();
                    // do the locktime item locking
                    $count++;
                    $finalids[] = $gid;
                } else {
                    $grade_items[$gid]->force_regrading();
                    $errors[$gid] = $result;
                }
            }
//.........这里部分代码省略.........
开发者ID:alanaipe2015,项目名称:moodle,代码行数:101,代码来源:gradelib.php

示例11: definition

 function definition()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     $options = array(GRADE_AGGREGATE_MEAN => get_string('aggregatemean', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN => get_string('aggregateweightedmean', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN2 => get_string('aggregateweightedmean2', 'grades'), GRADE_AGGREGATE_EXTRACREDIT_MEAN => get_string('aggregateextracreditmean', 'grades'), GRADE_AGGREGATE_MEDIAN => get_string('aggregatemedian', 'grades'), GRADE_AGGREGATE_MIN => get_string('aggregatemin', 'grades'), GRADE_AGGREGATE_MAX => get_string('aggregatemax', 'grades'), GRADE_AGGREGATE_MODE => get_string('aggregatemode', 'grades'), GRADE_AGGREGATE_SUM => get_string('aggregatesum', 'grades'));
     // visible elements
     $mform->addElement('header', 'headercategory', get_string('gradecategory', 'grades'));
     $mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
     $mform->addRule('fullname', null, 'required', null, 'client');
     $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $options);
     $mform->setHelpButton('aggregation', array('aggregation', get_string('aggregation', 'grades'), 'grade'));
     if ((int) $CFG->grade_aggregation_flag & 2) {
         $mform->setAdvanced('aggregation');
     }
     $mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
     $mform->setHelpButton('aggregateonlygraded', array('aggregateonlygraded', get_string('aggregateonlygraded', 'grades'), 'grade'), true);
     $mform->disabledIf('aggregateonlygraded', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     if ((int) $CFG->grade_aggregateonlygraded_flag & 2) {
         $mform->setAdvanced('aggregateonlygraded');
     }
     if (empty($CFG->enableoutcomes)) {
         $mform->addElement('hidden', 'aggregateoutcomes');
         $mform->setType('aggregateoutcomes', PARAM_INT);
     } else {
         $mform->addElement('checkbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
         $mform->setHelpButton('aggregateoutcomes', array('aggregateoutcomes', get_string('aggregateoutcomes', 'grades'), 'grade'), true);
         if ((int) $CFG->grade_aggregateoutcomes_flag & 2) {
             $mform->setAdvanced('aggregateoutcomes');
         }
     }
     $mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades'));
     $mform->setHelpButton('aggregatesubcats', array('aggregatesubcats', get_string('aggregatesubcats', 'grades'), 'grade'), true);
     if ((int) $CFG->grade_aggregatesubcats_flag & 2) {
         $mform->setAdvanced('aggregatesubcats');
     }
     $options = array(0 => get_string('none'));
     for ($i = 1; $i <= 20; $i++) {
         $options[$i] = $i;
     }
     $mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $options);
     $mform->setHelpButton('keephigh', array('keephigh', get_string('keephigh', 'grades'), 'grade'), true);
     if ((int) $CFG->grade_keephigh_flag & 2) {
         $mform->setAdvanced('keephigh');
     }
     $mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options);
     $mform->setHelpButton('droplow', array('droplow', get_string('droplow', 'grades'), 'grade'), true);
     $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
     if ((int) $CFG->grade_droplow_flag & 2) {
         $mform->setAdvanced('droplow');
     }
     $mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
     $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
     /// parent category related settings
     $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
     $options = array();
     $default = '';
     $coefstring = '';
     $categories = grade_category::fetch_all(array('courseid' => $COURSE->id));
     foreach ($categories as $cat) {
         $cat->apply_forced_settings();
         $options[$cat->id] = $cat->get_name();
         if ($cat->is_course_category()) {
             $default = $cat->id;
         }
         if ($cat->is_aggregationcoef_used()) {
             if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
                 $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef';
             } else {
                 if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
                     $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';
                 } else {
                     $coefstring = 'aggregationcoef';
                 }
             }
         } else {
             $mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $cat->id);
         }
     }
     if (count($categories) > 1) {
         $mform->addElement('select', 'parentcategory', get_string('gradecategory', 'grades'), $options);
     }
     if ($coefstring !== '') {
         $mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
         $mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'), true);
     }
     /// user preferences
     $mform->addElement('header', 'headerpreferences', get_string('myreportpreferences', 'grades'));
     $options = array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default', 'grades'), GRADE_REPORT_AGGREGATION_VIEW_FULL => get_string('fullmode', 'grades'), GRADE_REPORT_AGGREGATION_VIEW_AGGREGATES_ONLY => get_string('aggregatesonly', 'grades'), GRADE_REPORT_AGGREGATION_VIEW_GRADES_ONLY => get_string('gradesonly', 'grades'));
     $label = get_string('aggregationview', 'grades') . ' (' . get_string('default', 'grades') . ': ' . $options[$CFG->grade_report_aggregationview] . ')';
     $mform->addElement('select', 'pref_aggregationview', $label, $options);
     $mform->setHelpButton('pref_aggregationview', array('aggregationview', get_string('aggregationview', 'grades'), 'grade'), true);
     $mform->setDefault('pref_aggregationview', GRADE_REPORT_PREFERENCE_DEFAULT);
     $mform->setAdvanced('pref_aggregationview');
     // hidden params
     $mform->addElement('hidden', 'id', 0);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'courseid', 0);
     $mform->setType('courseid', PARAM_INT);
     /// add return tracking info
     $gpr = $this->_customdata['gpr'];
//.........这里部分代码省略.........
开发者ID:r007,项目名称:PMoodle,代码行数:101,代码来源:category_form.php

示例12: 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);
             }
         }
     }
     //if marking category visible make sure parent category is visible MDL-21367
     if (!$hidden) {
         $category_array = grade_category::fetch_all(array('id' => $this->parent));
         if ($category_array && array_key_exists($this->parent, $category_array)) {
             $category = $category_array[$this->parent];
             //call set_hidden on the category regardless of whether it is hidden as its parent might be hidden
             //if($category->is_hidden()) {
             $category->set_hidden($hidden, false);
             //}
         }
     }
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:35,代码来源:grade_category.php

示例13: definition

 function definition()
 {
     global $COURSE, $CFG, $DB;
     $mform =& $this->_form;
     $item = $this->_customdata['current'];
     /// visible elements
     $mform->addElement('header', 'general', get_string('gradeitem', 'grades'));
     $mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
     $mform->setType('itemname', PARAM_TEXT);
     $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades'));
     $mform->addHelpButton('iteminfo', 'iteminfo', 'grades');
     $mform->setType('iteminfo', PARAM_TEXT);
     $mform->addElement('text', 'idnumber', get_string('idnumbermod'));
     $mform->addHelpButton('idnumber', 'idnumbermod');
     $mform->setType('idnumber', PARAM_RAW);
     if (!empty($item->id)) {
         $gradeitem = new grade_item(array('id' => $item->id, 'courseid' => $item->courseid));
         // If grades exist set a message so the user knows why they can not alter the grade type or scale.
         // We could never change the grade type for external items, so only need to show this for manual grade items.
         if ($gradeitem->has_grades() && !$gradeitem->is_external_item()) {
             // Set a message so the user knows why they can not alter the grade type or scale.
             if ($gradeitem->gradetype == GRADE_TYPE_SCALE) {
                 $gradesexistmsg = get_string('modgradecantchangegradetyporscalemsg', 'grades');
             } else {
                 $gradesexistmsg = get_string('modgradecantchangegradetypemsg', 'grades');
             }
             $gradesexisthtml = '<div class=\'alert\'>' . $gradesexistmsg . '</div>';
             $mform->addElement('static', 'gradesexistmsg', '', $gradesexisthtml);
         }
     }
     // Manual grade items cannot have grade type GRADE_TYPE_NONE.
     $options = array(GRADE_TYPE_VALUE => get_string('typevalue', 'grades'), GRADE_TYPE_SCALE => get_string('typescale', 'grades'), GRADE_TYPE_TEXT => get_string('typetext', 'grades'));
     $mform->addElement('select', 'gradetype', get_string('gradetype', 'grades'), $options);
     $mform->addHelpButton('gradetype', 'gradetype', 'grades');
     $mform->setDefault('gradetype', GRADE_TYPE_VALUE);
     //$mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $options = array(0 => get_string('usenoscale', 'grades'));
     if ($scales = grade_scale::fetch_all_local($COURSE->id)) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     if ($scales = grade_scale::fetch_all_global()) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     // ugly BC hack - it was possible to use custom scale from other courses :-(
     if (!empty($item->scaleid) and !isset($options[$item->scaleid])) {
         if ($scale = grade_scale::fetch(array('id' => $item->scaleid))) {
             $options[$scale->id] = $scale->get_name() . get_string('incorrectcustomscale', 'grades');
         }
     }
     $mform->addElement('select', 'scaleid', get_string('scale'), $options);
     $mform->addHelpButton('scaleid', 'typescale', 'grades');
     $mform->disabledIf('scaleid', 'gradetype', 'noteq', GRADE_TYPE_SCALE);
     $choices = array();
     $choices[''] = get_string('choose');
     $choices['no'] = get_string('no');
     $choices['yes'] = get_string('yes');
     $mform->addElement('select', 'rescalegrades', get_string('modgraderescalegrades', 'grades'), $choices);
     $mform->addHelpButton('rescalegrades', 'modgraderescalegrades', 'grades');
     $mform->disabledIf('rescalegrades', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->addElement('text', 'grademax', get_string('grademax', 'grades'));
     $mform->addHelpButton('grademax', 'grademax', 'grades');
     $mform->disabledIf('grademax', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->setType('grademax', PARAM_RAW);
     if ((bool) get_config('moodle', 'grade_report_showmin')) {
         $mform->addElement('text', 'grademin', get_string('grademin', 'grades'));
         $mform->addHelpButton('grademin', 'grademin', 'grades');
         $mform->disabledIf('grademin', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
         $mform->setType('grademin', PARAM_RAW);
     }
     $mform->addElement('text', 'gradepass', get_string('gradepass', 'grades'));
     $mform->addHelpButton('gradepass', 'gradepass', 'grades');
     $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     $mform->setType('gradepass', PARAM_RAW);
     $mform->addElement('text', 'multfactor', get_string('multfactor', 'grades'));
     $mform->addHelpButton('multfactor', 'multfactor', 'grades');
     $mform->setAdvanced('multfactor');
     $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     $mform->setType('multfactor', PARAM_RAW);
     $mform->addElement('text', 'plusfactor', get_string('plusfactor', 'grades'));
     $mform->addHelpButton('plusfactor', 'plusfactor', 'grades');
     $mform->setAdvanced('plusfactor');
     $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     $mform->setType('plusfactor', PARAM_RAW);
     /// grade display prefs
     $default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype);
     $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'), GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'), GRADE_DISPLAY_TYPE_REAL_PERCENTAGE => get_string('realpercentage', 'grades'), GRADE_DISPLAY_TYPE_REAL_LETTER => get_string('realletter', 'grades'), GRADE_DISPLAY_TYPE_LETTER_REAL => get_string('letterreal', 'grades'), GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE => get_string('letterpercentage', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER => get_string('percentageletter', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_REAL => get_string('percentagereal', 'grades'));
     asort($options);
     foreach ($options as $key => $option) {
         if ($key == $default_gradedisplaytype) {
             $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
             break;
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:item_form.php

示例14: definition

 function definition()
 {
     global $COURSE, $CFG;
     $mform =& $this->_form;
     /// visible elements
     $mform->addElement('header', 'general', get_string('gradeitem', 'grades'));
     $mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
     $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades'));
     $mform->setHelpButton('iteminfo', array('iteminfo', get_string('iteminfo', 'grades'), 'grade'), true);
     $mform->addElement('text', 'idnumber', get_string('idnumbermod'));
     $mform->setHelpButton('idnumber', array('idnumber', get_string('idnumber', 'grades'), 'grade'), true);
     $options = array(GRADE_TYPE_NONE => get_string('typenone', 'grades'), GRADE_TYPE_VALUE => get_string('typevalue', 'grades'), GRADE_TYPE_SCALE => get_string('typescale', 'grades'), GRADE_TYPE_TEXT => get_string('typetext', 'grades'));
     $mform->addElement('select', 'gradetype', get_string('gradetype', 'grades'), $options);
     $mform->setHelpButton('gradetype', array('gradetype', get_string('gradetype', 'grades'), 'grade'), true);
     $mform->setDefault('gradetype', GRADE_TYPE_VALUE);
     //$mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $options = array(0 => get_string('usenoscale', 'grades'));
     if ($scales = get_records('scale')) {
         foreach ($scales as $scale) {
             $options[$scale->id] = format_string($scale->name);
         }
     }
     $mform->addElement('select', 'scaleid', get_string('scale'), $options);
     $mform->setHelpButton('scaleid', array('scaleid', get_string('scaleid', 'grades'), 'grade'), true);
     $mform->disabledIf('scaleid', 'gradetype', 'noteq', GRADE_TYPE_SCALE);
     $mform->addElement('text', 'grademax', get_string('grademax', 'grades'));
     $mform->setHelpButton('grademax', array('grademax', get_string('grademax', 'grades'), 'grade'), true);
     $mform->disabledIf('grademax', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->addElement('text', 'grademin', get_string('grademin', 'grades'));
     $mform->setHelpButton('grademin', array('grademin', get_string('grademin', 'grades'), 'grade'), true);
     $mform->disabledIf('grademin', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->addElement('text', 'gradepass', get_string('gradepass', 'grades'));
     $mform->setHelpButton('gradepass', array('gradepass', get_string('gradepass', 'grades'), 'grade'), true);
     $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     $mform->addElement('text', 'multfactor', get_string('multfactor', 'grades'));
     $mform->setHelpButton('multfactor', array('multfactor', get_string('multfactor', 'grades'), 'grade'), true);
     $mform->setAdvanced('multfactor');
     $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     $mform->addElement('text', 'plusfactor', get_string('plusfactor', 'grades'));
     $mform->setHelpButton('plusfactor', array('plusfactor', get_string('plusfactor', 'grades'), 'grade'), true);
     $mform->setAdvanced('plusfactor');
     $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     /// grade display prefs
     $default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype);
     $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'), GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
     foreach ($options as $key => $option) {
         if ($key == $default_gradedisplaytype) {
             $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
             break;
         }
     }
     $mform->addElement('select', 'display', get_string('gradedisplaytype', 'grades'), $options);
     $mform->setHelpButton('display', array('gradedisplaytype', get_string('gradedisplaytype', 'grades'), 'grade'), true);
     $default_gradedecimals = grade_get_setting($COURSE->id, 'decimalpoints', $CFG->grade_decimalpoints);
     $options = array(-1 => get_string('defaultprev', 'grades', $default_gradedecimals), 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5);
     $mform->addElement('select', 'decimals', get_string('decimalpoints', 'grades'), $options);
     $mform->setHelpButton('decimals', array('decimalpoints', get_string('decimalpoints', 'grades'), 'grade'), true);
     $mform->setDefault('decimals', -1);
     $mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
     if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
         $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
     }
     /// hiding
     // advcheckbox is not compatible with disabledIf!
     $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
     $mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade'));
     $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true));
     $mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade'));
     $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked');
     /// locking
     $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
     $mform->setHelpButton('locked', array('locked', get_string('locked', 'grades'), 'grade'));
     $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional' => true));
     $mform->setHelpButton('locktime', array('lockedafter', get_string('locktime', 'grades'), 'grade'));
     $mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
     /// parent category related settings
     $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
     $options = array();
     $default = '';
     $coefstring = '';
     $categories = grade_category::fetch_all(array('courseid' => $COURSE->id));
     foreach ($categories as $cat) {
         $cat->apply_forced_settings();
         $options[$cat->id] = $cat->get_name();
         if ($cat->is_course_category()) {
             $default = $cat->id;
         }
         if ($cat->is_aggregationcoef_used()) {
             if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
                 $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef';
             } else {
                 if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
                     $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';
                 } else {
                     if ($cat->aggregation == GRADE_AGGREGATE_SUM) {
//.........这里部分代码省略.........
开发者ID:r007,项目名称:PMoodle,代码行数:101,代码来源:item_form.php

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


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