function _get_coursemodule_info is being cachced

function _get_coursemodule_info is being cachced

by Raphael Goldman -
Number of replies: 6

Hello,

I have copied the file module, 

In my new module I need to open a link in a new window from the course page.

I wrote some code in the modulename_get_coursemodule_info function to attach an on click event to the activity.

I need to open the new window differently depeneding on the user browser.

The problem is that moodle is keeping the first enter of any user and since than all other users get the same onclick code as the first user.

How can I make moodle read my code everytime?

Thanks.

Raphael

Average of ratings: -
In reply to Raphael Goldman

תשובה ל: function _get_coursemodule_info is being cachced

by Raphael Goldman -

I have found a solution.

If I put those 2 lines in remark it is working.

the lines are at lib/modinfolib.php

$cachecoursemodinfo = cache::make('core', 'coursemodinfo');

      $cachecoursemodinfo->set($course->id, $coursemodinfo); 

What will be the meaning of putting those line in remark?

Thanks,

Raphael

In reply to Raphael Goldman

Re: תשובה ל: function _get_coursemodule_info is being cachced

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

No - you definitely don't want to do that. This will seriously harm the performance of your Moodle site.

If you want information that is calculated per-user (and can accept the performance hit this will entail) then use the MODNAME_cm_info_view function, which is called every time the course is viewed, rather than the MODNAME_get_coursemodule_info which is called once and then cached (until rebuild_course_cache($courseid) is called).

See mod/forum/lib.php, forum_cm_info_view(cm_info $cm) for an example.



In reply to Davo Smith

תשובה ל: Re: תשובה ל: function _get_coursemodule_info is being cachced

by Raphael Goldman -

Thanks,

Does this function return something or just set the info for each course module?

How can I set the onclick event for the module?

This the current function:

function cet_cm_info_view(cm_info $cm) {

    $details = $cm->get_custom_data();

    if ($details) {

        $cm->set_after_link(' ' . html_writer::tag('span', $details,

                array('class' => 'cetlinkdetails')));


    }


}

The problem is that $cm contain data off all activities in course ! I expected it to hold only daya of 1 activity.

Thanks,

Raphael

In reply to Raphael Goldman

Re: תשובה ל: Re: תשובה ל: function _get_coursemodule_info is being cachced

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Look in lib/modinfolib.php - class cm_info.

That should answer all your questions a lot quicker than asking in the forums.

In reply to Davo Smith

תשובה ל: Re: תשובה ל: Re: תשובה ל: function _get_coursemodule_info is being cachced

by Raphael Goldman -

Hi,

It is still not working.

If I set the onclick in  the 

cet_cm_info_view function nothing happen.

This is how I set the onclick.

$cm->set_on_click("http://www.google.com");

What m I doing wrong?

Thanks,

Raphael


In reply to Raphael Goldman

תשובה ל: Re: תשובה ל: Re: תשובה ל: function _get_coursemodule_info is being cachced

by Raphael Goldman -

This is the function declaration:

    /**

     * Sets value of on-click attribute for JavaScript.

     * Note: May not be called from _cm_info_view (only _cm_info_dynamic).

     * @param string $onclick New onclick attribute which should be HTML-escaped

     *   (empty string if none)

     * @return void

     */

    public function set_on_click($onclick) {

       // $this->check_not_view_only();

        $this->onclick = $onclick;

    }

So I can't use that function in cm_info_view, Is there any other solution?


Raphael