Site-Wide Reports

Site-Wide Reports

by Jeremy Schweitzer -
Number of replies: 8
Picture of Plugin developers Picture of Testers

The documentation for this module states that "Administrators (or those who have the capability of viewing site reports)" can see the list of all certificates generated; however, the second part of that doesn't seem to working. I need to have several non-adminstrators be able to see the list of all certificates generated (it's the only admin-style function they need).

Does this not work? Or what exact permissions does someone actually need in order to see the report?

Average of ratings: -
In reply to Jeremy Schweitzer

Re: Site-Wide Reports

by Kaalgat - -
Hi Jeremy

See that you have the Report My Certificates add-on installed on your site.

You should then be able to change the permission of who can see all of the issued certificates on the site, by changing one word in the report_my_certificates.php file.

Search for this word within the
report_my_certificates.php file:

is_primary_admin

And then replace that word with any one of the following words (according to your needs):

isadmin
iscreator
isediting
isguest
isguestuser
isloggedin
ismember
ismoving
isstudent
isteacher
isteacheredit
isteacherinanycourse

Save and upload the new file.

This should then allow that new user role to be able to see a list of
all of the certificates issued on the site, by accessing a link similar to this link for your site:

http://<your_moodle_site_path>/mod/certificate/report_my_certificates.php


Kaalgat.
Average of ratings: Useful (1)
In reply to Kaalgat -

Re: Site-Wide Reports

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
No. Don't do that. All those functions are deprecated.

The right way to handle this is to define a new capability

mod/certificate:viewmycertificatesreport

in the mod/certificate/db/access.php file.

Then change the code to check has_capability('mod/certificate:viewmycertificatesreport', get_context_instance(CONTEXT_SYSTEM));

Then, the administrator can choose who can see the report by editing the role definitions.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Site-Wide Reports

by Ms. Letha Sanders -

Hi Tim,

My access.php file isn't very big.  But, would this be the section I change to allow the administrator to choose who can see the report by editing the role definitions?

$mod_certificate_capabilities = array(

    'mod/certificate:view' => array(

        'captype' => 'read',
        'contextlevel' => CONTEXT_MODULE,
        'legacy' => array(
            'student' => CAP_ALLOW,
            'teacher' => CAP_ALLOW,
            'editingteacher' => CAP_ALLOW,
            'coursecreator' => CAP_ALLOW,
            'admin' => CAP_ALLOW
        )
    ),

Would I replace all of the above with this:  has_capability('mod/certificate:viewmycertificatesreport', get_context_instance(CONTEXT_SYSTEM));

It's probably true that the inexperienced have no business messing with code.  That's why I need to be very clear with what I change. 

Thank you for your instruction.

Ms. Letha 


In reply to Ms. Letha Sanders

Re: Site-Wide Reports

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
No, you have not really understood how the roles system works.

.../db/access.php just defines what capabilities exist. The bit above in yellow really only tells Moodle that there is a capability called'mod/certificate:view'. The rest is just details.

You will see that $mod_certificate_capabilities is an array. You can define as many capabilities as you like by adding more elements to the array.

When a plugin is installed or upgraded, the list of capabilities is loaded from .../db/access.php and stored in the database.

Admins control which users have which capabilities by going to Admin -> Users -> Permissions -> Define roles in the Admin UI. (Some of the yellow details above are about setting the defaults for those admin settings.) The other things that affect what a user can do are what role assignments they have, and whether there are any role overrides.

The place to put code like has_capability('mod/certificate:viewmycertificatesreport', get_context_instance(CONTEXT_SYSTEM)) is the place where it currently says is_primary_admin, and Kaalgat - told you to change it.

However, if you are not very confident messing with PHP code, it may be better to wait for the maintainers of this bit of code to make the necessary changes, and release an updated version of the module.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Site-Wide Report

by Kaalgat - -
Hi

Ms. Letha persuaded me to build this functionality into a newer version of the add-on available here, I followed Tim's suggestions.

It now uses the mod/certificate:manage role to check to display all the certificates on the site, or only certificates achieved by the logged in user.

Kaalgat.

In reply to Kaalgat -

Re: Site-Wide Report

by Jeremy Schweitzer -
Picture of Plugin developers Picture of Testers
Kaalgat,

Thanks for sending me a note that you'd made changes. I'm just starting to teach myself to code so that I can hopefully start to do enhancements like this myself someday.

It looks like we don't have access to the updated version yet, but I'll try it as soon as it's available.

Thanks,
Jeremy