diff --git a/blocks/participants/block_participants.php b/blocks/participants/block_participants.php index 9d35b482009..da124328c35 100644 --- a/blocks/participants/block_participants.php +++ b/blocks/participants/block_participants.php @@ -35,15 +35,6 @@ class block_participants extends block_list { $this->content->items[] = ''.get_string('participants').''; $this->content->icons[] = ''; - - if (isteacher($this->instance->pageid)) { - $strparticipation = get_string('participationreport'); - $this->content->items[] = ''.$strparticipation.''; - $this->content->icons[] = ''; - - } - } diff --git a/course/report/participation/index.php b/course/report/participation/index.php new file mode 100644 index 00000000000..e2bde1284a6 --- /dev/null +++ b/course/report/participation/index.php @@ -0,0 +1,354 @@ +id); + + if (!isteacher($course->id)) { + print_error('mustbeteacher',$CFG->wwwroot.'/course/view.php?id='.$course->id); + } + + $strparticipation = get_string('participationreport'); + $strviews = get_string('views'); + $strposts = get_string('posts'); + $strview = get_string('view'); + $strpost = get_string('post'); + $strallactions = get_string('allactions'); + $strreports = get_string('reports'); + + $strnav = "id\">$course->shortname -> + id\">$strreports -> ". $strparticipation; + + print_header($course->fullname.' '.$strparticipation,$strparticipation,$strnav); + + $allowedmodules = array('assignment','book','chat','choice','exercise','forum','glossary','hotpot', + 'journal','lesson','questionnaire','quiz','resource','scorm', + 'survey','wiki','workshop'); // some don't make sense here - eg 'label' + + if (!$modules = get_records_sql('SELECT DISTINCT module,name FROM '.$CFG->prefix.'course_modules cm JOIN '. + $CFG->prefix.'modules m ON cm.module = m.id WHERE course = '.$course->id)) { + print_error('noparticipatorycms',$CFG->wwwroot.'/course/view.php?id='.$course->id); + } + + + $modoptions = array(); + foreach ($modules as $m) { + if (in_array($m->name,$allowedmodules)) { + $modoptions[$m->module] = get_string('modulename',$m->name); + } + } + + $timeoptions = array(); + // get minimum log time for this course + $minlog = get_field_sql('SELECT min(time) FROM '.$CFG->prefix.'log WHERE course = '.$course->id); + + $now = usergetmidnight(time()); + + // days + for ($i = 1; $i < 7; $i++) { + if (strtotime('-'.$i.' days',$now) >= $minlog) { + $timeoptions[strtotime('-'.$i.' days',$now)] = get_string('numdays','moodle',$i); + } + } + // weeks + for ($i = 1; $i < 10; $i++) { + if (strtotime('-'.$i.' weeks',$now) >= $minlog) { + $timeoptions[strtotime('-'.$i.' weeks',$now)] = get_string('numweeks','moodle',$i); + } + } + // months + for ($i = 2; $i < 12; $i++) { + if (strtotime('-'.$i.' months',$now) >= $minlog) { + $timeoptions[strtotime('-'.$i.' months',$now)] = get_string('nummonths','moodle',$i); + } + } + // try a year + if (strtotime('-1 year',$now) >= $minlog) { + $timeoptions[strtotime('-1 year',$now)] = get_string('lastyear'); + } + + $useroptions = array(0 => $course->students, + 1 => $course->teachers, + ); + + $actionoptions = array('' => $strallactions, + 'view' => $strview, + 'post' => $strpost, + ); + + + // print first controls. + echo '
'."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + "
\n". + get_string('activitymodule').' '; + choose_from_menu($modoptions,'moduleid',$moduleid); + echo "\n". + get_string('lookback').' '; + choose_from_menu($timeoptions,'timefrom',$timefrom); + echo "". + get_string('showonly').' '; + choose_from_menu($useroptions,'teachers',$teachers,''); + echo "\n". + get_string('showactions'),' '; + choose_from_menu($actionoptions,'action',$action,''); + echo ''; + helpbutton('participationreport',get_string('participationreport')); + echo + ''."\n". + "
\n". + "
\n"; + + if (empty($moduleid)) { + notify(get_string('selectamodule')); + print_footer(); + exit; + } + + $baseurl = $CFG->wwwroot.'/course/participation.php?id='.$course->id.'&teachers=' + .$teachers.'&instanceid='.$instanceid.'&timefrom='.$timefrom.'&moduleid=' + .$moduleid.'&action='.$action.'&perpage='.$perpage; + + + // from here assume we have at least the module we're using. + $module = get_record('modules','id',$moduleid); + $modulename = get_string('modulename',$module->name); + + require_once($CFG->dirroot.'/mod/'.$module->name.'/lib.php'); + + $viewfun = $module->name.'_get_view_actions'; + $postfun = $module->name.'_get_post_actions'; + + if (!function_exists($viewfun) || !function_exists($postfun)) { + error(get_string('modulemisssingcode','error',$module->name),$baseurl); + } + + $viewnames = $viewfun(); + $postnames = $postfun(); + + // get all instances of this module in the course. + if (!$instances = get_all_instances_in_course($module->name,$course)) { + error(get_string('noinstances','error',$modulename)); + } + + $instanceoptions = array(); + + foreach ($instances as $instance) { + $instanceoptions[$instance->id] = $instance->name; + } + + if (count($instanceoptions) == 1) { // just display it if there's only one. + $instanceid = array_pop(array_keys($instanceoptions)); + } + + echo '
'. + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + '
'; + choose_from_menu($instanceoptions,'instanceid',$instanceid); + echo '
'."\n". + "
\n"; + + if (!empty($instanceid)) { + if (!$cm = get_coursemodule_from_instance($module->name,$instanceid,$course->id)) { + print_error('cmunknown'); + } + + require_once($CFG->dirroot.'/lib/tablelib.php'); + $table = new flexible_table('course-participation-'.$course->id.'-'.$cm->id.'-'.$teachers); + $table->course = $course; + + $table->define_columns(array('fullname','count','')); + $table->define_headers(array(get_string('user'),((!empty($action)) ? get_string($action) : get_string('allactions')),get_string('select'))); + $table->define_baseurl($baseurl); + + $table->set_attribute('align','center'); + $table->set_attribute('cellpadding','5'); + $table->set_attribute('class', 'generaltable generalbox'); + + $table->sortable(true,'lastname','ASC'); + + $table->set_control_variables(array( + TABLE_VAR_SORT => 'ssort', + TABLE_VAR_HIDE => 'shide', + TABLE_VAR_SHOW => 'sshow', + TABLE_VAR_IFIRST => 'sifirst', + TABLE_VAR_ILAST => 'silast', + TABLE_VAR_PAGE => 'spage' + )); + $table->setup(); + + + + $sql = 'SELECT DISTINCT e.userid, u.firstname,u.lastname,u.idnumber,u.nickname,count(l.action) as count FROM ' + . $CFG->prefix.'user_'.((!empty($teachers)) ? 'teachers' : 'students').' e ' + .' JOIN '.$CFG->prefix.'user u ON u.id = e.userid LEFT JOIN '.$CFG->prefix.'log l ON e.userid = l.userid ' + .' AND e.course = l.course AND l.time > '.$timefrom.' AND l.course = '.$course->id.' AND l.module = \''.$module->name.'\' ' + .' AND l.cmid = '.$cm->id; + switch ($action) { + case 'view': + $sql .= ' AND action IN (\''.implode('\',\'',$viewnames).'\' )'; + break; + case 'post': + $sql .= ' AND action IN (\''.implode('\',\'',$postnames).'\' )'; + break; + default: + // some modules have stuff we want to hide, ie mail blocked etc so do actually need to limit here. + $sql .= ' AND action IN (\''.implode('\',\'',array_merge($viewnames,$postnames)).'\' )'; + + } + + $sql .= ' WHERE e.course = '.$course->id; + + if ($table->get_sql_where()) { + $sql .= ' AND '.$table->get_sql_where(); //initial bar + } + + $sql .= ' GROUP BY e.userid,u.firstname,u.lastname,u.idnumber,u.nickname,l.userid'; + + if ($table->get_sql_sort()) { + $sql .= ' ORDER BY '.$table->get_sql_sort(); + } + + $countsql = 'SELECT COUNT(DISTINCT(e.userid)) FROM '.$CFG->prefix.'user_'.((!empty($teachers)) ? 'teachers' : 'students').' e ' + .' JOIN '.$CFG->prefix.'user u ON u.id = e.userid WHERE e.course = '.$course->id; + + $totalcount = count_records_sql($countsql); + + if ($table->get_sql_where()) { + $matchcount = count_records_sql($countsql.' AND '.$table->get_sql_where()); + } else { + $matchcount = $totalcount; + } + + echo '

'.$modulename . ' ' . $strviews.': '.implode(', ',$viewnames).'
' + . $modulename . ' ' . $strposts.': '.implode(', ',$postnames).'

'; + + $table->initialbars($totalcount > $perpage); + $table->pagesize($perpage, $matchcount); + + if($table->get_page_start() !== '' && $table->get_page_size() !== '') { + $sql .= ' '.sql_paging_limit($table->get_page_start(), $table->get_page_size()); + } + + if (!$users = get_records_sql($sql)) { + $users = array(); // tablelib will handle saying 'Nothing to display' for us. + } + + $data = array(); + + $a->count = $totalcount; + $a->items = $totalcount == 1 ? ((!empty($teachers)) ? $course->teacher : $course->student) : ((!empty($teachers)) ? $course->teachers : $course->students); + + if ($matchcount != $totalcount) { + $a->items .= ' ('.get_string('matched').' '.$matchcount.')'; + } + + echo '

'.get_string('counteditems', '', $a).'

'; + echo ' + +'; + echo '
'; + echo ''; + echo ''; + echo ''; + + foreach ($users as $u) { + $data = array(''.fullname($u,true).'', + ((!empty($u->count)) ? get_string('yes').' ('.$u->count.') ' : get_string('no')), + '', + ); + $table->add_data($data); + } + + $table->print_html(); + + if ($perpage == 99999) { + echo '
'.get_string('showperpage', '', DEFAULT_PAGE_SIZE).'
'; + } + else if ($matchcount > 0 && $perpage < $matchcount) { + echo '
'.get_string('showall', '', $matchcount).'
'; + } + + echo '
'; + echo ' '; + echo ' '; + if ($perpage >= $matchcount) { + echo ''; + } + $displaylist['messageselect.php'] = get_string('messageselectadd'); + choose_from_menu ($displaylist, "formaction", "", get_string("withselectedusers"), "if(checksubmit(this.form))this.form.submit();", ""); + helpbutton("participantswithselectedusers", get_string("withselectedusers")); + echo ''; + } + + print_footer(); + +?> diff --git a/course/report/participation/mod.php b/course/report/participation/mod.php new file mode 100644 index 00000000000..b850a0d0039 --- /dev/null +++ b/course/report/participation/mod.php @@ -0,0 +1,92 @@ +prefix.'course_modules cm JOIN '. + $CFG->prefix.'modules m ON cm.module = m.id WHERE course = '.$course->id)) { + print_error('noparticipatorycms',$CFG->wwwroot.'/course/view.php?id='.$course->id); + } + + + $modoptions = array(); + foreach ($modules as $m) { + if (in_array($m->name,$allowedmodules)) { + $modoptions[$m->module] = get_string('modulename',$m->name); + } + } + + $timeoptions = array(); + // get minimum log time for this course + $minlog = get_field_sql('SELECT min(time) FROM '.$CFG->prefix.'log WHERE course = '.$course->id); + + $now = usergetmidnight(time()); + + // days + for ($i = 1; $i < 7; $i++) { + if (strtotime('-'.$i.' days',$now) >= $minlog) { + $timeoptions[strtotime('-'.$i.' days',$now)] = get_string('numdays','moodle',$i); + } + } + // weeks + for ($i = 1; $i < 10; $i++) { + if (strtotime('-'.$i.' weeks',$now) >= $minlog) { + $timeoptions[strtotime('-'.$i.' weeks',$now)] = get_string('numweeks','moodle',$i); + } + } + // months + for ($i = 2; $i < 12; $i++) { + if (strtotime('-'.$i.' months',$now) >= $minlog) { + $timeoptions[strtotime('-'.$i.' months',$now)] = get_string('nummonths','moodle',$i); + } + } + // try a year + if (strtotime('-1 year',$now) >= $minlog) { + $timeoptions[strtotime('-1 year',$now)] = get_string('lastyear'); + } + + $useroptions = array(0 => $course->students, + 1 => $course->teachers, + ); + + $actionoptions = array('' => $strallactions, + 'view' => $strview, + 'post' => $strpost, + ); + + + // print first controls. + echo '
'."\n". + ''."\n". + ''."\n". + "
\n". + get_string('activitymodule').' '; + choose_from_menu($modoptions,'moduleid',0); + echo "\n". + get_string('lookback').' '; + choose_from_menu($timeoptions,'timefrom',0); + echo "". + get_string('showonly').' '; + choose_from_menu($useroptions,'teachers',0,''); + echo "\n". + get_string('showactions'),' '; + choose_from_menu($actionoptions,'action',0,''); + echo ''; + helpbutton('participationreport',get_string('participationreport')); + echo + ''."\n". + "
\n". + "
\n"; + + +?>