$mform->addElement('header', 'general', get_string('gradeitemsinc', 'grades')); // TODO: localize
$id = $this->_customdata['id']; // course id
$mform->addElement('hidden', 'id', $id);
- if ($grade_items = grade_get_items($id)) {
+ if ($grade_items = grade_grades::fetch_all(array('courseid'=>$id))) {
foreach ($grade_items as $grade_item) {
$element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->itemname, array('selected'=>'selected'), array(0, $grade_item->id));
$element->setChecked(1);
}
} else {
// else we get all items for this course
- $gradeitems = grade_get_items($this->id);
+ $gradeitems = grade_grades::fetch_all(array('courseid'=>$this->id));
}
if ($gradeitems) {
$mform->addElement('header', 'general', 'Gradeitems to be included'); // TODO: localize
$id = $this->_customdata['id']; // course id
$mform->addElement('hidden', 'id', $id);
- if ($grade_items = grade_get_items($id)) {
+ if ($grade_items = grade_grades::fetch_all(array('courseid'=>$id))) {
foreach ($grade_items as $grade_item) {
$element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->itemname, array('selected'=>'selected'), array(0, $grade_item->id));
$element->setChecked(1);
// print_gradeitem_selections($id);
// print all items for selections
// make this a standard function in lib maybe
-if ($grade_items = grade_get_items($id)) {
+if ($grade_items = grade_grades::fetch_all(array('courseid'=>$id))) {
echo '<form action="index.php" method="post">';
echo '<div>';
foreach ($grade_items as $grade_item) {
include_once($CFG->libdir.'/gradelib.php');
if ($id) {
- if ($grade_items = grade_get_items($id)) {
+ if ($grade_items = grade_grades::fetch_all(array('courseid'=>$id))) {
foreach ($grade_items as $grade_item) {
$gradeitems[$grade_item->idnumber] = $grade_item->itemname;
}
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="The course this item is part of" PREVIOUS="id" NEXT="categoryid"/>
<FIELD NAME="categoryid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="(optional) the category group this item belongs to" PREVIOUS="courseid" NEXT="itemname"/>
- <FIELD NAME="itemname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="The name of this item (pushed in by the module)" PREVIOUS="categoryid" NEXT="itemtype"/>
+ <FIELD NAME="itemname" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="The name of this item (pushed in by the module)" PREVIOUS="categoryid" NEXT="itemtype"/>
<FIELD NAME="itemtype" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="'mod', 'blocks', 'import', 'calculated' etc" PREVIOUS="itemname" NEXT="itemmodule"/>
- <FIELD NAME="itemmodule" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="'forum', 'quiz', 'csv', etc" PREVIOUS="itemtype" NEXT="iteminstance"/>
+ <FIELD NAME="itemmodule" TYPE="char" LENGTH="30" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="'forum', 'quiz', 'csv', etc" PREVIOUS="itemtype" NEXT="iteminstance"/>
<FIELD NAME="iteminstance" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="id of the item module" PREVIOUS="itemmodule" NEXT="itemnumber"/>
<FIELD NAME="itemnumber" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Can be used to distinguish multiple grades for an activity" PREVIOUS="iteminstance" NEXT="iteminfo"/>
- <FIELD NAME="iteminfo" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="Info and notes about this item XXX" PREVIOUS="itemnumber" NEXT="idnumber"/>
+ <FIELD NAME="iteminfo" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Info and notes about this item XXX" PREVIOUS="itemnumber" NEXT="idnumber"/>
<FIELD NAME="idnumber" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Arbitrary idnumber provided by the module responsible" PREVIOUS="iteminfo" NEXT="calculation"/>
<FIELD NAME="calculation" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Formula describing how to derive this grade from other items, referring to them using giXXX where XXX is grade item id ... eg something like: =sin(square([#gi20#])) + [#gi30#]" PREVIOUS="idnumber" NEXT="gradetype"/>
<FIELD NAME="gradetype" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" ENUM="false" COMMENT="0 = none, 1 = value, 2 = scale, 3 = text" PREVIOUS="calculation" NEXT="grademax"/>
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
- $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
+ $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
- $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
+ $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
$table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
- $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
+ $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
$table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
$table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0');
/// Define field path to be added to grade_categories
$table = new XMLDBTable('grade_categories');
$field = new XMLDBField('path');
- $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'depth');
+ $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'depth');
/// Launch add field path
$result = $result && add_field($table, $field);
/// Launch add field calculation
$result = $result && add_field($table, $field);
}
+ }
+
+ if ($result && $oldversion < 2007062401) {
+
+ /// Changing nullability of field itemname on table grade_items to null
+ $table = new XMLDBTable('grade_items');
+ $field = new XMLDBField('itemname');
+ $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'categoryid');
+
+ /// Launch change of nullability for field itemname
+ $result = $result && change_field_notnull($table, $field);
+
+ $field = new XMLDBField('itemmodule');
+ $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null, 'itemtype');
+
+ /// Launch change of nullability for field itemname
+ $result = $result && change_field_notnull($table, $field);
+
+ $field = new XMLDBField('iteminfo');
+ $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'itemnumber');
+
+ /// Launch change of nullability for field itemname
+ $result = $result && change_field_notnull($table, $field);
+
+
+ /// Changing nullability of field path on table grade_categories to null
+ $table = new XMLDBTable('grade_categories');
+ $field = new XMLDBField('path');
+ $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'depth');
+
+ /// Launch change of nullability for field path
+ $result = $result && change_field_notnull($table, $field);
+
/// Remove the obsoleted unitttests tables - they will be recreated automatically
$tables = array('grade_categories',
* A constant pointing to one of the predefined aggregation strategies (none, mean, median, sum etc) .
* @var int $aggregation
*/
- var $aggregation;
+ var $aggregation = GRADE_AGGREGATE_MEAN_ALL;
/**
* Keep only the X highest items.
* @var int $keephigh
*/
- var $keephigh;
+ var $keephigh = 0;
/**
* Drop the X lowest items.
* @var int $droplow
*/
- var $droplow;
+ var $droplow = 0;
/**
* Array of grade_items or grade_categories nested exactly 1 level below this category
*/
var $grade_item;
- /**
- * Constructor. Extends the basic functionality defined in grade_object.
- * @param array $params Can also be a standard object.
- * @param boolean $fetch Whether or not to fetch the corresponding row from the DB.
- * @param object $grade_item The associated grade_item object can be passed during construction.
- */
- function grade_category($params=NULL, $fetch=true) {
- $this->grade_object($params, $fetch);
- $this->path = grade_category::build_path($this);
- }
-
-
/**
* Builds this category's path string based on its parents (if any) and its own id number.
* This is typically done just before inserting this object in the DB for the first time,
/**
- * Finds and returns a grade_category object based on 1-3 field values.
+ * Finds and returns a grade_category instance based on params.
* @static
*
- * @param string $field1
- * @param string $value1
- * @param string $field2
- * @param string $value2
- * @param string $field3
- * @param string $value3
- * @param string $fields
- * @return object grade_category object or false if none found.
- */
- function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
- if ($grade_category = get_record('grade_categories', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
- $grade_category = new grade_category($grade_category);
- return $grade_category;
+ * @param array $params associative arrays varname=>value
+ * @return object grade_category instance or false if none found.
+ */
+ function fetch($params) {
+ if ($category = grade_object::fetch_helper('grade_categories', 'grade_category', $params)) {
+ $category->path = grade_category::build_path($category);
+ return $category;
+
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Finds and returns all grade_category instances based on params.
+ * @static
+ *
+ * @param array $params associative arrays varname=>value
+ * @return array array of grade_category insatnces or false if none found.
+ */
+ function fetch_all($params) {
+ if ($categories = grade_object::fetch_all_helper('grade_categories', 'grade_category', $params)) {
+ foreach ($categories as $key=>$value) {
+ $categories[$key]->path = grade_category::build_path($categories[$key]);
+ }
+ return $categories;
} else {
return false;
$items = array();
foreach($depends_on as $dep) {
- $items[$dep] = grade_item::fetch('id', $dep);
+ $items[$dep] = grade_item::fetch(array('id'=>$dep));
}
// where to look for final grades - include or grade item too
return false;
}
- $grade_item = new grade_item(array('courseid'=>$this->courseid, 'itemtype'=>'category', 'iteminstance'=>$this->id), false);
- if (!$grade_items = $grade_item->fetch_all_using_this()) {
+ $params = array('courseid'=>$this->courseid, 'itemtype'=>'category', 'iteminstance'=>$this->id);
+
+ if (!$grade_items = grade_item::fetch_all($params)) {
// create a new one
+ $grade_item = new grade_item($params, false);
$grade_item->gradetype = GRADE_TYPE_VALUE;
$grade_item->insert();
* The maximum allowable grade when this grade was created.
* @var float $rawgrademax
*/
- var $rawgrademax;
+ var $rawgrademax = 100;
/**
* The minimum allowable grade when this grade was created.
* @var float $rawgrademin
*/
- var $rawgrademin;
+ var $rawgrademin = 0;
/**
* id of the scale, if this grade is based on a scale.
* 0 if visible, 1 always hidden or date not visible until
* @var float $hidden
*/
- var $hidden;
+ var $hidden = 0;
/**
* 0 not locked, date when the item was locked
* @var float locked
*/
- var $locked;
+ var $locked = 0;
/**
* 0 no automatic locking, date when to lock the grade automatically
* @var float $locktime
*/
- var $locktime;
+ var $locktime = 0;
/**
* Exported flag
* @var boolean $exported
*/
- var $exported;
-
- /**
- * Constructor. Extends the basic functionality defined in grade_object.
- * @param array $params Can also be a standard object.
- * @param boolean $fetch Wether or not to fetch the corresponding row from the DB.
- */
- function grade_grades($params=NULL, $fetch=true) {
- $this->grade_object($params, $fetch);
- }
+ var $exported = 0;
/**
* Loads the grade_grades_text object linked to this grade (through the intersection of itemid and userid), and
*/
function load_text() {
if (empty($this->grade_grades_text->id)) {
- $this->grade_grades_text = grade_grades_text::fetch('itemid', $this->itemid, 'userid', $this->userid);
+ $this->grade_grades_text = grade_grades_text::fetch(array('itemid'=>$this->itemid, 'userid'=>$this->userid));
}
return $this->grade_grades_text;
*/
function load_grade_item() {
if (empty($this->grade_item) && !empty($this->itemid)) {
- $this->grade_item = grade_item::fetch('id', $this->itemid);
+ $this->grade_item = grade_item::fetch(array('id'=>$this->itemid));
}
return $this->grade_item;
}
}
/**
- * Finds and returns a grade_grades object based on 1-3 field values.
+ * Finds and returns a grade_grades instance based on params.
* @static
*
- * @param string $field1
- * @param string $value1
- * @param string $field2
- * @param string $value2
- * @param string $field3
- * @param string $value3
- * @param string $fields
- * @return object grade_category object or false if none found.
+ * @param array $params associative arrays varname=>value
+ * @return object grade_grades instance or false if none found.
*/
- function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
- if ($object = get_record('grade_grades', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
- $object = new grade_grades($object);
- return $object;
+ function fetch($params) {
+ return grade_object::fetch_helper('grade_grades', 'grade_grades', $params);
+ }
- } else {
- return false;
- }
+ /**
+ * Finds and returns all grade_grades instances based on params.
+ * @static
+ *
+ * @param array $params associative arrays varname=>value
+ * @return array array of grade_grades insatnces or false if none found.
+ */
+ function fetch_all($params) {
+ return grade_object::fetch_all_helper('grade_grades', 'grade_grades', $params);
}
/**
* Text format for information (FORMAT_PLAIN, FORMAT_HTML etc...).
* @var int $informationformat
*/
- var $informationformat;
+ var $informationformat = FORMAT_MOODLE;
/**
* Manual feedback from the teacher. This could be a code like 'mi'.
* Text format for feedback (FORMAT_PLAIN, FORMAT_HTML etc...).
* @var int $feedbackformat
*/
- var $feedbackformat;
+ var $feedbackformat = FORMAT_MOODLE;
/**
* The userid of the person who last modified this text.
var $usermodified;
/**
- * Finds and returns a grade_text object based on 1-3 field values.
+ * Finds and returns a grade_grades_text instance based on params.
* @static
*
- * @param boolean $static Unless set to true, this method will also set $this object with the returned values.
- * @param string $field1
- * @param string $value1
- * @param string $field2
- * @param string $value2
- * @param string $field3
- * @param string $value3
- * @param string $fields
- * @return object grade_text object or false if none found.
+ * @param array $params associative arrays varname=>value
+ * @return object grade_grades_text instance or false if none found.
*/
- function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
- if ($grade_text = get_record('grade_grades_text', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
- $grade_text = new grade_grades_text($grade_text);
- return $grade_text;
+ function fetch($params) {
+ return grade_object::fetch_helper('grade_grades_text', 'grade_grades_text', $params);
+ }
- } else {
- return false;
- }
+ /**
+ * Finds and returns all grade_grades_text instances based on params.
+ * @static
+ *
+ * @param array $params associative arrays varname=>value
+ * @return array array of grade_grades_text insatnces or false if none found.
+ */
+ function fetch_all($params) {
+ return grade_object::fetch_all_helper('grade_grades_text', 'grade_grades_text', $params);
}
/**
*/
function load_grade_item() {
if (empty($this->grade_item) && !empty($this->itemid)) {
- $this->grade_item = grade_item::fetch('id', $this->itemid);
+ $this->grade_item = grade_item::fetch(array('id'=>$this->itemid));
}
return $this->grade_item;
}
*/
var $note;
+ /**
+ * Which user account did the modification.
+ * @var string $usermodified
+ */
+ var $usermodified;
+
/**
* How the grade was modified ('manual', 'module', 'import' etc...).
* @var string $howmodified
*/
- var $howmodified;
+ var $howmodified = 'manual';
/**
- * Finds and returns a grade_history object based on 1-3 field values.
+ * Finds and returns a grade_history instance based on params.
* @static
*
- * @param string $field1
- * @param string $value1
- * @param string $field2
- * @param string $value2
- * @param string $field3
- * @param string $value3
- * @param string $fields
- * @return object grade_history object or false if none found.
+ * @param array $params associative arrays varname=>value
+ * @return object grade_history instance or false if none found.
*/
- function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
- if ($grade_history = get_record('grade_history', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
- $grade_history = new grade_history($grade_history);
- return $grade_history;
+ function fetch($params) {
+ return grade_object::fetch_helper('grade_history', 'grade_history', $params);
+ }
- } else {
- return false;
- }
+ /**
+ * Finds and returns all grade_history instances based on params.
+ * @static
+ *
+ * @param array $params associative arrays varname=>value
+ * @return array array of grade_history insatnces or false if none found.
+ */
+ function fetch_all($params) {
+ return grade_object::fetch_all_helper('grade_history', 'grade_history', $params);
}
/**
$history->newgrade = $newgrade;
$history->note = $note;
$history->howmodified = $howmodified;
- $history->timemodified = time();
- $history->usermodified = $USER->id;
return $history->insert();
}
var $itemname;
/**
- * e.g. 'mod', 'blocks', 'import', 'calculate' etc...
+ * e.g. 'category', 'total' and 'mod', 'blocks', 'import', etc...
* @var string $itemtype
*/
var $itemtype;
* The type of grade (0 = none, 1 = value, 2 = scale, 3 = text)
* @var int $gradetype
*/
- var $gradetype;
+ var $gradetype = GRADE_TYPE_VALUE;
/**
* Maximum allowable grade.
* @var float $grademax
*/
- var $grademax;
+ var $grademax = 100;
/**
* Minimum allowable grade.
* @var float $grademin
*/
- var $grademin;
+ var $grademin = 0;
/**
* id of the scale, if this grade is based on a scale.
var $outcome;
/**
- * grade required to pass. (grademin < gradepass <= grademax)
+ * grade required to pass. (grademin <= gradepass <= grademax)
* @var float $gradepass
*/
- var $gradepass;
+ var $gradepass = 0;
/**
* Multiply all grades by this number.
* @var float $multfactor
*/
- var $multfactor;
+ var $multfactor = 1.0;
/**
* Add this to all grades.
* @var float $plusfactor
*/
- var $plusfactor;
+ var $plusfactor = 0;
/**
* Sorting order of the columns.
* @var int $sortorder
*/
- var $sortorder;
+ var $sortorder = 0;
/**
* Date until which to hide this grade_item. If null, 0 or false, grade_item is not hidden. Hiding prevents viewing.
* @var int $hidden
*/
- var $hidden;
+ var $hidden = 0;
/**
- * Date until which to lock this grade_item. If null, 0 or false, grade_item is not locked. Locking prevents updating.
+ * Grade item lock flag. Enmpty if not locked, lcoked if any value presetn ,usually date when was locked. Locking prevents updating.
* @var int $locked
*/
- var $locked;
+ var $locked = 0;
+
+ /**
+ * Date when to lock the grade. Empty means no automatic locking.
+ * @var int $locktime
+ */
+ var $locktime = 0;
/**
* Whether or not the module instance referred to by this grade_item has been deleted.
* @var int $deleted
*/
- var $deleted;
+ var $deleted = 0;
/**
* If set, the whole column will be recalculated, then this flag will be switched off.
* @var boolean $needsupdate
*/
- var $needsupdate;
-
- /**
- * Constructor. Extends the basic functionality defined in grade_object.
- * @param array $params Can also be a standard object.
- * @param boolean $fetch Wether or not to fetch the corresponding row from the DB.
- */
- function grade_item($params=NULL, $fetch=true) {
- $this->grade_object($params, $fetch);
- }
+ var $needsupdate = 0;
/**
* In addition to update() as defined in grade_object, handle the grade_outcome and grade_scale objects.
}
/**
- * Finds and returns a grade_item object based on 1-3 field values.
+ * Finds and returns a grade_item instance based on params.
* @static
*
- * @param string $field1
- * @param string $value1
- * @param string $field2
- * @param string $value2
- * @param string $field3
- * @param string $value3
- * @param string $fields
- * @return object grade_item object or false if none found.
- */
- function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
- if ($grade_item = get_record('grade_items', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
- $grade_item = new grade_item($grade_item);
- return $grade_item;
+ * @param array $params associative arrays varname=>value
+ * @return object grade_item instance or false if none found.
+ */
+ function fetch($params) {
+ return grade_object::fetch_helper('grade_items', 'grade_item', $params);
+ }
- } else {
- return false;
- }
+ /**
+ * Finds and returns all grade_item instances based on params.
+ * @static
+ *
+ * @param array $params associative arrays varname=>value
+ * @return array array of grade_item insatnces or false if none found.
+ */
+ function fetch_all($params) {
+ return grade_object::fetch_all_helper('grade_items', 'grade_item', $params);
}
/**
}
if (!empty($this->scaleid)) {
- $this->scale = grade_scale::fetch('id', $this->scaleid);
+ $this->scale = grade_scale::fetch(array('id'=>$this->scaleid));
$this->scale->load_items();
$this->grademax = count($this->scale->scale_items) - 1;
$this->grademin = 0;
*/
function load_outcome() {
if (!empty($this->outcomeid)) {
- $this->outcome = grade_outcome::fetch('id', $this->outcomeid);
+ $this->outcome = grade_outcome::fetch(array('id'=>$this->outcomeid));
}
return $this->outcome;
}
$category = null;
if (!empty($this->categoryid)) {
- $category = grade_category::fetch('id', $this->categoryid);
+ $category = grade_category::fetch(array('id'=>$this->categoryid));
} elseif (!empty($this->iteminstance) && $this->itemtype == 'category') {
- $category = grade_category::fetch('id', $this->iteminstance);
+ $category = grade_category::fetch(array('id'=>$this->iteminstance));
}
return $category;
// first detect if we need to update calculation formula from [idnumber] to [#giXXX#] (after backup, etc.)
if (!$this->calculation_normalized and preg_match_all('/\[(?!#gi)(.*?)\]/', $this->calculation, $matches)) {
foreach ($matches[1] as $idnumber) {
- if ($grade_item = grade_item::fetch('courseid', $this->courseid, 'idnumber', $idnumber)) {
+ if ($grade_item = grade_item::fetch(array('courseid'=>$this->courseid, 'idnumber'=>$idnumber))) {
$this->calculation = str_replace('['.$grade_item->idnumber.']', '[#gi'.$grade_item->id.'#]', $this->calculation);
}
}
// denormalize formula - convert [#giXX#] to [idnumber]
if (preg_match_all('/\[#gi([0-9]+)#\]/', $formula, $matches)) {
foreach ($matches[1] as $id) {
- if ($grade_item = grade_item::fetch('id', $id)) {
+ if ($grade_item = grade_item::fetch(array('id'=>$id))) {
if (!empty($grade_item->idnumber)) {
$formula = str_replace('[#gi'.$grade_item->id.'#]', '['.$grade_item->idnumber.']', $formula);
}
}
// normalize formula - we want grade item ids [#giXXX#] instead of [idnumber]
- $grade_item = new grade_item(array('courseid'=>$this->courseid), false);
- if ($grade_items = $grade_item->fetch_all_using_this()) {
+ if ($grade_items = grade_item::fetch_all(array('courseid'=>$this->courseid))) {
foreach ($grade_items as $grade_item) {
$formula = str_replace('['.$grade_item->idnumber.']', '[#gi'.$grade_item->id.'#]', $formula);
}
/**
* Constructor. Optionally (and by default) attempts to fetch corresponding row from DB.
- * @param object $params an object with named parameters for this grade item.
+ * @param array $params an array with required parameters for this grade object.
* @param boolean $fetch Whether to fetch corresponding row from DB or not.
*/
function grade_object($params=NULL, $fetch = true) {
- if (!empty($params) && (is_array($params) || is_object($params))) {
- $this->assign_to_this($params);
-
- if ($fetch) {
- $records = $this->fetch_all_using_this();
- if ($records && count($records) > 0) {
- $this->assign_to_this(current($records));
- }
+ if (!empty($params) and (is_array($params) or is_object($params))) {
+ if ($fetch and $data = $this->fetch($params)) {
+ grade_object::set_properties($this, $data);
+
+ } else {
+ grade_object::set_properties($this, $params);
+ }
+ }
+ }
+
+ /**
+ * Finds and returns a grade_object instance based on params.
+ * @static abstract
+ *
+ * @param array $params associative arrays varname=>value
+ * @return object grade_object instance or false if none found.
+ */
+ function fetch($params) {
+ error('Abstract method fetch() not overrided in '.get_class($this));
+ }
+
+ /**
+ * Finds and returns all grade_object instances based on params.
+ * @static abstract
+ *
+ * @param array $params associative arrays varname=>value
+ * @return array array of grade_object insatnces or false if none found.
+ */
+ function fetch_all($params) {
+ error('Abstract method fetch_all() not overrided in '.get_class($this));
+ }
+
+ /**
+ * Factory method - uses the parameters to retrieve matching instance from the DB.
+ * @static final protected
+ * @return mixed object insatnce or false if not found
+ */
+ function fetch_helper($table, $classname, $params) {
+ // we have to do use this hack because of the incomplete OOP implementation in PHP4 :-(
+ // in PHP5 we could do it much better
+ if ($instances = grade_object::fetch_all_helper($table, $classname, $params)) {
+ if (count($instances) > 1) {
+ // we should not tolerate any errors here - proplems might appear later
+ error('Found more than one record in fetch() !');
}
+ return reset($instances);
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Factory method - uses the parameters to retrieve all matching instances from the DB.
+ * @static final protected
+ * @return mixed array of object instances or false if not found
+ */
+ function fetch_all_helper($table, $classname, $params) {
+ // we have to do use this hack because of the incomplete OOP implementation in PHP4 :-(
+ // in PHP5 we could do it much better
+ $instance = new $classname();
+
+ $classvars = (array)$instance;
+ $params = (array)$params;
+
+ $wheresql = array();
+
+ // remove incorrect params - warn developer if needed
+ foreach ($params as $var=>$value) {
+ if (!array_key_exists($var, $classvars) or in_array($var, $instance->nonfields)) {
+ debugging("Incorrect property name $var for class $classname");
+ continue;
+ }
+ if (is_null($value)) {
+ $wheresql[] = " $var IS NULL ";
+ } else {
+ $value = addslashes($value);
+ $wheresql[] = " $var = '$value' ";
+ }
+ }
+
+ if (empty($wheresql)) {
+ $wheresql = '';
+ } else {
+ $wheresql = implode("AND", $wheresql);
+ }
+
+ if ($datas = get_records_select($table, $wheresql, 'id')) {
+ $result = array();
+ foreach($datas as $data) {
+ $instance = new $classname();
+ grade_object::set_properties($instance, $data);
+ $result[$instance->id] = $instance;
+ }
+ return $result;
+
+ } else {
+ return false;
}
}
$this->timemodified = time();
- if (empty($this->usermodified)) {
+ if (array_key_exists('usermodified', $this)) {
$this->usermodified = $USER->id;
}
$this->timecreated = $this->timemodified = time();
- if (empty($this->usermodified)) {
+ if (array_key_exists('usermodified', $this)) {
$this->usermodified = $USER->id;
}
- $clonethis = fullclone($this);
-
- // Unset non-set and null fields
- foreach ($clonethis as $var => $val) {
- if (!isset($val)) {
- unset($clonethis->$var);
- }
- }
-
- if (!$this->id = insert_record($this->table, addslashes_recursive($clonethis), true)) {
+ if (!$this->id = insert_record($this->table, addslashes_recursive($this))) {
debugging("Could not insert object into db");
return false;
}
return false;
}
- $this->assign_to_this($params);
+ grade_object::set_properties($this, $params);
return true;
}
- /**
- * Uses the variables of this object to retrieve all matching objects from the DB.
- * @return array $objects
- */
- function fetch_all_using_this() {
- $variables = get_object_vars($this);
- $wheresql = '';
-
- foreach ($variables as $var => $value) {
- if (!empty($value) && !in_array($var, $this->nonfields)) {
- $value = addslashes($value);
- $wheresql .= " $var = '$value' AND ";
- }
- }
-
- // Trim trailing AND
- $wheresql = substr($wheresql, 0, strrpos($wheresql, 'AND'));
-
- $objects = get_records_select($this->table, $wheresql, 'id');
-
- if (!empty($objects)) {
- $full_objects = array();
-
- // Convert the stdClass objects returned by the get_records_select method into proper objects
- $classname = get_class($this);
- foreach ($objects as $id => $stdobject) {
- $full_objects[$id] = new $classname($stdobject, false);
- }
- return $full_objects;
- } else {
- return $objects;
- }
- }
-
-
/**
* Given an associated array or object, cycles through each key/variable
* and assigns the value to the corresponding variable in this object.
+ * @static final
*/
- function assign_to_this($params) {
- foreach ($params as $param => $value) {
- if (in_object_vars($param, $this)) {
- $this->$param = $value;
+ function set_properties(&$instance, $params) {
+ $classvars = (array)$instance;
+ foreach ($params as $var => $value) {
+ if (array_key_exists($var, $classvars)) {
+ $instance->$var = $value;
}
}
}
var $usermodified;
/**
- * Constructor. Extends the basic functionality defined in grade_object.
- * @param array $params Can also be a standard object.
- * @param boolean $fetch Wether or not to fetch the corresponding row from the DB.
+ * Finds and returns a grade_outcome instance based on params.
+ * @static
+ *
+ * @param array $params associative arrays varname=>value
+ * @return object grade_outcome instance or false if none found.
*/
- function grade_outcome($params=NULL, $fetch=true) {
- $this->grade_object($params, $fetch);
- if (!empty($this->scaleid)) {
- $this->scale = new grade_scale(array('id' => $this->scaleid));
- $this->scale->load_items();
+ function fetch($params) {
+ if ($outcome = grade_object::fetch_helper('grade_outcomes', 'grade_outcome', $params)) {
+ if (!empty($outcome->scaleid)) {
+ $outcome->scale = new grade_scale(array('id'=>$outcome->scaleid));
+ $outcome->scale->load_items();
+ }
+ return $outcome;
+
+ } else {
+ return false;
}
}
/**
- * Finds and returns a grade_outcome object based on 1-3 field values.
+ * Finds and returns all grade_outcome instances based on params.
* @static
*
- * @param boolean $static Unless set to true, this method will also set $this object with the returned values.
- * @param string $field1
- * @param string $value1
- * @param string $field2
- * @param string $value2
- * @param string $field3
- * @param string $value3
- * @param string $fields
- * @return object grade_outcome object or false if none found.
+ * @param array $params associative arrays varname=>value
+ * @return array array of grade_outcome insatnces or false if none found.
*/
- function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
- if ($grade_outcome = get_record('grade_outcomes', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
- $grade_outcome = new grade_outcome($grade_outcome);
- return $grade_outcome;
+ function fetch_all($params) {
+ if ($outcomes = grade_object::fetch_all_helper('grade_outcomes', 'grade_outcome', $params)) {
+ foreach ($outcomes as $key=>$value) {
+ if (!empty($outcomes[$key]->scaleid)) {
+ $outcomes[$key]->scale = new grade_scale(array('id'=>$outcomes[$key]->scaleid));
+ $outcomes[$key]->scale->load_items();
+ }
+ }
+ return $outcomes;
} else {
return false;
*/
var $courseid;
+ var $userid;
+
/**
* The name of the scale.
* @var string $name
var $description;
/**
- * Finds and returns a grade_scale object based on 1-3 field values.
+ * Finds and returns a grade_scale instance based on params.
* @static
*
- * @param string $field1
- * @param string $value1
- * @param string $field2
- * @param string $value2
- * @param string $field3
- * @param string $value3
- * @param string $fields
- * @return object grade_scale object or false if none found.
+ * @param array $params associative arrays varname=>value
+ * @return object grade_scale instance or false if none found.
*/
- function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
- if ($grade_scale = get_record('scale', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
- $grade_scale = new grade_scale($grade_scale);
- return $grade_scale;
+ function fetch($params) {
+ return grade_object::fetch_helper('scale', 'grade_scale', $params);
+ }
- } else {
- return false;
- }
+ /**
+ * Finds and returns all grade_scale instances based on params.
+ * @static
+ *
+ * @param array $params associative arrays varname=>value
+ * @return array array of grade_scale insatnces or false if none found.
+ */
+ function fetch_all($params) {
+ return grade_object::fetch_all_helper('scale', 'grade_scale', $params);
}
/**
$itemtree = array();
foreach ($children as $element) {
- $finals = array();
- if ($this->include_grades) {
- $final = new grade_grades();
- $final->itemid = $element['object']->id;
- $finals = $final->fetch_all_using_this();
+ if (!$this->include_grades or !$finals = grade_grades::fetch_all(array('itemid'=>$element['object']->id))) {
+ $finals = array();
}
$itemtree[$element['object']->sortorder] = array('object' => $element['object'], 'finalgrades' => $finals);
}
foreach ($items as $itemid => $item) {
- $finals = array();
-
- if ($this->include_grades) {
- $final = new grade_grades();
- $final->itemid = $itemid;
- $finals = $final->fetch_all_using_this();
+ if (!$this->include_grades or !$finals = grade_grades::fetch_all(array('itemid'=>$itemid))) {
+ $finals = array();
}
$sortorder = $item->sortorder;
return GRADE_UPDATE_FAILED;
}
- $grade_item = new grade_item(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber'), false);
- if (!$grade_items = $grade_item->fetch_all_using_this()) {
+ if (!$grade_items = grade_item::fetch_all(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber'))) {
// create a new one
$grade_item = false;
*/
function grade_is_locked($courseid, $itemtype, $itemmodule, $iteminstance, $itemnumber, $userid=NULL) {
- $grade_item = new grade_item(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber'), false);
- if (!$grade_items = $grade_item->fetch_all_using_this()) {
+ if (!$grade_items = grade_item::fetch_all(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber'))) {
return false;
} else if (count($grade_items) == 1){
/***** END OF PUBLIC API *****/
-/**
-* Extracts from the gradebook all the grade items attached to the calling object.
-* For example, an assignment may want to retrieve all the grade_items for itself,
-* and get three outcome scales in return. This will affect the grading interface.
-*
-* Note: Each parameter refines the search. So if you only give the courseid,
-* all the grade_items for this course will be returned. If you add the
-* itemtype 'mod', all grade_items for this courseif AND for the 'mod'
-* type will be returned, etc...
-*
-* @param int $courseid The id of the course to which the grade items belong
-* @param string $itemtype 'mod', 'blocks', 'import', 'calculated' etc
-* @param string $itemmodule 'forum, 'quiz', 'csv' etc
-* @param int $iteminstance id of the item module
-* @param int $itemnumber Can be used to distinguish multiple grades for an activity
-* @param string $itemname The name of the grade item
-* @param int $idnumber grade item Primary Key
-* @return array An array of grade items
-*/
-function grade_get_items($courseid, $itemtype=NULL, $itemmodule=NULL, $iteminstance=NULL, $itemnumber=NULL, $itemname=NULL, $idnumber=NULL) {
- $grade_item = new grade_item(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemname', 'itemnumber', 'idnumber'), false);
- $grade_items = $grade_item->fetch_all_using_this();
- return $grade_items;
-}
-
/**
* Updates all final grades in course.
*
set_field('grade_items', 'needsupdate', 1, 'courseid', $courseid);
}
- $grade_item = new grade_item(array('courseid'=>$courseid), false);
-
- if (!$grade_items = $grade_item->fetch_all_using_this()) {
+ if (!$grade_items = $grade_item->fetch_all(array('courseid'=>$courseid))) {
return true;
}
function grade_get_legacy_grade_item($modinstance, $grademax, $scaleid) {
// does it already exist?
- if ($grade_items = grade_get_items($modinstance->course, 'mod', $modinstance->modname, $modinstance->id, 0)) {
+ if ($grade_items = grade_grades::fetch_all(array('courseid'=>$modinstance->course, 'itemtype'=>'mod', 'itemmodule'=>$modinstance->modname, 'iteminstance'=>$modinstance->id, 'itemnumber'=>0))) {
if (count($grade_items) > 1) {
debugging('Multiple legacy grade_items found.');
return false;
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
- $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
+ $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
- $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
+ $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
$table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
- $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
+ $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
$table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
$table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1');
$table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
+ $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('deleted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
+
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN, array('categoryid'), 'grade_categories', array('id'));
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
- $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
+ $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
+
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id'));
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
- /// Adding keys to table grade_grades
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
$table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
$scale->scale = 'Way off topic, Not very helpful, Fairly neutral, Fairly helpful, Supportive, Some good information, Perfect answer!';
$scale->description = 'This scale defines some of qualities that make posts helpful within the Moodle help forums.\n Your feedback will help others see how their posts are being received.';
$scale->timemodified = mktime();
- $temp = explode(',', $scale->scale);
- $scale->max = count($temp) -1;
if ($scale->id = insert_record('scale', $scale)) {
$this->scale[0] = $scale;
+ $temp = explode(',', $scale->scale);
+ $this->scalemax[0] = count($temp) -1;
}
$scale = new stdClass();
$scale->scale = 'Distinction, Very Good, Good, Pass, Fail';
$scale->description = 'This scale is used to mark standard assignments.';
$scale->timemodified = mktime();
- $temp = explode(',', $scale->scale);
- $scale->max = count($temp) -1;
if ($scale->id = insert_record('scale', $scale)) {
$this->scale[1] = $scale;
+ $temp = explode(',', $scale->scale);
+ $this->scalemax[1] = count($temp) -1;
}
$scale = new stdClass();
if ($scale->id = insert_record('scale', $scale)) {
$this->scale[2] = $scale;
+ $temp = explode(',', $scale->scale);
+ $this->scalemax[2] = count($temp) -1;
}
$scale->name = 'unittestscale4';
if ($scale->id = insert_record('scale', $scale)) {
$this->scale[3] = $scale;
+ $temp = explode(',', $scale->scale);
+ $this->scalemax[3] = count($temp) -1;
}
$scale->name = 'unittestscale5';
if ($scale->id = insert_record('scale', $scale)) {
$this->scale[4] = $scale;
+ $temp = explode(',', $scale->scale);
+ $this->scalemax[4] = count($temp) -1;
}
}
$grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
$grade_category->keephigh = 100;
$grade_category->droplow = 0;
- $grade_category->hidden = 0;
$grade_category->timecreated = mktime();
$grade_category->timemodified = mktime();
$grade_category->depth = 1;
$grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
$grade_category->keephigh = 100;
$grade_category->droplow = 0;
- $grade_category->hidden = 0;
$grade_category->parent = $this->grade_categories[0]->id;
$grade_category->timecreated = mktime();
$grade_category->timemodified = mktime();
$grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
$grade_category->keephigh = 100;
$grade_category->droplow = 0;
- $grade_category->hidden = 0;
$grade_category->parent = $this->grade_categories[0]->id;
$grade_category->timecreated = mktime();
$grade_category->timemodified = mktime();
$grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
$grade_category->keephigh = 100;
$grade_category->droplow = 0;
- $grade_category->hidden = 0;
$grade_category->timecreated = mktime();
$grade_category->timemodified = mktime();
$grade_category->depth = 1;
$grade_item->gradetype = GRADE_TYPE_SCALE;
$grade_item->scaleid = $this->scale[0]->id;
$grade_item->grademin = 0;
- $grade_item->grademax = $this->scale[0]->max;
+ $grade_item->grademax = $this->scalemax[0];
$grade_item->iteminfo = 'Grade item used for unit testing';
$grade_item->timecreated = mktime();
$grade_item->timemodified = mktime();
$grade_item->gradetype = GRADE_TYPE_SCALE;
$grade_item->scaleid = $this->scale[0]->id;
$grade_item->grademin = 0;
- $grade_item->grademax = $this->scale[0]->max;
+ $grade_item->grademax = $this->scalemax[0];
$grade_item->iteminfo = 'Grade item used for unit testing';
$grade_item->timecreated = mktime();
$grade_item->timemodified = mktime();
function load_grade_outcomes() {
// Calculation for grade_item 1
$grade_outcome = new stdClass();
- $grade_outcome->itemid = $this->grade_items[0]->id;
$grade_outcome->shortname = 'Team work';
$grade_outcome->timecreated = mktime();
$grade_outcome->timemodified = mktime();
// Calculation for grade_item 2
$grade_outcome = new stdClass();
- $grade_outcome->itemid = $this->grade_items[1]->id;
$grade_outcome->shortname = 'Complete circuit board';
$grade_outcome->timecreated = mktime();
$grade_outcome->timemodified = mktime();
// Calculation for grade_item 3
$grade_outcome = new stdClass();
- $grade_outcome->itemid = $this->grade_items[2]->id;
$grade_outcome->shortname = 'Debug Java program';
$grade_outcome->timecreated = mktime();
$grade_outcome->timemodified = mktime();
$grade_category->insert();
+ $this->assertEqual('/'.$this->grade_categories[0]->id.'/'.$grade_category->id, $grade_category->path);
+
$last_grade_category = end($this->grade_categories);
$this->assertFalse(empty($grade_category->grade_item));
$grade_category = new grade_category();
$this->assertTrue(method_exists($grade_category, 'fetch'));
- $grade_category = grade_category::fetch('id', $this->grade_categories[0]->id);
+ $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);
}
+ function 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->assertEqual(count($this->grade_categories), count($grade_categories));
+ }
+
function test_grade_category_get_children() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'get_children'));
$child2 = new grade_item();
$child1->itemname = 'new grade_item';
$child2->itemname = 'new grade_item';
+ $child1->itemtype = 'something';
+ $child2->itemtype = 'something';
$child1->sortorder = 1;
$child2->sortorder = 2;
$child1->courseid = $grade_category->courseid;
$grade_grades = new grade_grades();
$this->assertTrue(method_exists($grade_grades, 'fetch'));
- $grade_grades = grade_grades::fetch('id', $this->grade_grades[0]->id);
- $this->assertEqual($this->grade_grades[0]->id, $grade_grades->id);
- $this->assertEqual($this->grade_grades[0]->rawgrade, $grade_grades->rawgrade);
+ $grades = grade_grades::fetch(array('id'=>$this->grade_grades[0]->id));
+ $this->assertEqual($this->grade_grades[0]->id, $grades->id);
+ $this->assertEqual($this->grade_grades[0]->rawgrade, $grades->rawgrade);
+ }
+
+ function test_grade_grades_fetch_all() {
+ $grade_grades = new grade_grades();
+ $this->assertTrue(method_exists($grade_grades, 'fetch_all'));
+
+ $grades = grade_grades::fetch_all(array());
+ $this->assertEqual(count($this->grade_grades), count($grades));
}
function test_grade_raw_update_feedback() {
$grade_grades_text = new grade_grades_text();
$this->assertTrue(method_exists($grade_grades_text, 'fetch'));
- $grade_grades_text = grade_grades_text::fetch('id', $this->grade_grades_text[0]->id);
+ $grade_grades_text = grade_grades_text::fetch(array('id'=>$this->grade_grades_text[0]->id));
$this->assertEqual($this->grade_grades_text[0]->id, $grade_grades_text->id);
$this->assertEqual($this->grade_grades_text[0]->information, $grade_grades_text->information);
}
+ function test_grade_grades_text_fetch_all() {
+ $grade_grades_text = new grade_grades_text();
+ $this->assertTrue(method_exists($grade_grades_text, 'fetch_all'));
+
+ $grade_grades_texts = grade_grades_text::fetch_all(array());
+ $this->assertEqual(count($this->grade_grades_text[0]), count($grade_grades_texts));
+ }
+
function test_grade_grades_text_load_grade_item() {
$grade_grades_text = new grade_grades_text($this->grade_grades_text[0]);
$this->assertTrue(method_exists($grade_grades_text, 'load_grade_item'));
$grade_history = new grade_history();
$this->assertTrue(method_exists($grade_history, 'fetch'));
- $grade_history = grade_history::fetch('id', $this->grade_history[0]->id);
+ $grade_history = grade_history::fetch(array('id'=>$this->grade_history[0]->id));
$this->assertEqual($this->grade_history[0]->id, $grade_history->id);
$this->assertEqual($this->grade_history[0]->note, $grade_history->note);
}
+
+ function test_grade_history_fetch_all() {
+ $grade_history = new grade_history();
+ $this->assertTrue(method_exists($grade_history, 'fetch_all'));
+
+ $histories = grade_history::fetch(array());
+ $this->assertEqual(count($this->grade_history), count($histories));
+ }
+
}
?>
$grade_item = new grade_item();\r
$this->assertTrue(method_exists($grade_item, 'fetch'));\r
\r
- $grade_item = grade_item::fetch('id', $this->grade_items[0]->id);\r
+ $grade_item = grade_item::fetch(array('id'=>$this->grade_items[0]->id));\r
$this->assertEqual($this->grade_items[0]->id, $grade_item->id);\r
$this->assertEqual($this->grade_items[0]->iteminfo, $grade_item->iteminfo);\r
\r
- $grade_item = grade_item::fetch('itemtype', $this->grade_items[1]->itemtype, 'itemmodule', $this->grade_items[1]->itemmodule);\r
+ $grade_item = grade_item::fetch(array('itemtype'=>$this->grade_items[1]->itemtype, 'itemmodule'=>$this->grade_items[1]->itemmodule));\r
$this->assertEqual($this->grade_items[1]->id, $grade_item->id);\r
$this->assertEqual($this->grade_items[1]->iteminfo, $grade_item->iteminfo);\r
}\r
\r
- function test_grade_item_fetch_all_using_this() {\r
+ function test_grade_item_fetch_all() {\r
$grade_item = new grade_item();\r
- $grade_item->itemtype = 'mod';\r
- $this->assertTrue(method_exists($grade_item, 'fetch_all_using_this'));\r
+ $this->assertTrue(method_exists($grade_item, 'fetch_all'));\r
\r
- $grade_items = $grade_item->fetch_all_using_this();\r
- $this->assertEqual(5, count($grade_items));\r
- $first_grade_item = reset($grade_items);\r
- $this->assertEqual($this->grade_items[0]->id, $first_grade_item->id);\r
+ $grade_items = grade_item::fetch_all(array('courseid'=>$this->courseid));\r
+ $this->assertEqual(count($this->grade_items), count($grade_items));\r
}\r
\r
-\r
/**\r
* Retrieve all final scores for a given grade_item.\r
*/\r
$grade_item = new grade_item($this->grade_items[1]);\r
$this->assertTrue(method_exists($grade_item, 'compute'));\r
\r
- $grade_grades = grade_grades::fetch('id', $this->grade_grades[3]->id);\r
+ $grade_grades = grade_grades::fetch(array('id'=>$this->grade_grades[3]->id));\r
$grade_grades->delete();\r
- $grade_grades = grade_grades::fetch('id', $this->grade_grades[4]->id);\r
+ $grade_grades = grade_grades::fetch(array('id'=>$this->grade_grades[4]->id));\r
$grade_grades->delete();\r
- $grade_grades = grade_grades::fetch('id', $this->grade_grades[5]->id);\r
+ $grade_grades = grade_grades::fetch(array('id'=>$this->grade_grades[5]->id));\r
$grade_grades->delete();\r
\r
$grade_item->compute();\r
\r
- $grade_grades = grade_grades::fetch('userid', $this->grade_grades[3]->userid, 'itemid', $this->grade_grades[3]->itemid);\r
+ $grade_grades = grade_grades::fetch(array('userid'=>$this->grade_grades[3]->userid, 'itemid'=>$this->grade_grades[3]->itemid));\r
$this->assertEqual($this->grade_grades[3]->finalgrade, $grade_grades->finalgrade);\r
- $grade_grades = grade_grades::fetch('userid', $this->grade_grades[4]->userid, 'itemid', $this->grade_grades[4]->itemid);\r
+ $grade_grades = grade_grades::fetch(array('userid'=>$this->grade_grades[4]->userid, 'itemid'=>$this->grade_grades[4]->itemid));\r
$this->assertEqual($this->grade_grades[4]->finalgrade, $grade_grades->finalgrade);\r
- $grade_grades = grade_grades::fetch('userid', $this->grade_grades[5]->userid, 'itemid', $this->grade_grades[5]->itemid);\r
+ $grade_grades = grade_grades::fetch(array('userid'=>$this->grade_grades[5]->userid, 'itemid'=>$this->grade_grades[5]->itemid));\r
$this->assertEqual($this->grade_grades[5]->finalgrade, $grade_grades->finalgrade);\r
}\r
\r
$this->assertTrue(method_exists($grade_outcome, 'insert'));
$grade_outcome->courseid = $this->courseid;
- $grade_outcome->shortname = 'Team work';
+ $grade_outcome->shortname = 'tw';
+ $grade_outcome->fullname = 'Team work';
$grade_outcome->insert();
$grade_outcome = new grade_outcome();
$this->assertTrue(method_exists($grade_outcome, 'fetch'));
- $grade_outcome = grade_outcome::fetch('id', $this->grade_outcomes[0]->id);
+ $grade_outcome = grade_outcome::fetch(array('id'=>$this->grade_outcomes[0]->id));
$this->assertEqual($this->grade_outcomes[0]->id, $grade_outcome->id);
$this->assertEqual($this->grade_outcomes[0]->shortname, $grade_outcome->shortname);
+
+ $this->assertEqual($this->scale[2]->id, $grade_outcome->scale->id);
+ }
+
+ function test_grade_outcome_fetch_all() {
+ $grade_outcome = new grade_outcome();
+ $this->assertTrue(method_exists($grade_outcome, 'fetch_all'));
+
+ $grade_outcomes = grade_outcome::fetch_all(array());
+ $this->assertEqual(count($this->grade_outcomes), count($grade_outcomes));
}
}
?>
$grade_scale = new grade_scale();
$this->assertTrue(method_exists($grade_scale, 'fetch'));
- $grade_scale = grade_scale::fetch('id', $this->scale[0]->id);
+ $grade_scale = grade_scale::fetch(array('id'=>$this->scale[0]->id));
$this->assertEqual($this->scale[0]->id, $grade_scale->id);
$this->assertEqual($this->scale[0]->name, $grade_scale->name);
}
$tree->remove_element(7);
$tree->renumber();
$tree->update_db();
- $item = grade_item::fetch('id', $this->grade_items[6]->id);
+ $item = grade_item::fetch(array('id'=>$this->grade_items[6]->id));
$this->assertTrue(empty($item->id));
$tree->move_element(4, 9);
$tree->renumber();
$tree->update_db();
- $item = grade_item::fetch('id', $this->grade_items[1]->id);
+ $item = grade_item::fetch(array('id'=>$this->grade_items[1]->id));
$this->assertFalse(empty($item->id));
$this->assertEqual(8, $item->sortorder);
* 3 users for 3 grade_items
*/
class gradelib_test extends grade_test {
-
- function test_grade_get_items() {
- if (get_class($this) == 'gradelib_test') {
- $grade_items = grade_get_items($this->courseid);
-
- $this->assertTrue(is_array($grade_items));
- $this->assertEqual(count($grade_items), 10);
- }
- }
-
-/*
-// obsolted function, should be replaced by grade_update() or removed completely
- function test_grade_create_category() {
- if (get_class($this) == 'gradelib_test') {
- $grade_category = new stdClass();
- $grade_category->timecreated = mktime();
- $grade_category->timemodified = mktime();
-
- $items = array(new grade_item(), new grade_item());
-
- $grade_category->id = grade_create_category($this->courseid, 'unittestcategory4', $items, GRADE_AGGREGATE_MEAN);
-
- $last_grade_category = end($this->grade_categories);
- $this->assertEqual($grade_category->id, $last_grade_category->id + 1);
-
- $db_grade_category = get_record('grade_categories', 'id', $grade_category->id);
- $db_grade_category = new grade_category($db_grade_category);
- $db_grade_category->load_grade_item();
- $this->grade_categories[] = $db_grade_category;
- $this->grade_items[] = $db_grade_category->grade_item;
- }
- }
-*/
function test_grade_is_locked() {
if (get_class($this) == 'gradelib_test') {
$grade_item = $this->grade_items[0];
fatal mod/chat/chatd.php /^ function fatal($message) {$/;" f
fault lib/soap/nusoap.php /^ function fault($faultcode,$faultstring,$faultactor='',$faultdetail=''){$/;" f
fcFPP auth/fc/fcFPP.php /^ function fcFPP($host="localhost", $port="3333")$/;" f
-fetch lib/grade/grade_calculation.php /^ function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;" f
-fetch lib/grade/grade_category.php /^ function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;" f
-fetch lib/grade/grade_grades_final.php /^ function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;" f
-fetch lib/grade/grade_grades_raw.php /^ function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;" f
-fetch lib/grade/grade_grades_text.php /^ function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;" f
-fetch lib/grade/grade_history.php /^ function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;" f
-fetch lib/grade/grade_item.php /^ function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;" f
-fetch lib/grade/grade_outcome.php /^ function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;" f
-fetch lib/grade/grade_scale.php /^ function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;" f
+fetch lib/grade/grade_calculation.php /^ function fetch($params) { $/;" f
+fetch lib/grade/grade_category.php /^ function fetch($params) { $/;" f
+fetch lib/grade/grade_grades_final.php /^ function fetch($params) { $/;" f
+fetch lib/grade/grade_grades_raw.php /^ function fetch($params) { $/;" f
+fetch lib/grade/grade_grades_text.php /^ function fetch($params) { $/;" f
+fetch lib/grade/grade_history.php /^ function fetch($params) { $/;" f
+fetch lib/grade/grade_item.php /^ function fetch($params) { $/;" f
+fetch lib/grade/grade_outcome.php /^ function fetch($params) { $/;" f
+fetch lib/grade/grade_scale.php /^ function fetch($params) { $/;" f
fetch lib/simpletestlib/http.php /^ function &fetch($timeout) {$/;" f
fetch lib/smarty/Smarty.class.php /^ function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)$/;" f
fetchResponse lib/simpletestlib/user_agent.php /^ function &fetchResponse($url, $encoding) {$/;" f
write lib/adodb/session/adodb-encrypt-sha1.php /^ function write($data, $key) $/;" f
write lib/adodb/session/adodb-session.php /^ function write($key, $val) $/;" f
write lib/adodb/session/adodb-session2.php /^ function write($key, $val) $/;" f
-write lib/excel/OLEwriter.php /^ function write($data) \/\/por ahora sólo a STDOUT$/;" f
+write lib/excel/OLEwriter.php /^ function write($data) \/\/por ahora s�lo a STDOUT$/;" f
write lib/excel/Worksheet.php /^ function write($row, $col, $token, $format = 0)$/;" f
write lib/excellib.class.php /^ function write($row, $col, $token, $format=0) {$/;" f
write lib/odslib.class.php /^ function write($row, $col, $token, $format=0) {$/;" f
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2007062301; // YYYYMMDD = date
+ $version = 2007062401; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.9 dev'; // Human-friendly version name