Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-75518

Improve mod_data preset plugins preview with real world examples

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.1
    • 3

      Since MDL-75149 the database activity has the feature to preview both user presets (create from a database instance) and plugin presets (static presets as installed plugins). By default, the preview uses generic values to represent the fields. However, for plugin presets have a preset.xml than can be expanded to include also field data samples.

      The proposal is to include real-world fields sample in the plugin presets to ensure the preview is less abstract and more down-to-earth. For now, this change will affect only the preset plugins, user plugins will require extra UX proposal and will be done in a separate issue (not in the roadmap yet).

      Technical shaping details (based on the code from MDL-75149):

      Point 1: Getting the preset.xml data from a mod_data\preset method is easy. The method should call $this->load_preset_xml(); to ensure $this->xmlinfo is loaded, the method will only parser the XML file once so it does not matter if it is called on every single method that needs to access the XML. There's an example of how to use it in mod_data\preset::get_fields method.

      Point 2: by default, field instances take the field data directly from the data_content table. To mark that the field is in preview mode, mod_data\preset::get_field_instance will use the set_preview method. Right now this method has only one boolean as param (the new preview value). With the new patch, this method should receive an optional array of sample field data extracted from a new mod_data\preset method and will be stored as a new class attribute.

      Point 3: each field plugin capable of having a preview will override the data_field_base::supports_preview and data_field_base::get_data_content_preview methods. However, in case the preset provides alternative field data from the preset.xml, meaning the method to patch is data_field_base::get_data_content because is the method that returns the entry data to use.

      The new logic should be:

      1. If the field is in preview mode and provides an alternative field data --> return the next provided field data.
      2. If the field is in preview mode and it does not have an alternative field data --> return the one generated by data_field_base::get_data_content_preview
      3. Otherwise, query the 'data_content' table to get the real field data.

      Point 4: the preset can provide more than one sample entry with all the fields data. This means that data_field_base::get_data_content should use the provided $recordid to return a different entry each time.  We cannot ensure how many entries the preset will provide so we need to use % operator like: $samples[$recordid % count($samples)]

      Point 5: the new logic in get_data_content and set_preview should be tested by PHPUnit. The specific preset preview should be tested using behat.

       

            Unassigned Unassigned
            tusefomal Ferran Recio
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.