course_level_notes.php
5.42 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
require_once (dirname ( __FILE__ ) . '/../../config.php');
require_once(dirname( __FILE__ ) .'/../../lib/phpexcel/PHPExcel.php');
global $OUTPUT, $title;
require_login ();
$context = context_system::instance ();
$PAGE->set_context ( $context );
function download_excel(){
global $DB, $CFG,$USER ,$PAGE;
$contextid;
if (isset($_GET['cid'])) {
$contextid=$_GET['cid'];
}
$parameter;
if ($contextid){
$parameter = array ($USER->id,$contextid);
}else{
$parameter = array ($USER->id);
}
$sql="select id,courseid from {block_mynotes} where userid=? and contextid=?";
$courseids = $DB->get_records_sql ( $sql, $parameter );
$courseid;
foreach ( $courseids as $value){
$courseid=$value->courseid;
}
$param=array($USER->id,$courseid);
$sql="select * from {block_mynotes} where userid=? and courseid=?";
$allNotes = $DB->get_records_sql ( $sql, $param );
$fullNotes = array ();
$i=0;
foreach ($allNotes as $notes ) {
$courseid=$notes->courseid;
$parameter = array ($courseid);
$sql="select fullname from {course} where id=?";
$coursename = $DB->get_record_sql ( $sql, $parameter );
$fullNotes [$i]['Sl.no']=$i+1;
$fullNotes [$i]['Course']=$coursename->fullname;
if($notes->activityname){
$fullNotes [$i]['activityname']=$notes->activityname;
}
$fullNotes [$i]['Content']=$notes->content;
$time=date('d M Y H:i A (T)', $notes->timecreated);
$fullNotes [$i]['Timecreated']=$time;
$fullNotes [$i]['Videotime']=$notes->notestime;
$fullNotes [$i]['Notesurl']=$notes->notesurl;
$i=$i+1;
}
if (!empty($fullNotes)){
$name = "Student_notes";
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle('Notes');
$default_border = array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
'color' => array('rgb'=>'9999ff')
);
$style_header = array(
'borders' => array(
'bottom' => $default_border,
'left' => $default_border,
'top' => $default_border,
'right' => $default_border,
),
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb'=>'E1E0F7'),
),
'font' => array(
'bold' => true,
)
);
$default_border1 = array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
'color' => array('rgb'=>'ff9999')
);
$style_header1 = array(
'borders' => array(
'bottom' => $default_border1,
'left' => $default_border1,
'top' => $default_border1,
'right' => $default_border1,
),
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb'=>'ff9999'),
),
'font' => array(
'bold' => true,
)
);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(50);
$objPHPExcel->getActiveSheet()->getCell("A1")->setValue("SL.No");
$objPHPExcel->getActiveSheet()->getCell("A1")->getStyle('A1')->applyFromArray($style_header);
$objPHPExcel->getActiveSheet()->getCell("B1")->setValue("Course");
$objPHPExcel->getActiveSheet()->getCell("B1")->getStyle('B1')->applyFromArray($style_header);
$objPHPExcel->getActiveSheet()->getCell("C1")->setValue("Activity ");
$objPHPExcel->getActiveSheet()->getCell("C1")->getStyle('C1')->applyFromArray($style_header);
$objPHPExcel->getActiveSheet()->getCell("D1")->setValue("Note");
$objPHPExcel->getActiveSheet()->getCell("D1")->getStyle('D1')->applyFromArray($style_header);
$objPHPExcel->getActiveSheet()->getCell("E1")->setValue("Time Created");
$objPHPExcel->getActiveSheet()->getCell("E1")->getStyle('E1')->applyFromArray($style_header);
$objPHPExcel->getActiveSheet()->getCell("F1")->setValue("Time in clip");
$objPHPExcel->getActiveSheet()->getCell("F1")->getStyle('F1')->applyFromArray($style_header);
$objPHPExcel->getActiveSheet()->getCell("G1")->setValue("URL");
$objPHPExcel->getActiveSheet()->getCell("G1")->getStyle('G1')->applyFromArray($style_header);
for($i=1;$i<=count($fullNotes)+1;$i++){
$objPHPExcel->getActiveSheet()->getCell('A'.($i+1))->setValue($i);
$objPHPExcel->getActiveSheet()->getCell('B'.($i+1))->setValue($fullNotes[$i-1]['Course']);
$objPHPExcel->getActiveSheet()->getCell('C'.($i+1))->setValue($fullNotes[$i-1]['activityname']);
$objPHPExcel->getActiveSheet()->getCell('D'.($i+1))->setValue($fullNotes[$i-1]['Content']);
$objPHPExcel->getActiveSheet()->getCell('E'.($i+1))->setValue($fullNotes[$i-1]['Timecreated']);
$objPHPExcel->getActiveSheet()->getCell('F'.($i+1))->setValue($fullNotes[$i-1]['Videotime']);
$objPHPExcel->getActiveSheet()->getCell('G'.($i+1))->setValue($fullNotes[$i-1]['Notesurl']);
}
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
header("Content-Disposition: attachment; filename=$name.xlsx");
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$objWriter->save('php://output');
exit();
}
}
download_excel();