Link to Gradebook in Essential Custom Dashboard Items Menu

Link to Gradebook in Essential Custom Dashboard Items Menu

by Emilie Lenel -
Number of replies: 17

Hi Mary
In the file core_rendered.php, the dashboard items are built with $branch->add
$branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);

For instance :
$branch->add('<em><i class="fa fa-user"></i>'.get_string('profile').'</em>',new moodle_url('/user/profile.php'),get_string('profile'));

How would i transpose your proposal with this code ?

Thanks again
Emilie

(Edited by Mary Evans - Split from another discussion about Gradebook link - original submission Tuesday, 22 July 2014, 12:41 PM)

Average of ratings: -
In reply to Emilie Lenel

Re: Link to Gradebook in Custom Menu

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Oh I see...sorry I thought you were adding this as a single branch.

This is what come of asking a question in someone elses question.

It's actually better to ask a question by starting a new thread if you cannot understand how to do something. This way we get a better idea of the problem you are having and build the answer around your theme.

OK...you don't need the array, so you need to add the id like this

$branch->add('<em><i class="fa fa-bar-chart-o"></i>'.get_string('my_grades', 'block_my_grades').'</em>',new moodle_url('/grade/report/user/index.php?id='.$USER->id), get_string('my_grades', 'block_my_grades'));    

In reply to Mary Evans

Re: Link to Gradebook in Custom Menu

by Emilie Lenel -

Dear Mary

Sorry for the confusion, indeed i should have created a new thread...

This code doesn't work, moodle is expecting a course id (nocourseid)

But maybe we can't access directly to the gradebook when we're out of a course ?

Emilie


In reply to Emilie Lenel

Re: Link to Gradebook in Custom Menu

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Well that code may well be wrong as I don't have access to a server to test it out. there really should be conditional statement to determine the conditions when it can be used and by whom. 

In reply to Emilie Lenel

Re: Link to Gradebook in Custom Menu

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Where is the block my grade? As.The link is a user ID not a course.

so this is nothing to do with the code I gave giampaolo but more to do with the lang string you are pointing it to. If the my_grade string is only accessible when in a course then you cannot access the grader outside of that course.

if you need a custom string then you need to add one in essential/lang/en/theme_essential.php

In reply to Mary Evans

Re: Link to Gradebook in Custom Menu

by Emilie Lenel -

Hi Mary,

The block my grade is on 'My page'

BTW, i tried today the code including the title directly :

$branch->add('<i class="fa fa-bar-chart-o"></i>Grades',new moodle_url('/grade/report/user/index.php?id='.$USER->id), 'Grades');

And still the msg error/nocourseid

We'll deploy the Essential theme in September, since we don't succeed to implement the link Grades into the dashboard, we'll add the block My grades by default on 'My page' instead.  But it's a real pitty, i am pretty sure students will expect to find 'Grades' into the dashboard, together with his msgs, agenda etc.

Emilie

In reply to Emilie Lenel

Re: Link to Gradebook in Custom Menu

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I'll be at my computer later today and will test this out.

In reply to Emilie Lenel

Re: Link to Gradebook in Custom Menu

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Try adding this url instead...
 new moodle_url('/grade/report/user/index.php?id=' . $COURSE->id)
      

And then enclose the branch with this conditional statement...

if (!empty($COURSE->id)) {
        if (($COURSE->id) >=2) {

add the modified branch here...

}

}


 

In reply to Mary Evans

Re: Link to Gradebook in Custom Menu

by Emilie Lenel -

Mary,

I tested your code in essential/renderers/core_rendered.php :

            if (!empty($COURSE->id)) {
                if (($COURSE->id) >=2) {
                    $branch->add('Grades',new moodle_url('/grade/report/user/index.php?id='.$COURSE->id), 'Grades');
                }
           }

It doesn't work either

From my page, or even a course page, $COURSE->id is always empty..

I tried without the conditional statement, the generated url is "http://lfoadtest.unicaen.fr/moodle/grade/report/user/index.php?id"

Emilie

In reply to Emilie Lenel

Re: Link to Gradebook in Custom Menu

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

    In that case try this..    

    if (!empty($COURSE->id)) {
                    $branch->add('Grades',new moodle_url('/grade/report/user/index.php?id='.$COURSE->id), 'Grades'); 
                }
    

In reply to Mary Evans

Re: Link to Gradebook in Custom Menu

by Emilie Lenel -

Hi Mary

Have you tested this code ? Does it work on your side ?

It doesn't work on my moodle, as mentioned $COURSE->id is always empty..


In reply to Emilie Lenel

Re: Link to Gradebook in Custom Menu

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Did you try that last code I posted? Because the link will not show up if there is no Course ID

the way I have the grader as a link is on a courses page so a student on a course can see the link iin the top menu bar on this site...

http://bylazydaisy.co.uk/moodle

so the fact that the code you have added is not correct for what you want to do.

i cannot test in essential theme until later this evening.

In reply to Emilie Lenel

Re: Link to Gradebook in Custom Menu

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Don't use the global, use '$this->page->course->id' within that method.

In reply to Gareth J Barnard

Re: Link to Gradebook in Custom Menu

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Thanks Gareth! I knew you would help me!

In reply to Emilie Lenel

Re: Link to Gradebook in Custom Menu

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Emilie,

Yes it does work on my site, but needed another setting to be added to the function, which I have added below. However, it will only show up in the menu when in a course page as the gradebook relates to the course the user is enrolled into,

        /*
        * This code adds the My Dashboard
        * functionality to the custommenu.
        */
        global $CFG, $COURSE, $USER;

        $hasdisplaymydashboard = (empty($this->page->theme->settings->displaymydashboard)) ? false : $this->page->theme->settings->displaymydashboard;
        if (isloggedin() && !isguestuser() && $hasdisplaymydashboard) {
            $branchlabel = '<i class="fa fa-dashboard"></i> '.get_string('mydashboard', 'theme_essential');
            $branchurl   = new moodle_url('/my/index.php');
            $branchtitle = get_string('mydashboard', 'theme_essential');
            $branchsort  = 10001;

            $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
            $branch->add('<em><i class="fa fa-user"></i> '.get_string('profile').'</em>',new moodle_url('/user/profile.php'),get_string('profile'));
            $branch->add('<em><i class="fa fa-calendar"></i> '.get_string('pluginname', 'block_calendar_month').'</em>',new moodle_url('/calendar/view.php'),get_string('pluginname', 'block_calendar_month'));
            // Check if messaging is enabled.
            if (!empty($CFG->messaging)) {
                $branch->add('<em><i class="fa fa-envelope"></i> '.get_string('pluginname', 'block_messages').'</em>',new moodle_url('/message/index.php'),get_string('pluginname', 'block_messages'));
            }
            // Check if badges are enabled.
            if (!empty($CFG->enablebadges)) {
                $branch->add('<em><i class="fa fa-certificate"></i> '.get_string('badges').'</em>',new moodle_url('/badges/mybadges.php'),get_string('badges'));
            }
            // Check if a course id exists.
            if (!empty($COURSE->id)) {
                if (($COURSE->id) >=2) {
                    $branch->add('<em><i class="fa fa-book"></i> '.get_string('grade').'</em>',new moodle_url('/grade/report/user/index.php?id='.$COURSE->id),get_string('grade'));
                }
            }
            $branch->add('<em><i class="fa fa-list-alt"></i> '.get_string('forumposts', 'mod_forum').'</em>',new moodle_url('/mod/forum/user.php?id='.$USER->id));
            $branch->add('<em><i class="fa fa-list"></i> '.get_string('discussions', 'mod_forum').'</em>',new moodle_url('/mod/forum/user.php?id='.$USER->id.'&mode=discussions'));
            $branch->add('<em><i class="fa fa-sign-out"></i> '.get_string('logout').'</em>',new moodle_url('/login/logout.php'),get_string('logout'));
        }

In reply to Mary Evans

Re: Link to Gradebook in Custom Menu

by Emilie Lenel -

Hi Mary

Thanks a lot !! it works !!! smile (maybe we could suggest to have it by default for next Essential release)

I replaced the /grade/report/user by /grade/report/overview to reach the overall gradebook

BTW, there's no possibility for a student to find 'My grades' in the dashboard menu when he is on 'my Page'  ?

And can you explain what is the function of $branchsort ?

Thanks again

Emilie

In reply to Emilie Lenel

Re: Link to Gradebook in Custom Menu

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

HI,

Well I am glad that works now. It was so frustrating being away from home and not able to do any testing.

Good idea about the Overview, I was trying to find that in the Profile menu and it is missing!  How odd...is that a BUG? Working with theme one tends to assume the links are in place, I was sad to find that this is not necessarily true. I need to follow that up,

$branchsort is the place holder for the branch.

For example if you wanted the 'My Dashboard' to be first in the menu bar then you would need to make'My Dashboard' $branchsort = -1 as position 1 is reserved for the main menu, if it is used, so you are in fact moving it 1 place to the left.

There have been discussions in the forum about the odd position changing of the 'My Dashboard' and the 'My Courses' branches. The main reason for this is that they both use $branchsort 10000 (which to me is a ridiculous value anyway) it would be better if these menus were given -1 and -2 so -2 would be first and -1 next then if the main menu existed these would follow after 'My Courses' and then the Language menu last.

So the sort is another word for positioning...

{custom positioning - defined in theme renderer ... -3 -2 -1} | {1 2 3 ... Main menu positioning - defined in theme settings page }

Hope that explains things?

Cheers

Mary

In reply to Mary Evans

Re: Link to Gradebook in Custom Menu

by Emilie Lenel -

Hi Mary

Thanks for your clear explanations !!! and your strong support !

I was also looking for a way to place 'my dashboard' in first position and 'mycourse' in 2nd in the menu bar, so you gave me the solution ! smile)


Cheers
Emilie