Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
MDL-35465 improve cohorts coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 16, 2012
1 parent 2f8c69e commit 6eb8bf7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 40 deletions.
7 changes: 3 additions & 4 deletions cohort/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -41,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
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
14 changes: 6 additions & 8 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 @@ -71,10 +69,10 @@

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');
Expand All @@ -83,7 +81,7 @@

$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 +96,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 +135,4 @@
echo $OUTPUT->single_button(new moodle_url('/cohort/edit.php', array('contextid'=>$context->id)), get_string('add'));
}

echo $OUTPUT->footer();
echo $OUTPUT->footer();
10 changes: 5 additions & 5 deletions cohort/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
/**
* Add new cohort.
*
* @param object $cohort
* @return int
* @param stdClass $cohort
* @return int new cohort id
*/
function cohort_add_cohort($cohort) {
global $DB;
Expand Down Expand Up @@ -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) {
Expand All @@ -82,7 +82,7 @@ function cohort_update_cohort($cohort) {

/**
* Delete cohort.
* @param object $cohort
* @param stdClass $cohort
* @return void
*/
function cohort_delete_cohort($cohort) {
Expand All @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions cohort/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
require_once($CFG->dirroot . '/cohot/lib.php');
require_once($CFG->dirroot . '/user/selector/lib.php');


/**
* Cohort assignment candidates
*/
Expand All @@ -40,12 +41,12 @@ public function __construct($name, $options) {

/**
* 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;

Expand Down Expand Up @@ -103,12 +104,12 @@ public function __construct($name, $options) {

/**
* 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;

Expand Down

0 comments on commit 6eb8bf7

Please sign in to comment.