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


PHP grade_category::fetch方法代码示例

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


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

示例1: test_grade_category_fetch

 function test_grade_category_fetch()
 {
     $grade_category = new grade_category();
     $this->assertTrue(method_exists($grade_category, 'fetch'));
     $grade_category = grade_category::fetch(array('id' => $this->grade_categories[0]->id));
     $this->assertEqual($this->grade_categories[0]->id, $grade_category->id);
     $this->assertEqual($this->grade_categories[0]->fullname, $grade_category->fullname);
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:8,代码来源:testgradecategory.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: build_html_tree

 /**
  * Recursive function for building the table holding the grade categories and items,
  * with CSS indentation and styles.
  *
  * @param array   $element The current tree element being rendered
  * @param boolean $totals Whether or not to print category grade items (category totals)
  * @param array   $parents An array of parent categories for the current element (used for indentation and row classes)
  *
  * @return string HTML
  */
 public function build_html_tree($element, $totals, $parents, $level, &$row_count)
 {
     global $CFG, $COURSE, $PAGE, $OUTPUT;
     $object = $element['object'];
     $eid = $element['eid'];
     $object->name = $this->gtree->get_element_header($element, true, true, true, true);
     $object->stripped_name = $this->gtree->get_element_header($element, false, false, false);
     $is_category_item = false;
     if ($element['type'] == 'categoryitem' || $element['type'] == 'courseitem') {
         $is_category_item = true;
     }
     $rowclasses = array();
     foreach ($parents as $parent_eid) {
         $rowclasses[] = $parent_eid;
     }
     $moveaction = '';
     $actionsmenu = new action_menu();
     $actionsmenu->initialise_js($PAGE);
     $actionsmenu->set_menu_trigger(get_string('edit'));
     $actionsmenu->set_owner_selector('grade-item-' . $eid);
     $actionsmenu->set_alignment(action_menu::TL, action_menu::BL);
     if (!$is_category_item && ($icon = $this->gtree->get_edit_icon($element, $this->gpr, true))) {
         $actionsmenu->add($icon);
     }
     if ($this->show_calculations && ($icon = $this->gtree->get_calculation_icon($element, $this->gpr, true))) {
         $actionsmenu->add($icon);
     }
     if ($element['type'] == 'item' or $element['type'] == 'category' and $element['depth'] > 1) {
         if ($this->element_deletable($element)) {
             $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'delete', 'eid' => $eid, 'sesskey' => sesskey()));
             $icon = new action_menu_link_secondary($aurl, new pix_icon('t/delete', get_string('delete')), get_string('delete'));
             $actionsmenu->add($icon);
         }
         $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'moveselect', 'eid' => $eid, 'sesskey' => sesskey()));
         $moveaction .= $OUTPUT->action_icon($aurl, new pix_icon('t/move', get_string('move')));
     }
     if ($icon = $this->gtree->get_hiding_icon($element, $this->gpr, true)) {
         $actionsmenu->add($icon);
     }
     if ($icon = $this->gtree->get_reset_icon($element, $this->gpr, true)) {
         $actionsmenu->add($icon);
     }
     $actions = $OUTPUT->render($actionsmenu);
     $returnrows = array();
     $root = false;
     $id = required_param('id', PARAM_INT);
     /// prepare move target if needed
     $last = '';
     /// print the list items now
     if ($this->moving == $eid) {
         // do not diplay children
         $cell = new html_table_cell();
         $cell->colspan = 12;
         $cell->attributes['class'] = $element['type'] . ' moving column-name level' . ($level + 1) . ' level' . ($level % 2 ? 'even' : 'odd');
         $cell->text = $object->name . ' (' . get_string('move') . ')';
         return array(new html_table_row(array($cell)));
     }
     if ($element['type'] == 'category') {
         $level++;
         $this->categories[$object->id] = $object->stripped_name;
         $category = grade_category::fetch(array('id' => $object->id));
         $item = $category->get_grade_item();
         // Add aggregation coef input if not a course item and if parent category has correct aggregation type
         $dimmed = $item->is_hidden() ? 'dimmed_text' : '';
         // Before we print the category's row, we must find out how many rows will appear below it (for the filler cell's rowspan)
         $aggregation_position = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
         $category_total_data = null;
         // Used if aggregationposition is set to "last", so we can print it last
         $html_children = array();
         $row_count = 0;
         foreach ($element['children'] as $child_el) {
             $moveto = null;
             if (empty($child_el['object']->itemtype)) {
                 $child_el['object']->itemtype = false;
             }
             if (($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') && !$totals) {
                 continue;
             }
             $child_eid = $child_el['eid'];
             $first = '';
             if ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
                 $first = array('first' => 1);
                 $child_eid = $eid;
             }
             if ($this->moving && $this->moving != $child_eid) {
                 $strmove = get_string('move');
                 $strmovehere = get_string('movehere');
                 $actions = $moveaction = '';
                 // no action icons when moving
                 $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'move', 'eid' => $this->moving, 'moveafter' => $child_eid, 'sesskey' => sesskey()));
//.........这里部分代码省略.........
开发者ID:HuiChangZhai,项目名称:moodle,代码行数:101,代码来源:lib.php

示例4: validation

 function validation($data, $files)
 {
     global $COURSE;
     $gradeitem = false;
     if ($data['id']) {
         $gradecategory = grade_category::fetch(array('id' => $data['id']));
         $gradeitem = $gradecategory->load_grade_item();
     }
     $errors = parent::validation($data, $files);
     if (array_key_exists('grade_item_gradetype', $data) and $data['grade_item_gradetype'] == GRADE_TYPE_SCALE) {
         if (empty($data['grade_item_scaleid'])) {
             $errors['grade_item_scaleid'] = get_string('missingscale', 'grades');
         }
     }
     if (array_key_exists('grade_item_grademin', $data) and array_key_exists('grade_item_grademax', $data)) {
         if (($data['grade_item_grademax'] != 0 or $data['grade_item_grademin'] != 0) and ($data['grade_item_grademax'] == $data['grade_item_grademin'] or $data['grade_item_grademax'] < $data['grade_item_grademin'])) {
             $errors['grade_item_grademin'] = get_string('incorrectminmax', 'grades');
             $errors['grade_item_grademax'] = get_string('incorrectminmax', 'grades');
         }
     }
     if ($data['id'] && $gradeitem->has_overridden_grades()) {
         if ($gradeitem->gradetype == GRADE_TYPE_VALUE) {
             if (grade_floats_different($data['grade_item_grademin'], $gradeitem->grademin) || grade_floats_different($data['grade_item_grademax'], $gradeitem->grademax)) {
                 if (empty($data['grade_item_rescalegrades'])) {
                     $errors['grade_item_rescalegrades'] = get_string('mustchooserescaleyesorno', 'grades');
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:category_form.php

示例5: save_gradebook

 /**
  * Saves a gradebook (a set of grade items and scores related to a course),
  * also creates the categories based on the item type
  *
  * @param object $gradebook an object with at least course_id and items set
  * items should contain grade_items (courseid. categoryid, name, scores)
  * scores should contain grade_grade (user_id, score)
  * @return stdClass the saved gradebook with all items and scores in the same structure,
  * errors are recorded as grade_item->errors and score->error
  * @throws InvalidArgumentException
  */
 public static function save_gradebook($gradebook)
 {
     global $CFG;
     if (!$gradebook) {
         throw new InvalidArgumentException("gradebook must be set");
     }
     if (!isset($gradebook->course_id)) {
         throw new InvalidArgumentException("gradebook->course_id must be set");
     }
     if (!isset($gradebook->items) || empty($gradebook->items)) {
         throw new InvalidArgumentException("gradebook->items must be set and include items");
     }
     $gb_saved = new stdClass();
     $gb_saved->items = array();
     $gb_saved->course_id = $gradebook->course_id;
     $course = self::get_course($gradebook->course_id);
     if (!$course) {
         throw new InvalidArgumentException("No course found with course_id ({$gradebook->course_id})");
     }
     $gb_saved->course = $course;
     // extra permissions check on gradebook manage/update
     $user_id = self::require_user();
     if (class_exists('context_course')) {
         // for Moodle 2.2+
         $context = context_course::instance($course->id);
     } else {
         /** @noinspection PhpDeprecationInspection */
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
         // deprecated
     }
     if (!$context || !has_capability('moodle/grade:manage', $context, $user_id)) {
         throw new InvalidArgumentException("User ({$user_id}) cannot manage the gradebook in course id={$course->id} (" . var_export($course, true) . "), context: " . var_export($context, true));
     }
     // attempt to get the default iclicker category first
     $default_iclicker_category = grade_category::fetch(array('courseid' => $gradebook->course_id, 'fullname' => self::GRADE_CATEGORY_NAME));
     $default_iclicker_category_id = $default_iclicker_category ? $default_iclicker_category->id : null;
     //echo "\n\nGRADEBOOK: ".var_export($gradebook);
     // iterate through and save grade items by calling other method
     if (!empty($gradebook->items)) {
         $saved_items = array();
         $number = 0;
         foreach ($gradebook->items as $grade_item) {
             // check for this category
             $item_category_name = self::GRADE_CATEGORY_NAME;
             if (!empty($grade_item->type) && self::GRADE_CATEGORY_NAME != $grade_item->type) {
                 $item_category_name = $grade_item->type;
                 $item_category = grade_category::fetch(array('courseid' => $gradebook->course_id, 'fullname' => $item_category_name));
                 if (!$item_category) {
                     // create the category
                     $params = array('courseid' => $gradebook->course_id, 'fullname' => $item_category_name);
                     $grade_category = new grade_category($params, false);
                     // Use default aggregation type.
                     $grade_category->aggregation = $CFG->grade_aggregation;
                     $grade_category->insert(self::GRADE_LOCATION_STR);
                     $item_category_id = $grade_category->id;
                 } else {
                     $item_category_id = $item_category->id;
                 }
             } else {
                 // use default
                 if (!$default_iclicker_category_id) {
                     // create the category
                     $params = array('courseid' => $gradebook->course_id, 'fullname' => self::GRADE_CATEGORY_NAME);
                     $grade_category = new grade_category($params, false);
                     // Use default aggregation type.
                     $grade_category->aggregation = $CFG->grade_aggregation;
                     $grade_category->insert(self::GRADE_LOCATION_STR);
                     $default_iclicker_category_id = $grade_category->id;
                 }
                 $item_category_id = $default_iclicker_category_id;
             }
             $grade_item->categoryid = $item_category_id;
             $grade_item->typename = $item_category_name;
             $grade_item->courseid = $gradebook->course_id;
             $grade_item->item_number = $number;
             $saved_grade_item = self::save_grade_item($grade_item);
             $saved_items[] = $saved_grade_item;
             $number++;
         }
         $gb_saved->items = $saved_items;
     }
     $gb_saved->default_category_id = $default_iclicker_category_id;
     //echo "\n\nRESULT: ".var_export($gb_saved);
     return $gb_saved;
 }
开发者ID:dirkcgrunwald,项目名称:iclicker-moodle2-integrate,代码行数:96,代码来源:iclicker_service.php

示例6: fetch_course_category

 /**
  * Return the course level grade_category object
  *
  * @param int $courseid The Course ID
  * @return grade_category Returns the course level grade_category instance
  */
 public static function fetch_course_category($courseid)
 {
     if (empty($courseid)) {
         debugging('Missing course id!');
         return false;
     }
     // course category has no parent
     if ($course_category = grade_category::fetch(array('courseid' => $courseid, 'parent' => null))) {
         return $course_category;
     }
     // create a new one
     $course_category = new grade_category();
     $course_category->insert_course_category($courseid);
     return $course_category;
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:21,代码来源:grade_category.php

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

示例8: grade_regrade_final_grades

            $grade_item->update();
            grade_regrade_final_grades($courseid);
            // Grade category checkbox inputs
        } elseif (preg_match('/aggregate(onlygraded|subcats|outcomes)_original_([0-9]*)/', $key, $matches) && confirm_sesskey()) {
            $setting = optional_param('aggregate' . $matches[1] . '_' . $matches[2], null, PARAM_BOOL);
            $original_value = required_param($matches[0], PARAM_BOOL);
            $a->id = $matches[2];
            $newvalue = null;
            if ($original_value == 1 && is_null($setting)) {
                $newvalue = 0;
            } elseif ($original_value == 0 && $setting == 1) {
                $newvalue = 1;
            } else {
                continue;
            }
            $grade_category = grade_category::fetch(array('id' => $a->id, 'courseid' => $courseid));
            $grade_category->{'aggregate' . $matches[1]} = $newvalue;
            $grade_category->update();
            grade_regrade_final_grades($courseid);
        }
    }
}
// Print Table of categories and items
print_box_start('gradetreebox generalbox');
echo '<form id="gradetreeform" method="post" action="' . $returnurl . '">';
echo '<div>';
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
// Build up an array of categories for move drop-down (by reference)
$categories = array();
$level = 0;
$row_count = 0;
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:31,代码来源:index.php

示例9: test_update_grade_update_item

 /**
  * Tests the gradebookservice update grade with cases that should
  * result in success.
  *
  * @return void
  */
 public function test_update_grade_update_item()
 {
     global $DB;
     $callback = 'block_mhaairs_gradebookservice_external::update_grade';
     $this->set_user('admin');
     // CREATE/UPDATE.
     $cases = $this->get_cases('tc_update_grade');
     foreach ($cases as $case) {
         if (!empty($case->hidden)) {
             continue;
         }
         try {
             $result = call_user_func_array($callback, $case->servicedata);
             $this->assertEquals($case->result, $result);
         } catch (Exception $e) {
             $result = get_class($e);
             $this->assertEquals($case->result, $result);
             continue;
         }
         // Fetch the item.
         $giparams = array('itemtype' => 'manual', 'itemmodule' => 'mhaairs', 'iteminstance' => $case->iteminstance, 'courseid' => $this->course->id, 'itemnumber' => $case->itemnumber);
         $gitem = grade_item::fetch($giparams);
         if (is_numeric($case->result) and (int) $case->result === 0) {
             // Verify successful update.
             $this->assertInstanceOf('grade_item', $gitem);
             $maxgrade = !empty($case->item_grademax) ? (int) $case->item_grademax : 100;
             $this->assertEquals($maxgrade, $gitem->grademax);
             if (!empty($case->item_categoryid)) {
                 // Fetch the category.
                 $fetchparams = array('fullname' => $case->item_categoryid, 'courseid' => $this->course->id);
                 $category = grade_category::fetch($fetchparams);
                 $categoryid = $category->id;
                 $this->assertEquals($gitem->categoryid, $categoryid);
             }
         } else {
             // Verify failed update.
             $this->assertEquals(false, $gitem);
         }
     }
 }
开发者ID:itamart,项目名称:moodle-block_mhaairs,代码行数:46,代码来源:gradebookservice_update_item_test.php

示例10: definition_after_data

 function definition_after_data()
 {
     global $CFG;
     $mform =& $this->_form;
     $checkbox_values = array(get_string('no'), get_string('yes'));
     if ($CFG->grade_aggregation != -1) {
         $agg_el =& $mform->getElement('aggregation');
         $agg_el->setValue($this->aggregation_types[$CFG->grade_aggregation]);
     }
     if ($CFG->grade_aggregateonlygraded != -1) {
         $agg_el =& $mform->getElement('aggregateonlygraded');
         $agg_el->setValue($checkbox_values[$CFG->grade_aggregateonlygraded]);
     }
     if ($CFG->grade_aggregateoutcomes != -1) {
         $agg_el =& $mform->getElement('aggregateoutcomes');
         $agg_el->setValue($checkbox_values[$CFG->grade_aggregateoutcomes]);
     }
     if ($CFG->grade_aggregatesubcats != -1) {
         $agg_el =& $mform->getElement('aggregatesubcats');
         $agg_el->setValue($checkbox_values[$CFG->grade_aggregatesubcats]);
     }
     if ($CFG->grade_keephigh != -1) {
         $agg_el =& $mform->getElement('keephigh');
         $agg_el->setValue($this->keepdrop_options[$CFG->grade_keephigh]);
     }
     if ($CFG->grade_droplow != -1) {
         $agg_el =& $mform->getElement('droplow');
         $agg_el->setValue($this->keepdrop_options[$CFG->grade_droplow]);
     }
     if ($id = $mform->getElementValue('id')) {
         $grade_category = grade_category::fetch(array('id' => $id));
         $grade_item = $grade_category->load_grade_item();
         if ($grade_item->is_calculated()) {
             // following elements are ignored when calculation formula used
             if ($mform->elementExists('aggregation')) {
                 $mform->removeElement('aggregation');
             }
             if ($mform->elementExists('keephigh')) {
                 $mform->removeElement('keephigh');
             }
             if ($mform->elementExists('droplow')) {
                 $mform->removeElement('droplow');
             }
             if ($mform->elementExists('aggregateonlygraded')) {
                 $mform->removeElement('aggregateonlygraded');
             }
             if ($mform->elementExists('aggregateoutcomes')) {
                 $mform->removeElement('aggregateoutcomes');
             }
             if ($mform->elementExists('aggregatesubcats')) {
                 $mform->removeElement('aggregatesubcats');
             }
         }
     }
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:55,代码来源:category_form.php

示例11: get_category_start_date

 public function get_category_start_date($course, $user, $category)
 {
     $itemtype = 'mod';
     $itemmodule = '';
     $iteminstance = '';
     $courseid = $course->id;
     $iteminstance = $category->iteminstance;
     $category_start_date = NULL;
     $course_category = grade_category::fetch(array('courseid' => $courseid, 'id' => $iteminstance));
     $grade_items = $course_category->get_children();
     foreach ($grade_items as $grade => $grade_value) {
         $grade_item = $grade_value["object"];
         $start_date = $this->get_activity_start_date($course, $user, $grade_item);
         if ($category_start_date > $start_date && $start_date != NULL || $category_start_date == NULL) {
             $category_start_date = $start_date;
         }
     }
     // echo $category_start_date ? $category_start_date->format('d-m-Y') : "-";
     return $category_start_date;
 }
开发者ID:abhiahirwar,项目名称:moodle_csv_report,代码行数:20,代码来源:grade_export_csv.php

示例12: array

             $grade_item->set_parent($item->categoryid);
             $grade_item->move_after_sortorder($item->sortorder);
         }
         $grade_items[] = $grade_item;
     }
 }
 // Create a grade_category to represent this module, if outcomes have been attached
 if (!empty($grade_items)) {
     // Add the module's normal grade_item as a child of this category
     $item_params = array('itemtype' => 'mod', 'itemmodule' => $fromform->modulename, 'iteminstance' => $fromform->instance, 'itemnumber' => 0, 'courseid' => $COURSE->id);
     $item = grade_item::fetch($item_params);
     // Only create the category if it will contain at least 2 items
     if ($item or count($grade_items) > 1) {
         // If we are here it means there is at least 1 outcome
         $cat_params = array('courseid' => $COURSE->id, 'fullname' => $fromform->name);
         $grade_category = grade_category::fetch($cat_params);
         if (!$grade_category) {
             $grade_category = new grade_category($cat_params);
             $grade_category->courseid = $COURSE->id;
             $grade_category->fullname = $fromform->name;
             $grade_category->insert();
         }
         $sortorder = $grade_category->sortorder;
         if ($item) {
             $item->set_parent($grade_category->id);
             $sortorder = $item->sortorder;
         }
         // Add the outcomes as children of this category
         foreach ($grade_items as $gi) {
             $gi->set_parent($grade_category->id);
             $gi->move_after_sortorder($sortorder);
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:31,代码来源:modedit.php

示例13: build_html_tree

 /**
  * Recursive function for building the table holding the grade categories and items,
  * with CSS indentation and styles.
  *
  * @param array               $element The current tree element being rendered
  * @param boolean             $totals Whether or not to print category grade items (category totals)
  * @param array               $parents An array of parent categories for the current element (used for indentation and row classes)
  *
  * @return string HTML
  */
 function build_html_tree($element, $totals, $parents, &$categories, $level, &$row_count)
 {
     global $CFG, $COURSE, $USER;
     $object = $element['object'];
     $eid = $element['eid'];
     $object->name = $this->gtree->get_element_header($element, true, true, false);
     $object->stripped_name = $this->gtree->get_element_header($element, false, false, false);
     $is_category_item = false;
     if ($element['type'] == 'categoryitem' || $element['type'] == 'courseitem') {
         $is_category_item = true;
     }
     $rowclasses = '';
     foreach ($parents as $parent_eid) {
         $rowclasses .= " {$parent_eid} ";
     }
     $actions = '';
     if (!$is_category_item) {
         $actions .= $this->gtree->get_edit_icon($element, $this->gpr);
     }
     $actions .= $this->gtree->get_calculation_icon($element, $this->gpr);
     if ($element['type'] == 'item' or $element['type'] == 'category' and $element['depth'] > 1) {
         if ($this->element_deletable($element)) {
             $actions .= '<a href="index.php?id=' . $COURSE->id . '&amp;action=delete&amp;eid=' . $eid . '&amp;sesskey=' . sesskey() . '"><img src="' . $CFG->pixpath . '/t/delete.gif" class="iconsmall" alt="' . get_string('delete') . '" title="' . get_string('delete') . '"/></a>';
         }
         $actions .= '<a href="index.php?id=' . $COURSE->id . '&amp;action=moveselect&amp;eid=' . $eid . '&amp;sesskey=' . sesskey() . '"><img src="' . $CFG->pixpath . '/t/move.gif" class="iconsmall" alt="' . get_string('move') . '" title="' . get_string('move') . '"/></a>';
     }
     $actions .= $this->gtree->get_hiding_icon($element, $this->gpr);
     $actions .= $this->gtree->get_locking_icon($element, $this->gpr);
     $mode = $USER->gradeediting[$COURSE->id] ? 'advanced' : 'simple';
     $html = '';
     $root = false;
     $id = required_param('id', PARAM_INT);
     /// prepare move target if needed
     $last = '';
     /// print the list items now
     if ($this->moving == $eid) {
         // do not diplay children
         return '<tr><td colspan="12" class="' . $element['type'] . ' moving">' . $object->name . ' (' . get_string('move') . ')</td></tr>';
     }
     if ($element['type'] == 'category') {
         $level++;
         $categories[$object->id] = $object->stripped_name;
         $category = grade_category::fetch(array('id' => $object->id));
         $item = $category->get_grade_item();
         // Add aggregation coef input if not a course item and if parent category has correct aggregation type
         $dimmed = $item->is_hidden() ? " dimmed " : "";
         // Before we print the category's row, we must find out how many rows will appear below it (for the filler cell's rowspan)
         $aggregation_position = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
         $category_total_data = null;
         // Used if aggregationposition is set to "last", so we can print it last
         $html_children = '';
         $row_count = 0;
         foreach ($element['children'] as $child_el) {
             $moveto = '';
             if (empty($child_el['object']->itemtype)) {
                 $child_el['object']->itemtype = false;
             }
             if (($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') && !$totals) {
                 continue;
             }
             $child_eid = $child_el['eid'];
             $first = '';
             if ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
                 $first = '&amp;first=1';
                 $child_eid = $eid;
             }
             if ($this->moving && $this->moving != $child_eid) {
                 $strmove = get_string('move');
                 $strmovehere = get_string('movehere');
                 $actions = '';
                 // no action icons when moving
                 $moveto = '<tr><td colspan="12"><a href="index.php?id=' . $COURSE->id . '&amp;action=move&amp;eid=' . $this->moving . '&amp;moveafter=' . $child_eid . '&amp;sesskey=' . sesskey() . $first . '"><img class="movetarget" src="' . $CFG->wwwroot . '/pix/movehere.gif" alt="' . $strmovehere . '" title="' . s($strmovehere) . '" /></a></td></tr>';
             }
             $newparents = $parents;
             $newparents[] = $eid;
             $row_count++;
             $child_row_count = 0;
             // If moving, do not print course and category totals, but still print the moveto target box
             if ($this->moving && ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category')) {
                 $html_children .= $moveto;
             } elseif ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
                 // We don't build the item yet because we first need to know the deepest level of categories (for category/name colspans)
                 $category_total_item = $this->build_html_tree($child_el, $totals, $newparents, $categories, $level, $child_row_count);
                 if (!$aggregation_position) {
                     $html_children .= $category_total_item;
                 }
             } else {
                 $html_children .= $this->build_html_tree($child_el, $totals, $newparents, $categories, $level, $child_row_count) . $moveto;
                 if ($this->moving) {
                     $row_count++;
//.........这里部分代码省略.........
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:101,代码来源:lib.php

示例14: definition_after_data

 function definition_after_data()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     $somecat = new grade_category();
     foreach ($somecat->forceable as $property) {
         if ((int) $CFG->{"grade_{$property}_flag"} & 1) {
             if ($mform->elementExists($property)) {
                 if (empty($CFG->grade_hideforcedsettings)) {
                     $mform->hardFreeze($property);
                 } else {
                     if ($mform->elementExists($property)) {
                         $mform->removeElement($property);
                     }
                 }
             }
         }
     }
     if ($CFG->grade_droplow > 0) {
         if ($mform->elementExists('keephigh')) {
             $mform->removeElement('keephigh');
         }
     } else {
         if ($CFG->grade_keephigh > 0) {
             if ($mform->elementExists('droplow')) {
                 $mform->removeElement('droplow');
             }
         }
     }
     if ($id = $mform->getElementValue('id')) {
         $grade_category = grade_category::fetch(array('id' => $id));
         $grade_item = $grade_category->load_grade_item();
         // remove agg coef if not used
         if ($grade_category->is_course_category()) {
             if ($mform->elementExists('parentcategory')) {
                 $mform->removeElement('parentcategory');
             }
             if ($mform->elementExists('aggregationcoef')) {
                 $mform->removeElement('aggregationcoef');
             }
         } else {
             // if we wanted to change parent of existing category - we would have to verify there are no circular references in parents!!!
             if ($mform->elementExists('parentcategory')) {
                 $mform->hardFreeze('parentcategory');
             }
             $parent_category = $grade_category->get_parent_category();
             $parent_category->apply_forced_settings();
             if (!$parent_category->is_aggregationcoef_used()) {
                 if ($mform->elementExists('aggregationcoef')) {
                     $mform->removeElement('aggregationcoef');
                 }
             } else {
                 //fix label if needed
                 $agg_el =& $mform->getElement('aggregationcoef');
                 $aggcoef = '';
                 if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
                     $aggcoef = 'aggregationcoefweight';
                 } else {
                     if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
                         $aggcoef = 'aggregationcoefextra';
                     }
                 }
                 if ($aggcoef !== '') {
                     $agg_el->setLabel(get_string($aggcoef, 'grades'));
                     $mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'), true);
                 }
             }
         }
         if ($grade_item->is_calculated()) {
             // following elements are ignored when calculation formula used
             if ($mform->elementExists('aggregation')) {
                 $mform->removeElement('aggregation');
             }
             if ($mform->elementExists('keephigh')) {
                 $mform->removeElement('keephigh');
             }
             if ($mform->elementExists('droplow')) {
                 $mform->removeElement('droplow');
             }
             if ($mform->elementExists('aggregateonlygraded')) {
                 $mform->removeElement('aggregateonlygraded');
             }
             if ($mform->elementExists('aggregateoutcomes')) {
                 $mform->removeElement('aggregateoutcomes');
             }
             if ($mform->elementExists('aggregatesubcats')) {
                 $mform->removeElement('aggregatesubcats');
             }
         }
         // If it is a course category, remove the "required" rule from the "fullname" element
         if ($grade_category->is_course_category()) {
             unset($mform->_rules['fullname']);
             $key = array_search('fullname', $mform->_required);
             unset($mform->_required[$key]);
         }
         // If it is a course category and its fullname is ?, show an empty field
         if ($grade_category->is_course_category() && $mform->getElementValue('fullname') == '?') {
             $mform->setDefault('fullname', '');
         }
     }
//.........这里部分代码省略.........
开发者ID:r007,项目名称:PMoodle,代码行数:101,代码来源:category_form.php

示例15: set_parent

 /**
  * Sets this item's categoryid. A generic method shared by objects that have a parent id of some kind.
  *
  * @param int $parentid The ID of the new parent
  * @param bool $updateaggregationfields Whether or not to convert the aggregation fields when switching between category.
  *                          Set this to false when the aggregation fields have been updated in prevision of the new
  *                          category, typically when the item is freshly created.
  * @return bool True if success
  */
 public function set_parent($parentid, $updateaggregationfields = true)
 {
     if ($this->is_course_item() or $this->is_category_item()) {
         print_error('cannotsetparentforcatoritem');
     }
     if ($this->categoryid == $parentid) {
         return true;
     }
     // find parent and check course id
     if (!($parent_category = grade_category::fetch(array('id' => $parentid, 'courseid' => $this->courseid)))) {
         return false;
     }
     $currentparent = $this->load_parent_category();
     if ($updateaggregationfields) {
         $this->set_aggregation_fields_for_aggregation($currentparent->aggregation, $parent_category->aggregation);
     }
     $this->force_regrading();
     // set new parent
     $this->categoryid = $parent_category->id;
     $this->parent_category =& $parent_category;
     return $this->update();
 }
开发者ID:mongo0se,项目名称:moodle,代码行数:31,代码来源:grade_item.php


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