Merge branch 'MDL-39536-25' of git://github.com/FMCorz/moodle into MOODLE_25_STABLE
This commit is contained in:
+20
-24
@@ -1045,40 +1045,36 @@ class completion_info {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether or not the course has activities with completion enabled.
|
||||
*
|
||||
* @return boolean true when there is at least one activity with completion enabled.
|
||||
*/
|
||||
public function has_activities() {
|
||||
$modinfo = get_fast_modinfo($this->course);
|
||||
foreach ($modinfo->get_cms() as $cm) {
|
||||
if ($cm->completion != COMPLETION_TRACKING_NONE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a list of activities for which completion is enabled on the
|
||||
* course. The list is ordered by the section order of those activities.
|
||||
*
|
||||
* @param array $modinfo For unit testing only, supply the value
|
||||
* here. Otherwise the method calls get_fast_modinfo
|
||||
* @return array Array from $cmid => $cm of all activities with completion enabled,
|
||||
* empty array if none
|
||||
*/
|
||||
public function get_activities($modinfo=null) {
|
||||
global $DB;
|
||||
|
||||
// Obtain those activities which have completion turned on
|
||||
$withcompletion = $DB->get_records_select('course_modules', 'course='.$this->course->id.
|
||||
' AND completion<>'.COMPLETION_TRACKING_NONE);
|
||||
if (!$withcompletion) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Use modinfo to get section order and also add in names
|
||||
if (empty($modinfo)) {
|
||||
$modinfo = get_fast_modinfo($this->course);
|
||||
}
|
||||
public function get_activities() {
|
||||
$modinfo = get_fast_modinfo($this->course);
|
||||
$result = array();
|
||||
foreach ($modinfo->sections as $sectioncms) {
|
||||
foreach ($sectioncms as $cmid) {
|
||||
if (array_key_exists($cmid, $withcompletion)) {
|
||||
$result[$cmid] = $withcompletion[$cmid];
|
||||
$result[$cmid]->modname = $modinfo->cms[$cmid]->modname;
|
||||
$result[$cmid]->name = $modinfo->cms[$cmid]->name;
|
||||
}
|
||||
foreach ($modinfo->get_cms() as $cm) {
|
||||
if ($cm->completion != COMPLETION_TRACKING_NONE) {
|
||||
$result[$cm->id] = $cm;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Completion lib advanced test case.
|
||||
*
|
||||
* This file contains the advanced test suite for completion lib.
|
||||
*
|
||||
* @package core_completion
|
||||
* @category phpunit
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/completionlib.php');
|
||||
|
||||
class completionlib_advanced_testcase extends advanced_testcase {
|
||||
|
||||
function test_get_activities() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Create a course with mixed auto completion data.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$completionauto = array('completion' => COMPLETION_TRACKING_AUTOMATIC);
|
||||
$completionmanual = array('completion' => COMPLETION_TRACKING_MANUAL);
|
||||
$completionnone = array('completion' => COMPLETION_TRACKING_NONE);
|
||||
$forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id), $completionauto);
|
||||
$page = $this->getDataGenerator()->create_module('page', array('course' => $course->id), $completionauto);
|
||||
$data = $this->getDataGenerator()->create_module('data', array('course' => $course->id), $completionmanual);
|
||||
|
||||
$forum2 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id), $completionnone);
|
||||
$page2 = $this->getDataGenerator()->create_module('page', array('course' => $course->id), $completionnone);
|
||||
$data2 = $this->getDataGenerator()->create_module('data', array('course' => $course->id), $completionnone);
|
||||
|
||||
// Create data in another course to make sure it's not considered.
|
||||
$course2 = $this->getDataGenerator()->create_course();
|
||||
$c2forum = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id), $completionauto);
|
||||
$c2page = $this->getDataGenerator()->create_module('page', array('course' => $course2->id), $completionmanual);
|
||||
$c2data = $this->getDataGenerator()->create_module('data', array('course' => $course2->id), $completionnone);
|
||||
|
||||
$c = new completion_info($course);
|
||||
$activities = $c->get_activities();
|
||||
$this->assertEquals(3, count($activities));
|
||||
$this->assertTrue(isset($activities[$forum->cmid]));
|
||||
$this->assertEquals($activities[$forum->cmid]->name, $forum->name);
|
||||
$this->assertTrue(isset($activities[$page->cmid]));
|
||||
$this->assertEquals($activities[$page->cmid]->name, $page->name);
|
||||
$this->assertTrue(isset($activities[$data->cmid]));
|
||||
$this->assertEquals($activities[$data->cmid]->name, $data->name);
|
||||
|
||||
$this->assertFalse(isset($activities[$forum2->cmid]));
|
||||
$this->assertFalse(isset($activities[$page2->cmid]));
|
||||
$this->assertFalse(isset($activities[$data2->cmid]));
|
||||
}
|
||||
|
||||
function test_has_activities() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Create a course with mixed auto completion data.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$course2 = $this->getDataGenerator()->create_course();
|
||||
$completionauto = array('completion' => COMPLETION_TRACKING_AUTOMATIC);
|
||||
$completionnone = array('completion' => COMPLETION_TRACKING_NONE);
|
||||
$c1forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id), $completionauto);
|
||||
$c2forum = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id), $completionnone);
|
||||
|
||||
$c1 = new completion_info($course);
|
||||
$c2 = new completion_info($course2);
|
||||
|
||||
$this->assertTrue($c1->has_activities());
|
||||
$this->assertFalse($c2->has_activities());
|
||||
}
|
||||
}
|
||||
@@ -514,31 +514,6 @@ WHERE
|
||||
$c->internal_set_data($cm, $data);
|
||||
}
|
||||
|
||||
function test_get_activities() {
|
||||
global $DB;
|
||||
|
||||
$c = new completion_info((object)array('id'=>42));
|
||||
|
||||
// Try with no activities
|
||||
$DB->expects($this->at(0))
|
||||
->method('get_records_select')
|
||||
->with('course_modules', 'course=42 AND completion<>'.COMPLETION_TRACKING_NONE)
|
||||
->will($this->returnValue(array()));
|
||||
$result = $c->get_activities();
|
||||
$this->assertEquals(array(), $result);
|
||||
|
||||
// Try with an activity (need to fake up modinfo for it as well)
|
||||
$DB->expects($this->at(0))
|
||||
->method('get_records_select')
|
||||
->with('course_modules', 'course=42 AND completion<>'.COMPLETION_TRACKING_NONE)
|
||||
->will($this->returnValue(array(13=>(object)array('id'=>13))));
|
||||
$modinfo = new stdClass;
|
||||
$modinfo->sections = array(array(1, 2, 3), array(12, 13, 14));
|
||||
$modinfo->cms[13] = (object)array('modname'=>'frog', 'name'=>'kermit');
|
||||
$result = $c->get_activities($modinfo);
|
||||
$this->assertEquals(array(13=>(object)array('id'=>13, 'modname'=>'frog', 'name'=>'kermit')), $result);
|
||||
}
|
||||
|
||||
// get_tracked_users() cannot easily be tested because it uses
|
||||
// get_role_users, so skipping that
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ function report_progress_extend_navigation_course($navigation, $course, $context
|
||||
}
|
||||
|
||||
$completion = new completion_info($course);
|
||||
$showonnavigation = ($showonnavigation && $completion->is_enabled() && count($completion->get_activities())>0);
|
||||
$showonnavigation = ($showonnavigation && $completion->is_enabled() && $completion->has_activities());
|
||||
if ($showonnavigation) {
|
||||
$url = new moodle_url('/report/progress/index.php', array('course'=>$course->id));
|
||||
$navigation->add(get_string('pluginname','report_progress'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
|
||||
|
||||
Reference in New Issue
Block a user