Skip to content

Commit

Permalink
Merge branch 'w38_MDL-35465_m24_cohortscleanup' of git://github.com/s…
Browse files Browse the repository at this point in the history
…kodak/moodle
  • Loading branch information
stronk7 committed Sep 18, 2012
2 parents 7783373 + 960931d commit 5ceded2
Show file tree
Hide file tree
Showing 10 changed files with 615 additions and 206 deletions.
15 changes: 5 additions & 10 deletions cohort/assign.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand All @@ -18,14 +17,13 @@
/**
* Cohort related management functions, this file needs to be included manually.
*
* @package core
* @subpackage cohort
* @package core_cohort
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once('../config.php');
require_once($CFG->dirroot.'/cohort/lib.php');
require('../config.php');
require_once($CFG->dirroot.'/cohort/locallib.php');

$id = required_param('id', PARAM_INT);

Expand All @@ -42,7 +40,7 @@
$returnurl = new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid));

if (!empty($cohort->component)) {
// we can not manually edit cohorts that were created by external systems, sorry
// We can not manually edit cohorts that were created by external systems, sorry.
redirect($returnurl);
}

Expand Down Expand Up @@ -80,10 +78,7 @@
if (!empty($userstoassign)) {

foreach ($userstoassign as $adduser) {
// no duplicates please
if (!$DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$adduser->id))) {
cohort_add_member($cohort->id, $adduser->id);
}
cohort_add_member($cohort->id, $adduser->id);
}

$potentialuserselector->invalidate_selected_users();
Expand Down
13 changes: 5 additions & 8 deletions cohort/edit.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand All @@ -15,12 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.


/**
* Cohort related management functions, this file needs to be included manually.
*
* @package core
* @subpackage cohort
* @package core_cohort
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand Down Expand Up @@ -58,7 +55,7 @@
$returnurl = new moodle_url('/cohort/index.php', array('contextid'=>$context->id));

if (!empty($cohort->component)) {
// we can not manually edit cohorts that were created by external systems, sorry
// We can not manually edit cohorts that were created by external systems, sorry.
redirect($returnurl);
}

Expand Down Expand Up @@ -97,12 +94,12 @@

$editoroptions = array('maxfiles'=>0, 'context'=>$context);
if ($cohort->id) {
// edit existing
// Edit existing.
$cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions, $context);
$strheading = get_string('editcohort', 'cohort');

} else {
// add new
// Add new.
$cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions, $context);
$strheading = get_string('addcohort', 'cohort');
}
Expand All @@ -125,7 +122,7 @@
cohort_add_cohort($data);
}

// use new context id, it could have been changed
// Use new context id, it could have been changed.
redirect(new moodle_url('/cohort/index.php', array('contextid'=>$data->contextid)));
}

Expand Down
18 changes: 7 additions & 11 deletions cohort/edit_form.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand All @@ -18,15 +17,12 @@
/**
* Cohort related management functions, this file needs to be included manually.
*
* @package core
* @subpackage cohort
* @package core_cohort
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/lib/formslib.php');

Expand All @@ -49,7 +45,7 @@ public function definition() {
$mform->addElement('select', 'contextid', get_string('context', 'role'), $options);

$mform->addElement('text', 'idnumber', get_string('idnumber', 'cohort'), 'maxlength="254" size="50"');
$mform->setType('idnumber', PARAM_RAW); // idnumbers are plain text, must not be changed
$mform->setType('idnumber', PARAM_RAW); // Idnumbers are plain text, must not be changed.

$mform->addElement('editor', 'description_editor', get_string('description', 'cohort'), null, $editoroptions);
$mform->setType('description_editor', PARAM_RAW);
Expand All @@ -69,7 +65,7 @@ public function validation($data, $files) {

$idnumber = trim($data['idnumber']);
if ($idnumber === '') {
// fine, empty is ok
// Fine, empty is ok.

} else if ($data['id']) {
$current = $DB->get_record('cohort', array('id'=>$data['id']), '*', MUST_EXIST);
Expand All @@ -95,16 +91,16 @@ protected function get_category_options($currentcontextid) {
$options = array();
$syscontext = context_system::instance();
if (has_capability('moodle/cohort:manage', $syscontext)) {
$options[$syscontext->id] = print_context_name($syscontext);
$options[$syscontext->id] = $syscontext->get_context_name();
}
foreach ($displaylist as $cid=>$name) {
$context = context_coursecat::instance($cid);
$options[$context->id] = $name;
}
// always add current - this is not likely, but if the logic gets changed it might be a problem
// Always add current - this is not likely, but if the logic gets changed it might be a problem.
if (!isset($options[$currentcontextid])) {
$context = context::instance_by_id($currentcontextid, MUST_EXIST);
$options[$context->id] = print_context_name($syscontext);
$options[$context->id] = $syscontext->get_context_name();
}
return $options;
}
Expand Down
28 changes: 18 additions & 10 deletions cohort/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand All @@ -18,8 +17,7 @@
/**
* Cohort related management functions, this file needs to be included manually.
*
* @package core
* @subpackage cohort
* @package core_cohort
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand Down Expand Up @@ -69,21 +67,31 @@

echo $OUTPUT->header();

echo $OUTPUT->heading(get_string('cohortsin', 'cohort', print_context_name($context)));
$cohorts = cohort_get_cohorts($context->id, $page, 25, $searchquery);

$count = '';
if ($cohorts['allcohorts'] > 0) {
if ($searchquery === '') {
$count = ' ('.$cohorts['allcohorts'].')';
} else {
$count = ' ('.$cohorts['totalcohorts'].'/'.$cohorts['allcohorts'].')';
}
}

echo $OUTPUT->heading(get_string('cohortsin', 'cohort', $context->get_context_name()).$count);

// add search form
// Add search form.
$search = html_writer::start_tag('form', array('id'=>'searchcohortquery', 'method'=>'get'));
$search .= html_writer::start_tag('div');
$search .= html_writer::label(get_string('searchcohort', 'cohort').':', 'cohort_search_q');
$search .= html_writer::label(get_string('searchcohort', 'cohort'), 'cohort_search_q'); // No : in form labels!
$search .= html_writer::empty_tag('input', array('id'=>'cohort_search_q', 'type'=>'text', 'name'=>'search', 'value'=>$searchquery));
$search .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('search', 'cohort')));
$search .= html_writer::end_tag('div');
$search .= html_writer::end_tag('form');
echo $search;

$cohorts = cohort_get_cohorts($context->id, $page, 25, $searchquery);

// output pagination bar
// Output pagination bar.
$params = array('page' => $page);
if ($contextid) {
$params['contextid'] = $contextid;
Expand All @@ -98,7 +106,7 @@
foreach($cohorts['cohorts'] as $cohort) {
$line = array();
$line[] = format_string($cohort->name);
$line[] = s($cohort->idnumber); // plain text
$line[] = s($cohort->idnumber); // All idnumbers are plain text.
$line[] = format_text($cohort->description, $cohort->descriptionformat);

$line[] = $DB->count_records('cohort_members', array('cohortid'=>$cohort->id));
Expand Down Expand Up @@ -137,4 +145,4 @@
echo $OUTPUT->single_button(new moodle_url('/cohort/edit.php', array('contextid'=>$context->id)), get_string('add'));
}

echo $OUTPUT->footer();
echo $OUTPUT->footer();
Loading

0 comments on commit 5ceded2

Please sign in to comment.