MDL-35465 improve cohorts coding style

This commit is contained in:
Petr Škoda 2012-09-16 21:38:28 +02:00
parent 2f8c69e199
commit 6eb8bf7f3a
6 changed files with 31 additions and 40 deletions

View File

@ -17,13 +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
*/
require_once('../config.php');
require('../config.php');
require_once($CFG->dirroot.'/cohort/locallib.php');
$id = required_param('id', PARAM_INT);
@ -41,7 +40,7 @@ $PAGE->set_url('/cohort/assign.php', array('id'=>$id));
$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);
}

View File

@ -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
@ -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
*/
@ -58,7 +55,7 @@ require_capability('moodle/cohort:manage', $context);
$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);
}
@ -97,12 +94,12 @@ if ($delete and $cohort->id) {
$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');
}
@ -125,7 +122,7 @@ if ($editform->is_cancelled()) {
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)));
}

View File

@ -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
@ -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');
@ -49,7 +45,7 @@ class cohort_edit_form extends moodleform {
$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);
@ -69,7 +65,7 @@ class cohort_edit_form extends moodleform {
$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);
@ -95,16 +91,16 @@ class cohort_edit_form extends moodleform {
$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;
}

View File

@ -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
@ -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
*/
@ -71,10 +69,10 @@ echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('cohortsin', 'cohort', print_context_name($context)));
// 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');
@ -83,7 +81,7 @@ 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;
@ -98,7 +96,7 @@ $data = array();
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));
@ -137,4 +135,4 @@ if ($manager) {
echo $OUTPUT->single_button(new moodle_url('/cohort/edit.php', array('contextid'=>$context->id)), get_string('add'));
}
echo $OUTPUT->footer();
echo $OUTPUT->footer();

View File

@ -27,8 +27,8 @@ defined('MOODLE_INTERNAL') || die();
/**
* Add new cohort.
*
* @param object $cohort
* @return int
* @param stdClass $cohort
* @return int new cohort id
*/
function cohort_add_cohort($cohort) {
global $DB;
@ -65,7 +65,7 @@ function cohort_add_cohort($cohort) {
/**
* Update existing cohort.
* @param object $cohort
* @param stdClass $cohort
* @return void
*/
function cohort_update_cohort($cohort) {
@ -82,7 +82,7 @@ function cohort_update_cohort($cohort) {
/**
* Delete cohort.
* @param object $cohort
* @param stdClass $cohort
* @return void
*/
function cohort_delete_cohort($cohort) {
@ -102,7 +102,7 @@ function cohort_delete_cohort($cohort) {
* Somehow deal with cohorts when deleting course category,
* we can not just delete them because they might be used in enrol
* plugins or referenced in external systems.
* @param object $category
* @param stdClass $category
* @return void
*/
function cohort_delete_category($category) {

View File

@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/cohot/lib.php');
require_once($CFG->dirroot . '/user/selector/lib.php');
/**
* Cohort assignment candidates
*/
@ -40,12 +41,12 @@ class cohort_candidate_selector extends user_selector_base {
/**
* Candidate users
* @param <type> $search
* @param string $search
* @return array
*/
public function find_users($search) {
global $DB;
//by default wherecondition retrieves all users except the deleted, not confirmed and guest
// By default wherecondition retrieves all users except the deleted, not confirmed and guest.
list($wherecondition, $params) = $this->search_sql($search, 'u');
$params['cohortid'] = $this->cohortid;
@ -103,12 +104,12 @@ class cohort_existing_selector extends user_selector_base {
/**
* Candidate users
* @param <type> $search
* @param string $search
* @return array
*/
public function find_users($search) {
global $DB;
//by default wherecondition retrieves all users except the deleted, not confirmed and guest
// By default wherecondition retrieves all users except the deleted, not confirmed and guest.
list($wherecondition, $params) = $this->search_sql($search, 'u');
$params['cohortid'] = $this->cohortid;