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

Allow setting a subset of the available units in moodleform duration field

    XMLWordPrintable

Details

    • MOODLE_27_STABLE, MOODLE_39_STABLE
    • MOODLE_39_STABLE
    • Easy
    • Hide

      A) Preparations

      1. Edit course/edit_form.php
      2. Look for a line with the comment // Description..
      3. Immediately before that line, insert the following code:

                $mform->addElement('header', 'duration',  get_string('durationunits', 'admin'));
                $mform->setExpanded('duration');
                $mform->addElement('duration', 'durationunitstest1', 'Duration units test 1', array('units' => array(60, 3600)));
                $mform->addElement('duration', 'durationunitstest2', 'Duration units test 2', array('units' => array(3600, 86400, 604800)));
                $mform->addElement('duration', 'durationunitstest3', 'Duration units test 3', array('units' => array(1)));
                $mform->addElement('duration', 'durationunitstest4', 'Duration units test 4', array('units' => array()));
                $mform->addElement('duration', 'durationunitstest5', 'Duration units test 5');
        

      4. Save changes.

      B) Verifications (with boost and classic)

      1. Go to any course existing in the site (or create a new one) and Edit settings
      2. In the form, after the course names and before the description there should be a "duration units" section, expanded with 5 elements.
      3. In that section, *verify that*:
        1. Duration units test 1 shows (in the units menu): minutes, hours
        2. Duration units test 2 shows: hours, days, weeks
        3. Duration units test 3 shows: seconds
        4. Duration units test 4 shows: seconds, minutes, hours, days, weeks
        5. Duration units test 5 shows: seconds, minutes, hours, days, weeks

      C) Don't forget to clean the changes performed to course/edit_form.php after the tests.

      Show
      A) Preparations Edit course/edit_form.php Look for a line with the comment // Description. . Immediately before that line, insert the following code: $mform->addElement('header', 'duration', get_string('durationunits', 'admin')); $mform->setExpanded('duration'); $mform->addElement('duration', 'durationunitstest1', 'Duration units test 1', array('units' => array(60, 3600))); $mform->addElement('duration', 'durationunitstest2', 'Duration units test 2', array('units' => array(3600, 86400, 604800))); $mform->addElement('duration', 'durationunitstest3', 'Duration units test 3', array('units' => array(1))); $mform->addElement('duration', 'durationunitstest4', 'Duration units test 4', array('units' => array())); $mform->addElement('duration', 'durationunitstest5', 'Duration units test 5'); Save changes. B) Verifications (with boost and classic) Go to any course existing in the site (or create a new one) and Edit settings In the form, after the course names and before the description there should be a "duration units" section, expanded with 5 elements. In that section, * verify that *: Duration units test 1 shows (in the units menu): minutes, hours Duration units test 2 shows: hours, days, weeks Duration units test 3 shows: seconds Duration units test 4 shows: seconds, minutes, hours, days, weeks Duration units test 5 shows: seconds, minutes, hours, days, weeks C) Don't forget to clean the changes performed to course/edit_form.php after the tests.

    Description

      The moodleform duration field allows the user to enter duration by one of the following units: weeks, days, hours, minutes, seconds.

      In some use cases we may want only a subset of the unit options. For instance, students should report time spent on a certain activity either by hours or by minutes.

      This can be implemented by adding to the field fourth paramter api an option 'units' that is an array of units to display.

      Attachments

        Issue Links

          Activity

            People

              timhunt Tim Hunt
              itamart Itamar Tzadok
              Mark Johnson Mark Johnson
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Anna Carissa Sadia Anna Carissa Sadia
              Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Sujith Haridasan, Huong Nguyen, Barbara Ramiro, Bas Brands, Mathew May
              Votes:
              2 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                15/Jun/20

                Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 hour, 5 minutes
                  1h 5m