Skip to content

Commit

Permalink
Merge pull request #50 from Syxton/33+
Browse files Browse the repository at this point in the history
Fix for cached responses and weird db issues
  • Loading branch information
Syxton authored Mar 9, 2018
2 parents 0eecf70 + 5a76624 commit f91aa38
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
24 changes: 18 additions & 6 deletions ajax/favorite.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,36 @@

$entry = $DB->get_record('block_custom_course_menu_etc', $params);

if ($entry) {
if ($entry) { // Favorite "course" row exists, remove as favorite.
$entry->fav = 0;
$DB->update_record('block_custom_course_menu_etc', $entry);

$params["item"] = 'favorite';
$params = array(
'userid' => $userid,
'item' => 'favorite',
'itemid' => $courseid
);
$DB->delete_records('block_custom_course_menu_etc', $params);
} else {
} else { // Favorite "course" does not exist, add as favorite.
$entry = (object) $params;
// Does a "course" record exist already?
$params["fav"] = 0;
if ($newentry = $DB->get_record('block_custom_course_menu_etc', $params)) {
// Update existing record.
$newentry->fav = 1;
$DB->update_record('block_custom_course_menu_etc', $newentry);
} else {
$DB->insert_record('block_custom_course_menu_etc', $entry);
}

$entry->item = 'favorite';
$entry->sortorder = 0;
$DB->insert_record('block_custom_course_menu_etc', $entry);
// A "favorite" record should not exist already, but check anyway.
$params["fav"] = 1;
$params["item"] = 'favorite';
if (!$newentry = $DB->get_record('block_custom_course_menu_etc', $params)) {
// Add "favorite" record.
$entry->item = 'favorite';
$entry->sortorder = 0;
$DB->insert_record('block_custom_course_menu_etc', $entry);
}
}
echo json_encode(array(true));
3 changes: 3 additions & 0 deletions js/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
sesskey: sessionid,
ids: ids,
sortorder: sortorder.join(","),
datetime: Date.now(),
};

return $.ajax({
Expand Down Expand Up @@ -157,6 +158,7 @@
var params = {
editing: editing ? 1 : 0,
sesskey: sessionid,
datetime: Date.now(),
};
$.ajax({
url: interfaceUrl,
Expand Down Expand Up @@ -191,6 +193,7 @@
var sessionid = M.cfg.sesskey;
var params = {
sesskey: sessionid,
datetime: Date.now(),
};

$.ajax({
Expand Down

0 comments on commit f91aa38

Please sign in to comment.