Instantiates a grade_outcome object from the DB if this item's outcomeid variable is set

@return grade_outcome This grade item's associated grade_outcome or null
494242
public function load_outcome() {
        if (!empty($this->outcomeid)) {
            $this->outcome = grade_outcome::fetch(array('id'=>$this->outcomeid));
        }
        return $this->outcome;
    }
653126
protected function pushResult()
    {
        if ($this->result !== null) {
            array_push($this->resultStack, $this->result);
        }
        $this->result = new ErrorResult();
        return $this->result;
    }
153664
public static function grade_competency_in_course_parameters() {
        $courseid = new external_value(
            PARAM_INT,
            'Course id',
            VALUE_REQUIRED
        );
        $userid = new external_value(
            PARAM_INT,
            'User id',
            VALUE_REQUIRED
        );
        $competencyid = new external_value(
            PARAM_INT,
            'Competency id',
            VALUE_REQUIRED
        );
        $grade = new external_value(
            PARAM_INT,
            'New grade',
            VALUE_REQUIRED
        );
        $note = new external_value(
            PARAM_NOTAGS,
            'A note to attach to the evidence',
            VALUE_DEFAULT
        );

        $params = array(
            'courseid' => $courseid,
            'userid' => $userid,
            'competencyid' => $competencyid,
            'grade' => $grade,
            'note' => $note,
        );
        return new external_function_parameters($params);
    }
371959
public function get_name() {
        global $DB;
        // For a course category, we return the course name if the fullname is set to '?' in the DB (empty in the category edit form)
        if (empty($this->parent) && $this->fullname == '?') {
            $course = $DB->get_record('course', array('id'=> $this->courseid));
            return format_string($course->fullname, false, array("context" => context_course::instance($this->courseid)));

        } else {
            // Grade categories can't be set up at system context (unlike scales and outcomes)
            // We therefore must have a courseid, and don't need to handle system contexts when filtering.
            return format_string($this->fullname, false, array("context" => context_course::instance($this->courseid)));
        }
    }
898555
public function spawnResult()
    {
        $result = null;
        foreach ($this->getAllImplementations(StorageWrite::class) as $impl) {
            $result = $impl->spawnResult();
        }
        return $result;
    }
733855
public Object initResult()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
	  SibTr.entry(tc, "initResult");  	

    Set theResults = new HashSet();
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
	  SibTr.exit(tc, "initResult");
    return theResults;
  }
20823
public function init() {
        global $PAGE;

        $result = new workshop_allocation_result($this);
        $customdata = array();
        $customdata['workshop'] = $this->workshop;
        $this->mform = new workshop_random_allocator_form($PAGE->url, $customdata);
        if ($this->mform->is_cancelled()) {
            redirect($this->workshop->view_url());
        } else if ($settings = $this->mform->get_data()) {
            $settings = workshop_random_allocator_setting::instance_from_object($settings);
            $this->execute($settings, $result);
            return $result;
        } else {
            // this branch is executed if the form is submitted but the data
            // doesn't validate and the form should be redisplayed
            // or on the first display of the form.
            $result->set_status(workshop_allocation_result::STATUS_VOID);
            return $result;
        }
    }
58824
public function get_default_grade() {
        $scaleid = $this->get('scaleid');
        $scaleconfig = $this->get('scaleconfiguration');
        if ($scaleid === null) {
            $scaleconfig = $this->get_framework()->get('scaleconfiguration');
        }
        return competency_framework::get_default_grade_from_scale_configuration($scaleconfig);
    }
1371954
public function NewObject() {
		$id = (int) $this->request->requestVar('new');
		if ($id) {
			$item = DataObject::get_by_id($this->CreateType, $id);
			if (!$item) {
				$item = Versioned::get_by_stage($this->CreateType, 'Stage')->byID($id);
			}
			return $item;
		}

		return null;
	}
553772
@Override
	public T get() {
		T result = object;
		if (result == null) {
			synchronized (this) {
				result = object;
				if (result == null) {
					object = result = init();
				}
			}
		}
		return result;
	}
640007
public function get_gradinginstance() {
        if (is_array($this->gradingattributes) && array_key_exists('gradinginstance', $this->gradingattributes)) {
            return $this->gradingattributes['gradinginstance'];
        } else {
            return null;
        }
    }
418741
public function get_value() {
        $this->label = $this->grade->grade_item->itemname;

        $val = $this->grade->finalgrade;
        if ($this->grade->grade_item->scaleid) {
            return $val ? (int)$val : -1;
        } else {
            return $val ? format_float($val, $this->grade->grade_item->get_decimals()) : '';
        }
    }
330980
public function beginOnce()
    {
        $this->createQuery();

        GapOrm::getDriver()->query($this->getQuery(), []);

        $obj = GapOrm::getDriver()->selectOnce();
        $obj = $this->convertFromDB($obj);

        if ($obj) {
            return $obj;
        }

        return null;
    }
1015566
public static function get_grades_report_returns() {

        $reviewstructure = new external_single_structure(
            array(
                'userid' => new external_value(PARAM_INT, 'The id of the user (0 when is configured to do not display names).'),
                'assessmentid' => new external_value(PARAM_INT, 'The id of the assessment.'),
                'submissionid' => new external_value(PARAM_INT, 'The id of the submission assessed.'),
                'grade' => new external_value(PARAM_FLOAT, 'The grade for submission.'),
                'gradinggrade' => new external_value(PARAM_FLOAT, 'The grade for assessment.'),
                'gradinggradeover' => new external_value(PARAM_FLOAT, 'The aggregated grade overrided.'),
                'weight' => new external_value(PARAM_INT, 'The weight of the assessment for aggregation.'),
            )
        );

        return new external_single_structure(
            array(
                'report' => new external_single_structure(
                    array(
                        'grades' => new external_multiple_structure(
                            new external_single_structure(
                                array(
                                    'userid' => new external_value(PARAM_INT, 'The id of the user being displayed in the report.'),
                                    'submissionid' => new external_value(PARAM_INT, 'Submission id.'),
                                    'submissiontitle' => new external_value(PARAM_RAW, 'Submission title.'),
                                    'submissionmodified' => new external_value(PARAM_INT, 'Timestamp submission was updated.'),
                                    'submissiongrade' => new external_value(PARAM_FLOAT, 'Aggregated grade for the submission.',
                                        VALUE_OPTIONAL),
                                    'gradinggrade' => new external_value(PARAM_FLOAT, 'Computed grade for the assessment.',
                                        VALUE_OPTIONAL),
                                    'submissiongradeover' => new external_value(PARAM_FLOAT, 'Grade for the assessment overrided
                                        by the teacher.', VALUE_OPTIONAL),
                                    'submissiongradeoverby' => new external_value(PARAM_INT, 'The id of the user who overrided
                                        the grade.', VALUE_OPTIONAL),
                                    'submissionpublished' => new external_value(PARAM_INT, 'Whether is a submission published.',
                                        VALUE_OPTIONAL),
                                    'reviewedby' => new external_multiple_structure($reviewstructure, 'The users who reviewed the
                                        user submission.', VALUE_OPTIONAL),
                                    'reviewerof' => new external_multiple_structure($reviewstructure, 'The assessments the user
                                        reviewed.', VALUE_OPTIONAL),
                                )
                            )
                        ),
                        'totalcount' => new external_value(PARAM_INT, 'Number of total submissions.'),
                    )
                ),
                'warnings' => new external_warnings()
            )
        );
    }
1007656
public function definition_after_data() {

        $mform =& $this->_form;

        if ($id = $mform->getElementValue('update')) {
            $instance   = $mform->getElementValue('instance');

            $gradeitems = grade_item::fetch_all(array(
                'itemtype'      => 'mod',
                'itemmodule'    => 'workshop',
                'iteminstance'  => $instance,
                'courseid'      => $this->course->id));

            if (!empty($gradeitems)) {
                foreach ($gradeitems as $gradeitem) {
                    // here comes really crappy way how to set the value of the fields
                    // gradecategory and gradinggradecategory - grrr QuickForms
                    $decimalpoints = $gradeitem->get_decimals();
                    if ($gradeitem->itemnumber == 0) {
                        $mform->setDefault('submissiongradepass', format_float($gradeitem->gradepass, $decimalpoints));
                        $group = $mform->getElement('submissiongradegroup');
                        $elements = $group->getElements();
                        foreach ($elements as $element) {
                            if ($element->getName() == 'gradecategory') {
                                $element->setValue($gradeitem->categoryid);
                            }
                        }
                    } else if ($gradeitem->itemnumber == 1) {
                        $mform->setDefault('gradinggradepass', format_float($gradeitem->gradepass, $decimalpoints));
                        $group = $mform->getElement('gradinggradegroup');
                        $elements = $group->getElements();
                        foreach ($elements as $element) {
                            if ($element->getName() == 'gradinggradecategory') {
                                $element->setValue($gradeitem->categoryid);
                            }
                        }
                    }
                }
            }
        }
        $typevalues = $mform->getElementValue('submissiontypes');
        foreach (['submissiontypetext', 'submissiontypefile'] as $type) {
            // Don't leave a disabled "required" checkbox checked.
            if (!$typevalues[$type . 'available']) {
                $mform->setDefault($type . 'required', 0);
            }
        }

        parent::definition_after_data();
    }
914357
public static function get_grades($assignmentids, $since = 0) {
        global $DB;
        $params = self::validate_parameters(self::get_grades_parameters(),
                        array('assignmentids' => $assignmentids,
                              'since' => $since));

        $assignments = array();
        $warnings = array();
        $requestedassignmentids = $params['assignmentids'];

        // Check the user is allowed to get the grades for the assignments requested.
        $placeholders = array();
        list($sqlassignmentids, $placeholders) = $DB->get_in_or_equal($requestedassignmentids, SQL_PARAMS_NAMED);
        $sql = "SELECT cm.id, cm.instance FROM {course_modules} cm JOIN {modules} md ON md.id = cm.module ".
               "WHERE md.name = :modname AND cm.instance ".$sqlassignmentids;
        $placeholders['modname'] = 'assign';
        $cms = $DB->get_records_sql($sql, $placeholders);
        foreach ($cms as $cm) {
            try {
                $context = context_module::instance($cm->id);
                self::validate_context($context);
                $assign = new assign($context, null, null);
                $assign->require_view_grades();
            } catch (Exception $e) {
                $requestedassignmentids = array_diff($requestedassignmentids, array($cm->instance));
                $warning = array();
                $warning['item'] = 'assignment';
                $warning['itemid'] = $cm->instance;
                $warning['warningcode'] = '1';
                $warning['message'] = 'No access rights in module context';
                $warnings[] = $warning;
            }
        }

        // Create the query and populate an array of grade records from the recordset results.
        if (count ($requestedassignmentids) > 0) {
            $placeholders = array();
            list($inorequalsql, $placeholders) = $DB->get_in_or_equal($requestedassignmentids, SQL_PARAMS_NAMED);

            $sql = "SELECT ag.id,
                           ag.assignment,
                           ag.userid,
                           ag.timecreated,
                           ag.timemodified,
                           ag.grader,
                           ag.grade,
                           ag.attemptnumber
                      FROM {assign_grades} ag, {assign_submission} s
                     WHERE s.assignment $inorequalsql
                       AND s.userid = ag.userid
                       AND s.latest = 1
                       AND s.attemptnumber = ag.attemptnumber
                       AND ag.timemodified  >= :since
                       AND ag.assignment = s.assignment
                  ORDER BY ag.assignment, ag.id";

            $placeholders['since'] = $params['since'];
            $rs = $DB->get_recordset_sql($sql, $placeholders);
            $currentassignmentid = null;
            $assignment = null;
            foreach ($rs as $rd) {
                $grade = array();
                $grade['id'] = $rd->id;
                $grade['userid'] = $rd->userid;
                $grade['timecreated'] = $rd->timecreated;
                $grade['timemodified'] = $rd->timemodified;
                $grade['grader'] = $rd->grader;
                $grade['attemptnumber'] = $rd->attemptnumber;
                $grade['grade'] = (string)$rd->grade;

                if (is_null($currentassignmentid) || ($rd->assignment != $currentassignmentid )) {
                    if (!is_null($assignment)) {
                        $assignments[] = $assignment;
                    }
                    $assignment = array();
                    $assignment['assignmentid'] = $rd->assignment;
                    $assignment['grades'] = array();
                    $requestedassignmentids = array_diff($requestedassignmentids, array($rd->assignment));
                }
                $assignment['grades'][] = $grade;

                $currentassignmentid = $rd->assignment;
            }
            if (!is_null($assignment)) {
                $assignments[] = $assignment;
            }
            $rs->close();
        }
        foreach ($requestedassignmentids as $assignmentid) {
            $warning = array();
            $warning['item'] = 'assignment';
            $warning['itemid'] = $assignmentid;
            $warning['warningcode'] = '3';
            $warning['message'] = 'No grades found';
            $warnings[] = $warning;
        }

        $result = array();
        $result['assignments'] = $assignments;
        $result['warnings'] = $warnings;
        return $result;
    }
767632
static function fromResult(PDOStatement $result, $class_name = null, $use_pool = null) {
		if (null === $class_name) {
			$class_name = get_called_class();
		}
		if (null === $use_pool) {
			$use_pool = static::$_poolEnabled;
		}

		$objects = array();
		if (is_array($class_name)) {
			$class_names = $class_name;
			unset($class_name);
			while ($values = $result->fetch(PDO::FETCH_NUM)) {
				unset($main_object);
				$startcol = 0;
				foreach ($class_names as $key => $class_name) {
					$object = new $class_name;
					if (!$object->fromNumericResultArray($values, $startcol)) {
						continue;
					}

					if (
						$use_pool
						&& ($pk = $object->getPrimaryKey())
						&& ($pool_object = $object->retrieveFromPool($object->{'get' . $pk}()))
					) {
						$object = $pool_object;
					}

					if ($use_pool) {
						$object->insertIntoPool($object);
					}

					if (!isset($main_object)) {
						$main_object = $objects[] = $object;
					} else {
						if (method_exists($main_object, 'set' . $class_name)) {
							$main_object->{'set' . $class_name}($object);
						} else {
							$main_object->{$class_name} = $object;
						}
					}
				}
			}
		} else {
			// PDO::FETCH_PROPS_LATE is required to call the ctor after hydrating the fields
			$flags = PDO::FETCH_CLASS;
			if (defined('PDO::FETCH_PROPS_LATE')) {
				$flags |= PDO::FETCH_PROPS_LATE;
			}
			$result->setFetchMode($flags, $class_name);
			while (false !== ($object = $result->fetch())) {
				if (
					$use_pool
					&& (!empty($pk) || ($pk = $object->getPrimaryKey()))
					&& ($pool_object = $object->retrieveFromPool($object->{'get' . $pk}()))
				) {
					$object = $pool_object;
				} else {
					$object->castInts();
					$object->setNew(false);
				}

				$objects[] = $object;

				if ($use_pool) {
					$object->insertIntoPool($object);
				}
			}
		}
		return $objects;
	}