forked from windwild/moodle-local_courseranker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.php
126 lines (111 loc) · 3.74 KB
/
renderer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* Course Ranker render class
*
* @package local_courseranker
* @copyright 2012 Gao Jiayang (http://windwild.net)
* @author Gao Jiayang
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once(dirname(__FILE__).'/locallib.php');
require_once 'config.php';
class local_courseranker_renderer extends plugin_renderer_base{
/**
* this function is used to get output HTML of all selected
* courses' score and rank.
*
* @Copyright(c) 2012, Gao Jiayang All Rights Reserved.
* @Author Gao Jiayang http://windwild.net
* @param none
* @return string. html of courses's score and rank.
*/
function note() {
return $this->box('表中数据系根据学生活动自动计算得出。每小时刷新一次。');
}
function coursetable(){
global $cr_config;
$output = '';
$results = get_course_table();
$table = new html_table();
$table->head = array('排名', '课程名称', '主讲教师', '学生数', '人均活跃度', '详细排名');
$pos =1;
foreach ($results as $result){
if($result['ave_score'] < $cr_config->minimum_ave_score ||
$result['student_number'] < $cr_config->minimum_student_number){
continue;
}
$cell1 = new html_table_cell();
$cell2 = new html_table_cell();
$cell3 = new html_table_cell();
$cell4 = new html_table_cell();
$cell5 = new html_table_cell();
$cell6 = new html_table_cell();
$cell1->text = $pos;
if($pos <= $cr_config->highlight){
$cell2->text = '<a href="../../course/view.php?id='.$result['course_id'].' ">'.$result['fullname'].'</a>';
}else{
$cell2->text = '<a href="../../course/view.php?id='.$result['course_id'].' ">'.$result['fullname'].'</a>';
}
$teacher_count=0;
foreach ($result['course_teacher'] as $teacher){
$teacher_name = $teacher['lastname'].' '.$teacher['firstname']."<br>";
$user = new stdClass();
$user->firstname = $teacher['firstname'];
$user->lastname = $teacher['lastname'];
$teacher_name = fullname($user);
$cell3->text .= '<a href="../../user/view.php?id='.$teacher['user_id'].'">'.$teacher_name.' </a> ';
$teacher_count++;
if($teacher_count % 4 == 0){
$cell3->text .= '<br>';
}
}
$cell4->text = $result['student_number'];
$cell5->text = $result['ave_score'];
$cell6->text = '<a href="userrank.php?course_id='.$result['course_id'].'">'.'学生排名'.' </a> ';
$row = new html_table_row();
if($pos <= $cr_config->highlight){
$row->style = 'background-color:yellow';
}
$row->cells[] = $cell1;
$row->cells[] = $cell2;
$row->cells[] = $cell3;
$row->cells[] = $cell4;
$row->cells[] = $cell5;
$row->cells[] = $cell6;
$table->data[] = $row;
++$pos;
}
$output .= html_writer::table($table);
return $output;
}
function user_rank($course_id){
global $cr_config;
$output = '';
$results = get_user_rank($course_id);
$table = new html_table();
$table->head = array('排名', '姓名', '活跃度');
$pos =1;
foreach ($results as $result){
$user = new stdClass();
$user->firstname = $result['firstname'];
$user->lastname = $result['lastname'];
$user_fullname = fullname($user);
$cell0 = new html_table_cell();
$cell1 = new html_table_cell();
$cell2 = new html_table_cell();
$cell0->text = $pos;
$cell1->text = $result['lastname'].' '.$result['firstname'];
$cell1->text = '<a href="../../user/view.php?id='.$result['userid'].'">'.$user_fullname.' </a> ';
$cell2->text = $result['score'];
$row = new html_table_row();
$row->cells[] = $cell0;
$row->cells[] = $cell1;
$row->cells[] = $cell2;
$table->data[] = $row;
++$pos;
}
$output .= html_writer::table($table);
return $output;
}
}