Skip to content

Commit fd2de58

Browse files
authored
Merge pull request #30 from bdecentgmbh/dev
Dev
2 parents 1c01a3c + bd9b8b1 commit fd2de58

27 files changed

+383
-94
lines changed

lang/en/local_learningtools.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
$string['sortbycourse'] = "Sort by course";
9090
$string['viewcourse'] = "View course";
9191
$string['viewactivity'] = "View Activity";
92+
$string['viewchapter'] = "View Chapter";
9293
$string['deletemessage'] = 'Delete Message';
9394
$string['deletemsgcheckfull'] = 'Are you absolutely sure you want to completely delete the bookmarks, including their bookmarks and other bookmarks data?';
9495
$string['deletednotmessage'] = 'Could not delete bookmarks!';
@@ -99,6 +100,9 @@
99100
$string['successbookmarkmessage'] = "This page bookmarked successfully and you can view the bookmarks under profile / learning tools / bookmarks.";
100101
$string['removebookmarkmessage'] = "This page bookmark removed and you can view the bookmarks under profile / learning tools / bookmarks.";
101102

103+
$string['successchapterbookmarkmessage'] = "This chapter bookmarked successfully and you can view the bookmarks under profile / learning tools / bookmarks.";
104+
$string['removechapterbookmarkmessage'] = "This chapter bookmark removed and you can view the bookmarks under profile / learning tools / bookmarks.";
105+
102106
// Notes strings.
103107

104108
$string['note'] = "Notes";
@@ -198,7 +202,6 @@
198202
$string['successtoolschedule'] = "Schedule added the user calendar";
199203

200204
// Time management.
201-
202205
$string['timemanagement'] = 'Time management';
203206
$string['timemanagementheader'] = 'Time management for {$a->name}';
204207
$string['print'] = "Print";
@@ -242,5 +245,7 @@
242245
$string['strftimemonthdateyear'] = '%B, %dth %Y';
243246
$string['strftimeyearmonth'] = '%Y/%m/%d';
244247
$string['strftimemonthnamedate'] = '%B %d, %Y';
245-
$string['subplugintype_ltool'] = "Learning Tools";
246-
$string['subplugintype_ltool_plural'] = "ltools";
248+
$string['subplugintype_ltool'] = "Learning Tool";
249+
$string['subplugintype_ltool_plural'] = 'Learning Tools';
250+
$string['strbookmarked'] = "<i class='fa fa-bookmark'></i> Bookmarked";
251+
$string['strbookmark'] = "<i class='fa fa-bookmark'></i> Bookmark";

lib.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,9 @@ function local_learningtools_get_instance_tool_view_url($row) {
498498
$courseurl = new moodle_url('/course/view.php', array('id' => $data->courseid));
499499
$viewurl = $OUTPUT->single_button($courseurl, get_string('viewcourse', 'local_learningtools'), 'get');
500500
} else if ($data->instance == 'mod') {
501-
$viewurl = $OUTPUT->single_button($row->pageurl, get_string('viewactivity', 'local_learningtools'), 'get');
501+
$pageurl = $row->pageurl;
502+
$buttonstr = ($row->itemtype == 'chapter') ? 'viewchapter' : 'viewactivity';
503+
$viewurl = $OUTPUT->single_button($pageurl, get_string($buttonstr, 'local_learningtools'), 'get');
502504
} else {
503505
$viewurl = $OUTPUT->single_button($row->pageurl, get_string('viewpage', 'local_learningtools'), 'get');
504506
}

ltool/bookmarks/amd/build/learningbookmarks.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ltool/bookmarks/amd/build/learningbookmarks.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ltool/bookmarks/amd/src/learningbookmarks.js

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2222
*/
2323

24-
define(['core/str', 'core/ajax', 'core/notification'],
25-
function(String, Ajax, notification) {
24+
define(['core/str', 'core/ajax', 'core/notification', 'jquery'],
25+
function(String, Ajax, notification, $) {
2626

2727
/* global ltools, pagebookmarks */
2828

@@ -59,6 +59,38 @@ define(['core/str', 'core/ajax', 'core/notification'],
5959
}
6060

6161
}
62+
63+
// Content designer bookmarks.
64+
$(document).on('click', '.content-designer-learningtool-bookmark', function(e) {
65+
e.preventDefault();
66+
var button = $(this);
67+
var itemType = button.data('itemtype');
68+
var itemId = button.data('itemid');
69+
var userid = button.data('userid');
70+
var sesskey = button.data('sesskey');
71+
var course = button.data('courseid');
72+
var coursemodule = button.data('coursemodule');
73+
var contextlevel = button.data('contextlevel');
74+
var pagetype = button.data('pagetype');
75+
var pageurl = button.data('pageurl');
76+
// Prepare the parameters for the bookmark.
77+
var contextId = M.cfg.contextid;
78+
var params = {
79+
pagetitle: document.title,
80+
pageurl: pageurl,
81+
pageid: 0,
82+
itemtype: itemType,
83+
itemid: itemId,
84+
user: userid,
85+
sesskey: sesskey,
86+
course: course,
87+
coursemodule: coursemodule,
88+
contextlevel: contextlevel,
89+
pagetype: pagetype,
90+
};
91+
submitFormdata(contextId, params, button);
92+
});
93+
6294
var bookmarkssorttype = document.getElementById("bookmarkssorttype");
6395

6496
if (bookmarkssorttype) {
@@ -131,7 +163,7 @@ define(['core/str', 'core/ajax', 'core/notification'],
131163
* @param {object} formData form instance data.
132164
* @return {void} ajax response
133165
*/
134-
function submitFormdata(contextid, formData) {
166+
function submitFormdata(contextid, formData, button = null) {
135167

136168
if (formData.pagetitle == "") {
137169
formData.pagetitle = document.querySelector('title').innerHTML;
@@ -147,11 +179,32 @@ define(['core/str', 'core/ajax', 'core/notification'],
147179
type: response.notificationtype
148180
});
149181

182+
150183
let bookmarkmarked = document.getElementById('bookmarks-marked');
151184
if (response.bookmarksstatus) {
152-
bookmarkmarked.classList.add('marked');
185+
if (button) {
186+
require(['mod_contentdesigner/elements'], function(Elements) {
187+
var chapterId = formData.itemid;
188+
if (chapterId) {
189+
Elements.removeWarning();
190+
Elements.refreshContent();
191+
}
192+
});
193+
} else {
194+
bookmarkmarked.classList.add('marked');
195+
}
153196
} else {
154-
bookmarkmarked.classList.remove('marked');
197+
if (button) {
198+
require(['mod_contentdesigner/elements'], function(Elements) {
199+
var chapterId = formData.itemid;
200+
if (chapterId) {
201+
Elements.removeWarning();
202+
Elements.refreshContent();
203+
}
204+
});
205+
} else {
206+
bookmarkmarked.classList.remove('marked');
207+
}
155208
}
156209

157210
if (ltools.disappertimenotify != 0) {
@@ -160,7 +213,9 @@ define(['core/str', 'core/ajax', 'core/notification'],
160213
}, ltools.disappertimenotify);
161214
}
162215

163-
},
216+
},fail: function(error) {
217+
notification.exception(error);
218+
}
164219
}]);
165220
}
166221

ltool/bookmarks/classes/bookmarkstool_filter.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,20 @@ public function get_main_body($sqlconditions, $sqlparams, $sort, $sorttype, $pag
219219
WHERE $sqlconditions", $sqlparams);
220220
$pageingbar = $OUTPUT->paging_bar($totalbookmarks, $page, $perpage, $this->baseurl);
221221

222+
$dbman = $DB->get_manager();
222223
$res = [];
223224
$reports = [];
224225
if (!empty($records)) {
225226
foreach ($records as $row) {
226227
$list = [];
228+
$chaptertitle = '';
229+
if ($row->itemtype == 'chapter'&& $dbman->table_exists('cdelement_chapter')) {
230+
if ($chapter = $DB->get_record('cdelement_chapter', ['id' => $row->itemid])) {
231+
$chaptertitle = (!empty($chapter->title) ? " | " . $chapter->title : '');
232+
}
233+
}
227234
$data = local_learningtools_check_instanceof_block($row);
228-
$list['instance'] = $row->pagetitle;
235+
$list['instance'] = $row->pagetitle . $chaptertitle;
229236
$list['instanceinfo'] = $this->get_instance_bookmarkinfo($data);
230237
$list['courseinstance'] = ($data->instance == 'course') ? true : false;
231238
$list['time'] = $this->get_bookmark_time($row);

ltool/bookmarks/classes/privacy/provider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public static function get_metadata(collection $collection): collection {
5757
'pagetype' => 'privacy:metadata:bookmarks:pagetype',
5858
'pagetitle' => 'privacy:metadata:bookmarks:pagetitle',
5959
'pageurl' => 'privacy:metadata:bookmarks:pageurl',
60+
'itemtype' => 'privacy:metadata:bookmarks:itemtype',
61+
'itemid' => 'privacy:metadata:bookmarks:itemid',
6062
'timemodified' => 'privacy:metadata:bookmarks:timemodified'
6163
];
6264
$collection->add_database_table('ltool_bookmarks_data', $bookmarksmetadata, 'privacy:metadata:bookmarksmetadata');
@@ -205,6 +207,8 @@ public static function export_user_data(approved_contextlist $contextlist) {
205207
'pagetitle' => $record->pagetitle,
206208
'pagetype' => $record->pagetype,
207209
'pageurl' => $record->pageurl,
210+
'itemtype' => $record->itemtype,
211+
'itemid' => $record->itemid,
208212
'timecreated' => ($record->timecreated) ? transform::datetime($record->timecreated) : '-',
209213
];
210214
}, $records);

ltool/bookmarks/db/install.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<FIELD NAME="pagetype" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
1616
<FIELD NAME="pagetitle" TYPE="char" LENGTH="500" NOTNULL="false" SEQUENCE="false"/>
1717
<FIELD NAME="pageurl" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
18+
<FIELD NAME="itemtype" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
19+
<FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
1820
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
1921
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
2022
</FIELDS>

ltool/bookmarks/db/upgrade.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,34 @@ function xmldb_ltool_bookmarks_upgrade($oldversion) {
4848
}
4949
upgrade_plugin_savepoint(true, 2022022600, 'ltool', 'bookmarks');
5050
}
51+
52+
if ($oldversion < 2025041700) {
53+
// Modify the bookmarks table to support itemtype and itemid.
54+
$table = new xmldb_table('ltool_bookmarks_data');
55+
56+
// Add itemtype field if it doesn't exist.
57+
$field = new xmldb_field('itemtype', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, 'page', 'pageurl');
58+
if (!$dbman->field_exists($table, $field)) {
59+
$dbman->add_field($table, $field);
60+
}
61+
62+
// Add itemid field if it doesn't exist.
63+
$field = new xmldb_field('itemid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'itemtype');
64+
if (!$dbman->field_exists($table, $field)) {
65+
$dbman->add_field($table, $field);
66+
}
67+
68+
// Update existing records to use the new fields.
69+
$DB->execute("UPDATE {ltool_bookmarks_data} SET itemtype = 'page', itemid = 0");
70+
71+
// Create index for the new fields.
72+
$index = new xmldb_index('itemtype_itemid_idx', XMLDB_INDEX_NOTUNIQUE, ['itemtype', 'itemid']);
73+
if (!$dbman->index_exists($table, $index)) {
74+
$dbman->add_index($table, $index);
75+
}
76+
// Savepoint reached.
77+
upgrade_plugin_savepoint(true, 2025041700, 'ltool', 'bookmarks');
78+
}
79+
5180
return true;
5281
}

ltool/bookmarks/lang/en/ltool_bookmarks.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
$string['privacy:metadata:bookmarks:pagetype'] = 'Bookmarked pagetype';
4242
$string['privacy:metadata:bookmarks:pagetitle'] = 'Page title of Bookmarked page';
4343
$string['privacy:metadata:bookmarks:pageurl'] = 'Bookmarked page url';
44+
$string['privacy:metadata:bookmarks:itemtype'] = 'Bookmarked item type';
45+
$string['privacy:metadata:bookmarks:itemid'] = 'Bookmarked item id';
4446
$string['privacy:metadata:bookmarks:timecreated'] = 'Time of the bookmarks created';
4547
$string['privacy:metadata:bookmarks:timemodified'] = 'Time of the bookmarks modified';
4648
$string['privacy:metadata:bookmarksmetadata'] = 'List of users data stored in bookmarks subplugin';

0 commit comments

Comments
 (0)