Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ajax/favorite.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@
die();
}

$params = array(
$params = [
'userid' => $userid,
'item' => 'course',
'itemid' => $courseid,
'fav' => 1
);
'fav' => 1,
];

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

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

$params = array(
$params = [
'userid' => $userid,
'item' => 'favorite',
'itemid' => $courseid
);
'itemid' => $courseid,
];
$DB->delete_records('block_custom_course_menu_etc', $params);
} else { // Favorite "course" does not exist, add as favorite.
$entry = (object) $params;
Expand All @@ -79,4 +79,4 @@
$DB->insert_record('block_custom_course_menu_etc', $entry);
}
}
echo json_encode(array(true));
echo json_encode([true]);
12 changes: 6 additions & 6 deletions ajax/sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@

// Prepare parameters for furture sql query.
$ids = array_values($ids);
$params = array($type, $userid);
list($sqlidstest, $idsparams) = $DB->get_in_or_equal($ids);
$params = [$type, $userid];
[$sqlidstest, $idsparams] = $DB->get_in_or_equal($ids);
$params = array_merge($params, $idsparams);
$sqlidstest = ' AND itemid ' .$sqlidstest;
$sqlidstest = ' AND itemid ' . $sqlidstest;

$sql = 'SELECT itemid, id, item, sortorder, hide '
. 'FROM {block_custom_course_menu_etc} '
. 'WHERE item = ? '
. ' AND userid = ? ' .$sqlidstest;
. ' AND userid = ? ' . $sqlidstest;

$entries = $DB->get_records_sql($sql, $params);

foreach ($ids as $index => $id) {
if (isset($entries[$id])) {
$entry = $entries[$id];
} else {
$entry = new stdClass;
$entry = new stdClass();
$entry->hide = 0;
$entry->item = $type;
}
Expand All @@ -69,4 +69,4 @@
$DB->insert_record('block_custom_course_menu_etc', $entry);
}
}
echo json_encode(array(true));
echo json_encode([true]);
10 changes: 5 additions & 5 deletions ajax/toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
$catid = required_param('categoryid', PARAM_NOTAGS);
$userid = $USER->id;

$params = array(
$params = [
'userid' => $userid,
'categoryid' => $catid
);
'categoryid' => $catid,
];

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

Expand All @@ -46,11 +46,11 @@

$DB->update_record('block_custom_course_menu', $entry);
} else {
$entry = new stdClass;
$entry = new stdClass();
$entry->userid = $userid;
$entry->categoryid = $catid;
$entry->collapsed = 1;

$DB->insert_record('block_custom_course_menu', $entry);
}
echo json_encode(array(true));
echo json_encode([true]);
6 changes: 3 additions & 3 deletions ajax/visible.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
$item = 'course';
}

$params = array(
$params = [
'userid' => $userid,
'item' => $item,
'itemid' => $itemid,
);
];

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

Expand All @@ -64,4 +64,4 @@

$DB->insert_record('block_custom_course_menu_etc', $entry);
}
echo json_encode(array(true));
echo json_encode([true]);
79 changes: 49 additions & 30 deletions block_custom_course_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_custom_course_menu extends block_base {

/**
* Initialise the block.
*/
Expand Down Expand Up @@ -65,7 +64,7 @@ public function get_content() {
$this->page->requires->jquery();
$this->page->requires->js('/blocks/custom_course_menu/js/courses.js');

$this->content = new stdClass;
$this->content = new stdClass();
$this->content->footer = ' ';

$html = '<div id="custom_course_menu_application">'
Expand All @@ -76,32 +75,51 @@ public function get_content() {
$footer = "";
if (is_siteadmin($USER->id) || has_capability('moodle/cohort:manage', context_system::instance(), $USER->id)) {
$url = new moodle_url('/course/index.php');
$footer .= html_writer::tag('div', html_writer::link($url, get_string('fulllistofcourses') . '...'),
array('style' => 'text-align:center;'));
$footer .= html_writer::tag(
'div',
html_writer::link($url, get_string('fulllistofcourses') . '...'),
['style' => 'text-align:center;']
);
}

if (isset(get_config('block_custom_course_menu')->showsearch)) {
$showsearch = get_config('block_custom_course_menu')->showsearch;
if ($showsearch == 1 ||
($showsearch == 'admin' &&
(is_siteadmin($USER->id) ||
has_capability('moodle/cohort:manage', context_system::instance(), $USER->id)
)
if (
$showsearch == 1 ||
($showsearch == 'admin' &&
(is_siteadmin($USER->id) ||
has_capability('moodle/cohort:manage', context_system::instance(), $USER->id)
)
) {
$searchurl = new moodle_url('/course/search.php');
$footer .= html_writer::start_tag('form', array('id' => 'coursesearch',
'action' => $searchurl,
'method' => 'get'));
$footer .= html_writer::start_tag('fieldset', array('class' => 'coursesearchbox'));
$footer .= html_writer::empty_tag('input', array('type' => 'text',
'name' => 'search',
'class' => 'searchfield'));
$footer .= html_writer::link('javascript: coursesearch.submit()',
'<i class="fa fa-search"></i>',
array('id' => 'searchbutton'));
$footer .= html_writer::end_tag('fieldset');
$footer .= html_writer::end_tag('form');
)
) {
$searchurl = new moodle_url('/course/search.php');
$footer .= html_writer::start_tag(
'form',
[
'id' => 'coursesearch',
'action' => $searchurl,
'method' => 'get',
]
);
$footer .= html_writer::start_tag(
'fieldset',
['class' => 'coursesearchbox']
);
$footer .= html_writer::empty_tag(
'input',
[
'type' => 'text',
'name' => 'search',
'class' => 'searchfield',
]
);
$footer .= html_writer::link(
'javascript: coursesearch.submit()',
'<i class="fa fa-search"></i>',
['id' => 'searchbutton']
);
$footer .= html_writer::end_tag('fieldset');
$footer .= html_writer::end_tag('form');
}
}

Expand All @@ -110,20 +128,21 @@ public function get_content() {
// Takes into account hidden courses and permissions to get viewable count.
$courses = enrol_get_my_courses();

$hidelink = array();
$hidelink = [];
if (empty($courses) && empty($CFG->block_custom_course_menu_enablelastviewed)) {
$hidelink = array('class' => 'hidden');
$hidelink = ['class' => 'hidden'];
}

$this->content->text = '<div class="editingmode editingoff">';
$editicon = '<i class="fa editingicon"></i>';
$interface = new moodle_url('/blocks/custom_course_menu/interface.php');
$this->content->text .= html_writer::link($interface,
$editicon,
array_merge(array('id' => 'custom_course_menu_interface'), $hidelink));
$this->content->text .= html_writer::tag('div', '', array('style' => 'clear:both;'));
$this->content->text .= html_writer::link(
$interface,
$editicon,
array_merge(['id' => 'custom_course_menu_interface'], $hidelink)
);
$this->content->text .= html_writer::tag('div', '', ['style' => 'clear:both;']);
$this->content->text .= $html . '</div>';
return $this->content;
}
}

18 changes: 9 additions & 9 deletions classes/observers.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class observers {
*/
public static function user_deleted(\core\event\user_deleted $event) {
global $DB;
$DB->delete_records('block_custom_course_menu', array('userid' => $event->userid));
$DB->delete_records('block_custom_course_menu_etc', array('userid' => $event->userid));
$DB->delete_records('block_custom_course_menu', ['userid' => $event->userid]);
$DB->delete_records('block_custom_course_menu_etc', ['userid' => $event->userid]);
}

/**
Expand All @@ -51,15 +51,15 @@ public static function user_deleted(\core\event\user_deleted $event) {
*/
public static function course_deleted(\core\event\course_deleted $event) {
global $DB;
$DB->delete_records('block_custom_course_menu_etc', array(
$DB->delete_records('block_custom_course_menu_etc', [
'item' => 'course',
'itemid' => $event->courseid,
));
]);

$DB->delete_records('block_custom_course_menu_etc', array(
$DB->delete_records('block_custom_course_menu_etc', [
'item' => 'favorite',
'itemid' => $event->courseid,
));
]);
}

/**
Expand All @@ -70,10 +70,10 @@ public static function course_deleted(\core\event\course_deleted $event) {
*/
public static function course_category_deleted(\core\event\course_category_deleted $event) {
global $DB;
$DB->delete_records('block_custom_course_menu', array('categoryid' => $event->objectid));
$DB->delete_records('block_custom_course_menu_etc', array(
$DB->delete_records('block_custom_course_menu', ['categoryid' => $event->objectid]);
$DB->delete_records('block_custom_course_menu_etc', [
'item' => 'category',
'itemid' => $event->objectid,
));
]);
}
}
Loading
Loading