view.php
3.79 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
<?php
require_once (dirname ( __FILE__ ) . '/../../config.php');
// require_once (dirname ( __FILE__ ) . '/leaderboard_data.php');
// require_once ($CFG->dirroot . '/user/profile/lib.php');
global $OUTPUT, $title;
require_login ();
$context = context_system::instance ();
$PAGE->set_context ( $context );
// $PAGE->requires->css ( '/blocks/leaders/css/style.css' );
$PAGE->set_pagelayout( 'standard' );
$PAGE->set_title ( "Notes" );
$PAGE->requires->css ( '/blocks/mynotes/style.css' );
$PAGE->set_url ( '/blocks/mynotes/view.php' );
$PAGE->set_heading ( "User Notes" );
$PAGE->navbar->add ( 'Notes', new moodle_url ( '/blocks/mynotes/view.php' ) );
$PAGE->requires->js_call_amd ( 'block_mynotes/script', 'init' );
echo $OUTPUT->header ();
class notes{
public function allnotes(){
global $DB, $CFG,$USER , $PAGE;
$parameter = array ($USER->id);
$sql = "select * from {block_mynotes} where userid=? order by courseid asc";
$allNotes = $DB->get_records_sql ( $sql, $parameter );
$sql="select distinct courseid from {block_mynotes} where userid=? order by courseid asc";
$allCourses=$DB->get_records_sql ( $sql, $parameter );
$fullNotes = array ();
foreach ( $allNotes as $notes ) {
$fullNotes [] = $notes;
}
$fullCourseIds = array ();
foreach ( $allCourses as $courseId ) {
$fullCourseIds [] = $courseId;
}
//full notes list
$noteslist = array ();
for($i = 0; $i < count ( $fullCourseIds ); $i ++) {
foreach ( $fullNotes as $notes ) {
if ($fullCourseIds [$i]->courseid == $notes->courseid) {
$noteslist [$i] [] = $notes;
}
}
}
//coursenames
$courseName = array ();
foreach ( $fullCourseIds as $courseId ) {
$param = array (
$courseId->courseid
);
$sql = "select fullname from {course} where id=?";
$name = $DB->get_record_sql ( $sql, $param );
if ($courseId->courseid == 1) {
$courseName [] = 'Dashboard Notes';
} else {
$courseName [] = $name->fullname;
}
}
return array($fullCourseIds,$noteslist,$courseName);
}
public function viewNotes(){
global $DB ,$CFG ,$USER ,$PAGE;
$getallnotes = new notes ();
$Allnotes=$getallnotes->allnotes();
$CourseIds=$Allnotes[0];
$noteslist=$Allnotes[1];
$courseNameList=$Allnotes[2];
if(!empty($noteslist)){
echo '<a href="'.$CFG->wwwroot.'/blocks/mynotes/notes_excel.php" id="excel_download" class="float-md-right" style="text-decoration: none;">Downlaod Notes</a>';
for ($i=0;$i<count($courseNameList);$i++){
echo ('<div class="notes_section" id="'.$CourseIds[$i]->courseid.'">
<a href="#" class="notes_course fa fa-chevron-circle-right" id="icon'.$CourseIds[$i]->courseid.'" style="text-decoration: none;" >
'.' '.$courseNameList[$i].'</a></div>
<table class="notes_overview" id="notes_table_id'.$CourseIds[$i]->courseid.'">');
for ($j=0;$j<count($noteslist[$i]);$j++){
echo ('<tr class="overall_notes" id="notes'.$noteslist[$i][$j]->id.'">
<td class="notes_data">
<a href="#" class=" delete_note float-right mr-1 fa fa-trash" id="'.$noteslist[$i][$j]->id.'" style="text-decoration: none;" >delete</a>
<a href="#" class=" edit_note float-right mr-5 far fa-edit" id="'.$noteslist[$i][$j]->id.'" style="text-decoration: none;">edit</a>
<p id="notes_content'.$noteslist[$i][$j]->id.'">'.$noteslist[$i][$j]->content.'</p>
</td></tr>');
}
echo '</table>';
}
/* <i class="fa fa-trash" aria-hidden="true">delete</i> */
}else{
echo '<div class="alert alert-danger">
<strong> User notes are empty!</strong> User notes are not availale to display. Please make note while working with activities to view all notes.
</div>';
}
}
}
$viewnotes = new notes ();
$viewnotes->viewNotes ();
echo $OUTPUT->footer ();