Wunderbyte-GmbH / moodle-mod_datalynx

Repository for the Datalynx Module for Moodle
7 stars 5 forks source link

Time field option 'display format' does not render if 'Date only' is selected #180

Open goose2000 opened 2 years ago

goose2000 commented 2 years ago

I found that making a custom 'display format' only would affect the displayed date if 'Date only' was NOT selected.

My user expectation was that if the format is set, would override either Date or Date only.

` public function render_display_mode(stdClass $entry, array $params) { $field = $this->_field; $fieldid = $field->id();

    $strtime = '';
    if (isset($entry->{"c{$fieldid}_content"})) {
        if ($content = $entry->{"c{$fieldid}_content"}) {
            if (!empty($params['format'])) {
                $strtime = userdate($content, $params['format']);
            } else if (isset($params['date']) || $field->dateonly) {
                $strtime = userdate($content, get_string("strftimedate"));
            } else if (isset($params['timestamp'])) {
                $strtime = $content;
            } else if (!empty($field->displayformat)) {
                $strtime = userdate($content, $field->displayformat);
            } else {
                $date = getdate($content);
                if ($date['seconds'] || $date['minutes'] || $date['hours']) {
                    $strtime = userdate($content, get_string("strftimedatetime"));
                } else {
                    $strtime = userdate($content, get_string("strftimedate"));
                }
            }
        }
    }
    return $strtime;
}`
goose2000 commented 2 years ago

I moved the $field->displayformat condition to the top of the else if conditions, this respects the custom date format display and still lets you choose to input date only or with time fields too.

file: \mod\datalynx\field\time\renderer.php

` public function render_display_mode(stdClass $entry, array $params) { $field = $this->_field; $fieldid = $field->id();

    $strtime = '';
    if (isset($entry->{"c{$fieldid}_content"})) {
        if ($content = $entry->{"c{$fieldid}_content"}) {
            if (!empty($params['format'])) {
                $strtime = userdate($content, $params['format']);
    } else if (!empty($field->displayformat)) {  // this goes to the top
                $strtime = userdate($content, $field->displayformat);
            } else if (isset($params['date']) || $field->dateonly) {
                $strtime = userdate($content, get_string("strftimedate"));
            } else if (isset($params['timestamp'])) {
                $strtime = $content;
            } else {
                $date = getdate($content);
                if ($date['seconds'] || $date['minutes'] || $date['hours']) {
                    $strtime = userdate($content, get_string("strftimedatetime"));
                } else {
                    $strtime = userdate($content, get_string("strftimedate"));
                }
            }
        }
    }
    return $strtime;
}`
dasistwas commented 2 years ago

Hi @goose2000 , in order to integrate your patch it would be great if you could do the following:

1) Fork the repo to your account (right top on github) 2) Make the changes on your repo (you can use the online editor in github directly) 3) Make a pull request https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request#creating-the-pull-request

then I can merge your changes.

Kind regards, David