How to use Default Section Name with Custom Name in Weekly Topic?

How to use Default Section Name with Custom Name in Weekly Topic?

by Ricardo MacCord -
Number of replies: 1

Hi,

I'm using Moodle 2.5 with Formal White Theme, and I wanted to know how to use the Default Section Name With a Custom Name in the Weekly Topics.

When I use Default Section Name, Moodle display automatically the week date (ex: 7 april - 14 april), but I can't use a Custom Title. I wanted to keep this automatic week date function with a custom title. (ex: 7 april - 14 april - Module 01: How to study!).


The idea is to include the date automatcally without having to type it manually in the custom title.


I already searched the code "sectionname" and "usedefaultname" (and others like that), but I didn't find where Moodle create the HTML code. Can someone help me (to find where and what I have to change)?

Average of ratings: -
In reply to Ricardo MacCord

Re: How to use Default Section Name with Custom Name in Weekly Topic?

by Ricardo MacCord -

Ok guys, somehow I managed to solve my problem :D

In case anyone else have the same need that I did, here is the solution:


On Moodle 2.5, open the file course/format/weeks/lib.php, at line 53, find the code:

public function get_section_name($section) {
        $section = $this->get_section($section);
        if ((string)$section->name !== '') {
            // Return the name the user set.
            return format_string($section->name, true, array('context' => context_course::instance($this->courseid)));

        } else if ($section->section == 0) {
            // Return the general section.
            return get_string('section0name', 'format_weeks');

        } else {
            $dates = $this->get_section_dates($section);
            // We subtract 24 hours for display purposes.
            $dates->end = ($dates->end - 86400);
            $dateformat = get_string('strftimedateshort');
            $weekday = userdate($dates->start, $dateformat);
            $endweekday = userdate($dates->end, $dateformat);
            return $weekday.' - '.$endweekday;
        }
    }

And bring the $dates=$this... to the first IF, and then edit it the way you like. After the customization, my code looks like this:


    public function get_section_name($section) {
        $section = $this->get_section($section);
        if ((string)$section->name !== '') {
            // Return the name the user set.
           // TESTING TO INCLUDE THE AUTOMATIC DATES WITH THE SECTION NAME


           $dates = $this->get_section_dates($section);

            // We subtract 24 hours for display purposes.
            $dates->end = ($dates->end - 86400);
            $dateformat = get_string('strftimedateshort');
            $weekday = userdate($dates->start, $dateformat);
            $endweekday = userdate($dates->end, $dateformat);
            return '<span class="dateSection">'.$weekday.' a '.$endweekday.'</span>'.format_string($section->name, true, array('context' => context_course::instance($this->courseid)));

           // END OF TEST
            //return format_string($section->name, true, array('context' => context_course::instance($this->courseid)));

        } else if ($section->section == 0) {
            // Return the general section.
            return get_string('section0name', 'format_weeks');

        } else {
            $dates = $this->get_section_dates($section);
            // We subtract 24 hours for display purposes.
            $dates->end = ($dates->end - 86400);
            $dateformat = get_string('strftimedateshort');
            $weekday = userdate($dates->start, $dateformat);
            $endweekday = userdate($dates->end, $dateformat);
            return $weekday.' - '.$endweekday;
        }
    }


With this, if you use de Default Name, it will only display the dates, and if you use a Section Name, it will display the Dates + Section Name. See the image attached to see the result (ps: the position and style I changed with CSS).

Thanks for all the posts in the forum, it was with them that I managed to find some tips to my solution.


Attachment Untitled-1.jpg
Average of ratings: Useful (1)