Table des matières

Improved My Moodle Widgets

The widgets of the improved my page

The improved My page uses widgets to compose a customised structure of the user's dashboard. These widgets can be called in their order of appearance in the central configuration of the Improved my page local component

The widgets are designed to take on the appearance of blocks, so as not to disturb the display logic if blocks are used in Moodle's side areas.

List of widgets

Impact of the double column layout

If the double column layout is enabled by the presence of the left_edition_column widget, then it is possible to distribute the widgets between the right column and the left column. Add the _L suffix to force a widget to stack in the left column.

Static and conditional contents

The static_<n> widget has a particular behaviour. It generally lets you publish static contents on the dashboard, between widgets, possibly tied to a condition to meet. Using static widgets requires installing the Static contents plugin, which will provide the editing principle.

The general form of the widget name is static_<extension>.

profile name shortname: local_my now accepts a profile field name with underscore. If a value is to be filled in, use a double underscore

Modal values are the different values available for a profile field. If the field is of “list” type, these are the list values. If it is of “text” type, it will be the set of all the texts entered for this field in Moodle.

The field name and the modal value are separated by a DOUBLE “_”. Profile field names containing a single '_' are therefore accepted.

Modal values are filtered as follows to obtain the modal keys:

Extensibility/customisation of the component

Making new widgets is a relatively simple operation, and consists of writing a function with a name prefixed by local_my_print_<widgetname>(&$excludedcourses, &$courseareacourses) in a new local_modules.php file at the root of the component. The generic modules are coded in the modules.php file in the same place.

The widget function receives two parameters:

The widget function is a pseudo renderer that must return the HTML contained in the widget. You can generate this content directly in the function

  function local_my_print_mysimplewidget(&$excludedcourses, &$courseareacourses) {
      // Get a list of courses through a custom function (associative by id).
      $courses = local_my_get_custom_courseset();
  
      // Remove the courses captured by the course areas.
      if (!empty($courseareacourses)) {
          foreach ($courseareacourses as $cid) {
              if (array_key_exists($cid, $courses)) {
                  unset($courses[$cid]);
              }
          }
      } 
  
      // Remove the courses excluded before.
      if (!empty($excludedcourses)) {
          foreach ($excludedcourses as $cid) {
              if (array_key_exists($cid, $courses)) {
                  unset($courses[$cid]);
              }
          }
      } 
  
      // Add what remains to the exclusions.
      foreach (array_keys($courses) as $cid) {
          $excludedcourses[] = $cid;
      }
      
      $str = '';
      // Print the lists...
      return $str;
  } 

You can also, as in some widgets, use a template that must be located in the component's templates directory:

  function local_my_print_templatedwidget(&$excludedcourses, &$courseareacourses) {
      global $OUTPUT;
  
      // ... exclusion code (see above)
  
      $template = new StdClass();
      $template->data1 = 'value1';
      // ....
      
      return $OUTPUT->render_from_template('local_my/customtemplate', $template);
  }


Back to the technical guide - Back to the component index - Back to plugins index - Back to catalogue