Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment with restrictions changes "Availability" label #34

Open
seb-vial opened this issue Dec 5, 2022 · 0 comments
Open

Assignment with restrictions changes "Availability" label #34

seb-vial opened this issue Dec 5, 2022 · 0 comments

Comments

@seb-vial
Copy link

seb-vial commented Dec 5, 2022

Hi,

we recently noticed that the "Availability" label in assignments settings is replaced with JSON code if the assignment has restrictions.

image

To reproduce this issue, follow these steps:

  1. Enable metadata for modules
  2. Add an assigment with at least one restriction (it doesn’t matter which one)
  3. Go back to settings for the newly created assignment

You should see that the JSON code that describes the restriction has now replaced the "Availability" label.

Why is this happening ?

Well, Moodle is kinda responsible for this…

In the "course_modules" table, there is a "availability" column which will contain JSON if the module has some restrictions. Now, when building the form for the assignment, Moodle creates a header with the same name as the "availability" column and sets the value as a simple string that will be translated for the user (Availability in English).

In this plugin, there is a Moodle hook that will add any module metadata to the form (see coursemodule_standard_elements in context/module/classes/context_handler.php).
The problem with this method is that every piece of information is fetched from the database as an stdClass object which is then merged with metadata for this particular module. Finally this object is passed to populate the form. If the module has restriction, the "availability" header of the form is being replaced by the value of the column "availability" stored in the "course_modules" table (aka JSON value).

$formwrapper->get_coursemodule() could possibly be used instead of $this->get_instance() which builds the query to fetch the module information from the DB, but we pretty much get the same object with "availability" column. I’ve tried to make a simple intance object with the module id:

$instance = new \stdClass();
$instance->id = $this->instanceid;
local_metadata_load_data($instance, $this->contextlevel);
$formwrapper->set_data($instance);

and it works.
I believe this is working because the form is probably populated with values for the default assignment fields and it only needs the values for additionnal metadata fields. This is just a guess of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant