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

Standard Message API (code included)

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Inactive
    • Icon: Minor Minor
    • None
    • 1.9.4, 2.0
    • General
    • MOODLE_19_STABLE, MOODLE_20_STABLE

      I have found that recently every time I code a block or a module I end up writing up some sort of notification system to inform the user of errors or to inform the user that something worked successfully.

      So, I thought that a standard API would be nice to have because I have noticed that other modules are also having to create custom code for informing the user of what has happened. Also, by having a standard API, the look and feel of Moodle will be more singular.

      The proposed API has a method for setting any number of messages. These messages are stored in the session to allow for calling a redirect before printing the message. And of course, the API has a method for printing all of the messages. All messages are printed with notify().

      Note: The function for printing the messages could even be called in the theme header or in print_header so that all messages are printed in the same location.

      Here is the PHPdoc of the two functions:

      /**

      • Sets a message to be printed. Messages are printed
      • by calling {@link print_messages()}

        .
        *

      • @uses $SESSION
      • @param string $message The message to be printed
      • @param string $class Class to be passed to {@link notify()}. Usually notifyproblem or notifysuccess.
        * @param string $align Alignment of the message
        * @return boolean
        **/
        function set_message($message, $class="notifyproblem", $align='center')

        /**
        * Print all set messages.
        *
        * See {@link set_message()} for setting messages.
        *
        * Uses {@link notify()}

        to print the messages.
        *

      • @uses $SESSION
      • @return boolean
        **/
        function print_messages()

            Unassigned Unassigned
            bushido Mark Nielsen (Inactive)
            Votes:
            5 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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