コード例 #1
0
ファイル: grade_object_test.php プロジェクト: evltuma/moodle
 public function test_fetch_all_helper()
 {
     // Simple ID lookup.
     $params = array('id' => $this->grade_items[0]->id);
     $items = grade_object::fetch_all_helper('grade_items', 'grade_item', $params);
     $this->assertCount(1, $items);
     $item = array_shift($items);
     $this->assertInstanceOf('grade_item', $item);
     $this->assertEquals($item->id, $this->grade_items[0]->id);
     // Various parameters lookup, multiple results.
     $params = array('courseid' => $this->course->id, 'categoryid' => $this->grade_categories[1]->id);
     $items = grade_object::fetch_all_helper('grade_items', 'grade_item', $params);
     $this->assertCount(2, $items);
     $expecteditems = array($this->grade_items[0]->id => true, $this->grade_items[1]->id => true);
     foreach ($items as $item) {
         $this->assertInstanceOf('grade_item', $item);
         $this->assertArrayHasKey($item->id, $expecteditems);
         unset($expecteditems[$item->id]);
     }
     // Text column lookup.
     $params = array('iteminfo' => $this->grade_items[2]->iteminfo);
     $items = grade_object::fetch_all_helper('grade_items', 'grade_item', $params);
     $this->assertCount(1, $items);
     $item = array_shift($items);
     $this->assertInstanceOf('grade_item', $item);
     $this->assertEquals($item->id, $this->grade_items[2]->id);
     // Lookup using non-existing columns.
     $params = array('doesnotexist' => 'ignoreme', 'id' => $this->grade_items[0]->id);
     $items = grade_object::fetch_all_helper('grade_items', 'grade_item', $params);
     $this->assertCount(1, $items);
     $item = array_shift($items);
     $this->assertInstanceOf('grade_item', $item);
     $this->assertEquals($item->id, $this->grade_items[0]->id);
 }
コード例 #2
0
ファイル: grade_category.php プロジェクト: r007/PMoodle
 /**
  * Internal function - used only from fetch_course_category()
  * Normal insert() can not be used for course category
  * @param int $courseid
  * @return bool success
  */
 function insert_course_category($courseid)
 {
     $this->courseid = $courseid;
     $this->fullname = '?';
     $this->path = null;
     $this->parent = null;
     $this->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2;
     $this->apply_default_settings();
     $this->apply_forced_settings();
     $this->timecreated = $this->timemodified = time();
     if (!parent::insert('system')) {
         debugging("Could not insert this category: " . print_r($this, true));
         return false;
     }
     // build path and depth
     $this->update('system');
     return $this->id;
 }
コード例 #3
0
ファイル: conditionlib.php プロジェクト: ajv/Offline-Caching
 /**
  * Obtains the name of a grade item.
  *
  * @global object
  * @param object $gradeitemobj Object from get_record on grade_items table,
  *     (can be empty if you want to just get !missing)
  * @return string Name of item of !missing if it didn't exist
  */
 private static function get_grade_name($gradeitemobj)
 {
     global $CFG;
     if (isset($gradeitemobj->id)) {
         require_once $CFG->libdir . '/gradelib.php';
         $item = new grade_item();
         grade_object::set_properties($item, $gradeitemobj);
         return $item->get_name();
     } else {
         return '!missing';
         // Ooops, missing grade
     }
 }
コード例 #4
0
 /**
  * In addition to update() as defined in grade_object rounds the float numbers using php function,
  * the reason is we need to compare the db value with computed number to skip updates if possible.
  *
  * @param string $source from where was the object inserted (mod/forum, manual, etc.)
  * @return bool success
  */
 public function update($source = null)
 {
     $this->rawgrade = grade_floatval($this->rawgrade);
     $this->finalgrade = grade_floatval($this->finalgrade);
     $this->rawgrademin = grade_floatval($this->rawgrademin);
     $this->rawgrademax = grade_floatval($this->rawgrademax);
     return parent::update($source);
 }
コード例 #5
0
ファイル: grade_outcome.php プロジェクト: pzhu2004/moodle
 /**
  * Static method that returns all outcomes available in course
  *
  * @static
  * @param int $courseid
  * @return array
  */
 public static function fetch_all_available($courseid)
 {
     global $CFG, $DB;
     $result = array();
     $params = array($courseid);
     $sql = "SELECT go.*\n                  FROM {grade_outcomes} go, {grade_outcomes_courses} goc\n                 WHERE go.id = goc.outcomeid AND goc.courseid = ?\n              ORDER BY go.id ASC";
     if ($datas = $DB->get_records_sql($sql, $params)) {
         foreach ($datas as $data) {
             $instance = new grade_outcome();
             grade_object::set_properties($instance, $data);
             $result[$instance->id] = $instance;
         }
     }
     return $result;
 }
コード例 #6
0
ファイル: grade_category.php プロジェクト: covex-nn/moodle
 /**
  * Sets the grade_item's hidden variable and updates the grade_item.
  *
  * Overrides grade_item::set_hidden() to add cascading of the hidden value to grade items in this grade category
  *
  * @param int $hidden 0 mean always visible, 1 means always hidden and a number > 1 is a timestamp to hide until
  * @param bool $cascade apply to child objects too
  */
 public function set_hidden($hidden, $cascade = false)
 {
     $this->load_grade_item();
     //this hides the associated grade item (the course total)
     $this->grade_item->set_hidden($hidden, $cascade);
     //this hides the category itself and everything it contains
     parent::set_hidden($hidden, $cascade);
     if ($cascade) {
         if ($children = grade_item::fetch_all(array('categoryid' => $this->id))) {
             foreach ($children as $child) {
                 if ($child->can_control_visibility()) {
                     $child->set_hidden($hidden, $cascade);
                 }
             }
         }
         if ($children = grade_category::fetch_all(array('parent' => $this->id))) {
             foreach ($children as $child) {
                 $child->set_hidden($hidden, $cascade);
             }
         }
     }
     //if marking category visible make sure parent category is visible MDL-21367
     if (!$hidden) {
         $category_array = grade_category::fetch_all(array('id' => $this->parent));
         if ($category_array && array_key_exists($this->parent, $category_array)) {
             $category = $category_array[$this->parent];
             //call set_hidden on the category regardless of whether it is hidden as its parent might be hidden
             //if($category->is_hidden()) {
             $category->set_hidden($hidden, false);
             //}
         }
     }
 }
コード例 #7
0
ファイル: grade_item.php プロジェクト: Jtgadbois/Pedadida
 /**
  * Set the hidden status of grade_item and all grades.
  *
  * 0 mean always visible, 1 means always hidden and a number > 1 is a timestamp to hide until
  *
  * @param int $hidden new hidden status
  * @param bool $cascade apply to child objects too
  */
 public function set_hidden($hidden, $cascade = false)
 {
     parent::set_hidden($hidden, $cascade);
     if ($cascade) {
         if ($grades = grade_grade::fetch_all(array('itemid' => $this->id))) {
             foreach ($grades as $grade) {
                 $grade->grade_item =& $this;
                 $grade->set_hidden($hidden, $cascade);
             }
         }
     }
     //if marking item visible make sure category is visible MDL-21367
     if (!$hidden) {
         $category_array = grade_category::fetch_all(array('id' => $this->categoryid));
         if ($category_array && array_key_exists($this->categoryid, $category_array)) {
             $category = $category_array[$this->categoryid];
             //call set_hidden on the category regardless of whether it is hidden as its parent might be hidden
             //if($category->is_hidden()) {
             $category->set_hidden($hidden, false);
             //}
         }
     }
 }
コード例 #8
0
 /**
  * Static method - returns all outcomes available in course
  * @static
  * @param int $courseid
  * @return array
  */
 function fetch_all_available($courseid)
 {
     global $CFG;
     $result = array();
     $sql = "SELECT go.*\n                  FROM {$CFG->prefix}grade_outcomes go, {$CFG->prefix}grade_outcomes_courses goc\n                 WHERE go.id = goc.outcomeid AND goc.courseid = {$courseid}\n              ORDER BY go.id ASC";
     if ($datas = get_records_sql($sql)) {
         foreach ($datas as $data) {
             $instance = new grade_outcome();
             grade_object::set_properties($instance, $data);
             $result[$instance->id] = $instance;
         }
     }
     return $result;
 }
コード例 #9
0
 /**
  * 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);
 }
コード例 #10
0
ファイル: grade_scale.php プロジェクト: evltuma/moodle
 /**
  * Deletes this outcome from the database.
  *
  * @param string $source from where was the object deleted (mod/forum, manual, etc.)
  * @return bool success
  */
 public function delete($source = null)
 {
     global $DB;
     if (parent::delete($source)) {
         $context = context_system::instance();
         $fs = get_file_storage();
         $files = $fs->get_area_files($context->id, 'grade', 'scale', $this->id);
         foreach ($files as $file) {
             $file->delete();
         }
         return true;
     }
     return false;
 }
コード例 #11
0
function backup_gradebook_item_info($bf, $preferences, $backupall)
{
    global $CFG;
    require_once $CFG->libdir . '/gradelib.php';
    $status = true;
    // get all the grade_items, ordered by sort order since upon restoring, it is not always
    // possible to use the same sort order. We could at least preserve the sortorder by restoring
    // grade_items in the original sortorder
    if ($grade_items = get_records_sql("SELECT * FROM {$CFG->prefix}grade_items\n                                            WHERE courseid = {$preferences->backup_course}\n                                            ORDER BY sortorder ASC")) {
        //Begin grade_items tag
        fwrite($bf, start_tag("GRADE_ITEMS", 3, true));
        //Iterate for each item
        foreach ($grade_items as $grade_item) {
            // Instantiate a grade_item object, to access its methods
            $grade_item = grade_object::fetch_helper('grade_items', 'grade_item', $grade_item);
            // do not restore if this grade_item is a mod, and
            if ($grade_item->itemtype == 'mod') {
                // this still needs to be included, though grades can be ignored
            } else {
                if ($grade_item->itemtype == 'category') {
                    // if not all grade items are being backed up
                    // we ignore this type of grade_item and grades associated
                    if (!$backupall) {
                        continue;
                    }
                }
            }
            //Begin grade_item
            fwrite($bf, start_tag("GRADE_ITEM", 4, true));
            //Output individual fields
            fwrite($bf, full_tag("ID", 5, false, $grade_item->id));
            fwrite($bf, full_tag("CATEGORYID", 5, false, $grade_item->categoryid));
            fwrite($bf, full_tag("ITEMNAME", 5, false, $grade_item->itemname));
            fwrite($bf, full_tag("ITEMTYPE", 5, false, $grade_item->itemtype));
            fwrite($bf, full_tag("ITEMMODULE", 5, false, $grade_item->itemmodule));
            fwrite($bf, full_tag("ITEMINSTANCE", 5, false, $grade_item->iteminstance));
            fwrite($bf, full_tag("ITEMNUMBER", 5, false, $grade_item->itemnumber));
            fwrite($bf, full_tag("ITEMINFO", 5, false, $grade_item->iteminfo));
            fwrite($bf, full_tag("IDNUMBER", 5, false, $grade_item->idnumber));
            // use [idnumber] in calculation instead of [#giXXX#]
            fwrite($bf, full_tag("CALCULATION", 5, false, $grade_item->get_calculation()));
            fwrite($bf, full_tag("GRADETYPE", 5, false, $grade_item->gradetype));
            fwrite($bf, full_tag("GRADEMAX", 5, false, $grade_item->grademax));
            fwrite($bf, full_tag("GRADEMIN", 5, false, $grade_item->grademin));
            fwrite($bf, full_tag("SCALEID", 5, false, $grade_item->scaleid));
            fwrite($bf, full_tag("OUTCOMEID", 5, false, $grade_item->outcomeid));
            fwrite($bf, full_tag("GRADEPASS", 5, false, $grade_item->gradepass));
            fwrite($bf, full_tag("MULTFACTOR", 5, false, $grade_item->multfactor));
            fwrite($bf, full_tag("PLUSFACTOR", 5, false, $grade_item->plusfactor));
            fwrite($bf, full_tag("AGGREGATIONCOEF", 5, false, $grade_item->aggregationcoef));
            fwrite($bf, full_tag("DISPLAY", 5, false, $grade_item->plusfactor));
            fwrite($bf, full_tag("DECIMALS", 5, false, $grade_item->plusfactor));
            fwrite($bf, full_tag("HIDDEN", 5, false, $grade_item->hidden));
            fwrite($bf, full_tag("LOCKED", 5, false, $grade_item->locked));
            fwrite($bf, full_tag("LOCKTIME", 5, false, $grade_item->locktime));
            fwrite($bf, full_tag("NEEDSUPDATE", 5, false, $grade_item->needsupdate));
            fwrite($bf, full_tag("TIMECREATED", 5, false, $grade_item->timecreated));
            fwrite($bf, full_tag("TIMEMODIFIED", 5, false, $grade_item->timemodified));
            // back up the other stuff here
            // mod grades should only be backed up if selected
            if ($grade_item->itemtype == 'mod' && !backup_userdata_selected($preferences, $grade_item->itemmodule, $grade_item->iteminstance)) {
                // do not write grades if a mod grade_item is being restored
                // but userdata is not selected
            } else {
                $status = backup_gradebook_grades_info($bf, $preferences, $grade_item->id);
            }
            //End grade_item
            fwrite($bf, end_tag("GRADE_ITEM", 4, true));
        }
        //End grade_items tag
        $status = fwrite($bf, end_tag("GRADE_ITEMS", 3, true));
    }
    return $status;
}
コード例 #12
0
 public function test_course_completion_progress()
 {
     global $CFG, $DB;
     $CFG->enablecompletion = true;
     $DB->update_record('course', (object) ['id' => $this->course->id, 'enablecompletion' => 1]);
     $this->course = $DB->get_record('course', ['id' => $this->course->id]);
     $actual = local::course_completion_progress($this->course);
     $this->assertNull($actual);
     $this->create_extra_users();
     $this->setUser($this->extrasuspendedstudents[0]);
     $actual = local::course_completion_progress($this->course);
     $this->assertNull($actual);
     $this->setUser($this->students[0]);
     $actual = local::course_completion_progress($this->course);
     $this->assertNull($actual);
     // Create an assignment that is enabled for completion.
     $this->setUSer($this->teachers[0]);
     $assign = $this->create_instance(['course' => $this->course->id, 'name' => 'Assign!', 'completion' => COMPLETION_TRACKING_AUTOMATIC]);
     // Should now have something that can be tracked for progress.
     $this->setUser($this->students[0]);
     $actual = local::course_completion_progress($this->course);
     $this->assertInstanceOf('stdClass', $actual);
     $this->assertEquals(0, $actual->complete);
     $this->assertEquals(1, $actual->total);
     $this->assertEquals(0, $actual->progress);
     // Make sure completion updates on grading.
     $DB->set_field('course_modules', 'completiongradeitemnumber', 0, ['id' => $assign->get_course_module()->id]);
     $gradeitem = $assign->get_grade_item();
     grade_object::set_properties($gradeitem, array('gradepass' => 50.0));
     $gradeitem->update();
     $assignrow = $assign->get_instance();
     $grades = array();
     $grades[$this->students[0]->id] = (object) ['rawgrade' => 60, 'userid' => $this->students[0]->id];
     $assignrow->cmidnumber = null;
     assign_grade_item_update($assignrow, $grades);
     $actual = local::course_completion_progress($this->course);
     $this->assertInstanceOf('stdClass', $actual);
     $this->assertEquals(1, $actual->complete);
     $this->assertEquals(1, $actual->total);
     $this->assertEquals(100, $actual->progress);
     // Make sure course completion returns null when disabled at site level.
     $CFG->enablecompletion = false;
     $actual = local::course_completion_progress($this->course);
     $this->assertNull($actual);
     // Make sure course completion returns null when disabled at course level.
     $CFG->enablecompletion = true;
     $DB->update_record('course', (object) ['id' => $this->course->id, 'enablecompletion' => 0]);
     $this->course = $DB->get_record('course', ['id' => $this->course->id]);
     $actual = local::course_completion_progress($this->course);
     $this->assertNull($actual);
 }
コード例 #13
0
 /**
  * Internal function - used only from fetch_course_category()
  * Normal insert() can not be used for course category
  * @param int $courseid
  * @return bool success
  */
 function insert_course_category($courseid)
 {
     $this->courseid = $courseid;
     $this->fullname = get_string('coursegradecategory', 'grades');
     $this->path = null;
     $this->parent = null;
     $this->aggregate = GRADE_AGGREGATE_MEAN;
     if (!parent::insert('system')) {
         debugging("Could not insert this category: " . print_r($this, true));
         return false;
     }
     // build path and depth
     $this->update('system');
     return $this->id;
 }
コード例 #14
0
 /**
  * Deletes the grade_grade instance from the database.
  *
  * @param string $source The location the deletion occurred (mod/forum, manual, etc.).
  * @return bool Returns true if the deletion was successful, false otherwise.
  */
 public function delete($source = null)
 {
     $success = parent::delete($source);
     // If the grade was deleted successfully trigger a grade_deleted event.
     if ($success) {
         $this->load_grade_item();
         \core\event\grade_deleted::create_from_grade($this)->trigger();
     }
     return $success;
 }
コード例 #15
0
ファイル: condition_test.php プロジェクト: evltuma/moodle
 /**
  * Tests the is_available and get_description functions.
  */
 public function test_usage()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/mod/assign/locallib.php';
     $this->resetAfterTest();
     // Create course with completion turned on.
     $CFG->enablecompletion = true;
     $CFG->enableavailability = true;
     $generator = $this->getDataGenerator();
     $course = $generator->create_course(array('enablecompletion' => 1));
     $user = $generator->create_user();
     $generator->enrol_user($user->id, $course->id);
     $this->setUser($user);
     // Create a Page with manual completion for basic checks.
     $page = $generator->get_plugin_generator('mod_page')->create_instance(array('course' => $course->id, 'name' => 'Page!', 'completion' => COMPLETION_TRACKING_MANUAL));
     // Create an assignment - we need to have something that can be graded
     // so as to test the PASS/FAIL states. Set it up to be completed based
     // on its grade item.
     $assignrow = $this->getDataGenerator()->create_module('assign', array('course' => $course->id, 'name' => 'Assign!', 'completion' => COMPLETION_TRACKING_AUTOMATIC));
     $DB->set_field('course_modules', 'completiongradeitemnumber', 0, array('id' => $assignrow->cmid));
     $assign = new assign(context_module::instance($assignrow->cmid), false, false);
     // Get basic details.
     $modinfo = get_fast_modinfo($course);
     $pagecm = $modinfo->get_cm($page->cmid);
     $assigncm = $assign->get_course_module();
     $info = new \core_availability\mock_info($course, $user->id);
     // COMPLETE state (false), positive and NOT.
     $cond = new condition((object) array('cm' => (int) $pagecm->id, 'e' => COMPLETION_COMPLETE));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $information = $cond->get_description(false, false, $info);
     $information = \core_availability\info::format_info($information, $course);
     $this->assertRegExp('~Page!.*is marked complete~', $information);
     $this->assertTrue($cond->is_available(true, $info, true, $user->id));
     // INCOMPLETE state (true).
     $cond = new condition((object) array('cm' => (int) $pagecm->id, 'e' => COMPLETION_INCOMPLETE));
     $this->assertTrue($cond->is_available(false, $info, true, $user->id));
     $this->assertFalse($cond->is_available(true, $info, true, $user->id));
     $information = $cond->get_description(false, true, $info);
     $information = \core_availability\info::format_info($information, $course);
     $this->assertRegExp('~Page!.*is marked complete~', $information);
     // Mark page complete.
     $completion = new completion_info($course);
     $completion->update_state($pagecm, COMPLETION_COMPLETE);
     // COMPLETE state (true).
     $cond = new condition((object) array('cm' => (int) $pagecm->id, 'e' => COMPLETION_COMPLETE));
     $this->assertTrue($cond->is_available(false, $info, true, $user->id));
     $this->assertFalse($cond->is_available(true, $info, true, $user->id));
     $information = $cond->get_description(false, true, $info);
     $information = \core_availability\info::format_info($information, $course);
     $this->assertRegExp('~Page!.*is incomplete~', $information);
     // INCOMPLETE state (false).
     $cond = new condition((object) array('cm' => (int) $pagecm->id, 'e' => COMPLETION_INCOMPLETE));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $information = $cond->get_description(false, false, $info);
     $information = \core_availability\info::format_info($information, $course);
     $this->assertRegExp('~Page!.*is incomplete~', $information);
     $this->assertTrue($cond->is_available(true, $info, true, $user->id));
     // We are going to need the grade item so that we can get pass/fails.
     $gradeitem = $assign->get_grade_item();
     grade_object::set_properties($gradeitem, array('gradepass' => 50.0));
     $gradeitem->update();
     // With no grade, it should return true for INCOMPLETE and false for
     // the other three.
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_INCOMPLETE));
     $this->assertTrue($cond->is_available(false, $info, true, $user->id));
     $this->assertFalse($cond->is_available(true, $info, true, $user->id));
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $this->assertTrue($cond->is_available(true, $info, true, $user->id));
     // Check $information for COMPLETE_PASS and _FAIL as we haven't yet.
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE_PASS));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $information = $cond->get_description(false, false, $info);
     $information = \core_availability\info::format_info($information, $course);
     $this->assertRegExp('~Assign!.*is complete and passed~', $information);
     $this->assertTrue($cond->is_available(true, $info, true, $user->id));
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE_FAIL));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $information = $cond->get_description(false, false, $info);
     $information = \core_availability\info::format_info($information, $course);
     $this->assertRegExp('~Assign!.*is complete and failed~', $information);
     $this->assertTrue($cond->is_available(true, $info, true, $user->id));
     // Change the grade to be complete and failed.
     self::set_grade($assignrow, $user->id, 40);
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_INCOMPLETE));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $this->assertTrue($cond->is_available(true, $info, true, $user->id));
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE));
     $this->assertTrue($cond->is_available(false, $info, true, $user->id));
     $this->assertFalse($cond->is_available(true, $info, true, $user->id));
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE_PASS));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $information = $cond->get_description(false, false, $info);
     $information = \core_availability\info::format_info($information, $course);
     $this->assertRegExp('~Assign!.*is complete and passed~', $information);
     $this->assertTrue($cond->is_available(true, $info, true, $user->id));
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE_FAIL));
     $this->assertTrue($cond->is_available(false, $info, true, $user->id));
     $this->assertFalse($cond->is_available(true, $info, true, $user->id));
     $information = $cond->get_description(false, true, $info);
     $information = \core_availability\info::format_info($information, $course);
     $this->assertRegExp('~Assign!.*is not complete and failed~', $information);
     // Now change it to pass.
     self::set_grade($assignrow, $user->id, 60);
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_INCOMPLETE));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $this->assertTrue($cond->is_available(true, $info, true, $user->id));
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE));
     $this->assertTrue($cond->is_available(false, $info, true, $user->id));
     $this->assertFalse($cond->is_available(true, $info, true, $user->id));
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE_PASS));
     $this->assertTrue($cond->is_available(false, $info, true, $user->id));
     $this->assertFalse($cond->is_available(true, $info, true, $user->id));
     $information = $cond->get_description(false, true, $info);
     $information = \core_availability\info::format_info($information, $course);
     $this->assertRegExp('~Assign!.*is not complete and passed~', $information);
     $cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE_FAIL));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $information = $cond->get_description(false, false, $info);
     $information = \core_availability\info::format_info($information, $course);
     $this->assertRegExp('~Assign!.*is complete and failed~', $information);
     $this->assertTrue($cond->is_available(true, $info, true, $user->id));
     // Simulate deletion of an activity by using an invalid cmid. These
     // conditions always fail, regardless of NOT flag or INCOMPLETE.
     $cond = new condition((object) array('cm' => $assigncm->id + 100, 'e' => COMPLETION_COMPLETE));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $information = $cond->get_description(false, false, $info);
     $information = \core_availability\info::format_info($information, $course);
     $this->assertRegExp('~(Missing activity).*is marked complete~', $information);
     $this->assertFalse($cond->is_available(true, $info, true, $user->id));
     $cond = new condition((object) array('cm' => $assigncm->id + 100, 'e' => COMPLETION_INCOMPLETE));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
 }
コード例 #16
0
ファイル: grade_item.php プロジェクト: r007/PMoodle
 /**
  * In addition to perform parent::insert(), calls force_regrading() method too.
  * @param string $source from where was the object inserted (mod/forum, manual, etc.)
  * @return int PK ID if successful, false otherwise
  */
 function insert($source = null)
 {
     global $CFG;
     if (empty($this->courseid)) {
         error('Can not insert grade item without course id!');
     }
     // load scale if needed
     $this->load_scale();
     // add parent category if needed
     if (empty($this->categoryid) and !$this->is_course_item() and !$this->is_category_item()) {
         $course_category = grade_category::fetch_course_category($this->courseid);
         $this->categoryid = $course_category->id;
     }
     // always place the new items at the end, move them after insert if needed
     $last_sortorder = get_field_select('grade_items', 'MAX(sortorder)', "courseid = {$this->courseid}");
     if (!empty($last_sortorder)) {
         $this->sortorder = $last_sortorder + 1;
     } else {
         $this->sortorder = 1;
     }
     // add proper item numbers to manual items
     if ($this->itemtype == 'manual') {
         if (empty($this->itemnumber)) {
             $this->itemnumber = 0;
         }
     }
     // make sure there is not 0 in outcomeid
     if (empty($this->outcomeid)) {
         $this->outcomeid = null;
     }
     $this->timecreated = $this->timemodified = time();
     if (parent::insert($source)) {
         // force regrading of items if needed
         $this->force_regrading();
         return $this->id;
     } else {
         debugging("Could not insert this grade_item in the database!");
         return false;
     }
 }
コード例 #17
0
ファイル: grade_item.php プロジェクト: mongo0se/moodle
 /**
  * Returns whether the grade item can control the visibility of the grades
  *
  * @return bool
  */
 public function can_control_visibility()
 {
     if (core_component::get_plugin_directory($this->itemtype, $this->itemmodule)) {
         return !plugin_supports($this->itemtype, $this->itemmodule, FEATURE_CONTROLS_GRADE_VISIBILITY, false);
     }
     return parent::can_control_visibility();
 }
コード例 #18
0
 /**
  * In addition to update() it also updates grade_outcomes_courses if needed
  * @param string $source from where was the object inserted
  * @return boolean success
  */
 function update($source = null)
 {
     $this->timemodified = time();
     return parent::update($source);
 }
コード例 #19
0
 /**
  * Obtains the name of a grade item, also checking that it exists. Uses a
  * cache. The name returned is suitable for display.
  *
  * @param int $courseid Course id
  * @param int $gradeitemid Grade item id
  * @return string Grade name or empty string if no grade with that id
  */
 private static function get_cached_grade_name($courseid, $gradeitemid)
 {
     global $DB, $CFG;
     require_once $CFG->libdir . '/gradelib.php';
     // Get all grade item names from cache, or using db query.
     $cache = \cache::make('availability_grade', 'items');
     if (($cacheditems = $cache->get($courseid)) === false) {
         // We cache the whole items table not the name; the format_string
         // call for the name might depend on current user (e.g. multilang)
         // and this is a shared cache.
         $cacheditems = $DB->get_records('grade_items', array('courseid' => $courseid));
         $cache->set($courseid, $cacheditems);
     }
     // Return name from cached item or a lang string.
     if (!array_key_exists($gradeitemid, $cacheditems)) {
         return get_string('missing', 'availability_grade');
     }
     $gradeitemobj = $cacheditems[$gradeitemid];
     $item = new \grade_item();
     \grade_object::set_properties($item, $gradeitemobj);
     return $item->get_name();
 }
コード例 #20
0
ファイル: grade_object.php プロジェクト: vuchannguyen/web
 /**
  * Using this object's id field, fetches the matching record in the DB, and looks at
  * each variable in turn. If the DB has different data, the db's data is used to update
  * the object. This is different from the update() function, which acts on the DB record
  * based on the object.
  */
 public function update_from_db()
 {
     if (empty($this->id)) {
         debugging("The object could not be used in its state to retrieve a matching record from the DB, because its id field is not set.");
         return false;
     }
     global $DB;
     if (!($params = $DB->get_record($this->table, array('id' => $this->id)))) {
         debugging("Object with this id:{$this->id} does not exist in table:{$this->table}, can not update from db!");
         return false;
     }
     grade_object::set_properties($this, $params);
     return true;
 }
コード例 #21
0
ファイル: synchronize.php プロジェクト: jamesmcq/elis
 /**
  * Returns the grade items associated with the courses.
  *
  * @param array $courseids Array of course ids.
  * @return array Array of grade_items for each course level grade item.
  */
 public static function fetch_course_items(array $courseids)
 {
     global $DB;
     $courseitems = array();
     if (!empty($courseids)) {
         list($courseidssql, $courseidsparams) = $DB->get_in_or_equal($courseids);
         $select = 'courseid ' . $courseidssql . ' AND itemtype = ?';
         $params = array_merge($courseidsparams, array('course'));
         $rs = $DB->get_recordset_select('grade_items', $select, $params);
         $courseitems = array();
         foreach ($rs as $data) {
             $instance = new \grade_item();
             \grade_object::set_properties($instance, $data);
             $courseitems[$instance->id] = $instance;
         }
         $rs->close();
     }
     // Determine if any courses were missing.
     $receivedids = array();
     foreach ($courseitems as $item) {
         $receivedids[] = $item->courseid;
     }
     $missingids = array_diff($courseids, $receivedids);
     // Create grade items for any courses that didn't have one.
     if (!empty($missingids)) {
         foreach ($missingids as $courseid) {
             // First get category - it creates the associated grade item.
             $coursecategory = \grade_category::fetch_course_category($courseid);
             $gradeitem = $coursecategory->get_grade_item();
             $courseitems[$gradeitem->id] = $gradeitem;
         }
     }
     return $courseitems;
 }