Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/cohort/index.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 require('../config.php');
00028 require($CFG->dirroot.'/cohort/lib.php');
00029 require_once($CFG->libdir.'/adminlib.php');
00030 
00031 $contextid = optional_param('contextid', 0, PARAM_INT);
00032 $page = optional_param('page', 0, PARAM_INT);
00033 $searchquery  = optional_param('search', '', PARAM_RAW);
00034 
00035 require_login();
00036 
00037 if ($contextid) {
00038     $context = get_context_instance_by_id($contextid, MUST_EXIST);
00039 } else {
00040     $context = get_context_instance(CONTEXT_SYSTEM);
00041 }
00042 
00043 if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
00044     print_error('invalidcontext');
00045 }
00046 
00047 $category = null;
00048 if ($context->contextlevel == CONTEXT_COURSECAT) {
00049     $category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST);
00050 }
00051 
00052 $manager = has_capability('moodle/cohort:manage', $context);
00053 $canassign = has_capability('moodle/cohort:assign', $context);
00054 if (!$manager) {
00055     require_capability('moodle/cohort:view', $context);
00056 }
00057 
00058 $strcohorts = get_string('cohorts', 'cohort');
00059 
00060 if ($category) {
00061     $PAGE->set_pagelayout('report');
00062     $PAGE->set_context($context);
00063     $PAGE->set_url('/cohort/index.php', array('contextid'=>$context->id));
00064     $PAGE->set_title($strcohorts);
00065     $PAGE->set_heading($COURSE->fullname);
00066 } else {
00067     admin_externalpage_setup('cohorts', '', null, '', array('pagelayout'=>'report'));
00068 }
00069 
00070 echo $OUTPUT->header();
00071 
00072 echo $OUTPUT->heading(get_string('cohortsin', 'cohort', print_context_name($context)));
00073 
00074 // add search form
00075 $search  = html_writer::start_tag('form', array('id'=>'searchcohortquery', 'method'=>'get'));
00076 $search .= html_writer::start_tag('div');
00077 $search .= html_writer::label(get_string('searchcohort', 'cohort').':', 'cohort_search_q');
00078 $search .= html_writer::empty_tag('input', array('id'=>'cohort_search_q', 'type'=>'text', 'name'=>'search', 'value'=>$searchquery));
00079 $search .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('search', 'cohort')));
00080 $search .= html_writer::end_tag('div');
00081 $search .= html_writer::end_tag('form');
00082 echo $search;
00083 
00084 $cohorts = cohort_get_cohorts($context->id, $page, 25, $searchquery);
00085 
00086 // output pagination bar
00087 $params = array('page' => $page);
00088 if ($contextid) {
00089     $params['contextid'] = $contextid;
00090 }
00091 if ($search) {
00092     $params['search'] = $searchquery;
00093 }
00094 $baseurl = new moodle_url('/cohort/index.php', $params);
00095 echo $OUTPUT->paging_bar($cohorts['totalcohorts'], $page, 25, $baseurl);
00096 
00097 $data = array();
00098 foreach($cohorts['cohorts'] as $cohort) {
00099     $line = array();
00100     $line[] = format_string($cohort->name);
00101     $line[] = $cohort->idnumber;
00102     $line[] = format_text($cohort->description, $cohort->descriptionformat);
00103 
00104     $line[] = $DB->count_records('cohort_members', array('cohortid'=>$cohort->id));
00105 
00106     if (empty($cohort->component)) {
00107         $line[] = get_string('nocomponent', 'cohort');
00108     } else {
00109         $line[] = get_string('pluginname', $cohort->component);
00110     }
00111 
00112     $buttons = array();
00113     if (empty($cohort->component)) {
00114         if ($manager) {
00115             $buttons[] = html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id, 'delete'=>1)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/delete'), 'alt'=>get_string('delete'), 'class'=>'iconsmall')));
00116             $buttons[] =  html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/edit'), 'alt'=>get_string('edit'), 'class'=>'iconsmall')));
00117         }
00118         if ($manager or $canassign) {
00119             $buttons[] = html_writer::link(new moodle_url('/cohort/assign.php', array('id'=>$cohort->id)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('i/users'), 'alt'=>get_string('assign', 'core_cohort'), 'class'=>'iconsmall')));
00120         }
00121     }
00122     $line[] = implode(' ', $buttons);
00123 
00124     $data[] = $line;
00125 }
00126 $table = new html_table();
00127 $table->head  = array(get_string('name', 'cohort'), get_string('idnumber', 'cohort'), get_string('description', 'cohort'),
00128                       get_string('memberscount', 'cohort'), get_string('component', 'cohort'), get_string('edit'));
00129 $table->size  = array('20%', '10%', '40%', '10%', '10%', '10%');
00130 $table->align = array('left', 'left', 'left', 'left','center', 'center');
00131 $table->width = '80%';
00132 $table->data  = $data;
00133 echo html_writer::table($table);
00134 echo $OUTPUT->paging_bar($cohorts['totalcohorts'], $page, 25, $baseurl);
00135 
00136 if ($manager) {
00137     echo $OUTPUT->single_button(new moodle_url('/cohort/edit.php', array('contextid'=>$context->id)), get_string('add'));
00138 }
00139 
00140 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations