39da5eb9 by logesh

notes plugin

1 parent c1ef11fc
1 Copyright (c) 2013-2016 GitHub, Inc. and contributors
2
3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
...\ No newline at end of file ...\ No newline at end of file
1 Mynotes Block
2 --------------
3 A simpler mynotes system that integrates as moodle block to save user's notes
4 from different areas such as site, course, modules, etc.
5
6 This is a free plugin for Moodle that help to preserve uesr's notes.
7
8 Settings
9 --------
10 * Set the position for display editing icon.
11 * Set the number of records to be display
12
13 Appearances
14 ----------------------
15 * This block display on site page, any course-* and user page.
16
17 Features
18 --------
19
20 Any authenticated users can:
21
22 * Save new notes
23 * View saved notes by him/her
24 * Delete own notes
25
26 Requirements
27 ------------
28
29 * Moodle version 3.4
30
31 Installation
32 ------------
33
34 Within the ZIP file is a folder named mynotes, copy this folder into
35 your Moodle blocks folder (e.g /var/moodle/htdocs/blocks/ ). Once the folder
36 has been copied into your blocks folder, login to Moodle as admin and it should
37 detect the new block and install it.
38
39 Note that if you download the ZIP from Github the mynotes folder is called
40 'moodle-block_mynotes' and needs to be renamed after extraction to 'mynotes'.
41
42 Once installed this block, automatically added to page while installing. There is no need to add to every page.
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17 /**
18 * The mynotes block
19 *
20 * @package block_mynotes
21 * @author Gautam Kumar Das<gautam.arg@gmail.com>
22 */
23
24 defined('MOODLE_INTERNAL') || die();
25
26 require_once($CFG->dirroot . '/blocks/mynotes/lib.php');
27
28 /**
29 * Mynotes block.
30 *
31 * @package block_mynotes
32 *
33 */
34 class block_mynotes extends block_base {
35
36 public function init() {
37 $this->title = get_string('pluginname', 'block_mynotes');
38 }
39
40 public function has_config() {
41 return true;
42 }
43
44 public function applicable_formats() {
45 return array('all' => true);
46 }
47
48 public function instance_allow_multiple() {
49 return false;
50 }
51
52 public function hide_header() {
53 global $PAGE;
54 if (!$PAGE->user_is_editing()) {
55 return true;
56 }
57 }
58
59 /**
60 * The content object.
61 *
62 * @return stdObject
63 */
64 public function get_content() {
65 global $CFG, $PAGE;
66
67 static $jscount = 0;
68 if ($this->content !== null) {
69 return $this->content;
70 }
71
72 if (!isloggedin() or isguestuser()) {
73 return ''; // Never useful unless you are logged in as real users
74 }
75
76 if (!in_array($PAGE->context->contextlevel, array(CONTEXT_COURSE, CONTEXT_SYSTEM, CONTEXT_MODULE, CONTEXT_USER))) {
77 return '';
78 }
79
80 $this->content = new stdClass();
81 $this->content->footer = '';
82 $this->content->text = '';
83 if (empty($this->instance)) {
84 return $this->content;
85 }
86
87 $this->content = new stdClass();
88 $this->content->text = '';
89 if ($PAGE->user_is_editing()) {
90 $this->content->text = '<div class="inline-mynotes-opener">'.get_string('showmynotes', 'block_mynotes').'</div>';
91 }
92 $this->content->footer = '';
93
94 if ($jscount == 0) {
95 $this->block_mynotes_get_required_javascript();
96 $jscount++;
97 }
98 return $this->content;
99 }
100
101 /*
102 * load JS that requires into the page.
103 */
104 private function block_mynotes_get_required_javascript() {
105 global $PAGE, $CFG;
106 list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
107 $config = get_config('block_mynotes');
108
109 $mm = new block_mynotes_manager();
110 $currenttabindex = $mm->get_current_tab($context, $PAGE);
111 $arguments = array( 'arg'=> array(
112 'instanceid' => $this->instance->id,
113 'editing' => ($PAGE->user_is_editing()),
114 'editingicon_pos' => ($PAGE->user_is_editing()) ? 'mynotes-pos-inline' : $config->icondisplayposition,
115 'maxallowedcharacters' => $config->characterlimit,
116 'contextid' => $context->id,
117 'maxallowedcharacters_warning' => get_string('notmorethan', 'block_mynotes', $config->characterlimit),
118 'contextareas' => $mm->get_available_contextareas(),
119 'currenttabindex' => ($currenttabindex == null ? 'site' : $currenttabindex),
120 'perpage' => $config->mynotesperpage,
121 ),
122 );
123 // $PAGE->requires->string_for_js('charactersleft', 'block_mynotes');
124 $PAGE->requires->string_for_js('notmorethan', 'block_mynotes');
125 $PAGE->requires->string_for_js('mynotes', 'block_mynotes');
126 $PAGE->requires->string_for_js('showmynotes', 'block_mynotes');
127 $PAGE->requires->string_for_js('savedsuccess', 'block_mynotes');
128 $PAGE->requires->string_for_js('save', 'block_mynotes');
129 $PAGE->requires->string_for_js('placeholdercontent', 'block_mynotes');
130 $PAGE->requires->string_for_js('deletemynotes', 'block_mynotes');
131 $PAGE->requires->string_for_js('mynotescount', 'block_mynotes');
132 $PAGE->requires->string_for_js('previouspage', 'block_mynotes');
133 $PAGE->requires->string_for_js('nextpage', 'block_mynotes');
134 $PAGE->requires->string_for_js('nothingtodisplay', 'block_mynotes');
135 $PAGE->requires->string_for_js('mynotessavedundertab', 'block_mynotes');
136 $PAGE->requires->string_for_js('cancel', 'moodle');
137 $this->page->requires->js_call_amd('block_mynotes/mynotesblock', 'init', $arguments);
138 }
139 }
...\ No newline at end of file ...\ No newline at end of file
1 if (url.includes('/mod/hvp/')){
2 $(document).ready(function(){
3 var m = document.getElementsByClassName("h5p-iv-hotkey-instructions");
4 console.log(m);
5 var check=$("div.h5p-iv-hotkey-instructions").html();
6 var check1=$('div.h5p-iv-hotkey-instructions').text();
7 console.log(check);
8 console.log(check1);
9 setTimeout(function(){
10 $('#mynotepencil').click(function(){
11
12 var check=$('.h5p-iv-hotkey-instructions').html();
13 var check1=$('.h5p-iv-hotkey-instructions').text();
14 console.log(check);
15 console.log(check1);
16 alert(check);
17 // var valuetime= $(".h5p-control, .h5p-simple-time, .h5p-current, span.human-time").text();
18 // var newvalue= $('.h5p-control, .h5p-simple-time, .h5p-current, span.human-time').text();
19 var valuetime1= $(".h5p-controls-right .h5p-control .h5p-time .h5p-current .human-time").text();
20 var newvalue1= $('.h5p-controls-right .h5p-control .h5p-time .h5p-current .human-time').text();
21 // console.log(" click notes"+newvalue);
22 // var y =$('.human-time').html();
23 // console.log("first"+valuetime);console.log("second"+newvalue);
24 console.log("first"+valuetime1);console.log("second"+newvalue1);
25 // alert("hi");
26 });
27 }, 0500);
28 });
29 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17 /**
18 * Mynotes block caps.
19 *
20 * @package block_mynotes
21 * @author Gautam Kumar Das<gautam.arg@gmail.com>
22 */
23
24 defined('MOODLE_INTERNAL') || die();
25
26 $capabilities = array(
27
28 'block/mynotes:myaddinstance' => array(
29 'captype' => 'write',
30 'contextlevel' => CONTEXT_SYSTEM,
31 'archetypes' => array(
32 'user' => CAP_ALLOW
33 ),
34
35 'clonepermissionsfrom' => 'moodle/my:manageblocks'
36 ),
37
38 'block/mynotes:addinstance' => array(
39 'riskbitmask' => RISK_SPAM | RISK_XSS,
40
41 'captype' => 'write',
42 'contextlevel' => CONTEXT_BLOCK,
43 'archetypes' => array(
44 'editingteacher' => CAP_ALLOW,
45 'manager' => CAP_ALLOW
46 ),
47
48 'clonepermissionsfrom' => 'moodle/site:manageblocks'
49 ),
50 );
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17 defined('MOODLE_INTERNAL') || die();
18
19 /**
20 * Mynotes block installation.
21 *
22 * @package block_mynotes
23 */
24
25 function xmldb_block_mynotes_install() {
26 global $DB;
27
28 $obj = new stdClass();
29 $obj->blockname = 'mynotes';
30 $obj->parentcontextid = SITEID;
31 $obj->showinsubcontexts = 1;
32 $obj->pagetypepattern = '*';
33 $obj->defaultweight = 0;
34 $obj->defaultregion = BLOCK_POS_LEFT;
35 $obj->configdata = '';
36 $obj->timecreated = time();
37 $obj->timemodified = time();
38 $DB->insert_record('block_instances', $obj);
39
40 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 <?xml version="1.0" encoding="UTF-8" ?>
3 <XMLDB PATH="blocks/mynotes/db" VERSION="20160404" COMMENT="XMLDB file for my notes"
4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd">
6 <TABLES>
7 <TABLE NAME="block_mynotes" COMMENT="My Notes">
8 <FIELDS>
9 <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
10 <FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
11 <FIELD NAME="contextarea" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
12 <FIELD NAME="content" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
13 <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
14 <FIELD NAME="format" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
15 <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
16 <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
17 </FIELDS>
18 <KEYS>
19 <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
20 </KEYS>
21 </TABLE>
22 </TABLES>
23 </XMLDB>
1 <?php
2
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18 /**
19 * Strings for component 'block_mynotes', language 'en', branch 'MOODLE_29_STABLE'
20 *
21 * @package block_mynotes
22 * @author Gautam Kumar Das<gautam.arg@gmail.com>
23 */
24
25 $string['mynotes:myaddinstance'] = 'Add a new mynotes block to Dashboard';
26 $string['mynotes:addinstance'] = 'Add a new mynotes block';
27 $string['mynotes:post'] = 'Add a new note';
28 $string['mynotes:view'] = 'View own notes';
29 $string['mynotes:delete'] = 'Delete own notes';
30 $string['pluginname'] = 'My Notes';
31 $string['disabledmynotes'] = 'Disabled my notes';
32 $string['showmynotes'] = 'Show my notes';
33 $string['addnotes'] = 'Add notes';
34 $string['mynotes'] = 'My notes';
35 $string['mynotescount'] = 'Total count: ';
36 $string['mynotesrequirelogin'] = 'You must login to add/view your notes';
37 $string['deletemynotes'] = 'Delete note';
38 $string['site'] = 'Site';
39 $string['course'] = 'Course';
40 $string['mod'] = 'Modules';
41 $string['user'] = 'Personal';
42 $string['save'] = 'Save';
43 $string['savedsuccess'] = 'Your note has been added successfully';
44 $string['mynotessavedundertab'] = 'For this page, your notes will be saved under <strong>{$a} tab</strong>.';
45 $string['placeholdercontent'] = 'Enter note content...';
46 $string['charactersleft'] = 'Characters left: ';
47 $string['characterlimit'] = 'Characters limit: ';
48 $string['characterlimit_help'] = 'This setting defines the maximum characters limit to write a note.';
49 $string['notmorethan'] = 'Can not enter more than {$a} characters';
50 $string['bottomright'] = 'Bottom-Right';
51 $string['bottomleft'] = 'Bottom-Left';
52 $string['topright'] = 'Top-Right';
53 $string['topleft'] = 'Top-Left';
54 $string['icondisplayposition'] = 'Icon position';
55 $string['icondisplayposition_help'] = 'Choose the position for Note-Icon which will used to open popup.';
56 $string['mynotesperpage'] = 'Per page';
57 $string['mynotesperpage_help'] = 'Limit the notes display on per page';
58 $string['deletefailed'] = 'Delete action failed';
59 $string['nopermissiontodelete'] = 'You do not have permission to delete this note';
60 $string['previouspage'] = '<< Previous page';
61 $string['nextpage'] = 'Next page >>';
62 $string['nothingtodisplay'] = 'Nothing to display';
63 $string['nocharacterlimit'] = ' ';
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17 /**
18 * The mynotes block helper functions and callbacks
19 *
20 * @package block_mynotes
21 * @author Gautam Kumar Das<gautam.arg@gmail.com>
22 */
23
24 defined('MOODLE_INTERNAL') || die();
25
26
27 class block_mynotes_manager {
28
29 public $perpage = 5;
30 private $config = null;
31
32 /*
33 * Constructor.
34 */
35 public function __construct() {
36 $this->config = get_config('block_mynotes');
37 $this->perpage = $this->config->mynotesperpage;
38 }
39
40 /**
41 * Returns matched mynotes
42 *
43 * @param int $page
44 * @return array
45 */
46 public function get_mynotes($options) {
47 global $DB, $CFG, $USER, $OUTPUT;
48
49 $page = (!isset($options->page) || !$options->page) ? 0 : $options->page;
50 $perpage = $this->perpage;
51
52 $params = array();
53 $start = $page * $perpage;
54 $ufields = 'u.id';
55
56 $where = ' m.userid = :userid';
57 $params['userid'] = $USER->id;
58 /* if (isset($options->contextarea) && !empty($options->contextarea)) {
59 $where .= ' AND m.contextarea = :contextarea';
60 $params['contextarea'] = $options->contextarea;
61 }
62 if (isset($options->courseid) && $options->courseid) {
63 $where .= ' AND m.courseid = :courseid';
64 $params['courseid'] = $options->courseid;
65 } */
66 if(isset($options->contextid) && $options->contextid){
67 $where .= ' AND m.contextid = :contextid';
68 $params['contextid'] = $options->contextid;
69
70 }
71 $sql = "SELECT $ufields,
72 m.id AS mynoteid, m.content AS ccontent, m.contextarea, m.contextid, m.format AS cformat,
73 m.timecreated AS timecreated, c.fullname as coursename, m.courseid
74 FROM {block_mynotes} m
75 JOIN {user} u ON u.id = m.userid
76 LEFT JOIN {course} c ON c.id = m.courseid
77 WHERE $where
78 ORDER BY m.timecreated DESC";
79 $strftime = get_string('strftimerecentfull', 'langconfig');
80 $mynotes = array();
81 $formatoptions = array('overflowdiv' => true);
82 $start = (isset($options->limitfrom)) ? $options->limitfrom : $start;
83 $rs = $DB->get_recordset_sql($sql, $params, $start, $perpage);
84 foreach ($rs as $u) {
85 $c = new stdClass();
86 $c->id = $u->mynoteid;
87 $c->userid = $u->id;
88 if ($u->courseid != SITEID) {
89 $c->coursename = html_writer::link(course_get_url($u->courseid), $u->coursename);
90 } else {
91 $c->coursename = '';
92 }
93 $c->content = $u->ccontent;
94 $c->contextarea = $u->contextarea;
95 $c->format = $u->cformat;
96 $c->timecreated = userdate($u->timecreated, $strftime);
97 $c->content = format_text($c->content, $c->format, $formatoptions);
98 $c->delete = true;
99 $mynotes[] = $c;
100 }
101 $rs->close();
102 return $mynotes;
103 }
104
105 /**
106 * Returns count of the mynotes in a table where all the given conditions met.
107 *
108 * @param object $options
109 * @return int The count of records
110 */
111 public function count_mynotes($options) {
112 global $DB, $USER;
113 $params = array();
114 // $params ['contextid']= $options->contextid;
115 // $params= $options->contextid;
116 $sql='select COUNT(contextarea) from {block_mynotes} where contextid= :contextid';
117 $params ['contextid']= $options->contextid;
118 return $DB->count_records_sql($sql,$params);
119 /* $params['userid'] = $USER->id;
120 if (isset($options->contextarea) && !empty($options->contextarea)) {
121 $params['contextarea'] = $options->contextarea;
122 }
123 if (isset($options->contextid) && !empty($options->contextid)) {
124 $params['contextid'] = $options->contextid;
125 }
126 return $DB->count_records('block_mynotes',$params); */
127
128 }
129
130 /*
131 * Returns paging bar for mynotes
132 *
133 * @param object $options must contain properties(contextid, count, page, perpage)
134 * @return html
135 */
136 public function get_pagination($options) {
137 global $OUTPUT;
138 $baseurl = new moodle_url('/blocks/mynotes/mynotes_ajax.php',
139 array(
140 'contextid' => $options->contextid)
141 );
142 return $OUTPUT->paging_bar($options->count, $options->page, $this->perpage, $baseurl);
143 }
144
145 /*
146 * Adding new record of mynote.
147 *
148 * @return object of single mynote record if insert to DB else false
149 */
150 public function addmynote($context, $contextarea, $course, $content, $format = FORMAT_MOODLE) {
151 global $CFG, $DB, $USER, $OUTPUT;
152
153 $newnote = new stdClass;
154 $newnote->contextid = $context->id;
155 $newnote->contextarea = $contextarea;
156 $newnote->content = $content;
157 $newnote->courseid = $course->id;
158 $newnote->format = $format;
159 $newnote->userid = $USER->id;
160 $newnote->timecreated = time();
161
162 if ($cmtid = $DB->insert_record('block_mynotes', $newnote)) {
163 $newnote->id = $cmtid;
164 $newnote->content = format_text($newnote->content, $newnote->format, array('overflowdiv' => true));
165 $newnote->timecreated = userdate($newnote->timecreated, get_string('strftimerecentfull', 'langconfig'));
166 $newnote->coursename = ($newnote->courseid == SITEID) ? '' : $course->fullname;
167 if (!empty($newnote->coursename)) {
168 $newnote->coursename = html_writer::link(course_get_url($course), $newnote->coursename);
169 }
170 return $newnote;
171 } else {
172 return false;
173 }
174 }
175
176 /*
177 * Find all available context areas which is used to store and retrieve mynotes.
178 *
179 * @return array
180 */
181 public function get_available_contextareas() {
182 return array(
183 // 'site' => get_string('site', 'block_mynotes'),
184 // 'course' => get_string('course', 'block_mynotes'),
185 // 'mod' => get_string('mod', 'block_mynotes'),
186 'user' => get_string('user', 'block_mynotes'),
187 );
188 }
189 /*
190 * Find context area using context level.
191 *
192 * @param object $context
193 * @retrun string
194 */
195 public function get_current_tab($context, $page) {
196
197 /* if ($page->url->compare(new moodle_url('/user/view.php'), URL_MATCH_BASE)) {
198 return 'user';
199
200 } else if ($page->url->compare(new moodle_url('/user/profile.php'), URL_MATCH_BASE)) {
201 return 'user';
202
203 } else if ($context->contextlevel == CONTEXT_SYSTEM) {
204 return 'site';
205
206 } else if ($context->contextlevel == CONTEXT_COURSE) {
207 if ($context->instanceid == SITEID) {
208 return 'site';
209 }
210 return 'course';
211
212 } else if ($context->contextlevel == CONTEXT_MODULE) {
213 return 'mod';
214
215 } else if ($context->contextlevel == CONTEXT_USER) {
216 return 'user';
217
218 } else if ($context->contextlevel == CONTEXT_BLOCK) {
219 $parent = $context->get_parent_context();
220
221 if ($parent->contextlevel == CONTEXT_COURSE) {
222 return 'course';
223 } else if ($parent->contextlevel == CONTEXT_MODULE) {
224 return 'mod';
225 }
226 } */
227 return 'user';
228 }
229
230 /**
231 * Delete a note
232 *
233 * @param int $mynoteid
234 * @return bool
235 */
236 public function delete($mynoteid) {
237 global $DB, $USER;
238 if (!$mynote = $DB->get_record('block_mynotes', array('id' => $mynoteid))) {
239 throw new mynotes_exception('deletefailed', 'block_mynotes');
240 }
241 if ($USER->id != $mynote->userid) {
242 throw new mynotes_exception('nopermissiontodelete', 'block_mynotes');
243 }
244 return $DB->delete_records('block_mynotes', array('id' => $mynoteid));
245 }
246 }
247
248 /**
249 * Mynotes exception class
250 */
251 class mynotes_exception extends moodle_exception {
252 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17 /*
18 * Handling all ajax request for mynotes API
19 *
20 * @package block_mynotes
21 * @author Gautam Kumar Das<gautam.arg@gmail.com>
22 */
23 define('AJAX_SCRIPT', true);
24 define('NO_DEBUG_DISPLAY', true);
25
26 require_once('../../config.php');
27 require_once($CFG->dirroot.'/course/lib.php');
28 require_once($CFG->dirroot . '/blocks/mynotes/lib.php');
29
30 $contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
31 $contextarea = optional_param('contextarea', 'site', PARAM_ALPHA);
32 $action = optional_param('action', '', PARAM_ALPHA);
33 $page = optional_param('page', 0, PARAM_INT);
34
35 list($context, $course, $cm) = get_context_info_array($contextid);
36
37 if ( $contextid == SYSCONTEXTID || $context->contextlevel == CONTEXT_USER) {
38 $course = get_site();
39 }
40
41 $PAGE->set_url('/blocks/mynotes/mynotes_ajax.php');
42
43 require_course_login($course, true, $cm);
44
45 $PAGE->set_context($context);
46 if (!empty($cm)) {
47 $PAGE->set_cm($cm, $course);
48 } else if (!empty($course)) {
49 $PAGE->set_course($course);
50 }
51
52 if (!confirm_sesskey()) {
53 $error = array('error' => get_string('invalidsesskey', 'error'));
54 die(json_encode($error));
55 }
56
57 if (!isloggedin()) {
58 echo json_encode(array('error' => 'require_login'));
59 die();
60 }
61 $config = get_config('block_mynotes');
62
63 echo $OUTPUT->header(); //...send headers
64 // process ajax request
65 switch ($action) {
66 case 'add':
67 $content = optional_param('content', '', PARAM_RAW);
68 $manager = new block_mynotes_manager();
69 if ($note = $manager->addmynote($context, $contextarea, $course, $content)) {
70 $options = new stdClass();
71 $options->page = $page;
72 $options->courseid = $course->id;
73 $options->contextid = $context->id;
74 $options->context = $context;
75 $options->contextarea = $contextarea;
76 unset($options->courseid);
77 $count = $manager->count_mynotes($options);
78 echo json_encode(array('notes' => array($note), 'count' => $count));
79 } else {
80 echo json_encode(array('error' => 'Unable to add note'));
81 }
82 die();
83 break;
84 case 'get':
85 $manager = new block_mynotes_manager();
86 $options = new stdClass();
87 $options->page = $page;
88 $options->contextid = $context->id;
89 $options->contextarea = $contextarea;
90 $count = $manager->count_mynotes($options);
91 $notes = $manager->get_mynotes($options);
92 echo json_encode(array('notes' => $notes, 'count' => $count));
93 die();
94 break;
95 case 'delete':
96 $noteid = required_param('noteid', PARAM_INT);
97 $limitfrom = optional_param('lastnotecounts', 0, PARAM_INT);
98 $manager = new block_mynotes_manager();
99 if ($manager->delete($noteid)) {
100 $options = new stdClass();
101 $options->page = $page;
102 $options->contextarea = $contextarea;
103 $count = $manager->count_mynotes($options);
104 if ($limitfrom) {
105 $options->limitfrom = $limitfrom - 1;
106 }
107 $notes = $manager->get_mynotes($options);
108 echo json_encode(array('notes' => $notes, 'count' => $count, 'noteid' => $noteid));
109 }
110 die();
111 break;
112 }
113 die();
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17 /**
18 * Settings for the Mynotes block
19 *
20 * @package block_mynotes
21 * @author Gautam Kumar Das<gautam.arg@gmail.com>
22 */
23
24 defined('MOODLE_INTERNAL') || die;
25
26 if ($ADMIN->fulltree) {
27
28 $perpageoptions = array();
29 for ($i = 1; $i < 20; $i++) {
30 $perpageoptions[$i] = $i;
31 }
32 $settings->add(new admin_setting_configselect('block_mynotes/mynotesperpage', get_string('mynotesperpage', 'block_mynotes'),
33 get_string('mynotesperpage_help', 'block_mynotes'), 5, $perpageoptions));
34
35 $settings->add(new admin_setting_configtext('block_mynotes/characterlimit', get_string('characterlimit', 'block_mynotes'),
36 get_string('characterlimit_help', 'block_mynotes'), 180, PARAM_INT, 3));
37
38 $positionoptions = array();
39 $positionoptions['mynotes-pos-rb'] = get_string('bottomright', 'block_mynotes');
40 $positionoptions['mynotes-pos-lb'] = get_string('bottomleft', 'block_mynotes');
41 $positionoptions['mynotes-pos-rt'] = get_string('topright', 'block_mynotes');
42 $positionoptions['mynotes-pos-lt'] = get_string('topleft', 'block_mynotes');
43 $settings->add(new admin_setting_configselect('block_mynotes/icondisplayposition', get_string('icondisplayposition', 'block_mynotes'),
44 get_string('icondisplayposition_help', 'block_mynotes'), 'mynotes-pos-rb', $positionoptions));
45 }
...\ No newline at end of file ...\ No newline at end of file
1 #mynotes-opener { position: absolute; bottom:0px; background: #443355; width: 25px; height: 25px; }
2 div.mdl-align { min-height: 470px; }
3 .mynotes-pos-inline-text { padding: 10px; margin-left: 35px; cursor: pointer; }
4 .mynotes-pos-inline,
5 .mynotes-pos-rb,
6 .mynotes-pos-lb,
7 .mynotes-pos-rt,
8 .mynotes-pos-lt { width: 40px; height: 40px; position: fixed; background: #b31b1b; padding: 0; border-radius: 30px; text-align: center; }
9 .mynotes-pos-rb { bottom: 5px; right: 20px; }
10 .mynotes-pos-lb { bottom: 5px; left: 20px; }
11 .mynotes-pos-rt { top: 100px; right: 20px; }
12 .mynotes-pos-lt { top: 100px; left: 20px; }
13 .mynotes-pos-inline { position: relative; float: left; }
14 .mynotes-pos-inline >span.pencil, .mynotes-pos-rb >span.pencil, .mynotes-pos-lb>span.pencil, .mynotes-pos-rt>span.pencil, .mynotes-pos-lt>span.pencil { color: #fff; font-size: 29px; margin: 0; display: inline-block; font-weight: bold; cursor: pointer; line-height: 40px; }
15
16 .mynotes_base { display: inline-block; width: 100%; }
17 .mynotes_base .inputarea { background: #fff4d5; padding: 5px; margin-bottom: 10px; }
18 .mynotes_base .inputarea p {margin: 0; font-size: 13px; }
19 .mynotes_base .textarea { border: 1px solid gray; padding: 5px; background: #fff; }
20 .mynotes_base textArea:focus { border: none; box-shadow: none; }
21 .mynotes_base textArea {width:100%; max-width: 100%; margin: 0; padding: 0; max-height: 125px; border: none; box-shadow: none; }
22 .mynotes_base input[type="submit"], .mynotes_base input[type="submit"]:hover { margin: 0; padding: 3px 10px; border: none; background: #63ab36; color: #fff; }
23 .mynotes_base input[type="submit"][disabled="disabled"]:hover { background: #63ab36; cursor: not-allowed; }
24 .mynotes_base span.warning { color: #bd3c2f; margin-left: 15px; }
25 .mynotes_base .responsetext { color: #33b733; line-height: 20px; }
26 .mynotes_base .tabs-menu { height: 30px; float: left; clear: both; margin-bottom: 1px; }
27 .mynotes_base .tabs-menu li { padding: 0 10px; margin-right: 1px; height: 30px; line-height: 30px; float: left; list-style: none; background-color: #d84e36; cursor: pointer; }
28 .mynotes_base .tabs-menu li:first-child { border-radius: 7px 0 0 0; }
29 .mynotes_base .tabs-menu li:last-child { border-radius: 0 7px 0 0; }
30 .mynotes_base .tabs-menu li.current { position: relative; background-color: #ffe6a4; border-bottom: 1px solid #fff; z-index: 5; border-bottom: 2px solid #ffe6a4; }
31 .mynotes_base .tabs-menu li:first-child.current { border-left: 1px solid #d4d4d1; border-top: 1px solid #d4d4d4; }
32 .mynotes_base .tabs-menu li:last-child.current { border-right: 1px solid #d4d4d1; border-top: 1px solid #d4d4d4; }
33 .mynotes_base .tabs-menu li .menu-item { text-transform: uppercase; color: #fff; text-decoration: none; }
34 .mynotes_base .tabs-menu .current .menu-item { color: #000; }
35
36 .mynotes_base .tab { border: 1px solid #d4d4d1; clear: both; width: auto; background: #f7f7f4; }
37 .mynotes_base .tab .tab-content { display: none; }
38 .mynotes_base .tab .tab-content .notes-info { background: #ffe6a4; padding: 5px; position: relative; }
39 .mynotes_base .tab .tab-content .notes-info .count { color: #000; }
40 .mynotes_base .tab .tab-content .notes-info .mynotes-paging { position: absolute; right: 0; }
41 .mynotes_base .tab .tab-content .notes-info .mynotes-paging .paging a { margin: 5px; background: #c1621e; padding: 4px 10px; border-radius: 15px; color: #fff; }
42 .mynotes_base .tab .tab-content .notes-info .mynotes-paging .paging .separator { border-left: 1px solid gray; }
43 .mynotes_base .tab .tab-content ul.mynotes_lists { margin:0; clear: both; }
44 .mynotes_base .tab .tab-content ul.mynotes_lists li { list-style: none; position: relative; margin: 0 0 5px 0; padding: 5px; list-style: none; background-color: #fff; border-top: 1px solid #e3e4e4; }
45 .mynotes_base .tab .tab-content ul.mynotes_lists li .content { margin-right: 10px; word-wrap: break-word; }
46 .mynotes_base .tab .tab-content ul.mynotes_lists li .note-detail { display: inline-block; font-size: 11px; }
47 .mynotes_base .tab .tab-content ul.mynotes_lists li .time { color: #888; font-style: italic; display: inline-block; margin-left: 5px; font-size: 11px; }
48 .mynotes_base .tab .tab-content ul.mynotes_lists li a.mynote-delete { position: absolute; right: 0; margin:0 4px; }
49 .mynotes_base .tab .tab-content ul.mynotes_lists li a.mynote-delete span { color: #bbb; }
50
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17 /**
18 * Version details
19 *
20 * @package block_mynotes
21 * @author Gautam Kumar Das<gautam.arg@gmail.com>
22 */
23
24 defined('MOODLE_INTERNAL') || die();
25
26 $plugin->version = 2018011200; // The current plugin version (Date: YYYYMMDDXX)
27 $plugin->requires = 2015050500; // Requires this Moodle version
28 $plugin->component = 'block_mynotes'; // Full name of the plugin (used for diagnostics)
29 $plugin->release = 'V3.4 r1';
30 $plugin->maturity = MATURITY_STABLE;
...\ No newline at end of file ...\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!