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]));
 }
Beispiel #2
0
 public function course_completion_gauge(&$course, $div, $width = 160, $height = 160, $type = 'progressbar')
 {
     global $USER, $PAGE;
     $str = '';
     $completion = new completion_info($course);
     if ($completion->is_enabled(null)) {
         $alltracked = count($completion->get_activities());
         $progressinfo = $completion->get_progress_all('u.id = :userid', array('userid' => $USER->id));
         $completed = 0;
         if (!empty($progressinfo)) {
             if (!empty($progressinfo[$USER->id]->progress)) {
                 foreach ($progressinfo[$USER->id]->progress as $progressrecord) {
                     if ($progressrecord->completionstate) {
                         $completed++;
                     }
                 }
             }
         }
         $ratio = $alltracked == 0 ? 0 : round($completed / $alltracked * 100);
         $jqwrenderer = $PAGE->get_renderer('local_vflibs');
         if ($div == 'div') {
             $str .= '<div class="course-completion" title="' . get_string('completion', 'local_my', 0 + $ratio) . '">';
         } else {
             $str .= '<td class="course-completion" title="' . get_string('completion', 'local_my', 0 + $ratio) . '">';
         }
         if ($type == 'gauge') {
             $properties = array('width' => $width, 'height' => $height, 'max' => 100, 'crop' => 120);
             $str .= $jqwrenderer->jqw_bargauge_simple('completion-jqw-' . $course->id, array($ratio), $properties);
         } else {
             $properties = array('width' => $width, 'height' => $height, 'animation' => 300, 'template' => 'success');
             $str .= $jqwrenderer->jqw_progress_bar('completion-jqw-' . $course->id, $ratio, $properties);
         }
         if ($div == 'div') {
             $str .= '</div>';
         } else {
             $str .= '</td>';
         }
     } else {
         if ($div == 'div') {
             $str .= '<div class="course-completion">';
         } else {
             $str .= '<td class="course-completion">';
         }
         if ($div == 'div') {
             $str .= '</div>';
         } else {
             $str .= '</td>';
         }
     }
     return $str;
 }
Beispiel #3
0
/**
 * This function extends the navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $course The course to object for the report
 * @param stdClass $context The context of the course
 */
function progress_report_extend_navigation($navigation, $course, $context)
{
    global $CFG, $OUTPUT;
    $showonnavigation = has_capability('coursereport/progress:view', $context);
    $group = groups_get_course_group($course, true);
    // Supposed to verify group
    if ($group === 0 && $course->groupmode == SEPARATEGROUPS) {
        $showonnavigation = $showonnavigation && has_capability('moodle/site:accessallgroups', $context);
    }
    $completion = new completion_info($course);
    $showonnavigation = $showonnavigation && $completion->is_enabled() && count($completion->get_activities()) > 0;
    if ($showonnavigation) {
        $url = new moodle_url('/course/report/progress/index.php', array('course' => $course->id));
        $navigation->add(get_string('pluginname', 'coursereport_progress'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
    }
}
Beispiel #4
0
require_login($course);

// Check basic permission
require_capability('report/progress:view',$context);

// Get group mode
$group = groups_get_course_group($course,true); // Supposed to verify group
if ($group===0 && $course->groupmode==SEPARATEGROUPS) {
    require_capability('moodle/site:accessallgroups',$context);
}

// Get data on activities and progress of all users, and give error if we've
// nothing to display (no users or no activities)
$reportsurl = $CFG->wwwroot.'/course/report.php?id='.$course->id;
$completion = new completion_info($course);
$activities = $completion->get_activities();

// Generate where clause
$where = array();
$where_params = array();

if ($sifirst !== 'all') {
    $where[] = $DB->sql_like('u.firstname', ':sifirst', false);
    $where_params['sifirst'] = $sifirst.'%';
}

if ($silast !== 'all') {
    $where[] = $DB->sql_like('u.lastname', ':silast', false);
    $where_params['silast'] = $silast.'%';
}
function slides_make_outline($course,$topics_info,$sections,$editing){
	// TOPICS OUTLINE list
	echo '<li id="section--1" class="section outline clearfix" >';
	echo "<ul id='section-outline'>\n";
	
	// check activity completion and add to array where section id is key
	$completionbysection = array();
    $completioninfo = new completion_info($course);
    $activitieswithcompletion = $completioninfo->get_activities();
    //  unknown > 0 = incomplete < complete
	foreach($activitieswithcompletion as $activity){
		$completionbysection[$activity->section] = "complete";
		$activity_status_data = $completioninfo->get_data($activity->id, $USER->id);
	 	if($activity_status_data->completionstate < 0) {
	 		$completionbysection[$activity->section] = "unknown";
	 	} else if ($activity_status_data->completionstate === 0 && $completionbysection[$activity->section] != "unknown") {
	 		$completionbysection[$activity->section] = "incomplete";
	 	}
	}

	//sort by id
	for($i=0; $i<=$course->numsections; $i++) {
		$section = $sections[$i];
		$section_complete = isset($completionbysection[$section->id]) ? $completionbysection[$section->id] : "complete"; 
		
	    $sectionname = !empty($section->name) ? $section->name : "Topic " . $section->section;
	    $style = "left:" . $topics_info[$section->id]->x_offset . "; top:" .$topics_info[$section->id]->y_offset;
	    $css = $editing ? "$section_complete editing" : "$section_complete";
	    $css .= $section->visible ? "" : " hidden";
	    $css .= $course->marker == $i ? " highlight" : "";
	    echo '<li class="'. $css . '" id="topiclink' . $section->id . '" style="' .$style . ';">';
		echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section->section.'" title="'.$sectionname.'" class="outline-link">' .$sectionname;
	  //  echo "</a> $complete</li>\n";
	  // TODO: Fix complete
	    echo "</a></li>\n";
	}
	
	echo "</ul>\n";
  	echo "</li>\n";
  	
  
}
 /**
  * Test course module completion update event.
  */
 public function test_course_module_completion_updated_event()
 {
     global $USER, $CFG;
     $this->setup_data();
     $this->setAdminUser();
     $completionauto = array('completion' => COMPLETION_TRACKING_AUTOMATIC);
     $forum = $this->getDataGenerator()->create_module('forum', array('course' => $this->course->id), $completionauto);
     $c = new completion_info($this->course);
     $activities = $c->get_activities();
     $this->assertEquals(1, count($activities));
     $this->assertTrue(isset($activities[$forum->cmid]));
     $this->assertEquals($activities[$forum->cmid]->name, $forum->name);
     $current = $c->get_data($activities[$forum->cmid], false, $this->user->id);
     $current->completionstate = COMPLETION_COMPLETE;
     $current->timemodified = time();
     $sink = $this->redirectEvents();
     $c->internal_set_data($activities[$forum->cmid], $current);
     $events = $sink->get_events();
     $event = reset($events);
     $this->assertInstanceOf('\\core\\event\\course_module_completion_updated', $event);
     $this->assertEquals($forum->cmid, $event->get_record_snapshot('course_modules_completion', $event->objectid)->coursemoduleid);
     $this->assertEquals($current, $event->get_record_snapshot('course_modules_completion', $event->objectid));
     $this->assertEquals(context_module::instance($forum->cmid), $event->get_context());
     $this->assertEquals($USER->id, $event->userid);
     $this->assertEquals($this->user->id, $event->relateduserid);
     $this->assertInstanceOf('moodle_url', $event->get_url());
     $this->assertEventLegacyData($current, $event);
 }
Beispiel #7
0
    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);
    }
Beispiel #8
0
 /**
  * Get Activities completion status
  *
  * @param int $courseid ID of the Course
  * @param int $userid ID of the User
  * @return array of activities progress and warnings
  * @throws moodle_exception
  * @since Moodle 2.9
  * @throws moodle_exception
  */
 public static function get_activities_completion_status($courseid, $userid)
 {
     global $CFG, $USER;
     require_once $CFG->libdir . '/grouplib.php';
     $warnings = array();
     $arrayparams = array('courseid' => $courseid, 'userid' => $userid);
     $params = self::validate_parameters(self::get_activities_completion_status_parameters(), $arrayparams);
     $course = get_course($params['courseid']);
     $user = core_user::get_user($params['userid'], 'id', MUST_EXIST);
     $context = context_course::instance($course->id);
     self::validate_context($context);
     // Check that current user have permissions to see this user's activities.
     if ($user->id != $USER->id) {
         require_capability('report/progress:view', $context);
         if (!groups_user_groups_visible($course, $user->id)) {
             // We are not in the same group!
             throw new moodle_exception('accessdenied', 'admin');
         }
     }
     $completion = new completion_info($course);
     $activities = $completion->get_activities();
     $progresses = $completion->get_progress_all();
     $userprogress = $progresses[$user->id];
     $results = array();
     foreach ($activities as $activity) {
         // Check if current user has visibility on this activity.
         if (!$activity->uservisible) {
             continue;
         }
         // Get progress information and state.
         if (array_key_exists($activity->id, $userprogress->progress)) {
             $thisprogress = $userprogress->progress[$activity->id];
             $state = $thisprogress->completionstate;
             $timecompleted = $thisprogress->timemodified;
         } else {
             $state = COMPLETION_INCOMPLETE;
             $timecompleted = 0;
         }
         $results[] = array('cmid' => $activity->id, 'modname' => $activity->modname, 'instance' => $activity->instance, 'state' => $state, 'timecompleted' => $timecompleted, 'tracking' => $activity->completion);
     }
     $results = array('statuses' => $results, 'warnings' => $warnings);
     return $results;
 }
Beispiel #9
0
 function definition()
 {
     global $USER, $CFG, $DB, $js_enabled;
     $courseconfig = get_config('moodlecourse');
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $completion = new completion_info($course);
     $params = array('course' => $course->id);
     /// form definition
     //--------------------------------------------------------------------------------
     // Check if there is existing criteria completions
     if ($completion->is_course_locked()) {
         $mform->addElement('header', '', get_string('completionsettingslocked', 'completion'));
         $mform->addElement('static', '', '', get_string('err_settingslocked', 'completion'));
         $mform->addElement('submit', 'settingsunlock', get_string('unlockcompletiondelete', 'completion'));
     }
     // Get array of all available aggregation methods
     $aggregation_methods = $completion->get_aggregation_methods();
     // Overall criteria aggregation
     $mform->addElement('header', 'overallcriteria', get_string('overallcriteriaaggregation', 'completion'));
     $mform->addElement('select', 'overall_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods);
     $mform->setDefault('overall_aggregation', $completion->get_aggregation_method());
     // Course prerequisite completion criteria
     $mform->addElement('header', 'courseprerequisites', get_string('courseprerequisites', 'completion'));
     // Get applicable courses
     $courses = $DB->get_records_sql("\n                SELECT DISTINCT\n                    c.id,\n                    c.category,\n                    c.fullname,\n                    cc.id AS selected\n                FROM\n                    {course} c\n                LEFT JOIN\n                    {course_completion_criteria} cc\n                 ON cc.courseinstance = c.id\n                AND cc.course = {$course->id}\n                INNER JOIN\n                    {course_completion_criteria} ccc\n                 ON ccc.course = c.id\n                WHERE\n                    c.enablecompletion = " . COMPLETION_ENABLED . "\n                AND c.id <> {$course->id}\n            ");
     if (!empty($courses)) {
         if (count($courses) > 1) {
             $mform->addElement('select', 'course_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods);
             $mform->setDefault('course_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_COURSE));
         }
         // Get category list
         $list = array();
         $parents = array();
         make_categories_list($list, $parents);
         // Get course list for select box
         $selectbox = array();
         $selected = array();
         foreach ($courses as $c) {
             $selectbox[$c->id] = $list[$c->category] . ' / ' . s($c->fullname);
             // If already selected
             if ($c->selected) {
                 $selected[] = $c->id;
             }
         }
         // Show multiselect box
         $mform->addElement('select', 'criteria_course', get_string('coursesavailable', 'completion'), $selectbox, array('multiple' => 'multiple', 'size' => 6));
         // Select current criteria
         $mform->setDefault('criteria_course', $selected);
         // Explain list
         $mform->addElement('static', 'criteria_courses_explaination', '', get_string('coursesavailableexplaination', 'completion'));
     } else {
         $mform->addElement('static', 'nocourses', '', get_string('err_nocourses', 'completion'));
     }
     // Manual self completion
     $mform->addElement('header', 'manualselfcompletion', get_string('manualselfcompletion', 'completion'));
     $criteria = new completion_criteria_self($params);
     $criteria->config_form_display($mform);
     // Role completion criteria
     $mform->addElement('header', 'roles', get_string('manualcompletionby', 'completion'));
     $roles = get_roles_with_capability('moodle/course:markcomplete', CAP_ALLOW, get_context_instance(CONTEXT_COURSE, $course->id));
     if (!empty($roles)) {
         $mform->addElement('select', 'role_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods);
         $mform->setDefault('role_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ROLE));
         foreach ($roles as $role) {
             $params_a = array('role' => $role->id);
             $criteria = new completion_criteria_role(array_merge($params, $params_a));
             $criteria->config_form_display($mform, $role);
         }
     } else {
         $mform->addElement('static', 'noroles', '', get_string('err_noroles', 'completion'));
     }
     // Activity completion criteria
     $mform->addElement('header', 'activitiescompleted', get_string('activitiescompleted', 'completion'));
     $activities = $completion->get_activities();
     if (!empty($activities)) {
         if (count($activities) > 1) {
             $mform->addElement('select', 'activity_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods);
             $mform->setDefault('activity_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ACTIVITY));
         }
         foreach ($activities as $activity) {
             $params_a = array('moduleinstance' => $activity->id);
             $criteria = new completion_criteria_activity(array_merge($params, $params_a));
             $criteria->config_form_display($mform, $activity);
         }
     } else {
         $mform->addElement('static', 'noactivities', '', get_string('err_noactivities', 'completion'));
     }
     // Completion on date
     $mform->addElement('header', 'date', get_string('date'));
     $criteria = new completion_criteria_date($params);
     $criteria->config_form_display($mform);
     // Completion after enrolment duration
     $mform->addElement('header', 'duration', get_string('durationafterenrolment', 'completion'));
     $criteria = new completion_criteria_duration($params);
     $criteria->config_form_display($mform);
     // Completion on course grade
     $mform->addElement('header', 'grade', get_string('grade'));
     // Grade enable and passing grade
     $course_grade = $DB->get_field('grade_items', 'gradepass', array('courseid' => $course->id, 'itemtype' => 'course'));
     $criteria = new completion_criteria_grade($params);
     $criteria->config_form_display($mform, $course_grade);
     // Completion on unenrolment
     $mform->addElement('header', 'unenrolment', get_string('unenrolment', 'completion'));
     $criteria = new completion_criteria_unenrol($params);
     $criteria->config_form_display($mform);
     //--------------------------------------------------------------------------------
     $this->add_action_buttons();
     //--------------------------------------------------------------------------------
     $mform->addElement('hidden', 'id', $course->id);
     $mform->setType('id', PARAM_INT);
     // If the criteria are locked, freeze values and submit button
     if ($completion->is_course_locked()) {
         $except = array('settingsunlock');
         $mform->hardFreezeAllVisibleExcept($except);
         $mform->addElement('cancel');
     }
 }
 /**
  * Add appropriate new criteria options to the form
  *
  */
 public function get_options(&$mform)
 {
     global $DB;
     $none = true;
     $existing = array();
     $missing = array();
     $course = $DB->get_record('course', array('id' => $this->courseid));
     $info = new completion_info($course);
     $mods = $info->get_activities();
     $mids = array_keys($mods);
     if ($this->id !== 0) {
         $existing = array_keys($this->params);
         $missing = array_diff($existing, $mids);
     }
     if (!empty($missing)) {
         $mform->addElement('header', 'category_errors', get_string('criterror', 'badges'));
         $mform->addHelpButton('category_errors', 'criterror', 'badges');
         foreach ($missing as $m) {
             $this->config_options($mform, array('id' => $m, 'checked' => true, 'name' => get_string('error:nosuchmod', 'badges'), 'error' => true));
             $none = false;
         }
     }
     if (!empty($mods)) {
         $mform->addElement('header', 'first_header', $this->get_title());
         foreach ($mods as $mod) {
             $checked = false;
             if (in_array($mod->id, $existing)) {
                 $checked = true;
             }
             $param = array('id' => $mod->id, 'checked' => $checked, 'name' => get_string('modulename', $mod->modname) . ' - ' . $mod->name, 'error' => false);
             if ($this->id !== 0 && isset($this->params[$mod->id]['bydate'])) {
                 $param['bydate'] = $this->params[$mod->id]['bydate'];
             }
             if ($this->id !== 0 && isset($this->params[$mod->id]['grade'])) {
                 $param['grade'] = $this->params[$mod->id]['grade'];
             }
             $this->config_options($mform, $param);
             $none = false;
         }
     }
     // Add aggregation.
     if (!$none) {
         $mform->addElement('header', 'aggregation', get_string('method', 'badges'));
         $agg = array();
         $agg[] =& $mform->createElement('radio', 'agg', '', get_string('allmethodactivity', 'badges'), 1);
         $agg[] =& $mform->createElement('radio', 'agg', '', get_string('anymethodactivity', 'badges'), 2);
         $mform->addGroup($agg, 'methodgr', '', array('<br/>'), false);
         if ($this->id !== 0) {
             $mform->setDefault('agg', $this->method);
         } else {
             $mform->setDefault('agg', BADGE_CRITERIA_AGGREGATION_ANY);
         }
     }
     return array($none, get_string('error:noactivities', 'badges'));
 }
 /**
  * Test badges observer when course module completion event id fired.
  */
 public function test_badges_observer_course_module_criteria_review()
 {
     $this->preventResetByRollback();
     // Messaging is not compatible with transactions.
     $badge = new badge($this->coursebadge);
     $this->assertFalse($badge->is_issued($this->user->id));
     $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id));
     $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY));
     $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_ACTIVITY, 'badgeid' => $badge->id));
     $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY, 'module_' . $this->module->cmid => $this->module->cmid));
     // Set completion for forum activity.
     $c = new completion_info($this->course);
     $activities = $c->get_activities();
     $this->assertEquals(1, count($activities));
     $this->assertTrue(isset($activities[$this->module->cmid]));
     $this->assertEquals($activities[$this->module->cmid]->name, $this->module->name);
     $current = $c->get_data($activities[$this->module->cmid], false, $this->user->id);
     $current->completionstate = COMPLETION_COMPLETE;
     $current->timemodified = time();
     $sink = $this->redirectEmails();
     $c->internal_set_data($activities[$this->module->cmid], $current);
     $this->assertCount(1, $sink->get_messages());
     $sink->close();
     // Check if badge is awarded.
     $this->assertDebuggingCalled('Error baking badge image!');
     $this->assertTrue($badge->is_issued($this->user->id));
 }
                echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'" class="move up">'.
                     '<img src="'.$OUTPUT->pix_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a> ';
            }

            if ($section < $course->numsections) {    // Add a arrow to move section down
                echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'" class="move down">'.
                     '<img src="'.$OUTPUT->pix_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a> ';
            }
        }
      echo '</div>' . "\n";
	  
      
      // Match topics format behaviour where help is hidden if there is no completion activities
      // But do this per section.
      $completioninfo = new completion_info($course);
      $activitieswithcompletion = $completioninfo->get_activities();
      $hasCompletionActivites = false;
      foreach($activitieswithcompletion as $activity){
      	if($activity->section == $thissection->id){
        	$hasCompletionActivites = true;
        }
      }
      if ($hasCompletionActivites)
          $completioninfo->print_help_icon();
      
     /*
      * CONTENT
      */
      echo '<div class="content">';
          
            
     $stage->roadid = $roadid;
 }
 if (!isset($stage->questiontext) || $stage->questiontext === '') {
     $stage->addsimplequestion = optional_param('addsimplequestion', 0, PARAM_INT);
     $stage->noanswers = optional_param('noanswers', 2, PARAM_INT);
     if (!empty($addanswers)) {
         $stage->noanswers += NUMBER_NEW_ANSWERS;
     }
 }
 $stage->cmid = $cmid;
 $returnurl = new moodle_url('/mod/treasurehunt/edit.php', array('id' => $cmid, 'roadid' => $stage->roadid));
 $maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
 $editoroptions = array('trusttext' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes, 'context' => $context, 'subdirs' => file_area_contains_subdirs($context, 'mod_treasurehunt', 'cluetext', $stage->id));
 // List activities with Completion enabled
 $completioninfo = new completion_info($course);
 $completionactivities = $completioninfo->get_activities();
 $mform = new stage_form(null, array('current' => $stage, 'context' => $context, 'editoroptions' => $editoroptions, 'completionactivities' => $completionactivities));
 //name of the form you defined in file above.
 if ($mform->is_reloaded()) {
     // Si se ha recargado es porque hemos cambiado algo
 } else {
     if ($mform->is_cancelled()) {
         // You need this section if you have a cancel button on your form
         // here you tell php what to do if your user presses cancel
         // probably a redirect is called for!
         // PLEASE NOTE: is_cancelled() should be called before get_data().
         redirect($returnurl);
     } else {
         if ($stage = $mform->get_data()) {
             // Actualizamos los campos
             $timenow = time();
Beispiel #14
0
 /**
  * Defines the form fields.
  */
 public function definition()
 {
     global $USER, $CFG, $DB;
     $courseconfig = get_config('moodlecourse');
     $mform = $this->_form;
     $course = $this->_customdata['course'];
     $completion = new completion_info($course);
     $params = array('course' => $course->id);
     // Check if there are existing criteria completions.
     if ($completion->is_course_locked()) {
         $mform->addElement('header', 'completionsettingslocked', get_string('completionsettingslocked', 'completion'));
         $mform->addElement('static', '', '', get_string('err_settingslocked', 'completion'));
         $mform->addElement('submit', 'settingsunlock', get_string('unlockcompletiondelete', 'completion'));
     }
     // Get array of all available aggregation methods.
     $aggregation_methods = $completion->get_aggregation_methods();
     // Overall criteria aggregation.
     $mform->addElement('header', 'overallcriteria', get_string('general', 'core_form'));
     // Map aggregation methods to context-sensitive human readable dropdown menu.
     $overallaggregationmenu = array();
     foreach ($aggregation_methods as $methodcode => $methodname) {
         if ($methodcode === COMPLETION_AGGREGATION_ALL) {
             $overallaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('overallaggregation_all', 'core_completion');
         } else {
             if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                 $overallaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('overallaggregation_any', 'core_completion');
             } else {
                 $overallaggregationmenu[$methodcode] = $methodname;
             }
         }
     }
     $mform->addElement('select', 'overall_aggregation', get_string('overallaggregation', 'core_completion'), $overallaggregationmenu);
     $mform->setDefault('overall_aggregation', $completion->get_aggregation_method());
     // Activity completion criteria
     $label = get_string('coursecompletioncondition', 'core_completion', get_string('activitiescompleted', 'core_completion'));
     $mform->addElement('header', 'activitiescompleted', $label);
     // Get the list of currently specified conditions and expand the section if some are found.
     $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ACTIVITY);
     if (!empty($current)) {
         $mform->setExpanded('activitiescompleted');
     }
     $activities = $completion->get_activities();
     if (!empty($activities)) {
         if (!$completion->is_course_locked()) {
             $this->add_checkbox_controller(1, null, null, 0);
         }
         foreach ($activities as $activity) {
             $params_a = array('moduleinstance' => $activity->id);
             $criteria = new completion_criteria_activity(array_merge($params, $params_a));
             $criteria->config_form_display($mform, $activity);
         }
         $mform->addElement('static', 'criteria_role_note', '', get_string('activitiescompletednote', 'core_completion'));
         if (count($activities) > 1) {
             // Map aggregation methods to context-sensitive human readable dropdown menu.
             $activityaggregationmenu = array();
             foreach ($aggregation_methods as $methodcode => $methodname) {
                 if ($methodcode === COMPLETION_AGGREGATION_ALL) {
                     $activityaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('activityaggregation_all', 'core_completion');
                 } else {
                     if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                         $activityaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('activityaggregation_any', 'core_completion');
                     } else {
                         $activityaggregationmenu[$methodcode] = $methodname;
                     }
                 }
             }
             $mform->addElement('select', 'activity_aggregation', get_string('activityaggregation', 'core_completion'), $activityaggregationmenu);
             $mform->setDefault('activity_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ACTIVITY));
         }
     } else {
         $mform->addElement('static', 'noactivities', '', get_string('err_noactivities', 'completion'));
     }
     // Course prerequisite completion criteria.
     $label = get_string('coursecompletioncondition', 'core_completion', get_string('dependenciescompleted', 'core_completion'));
     $mform->addElement('header', 'courseprerequisites', $label);
     // Get the list of currently specified conditions and expand the section if some are found.
     $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_COURSE);
     if (!empty($current)) {
         $mform->setExpanded('courseprerequisites');
     }
     // Get applicable courses (prerequisites).
     $courses = $DB->get_records_sql("\n                SELECT DISTINCT c.id, c.category, c.fullname, cc.id AS selected\n                  FROM {course} c\n             LEFT JOIN {course_completion_criteria} cc ON cc.courseinstance = c.id AND cc.course = {$course->id}\n            INNER JOIN {course_completion_criteria} ccc ON ccc.course = c.id\n                 WHERE c.enablecompletion = " . COMPLETION_ENABLED . "\n                       AND c.id <> {$course->id}");
     if (!empty($courses)) {
         // Get category list.
         require_once $CFG->libdir . '/coursecatlib.php';
         $list = coursecat::make_categories_list();
         // Get course list for select box.
         $selectbox = array();
         $selected = array();
         foreach ($courses as $c) {
             $selectbox[$c->id] = $list[$c->category] . ' / ' . format_string($c->fullname, true, array('context' => context_course::instance($c->id)));
             // If already selected ...
             if ($c->selected) {
                 $selected[] = $c->id;
             }
         }
         // Show multiselect box.
         $mform->addElement('select', 'criteria_course', get_string('coursesavailable', 'completion'), $selectbox, array('multiple' => 'multiple', 'size' => 6));
         // Select current criteria.
         $mform->setDefault('criteria_course', $selected);
         // Explain list.
         $mform->addElement('static', 'criteria_courses_explaination', '', get_string('coursesavailableexplaination', 'completion'));
         if (count($courses) > 1) {
             // Map aggregation methods to context-sensitive human readable dropdown menu.
             $courseaggregationmenu = array();
             foreach ($aggregation_methods as $methodcode => $methodname) {
                 if ($methodcode === COMPLETION_AGGREGATION_ALL) {
                     $courseaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('courseaggregation_all', 'core_completion');
                 } else {
                     if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                         $courseaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('courseaggregation_any', 'core_completion');
                     } else {
                         $courseaggregationmenu[$methodcode] = $methodname;
                     }
                 }
             }
             $mform->addElement('select', 'course_aggregation', get_string('courseaggregation', 'core_completion'), $courseaggregationmenu);
             $mform->setDefault('course_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_COURSE));
         }
     } else {
         $mform->addElement('static', 'nocourses', '', get_string('err_nocourses', 'completion'));
     }
     // Completion on date
     $label = get_string('coursecompletioncondition', 'core_completion', get_string('completionondate', 'core_completion'));
     $mform->addElement('header', 'date', $label);
     // Expand the condition section if it is currently enabled.
     $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_DATE);
     if (!empty($current)) {
         $mform->setExpanded('date');
     }
     $criteria = new completion_criteria_date($params);
     $criteria->config_form_display($mform);
     // Completion after enrolment duration
     $label = get_string('coursecompletioncondition', 'core_completion', get_string('enrolmentduration', 'core_completion'));
     $mform->addElement('header', 'duration', $label);
     // Expand the condition section if it is currently enabled.
     $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_DURATION);
     if (!empty($current)) {
         $mform->setExpanded('duration');
     }
     $criteria = new completion_criteria_duration($params);
     $criteria->config_form_display($mform);
     // Completion on unenrolment
     $label = get_string('coursecompletioncondition', 'core_completion', get_string('unenrolment', 'core_completion'));
     $mform->addElement('header', 'unenrolment', $label);
     // Expand the condition section if it is currently enabled.
     $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_UNENROL);
     if (!empty($current)) {
         $mform->setExpanded('unenrolment');
     }
     $criteria = new completion_criteria_unenrol($params);
     $criteria->config_form_display($mform);
     // Completion on course grade
     $label = get_string('coursecompletioncondition', 'core_completion', get_string('coursegrade', 'core_completion'));
     $mform->addElement('header', 'grade', $label);
     // Expand the condition section if it is currently enabled.
     $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_GRADE);
     if (!empty($current)) {
         $mform->setExpanded('grade');
     }
     $course_grade = $DB->get_field('grade_items', 'gradepass', array('courseid' => $course->id, 'itemtype' => 'course'));
     if (!$course_grade) {
         $course_grade = '0.00000';
     }
     $criteria = new completion_criteria_grade($params);
     $criteria->config_form_display($mform, $course_grade);
     // Manual self completion
     $label = get_string('coursecompletioncondition', 'core_completion', get_string('manualselfcompletion', 'core_completion'));
     $mform->addElement('header', 'manualselfcompletion', $label);
     // Expand the condition section if it is currently enabled.
     $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_SELF);
     if (!empty($current)) {
         $mform->setExpanded('manualselfcompletion');
     }
     $criteria = new completion_criteria_self($params);
     $criteria->config_form_display($mform);
     $mform->addElement('static', 'criteria_self_note', '', get_string('manualselfcompletionnote', 'core_completion'));
     // Role completion criteria
     $label = get_string('coursecompletioncondition', 'core_completion', get_string('manualcompletionby', 'core_completion'));
     $mform->addElement('header', 'roles', $label);
     // Expand the condition section if it is currently enabled.
     $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ROLE);
     if (!empty($current)) {
         $mform->setExpanded('roles');
     }
     $roles = get_roles_with_capability('moodle/course:markcomplete', CAP_ALLOW, context_course::instance($course->id, IGNORE_MISSING));
     if (!empty($roles)) {
         foreach ($roles as $role) {
             $params_a = array('role' => $role->id);
             $criteria = new completion_criteria_role(array_merge($params, $params_a));
             $criteria->config_form_display($mform, $role);
         }
         $mform->addElement('static', 'criteria_role_note', '', get_string('manualcompletionbynote', 'core_completion'));
         // Map aggregation methods to context-sensitive human readable dropdown menu.
         $roleaggregationmenu = array();
         foreach ($aggregation_methods as $methodcode => $methodname) {
             if ($methodcode === COMPLETION_AGGREGATION_ALL) {
                 $roleaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('roleaggregation_all', 'core_completion');
             } else {
                 if ($methodcode === COMPLETION_AGGREGATION_ANY) {
                     $roleaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('roleaggregation_any', 'core_completion');
                 } else {
                     $roleaggregationmenu[$methodcode] = $methodname;
                 }
             }
         }
         $mform->addElement('select', 'role_aggregation', get_string('roleaggregation', 'core_completion'), $roleaggregationmenu);
         $mform->setDefault('role_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ROLE));
     } else {
         $mform->addElement('static', 'noroles', '', get_string('err_noroles', 'completion'));
     }
     // Add common action buttons.
     $this->add_action_buttons();
     // Add hidden fields.
     $mform->addElement('hidden', 'id', $course->id);
     $mform->setType('id', PARAM_INT);
     // If the criteria are locked, freeze values and submit button.
     if ($completion->is_course_locked()) {
         $except = array('settingsunlock');
         $mform->hardFreezeAllVisibleExcept($except);
         $mform->addElement('cancel');
     }
 }