89341b62 by logesh

chnages in notestime for vimeo player

1 parent aaddd433
......@@ -23,6 +23,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
};
var mynotes = {
getMynotesValidatedUrl: function(baseurl) {
var a = document.createElement('a');
a.href = baseurl;
return (a.search.length > 0) ? baseurl : baseurl + '?';
......@@ -74,78 +75,22 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
var params = {};
var scope = this;
var url= $(location).attr('href');
//notes player time starts
$('document').ready(function(){
if(url.includes('/mod/page/view.php')){
if(url.includes('/mod/page/view.php')){
//notes player timer starts
var iframe = document.querySelector('iframe');
// console.log(iframe);
var player = new Vimeo.Player(iframe);
console.log(player);
player.pause().then(function() {
})
var time;
player.getCurrentTime().then(function(seconds) {
var str = '</br></br><font color="green">newly You have taken notes at ';
str +=seconds;
str +=" secs in this video.</font>";
var rootPath = M.cfg.wwwroot;
$.ajax({
url: rootPath + "/blocks/mynotes/timerajax.php",
type: 'POST',
data: {notestime: 'pollathavan'},
success: function(data){
}
});
// if ( url.includes('/mod/page/view.php') ){
$.ajax({url: rootPath + "/blocks/mynotes/timerajax.php", success: function(result){
if(result){
var JSONObject = JSON.parse(result);
var profile_field=JSONObject.profile2;
console.log("***************");
console.log(profile_field);
console.log("***************");
// $('.'+profile_field).show();
}
}});
// }
// params['notestime'] = str;
// console.log(str);
})
//
// var result = str.fontcolor("green");
player.pause()
}
});
//notes player time ends
if (args['scope']) {
scope = args['scope'];
}
params['contextarea'] = scope.currenttab.replace(CONFIG.prefix, '');
params['contextarea'] = params['contextarea'].replace('#', '');
if (args.params) {
for (i in args.params) {
params[i] = args.params[i];
......@@ -153,7 +98,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
}
params['sesskey'] = M.cfg.sesskey;
var cfg = {
method: 'POST',
on: {
......@@ -191,11 +135,32 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
Y.io(this.api, cfg);
},
saveMynotes: function(e) {
var result='';
e.preventDefault();
var scope = this;
if (scope.checkInputText() == false) {
return false;
}
var url= $(location).attr('href');
if(url.includes('/mod/page/view.php')){
//notes player timer starts
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);
player.pause();
player.getCurrentTime().then(function(seconds) {
var str = "</br>You have taken notes at ";
str +=seconds;
str +=" in this video."
result = str.fontcolor("green");
var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
if (ta.val() == "" || ta.val() == M.util.get_string('placeholdercontent', 'block_mynotes')) {
return false;
......@@ -205,14 +170,19 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
content: ta.val(),
action: 'add',
contextarea: scope.currenttabindex,
notestime:result,
};
ta.attr('disabled', true);
ta.css({
'backgroundImage': 'url(' + M.util.image_url('i/loading_small', 'core') + ')',
'backgroundRepeat': 'no-repeat',
'backgroundPosition': 'center center'
});
this.request({
scope.request({
params: arg,
callback: function(id, ret, args) {
if (!ret.notes) {
......@@ -238,8 +208,69 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
$(SELECTORS.MYNOTES_BASE).find('.responsetext').html(M.util.get_string('savedsuccess', 'block_mynotes'));
}
});
});
}
else{
var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
if (ta.val() == "" || ta.val() == M.util.get_string('placeholdercontent', 'block_mynotes')) {
return false;
}
var arg = {
contextid: CONFIG.contextid,
content: ta.val(),
action: 'add',
contextarea: scope.currenttabindex,
notestime:result,
};
ta.attr('disabled', true);
ta.css({
'backgroundImage': 'url(' + M.util.image_url('i/loading_small', 'core') + ')',
'backgroundRepeat': 'no-repeat',
'backgroundPosition': 'center center'
});
scope.request({
params: arg,
callback: function(id, ret, args) {
if (!ret.notes) {
return false;
}
$('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html('');
$('#id_mynotecontent-' + CONFIG.instanceid).val(M.util.get_string('placeholdercontent', 'block_mynotes'));
$('#id_mynotecontent-' + CONFIG.instanceid).removeAttr('disabled');
$('#id_mynotecontent-' + CONFIG.instanceid).css({
backgroundImage: ''
});
if (scope.currenttab != scope.defaulttab) {
scope.currenttab = scope.defaulttab;
var tab = scope.currenttab.replace('#', '#tab-');
$(SELECTORS.MYNOTES_BASE + ' ul.tabs-menu li').removeClass("current");
$(SELECTORS.MYNOTES_BASE + ' ' + tab).addClass('current');
$(SELECTORS.MYNOTES_BASE + ' .tab-content').has(scope.currenttab).addClass('current');
$(SELECTORS.MYNOTES_BASE + ' .tab-content').not(scope.currenttab).css("display", "none");
$(SELECTORS.MYNOTES_BASE + ' ' + scope.currenttab + '.tab-content').css("display", "block");
}
scope.addToList(ret, 'add');
scope.displayMynotes();
$(SELECTORS.MYNOTES_BASE).find('.responsetext').html(M.util.get_string('savedsuccess', 'block_mynotes'));
}
});
}
},
addToList: function(notesobj, action = '') {
var scope = this;
var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list');
if (action == 'add') {
......@@ -257,9 +288,13 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
getMynotes: function(page = 0) {
var scope = this;
page = parseInt(page);
var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list');
var notescount = el.find('li').length;
var lastpage = Math.ceil(notescount / CONFIG.perpage);
if (notescount > 0 && lastpage > page) {
scope.displayMynotes();
return false;
......@@ -278,6 +313,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
});
},
updateMynotesInfo: function(mynotescount, page) {
console.log(mynotescount);
page = parseInt(page);
mynotescount = parseInt(mynotescount);
var scope = this;
......@@ -297,15 +333,20 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
pagenum = page + 1;
if (pagenum != lastpage) {
nextlink = scope.createLink(pagenum, M.util.get_string('nextpage', 'block_mynotes'), 'next');
}
paging = prevlink;
if (prevlink != '' && nextlink != '') {
paging += '<span class="separator"></span>';
}
paging += nextlink;
paging = '<span class="paging">' + paging + '</span>';
}
var noteinfo = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab);
if (mynotescount > 0) {
noteinfo.find('.count').html(M.util.get_string('mynotescount', 'block_mynotes') + '' + mynotescount);
} else {
......@@ -337,16 +378,20 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
return '<a href="' + this.api + '&page=' + page + '"' + classattribute + '>' + text + '</a>';
},
displayMynotes: function() {
var scope = this;
var page = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('onpage'));
var mynotescount = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('notes-count'));
var el = $(SELECTORS.MYNOTES_BASE).find(' ' + scope.currenttab + '-list');
var notescount = el.find('li').length;
var lastpage = Math.ceil(notescount / CONFIG.perpage);
if (notescount > 0 && lastpage <= page) {
page = lastpage - 1;
}
var upperlimit = page * CONFIG.perpage + CONFIG.perpage;
//parsing required for backward flow
var upperlimit = (parseInt(page) * parseInt(CONFIG.perpage))+ (parseInt(CONFIG.perpage));
var lowerlimit = page * CONFIG.perpage;
el.find('li').css('display', 'none');
el.find('li').each(function(i, el) {
......@@ -378,21 +423,33 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
}
});
$('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'focus blur', function(e) {
var url= $(location).attr('href');
if(url.includes('/mod/page/view.php')){
//notes player timer starts
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);
player.pause()
}
scope.toggle_textarea(e);
});
$('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'change keypress keyup', function(e) {
scope.getWarnings(scope.checkInputText());
});
$('body').delegate(SELECTORS.MYNOTES_BASE + ' .mynotes-paging .paging a', 'click', function(e) {
e.preventDefault();
var regex = new RegExp(/[\?&]page=(\d+)/);
var results = regex.exec($(this).attr('href'));
var page = 0;
if (results[1]) {
page = results[1];
}
$(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('onpage', parseInt(page));
scope.getMynotes(page);
});
$('body').delegate(SELECTORS.MYNOTES_BASE + ' a.mynote-delete', 'click', function(e) {
e.preventDefault();
......@@ -418,6 +475,17 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
});
},
displayDialogue: function(e) {
var url= $(location).attr('href');
if(url.includes('/mod/page/view.php')){
//notes player timer starts
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);
player.pause()
}
var scope = mynotes;
if (panel === null) {
str.get_strings([{
......
define(["jquery"],function(e){return{init:function(){var n=e(location).attr("href");e("document").ready(function(){if(n.includes("/mod/page/view.php")){var t=document.querySelector("iframe"),i=new Vimeo.Player(t);console.log(i),e("#mynotepencil").click(function(){setTimeout(function(){i.getCurrentTime().then(function(e){})},1e3)})}})}}});
\ No newline at end of file
define(["jquery"],function(e){return{init:function(){var n=e(location).attr("href");e("document").ready(function(){if(n.includes("/mod/page/view.php")){var e=document.querySelector("iframe");new Vimeo.Player(e)}})}}});
\ No newline at end of file
......
......@@ -23,6 +23,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
};
var mynotes = {
getMynotesValidatedUrl: function(baseurl) {
var a = document.createElement('a');
a.href = baseurl;
return (a.search.length > 0) ? baseurl : baseurl + '?';
......@@ -74,78 +75,22 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
var params = {};
var scope = this;
var url= $(location).attr('href');
//notes player time starts
$('document').ready(function(){
if(url.includes('/mod/page/view.php')){
if(url.includes('/mod/page/view.php')){
//notes player timer starts
var iframe = document.querySelector('iframe');
// console.log(iframe);
var player = new Vimeo.Player(iframe);
console.log(player);
player.pause().then(function() {
})
var time;
player.getCurrentTime().then(function(seconds) {
var str = '</br></br><font color="green">newly You have taken notes at ';
str +=seconds;
str +=" secs in this video.</font>";
var rootPath = M.cfg.wwwroot;
$.ajax({
url: rootPath + "/blocks/mynotes/timerajax.php",
type: 'POST',
data: {notestime: 'pollathavan'},
success: function(data){
player.pause()
}
});
// if ( url.includes('/mod/page/view.php') ){
$.ajax({url: rootPath + "/blocks/mynotes/timerajax.php", success: function(result){
if(result){
var JSONObject = JSON.parse(result);
var profile_field=JSONObject.profile2;
console.log("***************");
console.log(profile_field);
console.log("***************");
// $('.'+profile_field).show();
}
}});
// }
// params['notestime'] = str;
// console.log(str);
})
//
// var result = str.fontcolor("green");
}
});
//notes player time ends
if (args['scope']) {
scope = args['scope'];
}
params['contextarea'] = scope.currenttab.replace(CONFIG.prefix, '');
params['contextarea'] = params['contextarea'].replace('#', '');
if (args.params) {
for (i in args.params) {
params[i] = args.params[i];
......@@ -153,7 +98,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
}
params['sesskey'] = M.cfg.sesskey;
var cfg = {
method: 'POST',
on: {
......@@ -191,11 +135,32 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
Y.io(this.api, cfg);
},
saveMynotes: function(e) {
var result='';
e.preventDefault();
var scope = this;
if (scope.checkInputText() == false) {
return false;
}
var url= $(location).attr('href');
if(url.includes('/mod/page/view.php')){
//notes player timer starts
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);
player.pause();
player.getCurrentTime().then(function(seconds) {
var str = "</br>You have taken notes at ";
str +=seconds;
str +=" in this video."
result = str.fontcolor("green");
var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
if (ta.val() == "" || ta.val() == M.util.get_string('placeholdercontent', 'block_mynotes')) {
return false;
......@@ -205,14 +170,19 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
content: ta.val(),
action: 'add',
contextarea: scope.currenttabindex,
notestime:result,
};
ta.attr('disabled', true);
ta.css({
'backgroundImage': 'url(' + M.util.image_url('i/loading_small', 'core') + ')',
'backgroundRepeat': 'no-repeat',
'backgroundPosition': 'center center'
});
this.request({
scope.request({
params: arg,
callback: function(id, ret, args) {
if (!ret.notes) {
......@@ -238,8 +208,69 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
$(SELECTORS.MYNOTES_BASE).find('.responsetext').html(M.util.get_string('savedsuccess', 'block_mynotes'));
}
});
});
}
else{
var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
if (ta.val() == "" || ta.val() == M.util.get_string('placeholdercontent', 'block_mynotes')) {
return false;
}
var arg = {
contextid: CONFIG.contextid,
content: ta.val(),
action: 'add',
contextarea: scope.currenttabindex,
notestime:result,
};
ta.attr('disabled', true);
ta.css({
'backgroundImage': 'url(' + M.util.image_url('i/loading_small', 'core') + ')',
'backgroundRepeat': 'no-repeat',
'backgroundPosition': 'center center'
});
scope.request({
params: arg,
callback: function(id, ret, args) {
if (!ret.notes) {
return false;
}
$('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html('');
$('#id_mynotecontent-' + CONFIG.instanceid).val(M.util.get_string('placeholdercontent', 'block_mynotes'));
$('#id_mynotecontent-' + CONFIG.instanceid).removeAttr('disabled');
$('#id_mynotecontent-' + CONFIG.instanceid).css({
backgroundImage: ''
});
if (scope.currenttab != scope.defaulttab) {
scope.currenttab = scope.defaulttab;
var tab = scope.currenttab.replace('#', '#tab-');
$(SELECTORS.MYNOTES_BASE + ' ul.tabs-menu li').removeClass("current");
$(SELECTORS.MYNOTES_BASE + ' ' + tab).addClass('current');
$(SELECTORS.MYNOTES_BASE + ' .tab-content').has(scope.currenttab).addClass('current');
$(SELECTORS.MYNOTES_BASE + ' .tab-content').not(scope.currenttab).css("display", "none");
$(SELECTORS.MYNOTES_BASE + ' ' + scope.currenttab + '.tab-content').css("display", "block");
}
scope.addToList(ret, 'add');
scope.displayMynotes();
$(SELECTORS.MYNOTES_BASE).find('.responsetext').html(M.util.get_string('savedsuccess', 'block_mynotes'));
}
});
}
},
addToList: function(notesobj, action = '') {
var scope = this;
var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list');
if (action == 'add') {
......@@ -257,9 +288,13 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
getMynotes: function(page = 0) {
var scope = this;
page = parseInt(page);
var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list');
var notescount = el.find('li').length;
var lastpage = Math.ceil(notescount / CONFIG.perpage);
if (notescount > 0 && lastpage > page) {
scope.displayMynotes();
return false;
......@@ -272,12 +307,14 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
this.request({
params: arg,
callback: function(id, ret, args) {
scope.addToList(ret);
scope.displayMynotes();
}
});
},
updateMynotesInfo: function(mynotescount, page) {
page = parseInt(page);
mynotescount = parseInt(mynotescount);
var scope = this;
......@@ -297,15 +334,20 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
pagenum = page + 1;
if (pagenum != lastpage) {
nextlink = scope.createLink(pagenum, M.util.get_string('nextpage', 'block_mynotes'), 'next');
}
paging = prevlink;
if (prevlink != '' && nextlink != '') {
paging += '<span class="separator"></span>';
}
paging += nextlink;
paging = '<span class="paging">' + paging + '</span>';
}
var noteinfo = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab);
if (mynotescount > 0) {
noteinfo.find('.count').html(M.util.get_string('mynotescount', 'block_mynotes') + '' + mynotescount);
} else {
......@@ -337,16 +379,20 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
return '<a href="' + this.api + '&page=' + page + '"' + classattribute + '>' + text + '</a>';
},
displayMynotes: function() {
var scope = this;
var page = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('onpage'));
var mynotescount = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('notes-count'));
var el = $(SELECTORS.MYNOTES_BASE).find(' ' + scope.currenttab + '-list');
var notescount = el.find('li').length;
var lastpage = Math.ceil(notescount / CONFIG.perpage);
if (notescount > 0 && lastpage <= page) {
page = lastpage - 1;
}
var upperlimit = page * CONFIG.perpage + CONFIG.perpage;
//parsing required for backward flow
var upperlimit = (parseInt(page) * parseInt(CONFIG.perpage))+ (parseInt(CONFIG.perpage));
var lowerlimit = page * CONFIG.perpage;
el.find('li').css('display', 'none');
el.find('li').each(function(i, el) {
......@@ -378,21 +424,33 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
}
});
$('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'focus blur', function(e) {
var url= $(location).attr('href');
if(url.includes('/mod/page/view.php')){
//notes player timer starts
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);
player.pause()
}
scope.toggle_textarea(e);
});
$('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'change keypress keyup', function(e) {
scope.getWarnings(scope.checkInputText());
});
$('body').delegate(SELECTORS.MYNOTES_BASE + ' .mynotes-paging .paging a', 'click', function(e) {
e.preventDefault();
var regex = new RegExp(/[\?&]page=(\d+)/);
var results = regex.exec($(this).attr('href'));
var page = 0;
if (results[1]) {
page = results[1];
}
$(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('onpage', parseInt(page));
scope.getMynotes(page);
});
$('body').delegate(SELECTORS.MYNOTES_BASE + ' a.mynote-delete', 'click', function(e) {
e.preventDefault();
......@@ -418,6 +476,17 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
});
},
displayDialogue: function(e) {
var url= $(location).attr('href');
if(url.includes('/mod/page/view.php')){
//notes player timer starts
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);
player.pause()
}
var scope = mynotes;
if (panel === null) {
str.get_strings([{
......
......@@ -12,38 +12,6 @@ define(['jquery'], function($) {
var player = new Vimeo.Player(iframe);
console.log(player);
$('#mynotepencil').click(function(){
setTimeout(function(){
player.getCurrentTime().then(function(seconds) {
var str = "</br><br><div style='display: none !important;'> You have taken notes at ";
str +=seconds;
str +=" in this video.</div>"
// var result = str.fontcolor("green");
// $("#id_mynotecontent-54").val(str);
})
// console.log($mynotestime);
// console.log(self);
//
// var str = "<div> You have taken notes at ";
// str +=time;
// str +=" in this video.</div>"
// var result = str.fontcolor("green");
// $("#id_mynotecontent-258").val(result);
}, 1000);
});
}
});
}
......
......@@ -70,7 +70,7 @@ class block_mynotes_manager {
}
$sql = "SELECT $ufields,
m.id AS mynoteid, m.content AS ccontent, m.contextarea, m.contextid, m.format AS cformat,
m.timecreated AS timecreated, c.fullname as coursename, m.courseid
m.timecreated AS timecreated,m.notestime AS notestime, c.fullname as coursename, m.courseid
FROM {block_mynotes} m
JOIN {user} u ON u.id = m.userid
LEFT JOIN {course} c ON c.id = m.courseid
......@@ -94,6 +94,13 @@ class block_mynotes_manager {
$c->contextarea = $u->contextarea;
$c->format = $u->cformat;
$c->timecreated = userdate($u->timecreated, $strftime);
$c->userid = $u->id;
if (!empty($u->notestime)) {
$c->notestime = $u->notestime;
} else {
$c->notestime = '';
}
// $c->notestime = $u->notestime;
$c->content = format_text($c->content, $c->format, $formatoptions);
$c->delete = true;
$mynotes[] = $c;
......@@ -108,24 +115,59 @@ class block_mynotes_manager {
* @param object $options
* @return int The count of records
*/
public function count_mynotes($options) {
/* public function count_mynotes($options) {
global $DB, $USER;
$params = array();
// $params ['contextid']= $options->contextid;
// $params= $options->contextid;
$params['userid'] = $USER->id;
$sql='select COUNT(contextarea) from {block_mynotes} where contextid= :contextid';
$params ['contextid']= $options->contextid;
return $DB->count_records_sql($sql,$params);
/* $params['userid'] = $USER->id;
print_object($sql);
// return $DB->count_records_sql($sql,$params);
if (isset($options->contextarea) && !empty($options->contextarea)) {
$params['contextarea'] = $options->contextarea;
}
if (isset($options->contextid) && !empty($options->contextid)) {
$params['contextid'] = $options->contextid;
}
return $DB->count_records('block_mynotes',$params); */
return $DB->count_records('block_mynotes',$params);
} */
public function count_mynotes($options) {
global $DB, $USER;
$params = array();
$params['userid'] = $USER->id;
if (isset($options->contextarea) && !empty($options->contextarea)) {
$params['contextarea'] = $options->contextarea;
}
if (isset($options->contextid) && !empty($options->contextid)) {
$params['contextid'] = $options->contextid;
}
$sql='select count(contextarea) from {block_mynotes} where userid=? and contextarea=? and contextid=?';
$result=$DB->get_records_sql($sql,$params);
$count;
foreach ($result as $val){
$count=$val->count;
}
return $count;
// return $DB->count_records('block_mynotes', $params);
}
/*
* Returns paging bar for mynotes
......@@ -149,7 +191,7 @@ class block_mynotes_manager {
*/
public function addmynote($context, $contextarea, $course, $content,$timer, $format = FORMAT_MOODLE) {
global $CFG, $DB, $USER, $OUTPUT;
$content=$content.$timer;
// $content=$content.$timer;
$newnote = new stdClass;
$newnote->contextid = $context->id;
$newnote->contextarea = $contextarea;
......@@ -158,12 +200,14 @@ class block_mynotes_manager {
$newnote->format = $format;
$newnote->userid = $USER->id;
$newnote->timecreated = time();
$newnote->notestime=$timer;
if ($cmtid = $DB->insert_record('block_mynotes', $newnote)) {
$newnote->id = $cmtid;
$newnote->content = format_text($newnote->content, $newnote->format, array('overflowdiv' => true));
$newnote->timecreated = userdate($newnote->timecreated, get_string('strftimerecentfull', 'langconfig'));
$newnote->coursename = ($newnote->courseid == SITEID) ? '' : $course->fullname;
$newnote->notestime = ($newnote->notestime) ? '' : $newnote->notestime;
if (!empty($newnote->coursename)) {
$newnote->coursename = html_writer::link(course_get_url($course), $newnote->coursename);
}
......@@ -250,3 +294,4 @@ class block_mynotes_manager {
*/
class mynotes_exception extends moodle_exception {
}
......
......@@ -62,6 +62,7 @@ $config = get_config('block_mynotes');
echo $OUTPUT->header(); //...send headers
// process ajax request
switch ($action) {
case 'add':
$content = optional_param('content', '', PARAM_RAW);
......@@ -75,8 +76,10 @@ switch ($action) {
$options->contextid = $context->id;
$options->context = $context;
$options->contextarea = $contextarea;
// $options->notestime=$timer;
unset($options->courseid);
$count = $manager->count_mynotes($options);
echo json_encode(array('notes' => array($note), 'count' => $count));
} else {
echo json_encode(array('error' => 'Unable to add note'));
......@@ -89,9 +92,21 @@ switch ($action) {
$options->page = $page;
$options->contextid = $context->id;
$options->contextarea = $contextarea;
$options->courseid = $course->id;
$count = $manager->count_mynotes($options);
$notes = $manager->get_mynotes($options);
if (empty($notes)){
$count=0;
echo json_encode(array('notes' => $notes, 'count' => $count));
}
else{
echo json_encode(array('notes' => $notes, 'count' => $count));
}
die();
break;
case 'delete':
......@@ -101,12 +116,17 @@ switch ($action) {
if ($manager->delete($noteid)) {
$options = new stdClass();
$options->page = $page;
$options->contextid = $context->id;
$options->contextarea = $contextarea;
$options->courseid = $course->id;
$count = $manager->count_mynotes($options);
if ($limitfrom) {
$options->limitfrom = $limitfrom - 1;
}
$notes = $manager->get_mynotes($options);
echo json_encode(array('notes' => $notes, 'count' => $count, 'noteid' => $noteid));
}
die();
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!