Question Page Title Formatting in Moodle 2.0.1

Question Page Title Formatting in Moodle 2.0.1

Matt Fedorko - ން
Number of replies: 31

Hello, this is a repost of an issue we're having from the Quiz Module forum. It belongs here -- the quizzes, as near as I can tell, work properly.

This is not the same issue as the changes in page titles in Content Pages in Lessons, referenced here: http://moodle.org/mod/forum/discuss.php?d=165481

This occurs in all themes, including Base. It occurs in both Question Pages migrated from 1.9 as well as new Question Pages made in 2.0. It is a serious problem in IE8 -- the text goes off the screen and no horizontal scroll bar is presented. Chrome and Firefox will at least wrap the code for you. To quote Mike's original post:

"The Page Title is not being output, and the page content is being put inside the legend tag.

The problem code:

<legend class="ftoggler">
<div class="box contents">
<p>
You need to connect a PV system with a 240V single phase output to a 120V/240V single phase electrical panel with a 100A master circuit breaker.  You do not know anything else about the busbars.  What is the maximum output power in watts) that the NEC permits for the PV system's inverter?
</p>
</div>
</legend>

This renders thusly:

IE screw up question page

To continue quoting Mike:

"As you can see, the "Page Title" is no where to be seen, and the "Page Content" has been put into the legend tag of the fieldset. (Firefox & Chrome render this slightly differently:FF injects the "missing" legend end tag, and Chrome will wrap the text so it's at least all visible)

Is there a known fix for this?"

Anyone?

Thanks in advance. This is the first issue I've come across in 2.0 that renders something unusable.

Average of ratings: -
In reply to Matt Fedorko

Re: Question Page Title Formatting in Moodle 2.0.1

Joseph Rézeau - ން
ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ

Hi Matt,

As I've said before, it is impossible to help you if we cannot replicate your problem. As you may be aware, there have been enormous changes between 1.9 and 2.0 moodle versions, especially in the themes. I suspect that your conversion of your former 1.9 theme to 2.0 is causing the problem.

If you switch your moodle 2.0 site to plain Standard theme (for 2.0), are you still having the display problem or does it disappear?

Also, what really matters in the end is how the Lesson pages look to the student, not to the teacher. All the screenshots that have been posted so far show the teacher view. What about a student screenshot, with one of the core 2.0 themes, and especially Standard theme?

Joseph

In reply to Joseph Rézeau

Re: Question Page Title Formatting in Moodle 2.0.1

Matt Fedorko - ން

Thanks for your persistence, Joe, and I apologize we keep posting images in our theme. We're doing that because we've seen no reason to stop using our theme since we switch to other themes to check that these problems exist, which they do, then switch back to at least maintain our branding.

Here is what this problem looks like in Standard theme.

Standard theme error

As you can see, the problem still exists in Student view in the Standard theme. I have checked at least 6 themes now and do not feel like posting screen shots of this same error in every theme.

We did not convert a 1.9 theme to a 2.0 theme, we recreated our 1.9 theme in 2.0 by modifying 2.0's Base theme.

I hope this puts your suspicions that these problems are related to our theme to rest. I have not yet posted a problem on this forum without first checking other themes. Again, we're using our theme still because I see no point in doing otherwise if the problem exists in both places.

 

FYI: The title for this Question Page is "Question on Load Side Connections." That does not appear anywhere when the page is displayed or previewed, as a student or a teacher or a guest, in the Standard theme, in the Base theme, in our theme or the magazine theme, or any of the other ones I've tried. The full text of the question is only partially shown in the screenshot above. At least 2 sentences are not shown at all, and the ones that are shown are truncated.

In reply to Matt Fedorko

Re: Question Page Title Formatting in Moodle 2.0.1

Matt Fedorko - ން

Joseph, let me ask, are you not able to replicate this issue on your install of 2.0? You create Question Pages inside Lessons, and when they are viewed (Preview or by a student), they are formatted correctly (displaying Question Page title and text appropriately, without running off the screen)? If not, what do you recommend we try next? Wait for a new build?

As I've said, this is the only problem I've yet mentioned that is a game ender. If the student can not see the question fully in a question page, they can not continue with the lesson.

Thank you for your time.

In reply to Matt Fedorko

Re: Question Page Title Formatting in Moodle 2.0.1

Joseph Rézeau - ން
ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ

Matt,

Here is a screenshot of a "short answer" question in Lesson, moodle 2.0.1, using Standard theme. The question text displays correctly.

Please note that in Moodle 1.9 and 2.0 alike the page title is not displayed for pages of the Question type, it is only displayed for questions of the "Branch table" (1.9) now called "Content Page" (2.0) type. This does not seem very coherent.

Just to make sure: when you create a question in Lesson in moodle 2.0, using Standard theme, do you actually type the question text in the HTML editor, or do you copy-paste from somewhere else (thus maybe bringing extra formatting which causes the display problem)?

Joseph

Attachment 06-01-2011 23-49-31.jpg
In reply to Joseph Rézeau

Re: Question Page Title Formatting in Moodle 2.0.1

Matt Fedorko - ން

Joseph,

Well, HUH.

I have seen the problems with copying and pasting out of word processors and websites before -- if I have to do a large amount of copying and pasting I copy everything into Notepad and out again in order to strip formatting. I typed a short answer question into the Standard theme and it displayed like this in IE 8:

IE QP

And like this in Chrome:

Chrome QP

While it's certainly readable in Chrome, my audience is predominantly older (north of 45 or 50) and more likely than not to be using IE -- I'm not sure recommending a browser change would fly.

The formatting does seem to just be a little OFF in IE across the site. Check out the Button in the IE shot, for instance -- a lot of them around the site are like this in IE, with the last letter being cut off (the Edit page contents button at the top is like this as well). In your screenshot, they're not. Anyway, that's neither here nor there.

Is this not the same issue?

http://moodle.org/mod/forum/discuss.php?d=165804

referencing: http://moodle.org/mod/forum/discuss.php?d=165323

 

 

In reply to Matt Fedorko

Re: Question Page Title Formatting in Moodle 2.0.1

Mike Holzer - ން

Alright, I tracked down the problem and have a fix!

To reitterate:

On a Lesson question page, the question content is being used as the title. The question title is completely disregarded.

This issue affects all question types (short answer, essay, multichoice, matching, numeric, true/false).

 

Problem:

The backend showing the 2 fields

Figure 1: The backend showing the 2 fields


The page title is completely absent from the rendered question and the content is found where the title SHOULD be.

The rendered question. Note no page title and the legend being off kilter

Figure 2: The rendered question. Note no page title and the legend being off kilter

Firefox and Chrome handle this issue much more gracefully than IE, but it’s still wrong.

 

A closer look at the code reveals that in fact the page content is being placed inside of the legend (markup and all) which is almost definitely wrong.

<fieldset class="clearfix"  id="pageheader">

<legend class="ftoggler">

<div class="box contents">

<p>This is a big ol question and you should probably have this be a buig fraking pain in the neck…SNIP

</p>

</div>

</legend>

<div class="advancedbutton"></div>

<div class="fcontainer clearfix">

<div class="fitem">

<div class="fitemtitle">

<label for="id_answer">Your answer </label>

</div>

<div class="felement ftext">

<input size="50" maxlength="200" name="answer" type="text" id="id_answer" />

</div>

</div>

</div>

</fieldset>

Table 1 Incorrectly rendered code

Solution:

You will modify the following files inside of /mod/lesson/pagetypes/:

  • shortanswer.php
  • truefalse.php
  • numerical.php
  • multichoice.php
  • matching.php
  • essay.php

In each file you will modify the function display().

 

Modifying display()

Find the line that looks something like

$mform = new lesson_display_answer_form_ANSWERTYPE(…);

 

The second parameter of new lesson_display_answer_form_ANSWERTYPE() is an array. Inside that array you should see ‘content’->$this->getContents(). Add to the array 'title'=>$this->title. Order doesn’t matter.

You’re done modifying display(). Now onto modifying lesson_display_answer_form_ANSWERTYPE::definition()!

Modifying lesson_display_answer_form_ANSWERTYPE::definition()

Find the line that looks like $contents = $this->_customdata['contents'];

Under that line, add $title = $this->_customdata['title'];

Comment out the line that looks like $mform->addElement('header', 'pageheader', $OUTPUT->box($contents, 'contents'));

 

Add the following two lines under the line you just commented out:

 

$mform->addElement('header', 'pageheader', $title);

$mform->addElement('html', $OUTPUT->box($contents, 'contents'));

 

That’s it! You’ve fixed this rendering issue. Save your changes and test to be sure it’s working. Be sure to make these fixes in all 6 question-type files.   The content and the title are now in the correct places!

Figure 3: The content and the title are now in the correct places!

<fieldset class="clearfix"  id="pageheader">

<legend class="ftoggler">lesson question 1</legend>

<div class="advancedbutton"></div>

<div class="fcontainer clearfix">

<div class="box contents"><p>This is a big ol question and you should probably have this be a …SNIP</p>

</div>

<div class="fitem">

<div class="fitemtitle">

<label for="id_answer">Your answer </label>

</div>

<div class="felement ftext">

<input size="50" maxlength="200" name="answer" type="text" id="id_answer" />

</div>

</div>

</div>

</fieldset>

Table 2 The correctly rendered code

In reply to Mike Holzer

Re: Question Page Title Formatting in Moodle 2.0.1

Mike Holzer - ން

I'd like to commit this into the codebase, can someone tell me how to go about actually contributing?

In reply to Mike Holzer

Re: Question Page Title Formatting in Moodle 2.0.1

Joseph Rézeau - ން
ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ

Hi Mike,

Thank you for investigating this problem and suggesting a fix.

A.- Your fix works for the pages where the questions are viewed, but throws an error and does not print the title on the "check responses" pages. Notice: Undefined index: title in \moodle\mod\lesson\pagetypes\multichoice.php on line 492 because $this->_customdata['title'] does not exist when viewing the "check responses" pages.

B.- My suggested fix below retains your proposal for printing the question pages titles, fixing the MSIE display bug, plus it prints titles on the  "check responses" pages (without a PHP notice error).

  1. In the mod/lesson/pagetypes/ folder, for each of the following files: shortanswer.php, truefalse.php, numerical.php, multichoice.php, matching.php and essay.php:
    1. locate public function display($renderer, $attempt)
      1. a few lines down that function, locate $params = array() and add title param at the end:
      2. $params = array('answers'=>$answers, 'lessonid'=>$this->lesson->id, 'contents'=>$this->get_contents(), 'attempt'=>$attempt, 'title'=>$this->title);
    2. locate public function definition()
      1. below lines if (array_key_exists('attempt', $this->_customdata))  {...}
      2. change existing line $mform->addElement('header', 'pageheader', $OUTPUT->box($contents, 'contents')); to:
      3. if (array_key_exists('title', $this->_customdata)) {
        $mform->addElement('header', 'pageheader', $this->_customdata['title']);
        $mform->addElement('html', $OUTPUT->box($contents, 'contents'));
        } else {
        $mform->addElement('header', 'pageheader', $OUTPUT->box($contents, 'contents'));
        }
  2. In file mod/lesson/locallib.php
    1. locate final public function record_attempt($context)
    2. locate (around line 2025) line $result->feedback .= $OUTPUT->box(format_text($this->get_contents(), $this->properties->contentsformat, $options), 'generalbox boxaligncenter');
    3. replace that line with those 2 lines:
    4. $result->feedback = $OUTPUT->heading($this->properties->title, 2);
      $result->feedback .= $OUTPUT->box(format_text($this->get_contents(), $this->properties->contentsformat, $options), 'generalbox boxaligncenter');

See results (in MSIE 8) on attached screenshots #1 and #2.

However, there remain a couple of display problems (in any browser and any theme) with the sideblocks...

ATB

Joseph

Attachment 21-01-2011 12-18-57.jpg
In reply to Joseph Rézeau

Re: Question Page Title Formatting in Moodle 2.0.1

Mike Holzer - ން

Joseph,

Thanks for verifying my fix. I wasn't aware of the second part of that. I'm glad we were collectively able to piece this together. Now let's get it into the codebase so noone else has this problem! ހިނިތުން ވުން

In reply to Joseph Rézeau

Re: Question Page Title Formatting in Moodle 2.0.1

Panagiotis Iliopoulos - ން

Hello Joseph,

I have the same problem and I tried to follow your instructions but I can't locate the code you are saying, i.e. can't locate this: $params = array() or even this public function definition()

I have attached here my essay.php file to see it for yourself.

I actually thought that this problem was a theme problem http://moodle.org/mod/forum/discuss.php?d=167916&mode=3

Any thoughts as to how I should procceed about solving this?

Regards Panos

In reply to Panagiotis Iliopoulos

Re: Question Page Title Formatting in Moodle 2.0.1

Joseph Rézeau - ން
ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ

Hello Panos,

Thanks for reporting this. I'm afraid I had taken our friend Matt Fedorko's word and not thoroughly checked that it worked for all question types.ރަކި

Here then is the correct hack for all the question types:

In the mod/lesson/pagetypes/ folder, for each of the following files: truefalse.php, multichoice.php, matching.php:
locate public function display($renderer, $attempt)
a few lines down that function, locate $params = array() and add 'title' at the end:
$params = array('answers'=>$answers, 'lessonid'=>$this->lesson->id, 'contents'=>$this->get_contents(), 'attempt'=>$attempt, 'title'=>$this->title);
--------------------
In the mod/lesson/pagetypes/ folder, for essay.php, shortanswer.php, numerical.php:
where *** = essay / shortanswer /numerical:
locate public function display($renderer, $attempt)
a few lines down that function, locate:
$mform = new lesson_display_answer_form_***($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents()));
and add 'title' at the end:
$mform = new lesson_display_answer_form_***($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents(), 'title'=>$this->title));

Joseph

In reply to Joseph Rézeau

Re: Question Page Title Formatting in Moodle 2.0.1

Matt Fedorko - ން

I do not have examples of all of the question types in my Lessons -- 97% of my questions are multiple choice and numerical, both of which had this problem until Mike and Joseph's fixes took care of it. The remaining 3% are matching problems which had their own formatting oddity that was fixable at the theme level, I believe.  I was able to verify the two fixes as far as my user experience required.

In reply to Joseph Rézeau

Re: Question Page Title Formatting in Moodle 2.0.1

Panagiotis Iliopoulos - ން

Unfortunately Joseph this hack doesn't work for me.

I attached the "hacked" files, in case I made a mistake.

I hope a solution for this will be included in a future moodle release in the core.

Regards Panos

In reply to Panagiotis Iliopoulos

Re: Question Page Title Formatting in Moodle 2.0.1

Joseph Rézeau - ން
ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ

Panos,

When you say "it does not work", what exactly happens (compared with the non-hacked original moodle files) ?

Joseph

In reply to Joseph Rézeau

Re: Question Page Title Formatting in Moodle 2.0.1

Panagiotis Iliopoulos - ން

Hello Joseph,

Nothing happens when I apply this hack.

The view of the pages is the same, the question title in IE simply does not wrap and it seems as the hack has no affect on the outcome of how the pages look like.

I know it sounds weird but its true.

Panos

In reply to Panagiotis Iliopoulos

Re: Question Page Title Formatting in Moodle 2.0.1

Mike Holzer - ން

Panos,

I just looked at your attached files, and it doesn't look like you added the  additional code for the title in the definition() functions of the classes (the content is still being put into the header area instead of the title).

Follow the directions I posted earlier in this thread (clicky) along with the expanded fix Joseph outlined immediately below it.

 

Let me know if that helps!

In reply to Mike Holzer

Re: Question Page Title Formatting in Moodle 2.0.1

Panagiotis Iliopoulos - ން

Well this is embarrassin ރަކި

I didn't realize I had to apply both fixes ހިނިތުން ވުން

I will do it as soon as possible and I will get back to you.

Panos

In reply to Panagiotis Iliopoulos

Re: Question Page Title Formatting in Moodle 2.0.1

Panagiotis Iliopoulos - ން

Hello Joseph and Mike,

Well I applied the fixes, correctly this time and they work ހިނިތުން ވުން but they work only for True/false, Multichoice, Short answer, Numerical and Essay. As far as Matching in the matching.php file I finsd the following lines of code:

public function display($renderer, $attempt) {
global $USER, $CFG, $PAGE;
$mform = $this->make_answer_form($attempt);
$data = new stdClass;
$data->id = $PAGE->cm->id;
$data->pageid = $this->properties->id;
$mform->set_data($data);
return $mform->display();

}

So I cannot apply the fix cause it says

locate public function display($renderer, $attempt)

which I can, but then is says

a few lines down that function, locate $params = array() and add 'title' at the end:
$params = array('answers'=>$answers, 'lessonid'=>$this->lesson->id, 'contents'=>$this->get_contents(), 'attempt'=>$attempt, 'title'=>$this->title);

which I can't locate :P


So it works for most of the question types but not all of the question types.

But when I create and then preview a matching question page the content of the page is shown correctly were it should be located but it doesn't show the title of the page, which is normal if you consider the hack you proposed and I applied.

Regards Panos

In reply to Panagiotis Iliopoulos

Re: Question Page Title Formatting in Moodle 2.0.1

Mike Holzer - ން

Panos,

Yes, in matching it's a bit different. The renderers were written inconsistently so I can understand your confusion. If you go into the function make_answer_form() in matching.php you'll see the $params array towards the bottom.


Sorry about the confusion.

 

In reply to Mike Holzer

Re: Question Page Title Formatting in Moodle 2.0.1

Panagiotis Iliopoulos - ން

Hello Mike,

Thanks for the info, everything works fine now ހިނިތުން ވުން

This hack should really be included in the core code of moodle in a future release asap.

Panos

In reply to Mike Holzer

Re: Question Page Title Formatting in Moodle 2.0.1

Katie Fraser - ން

Hi, I think I'm having the same problem (text not wrapping and showing up in the title of my lesson instead of the content area). Could you please tell me exactly where to go to correct the code? I saw where you wrote "You will modify the following files inside of /mod/lesson/pagetypes/:" but I'm not sure where to go to do this...?  Thanks for your help -

 

In reply to Katie Fraser

Re: Question Page Title Formatting in Moodle 2.0.1

Katie Fraser - ން

Ok, I think I found the general area I should go... site admin, XMLDB editor, and then either mod/lesson/db or mod/page/db (I'm using Moodle 2.0 if that makes a difference). Not sure which one of these I should go into or what to do once I'm there. Any direction you could provide would be greatly appreciated. This is unfamiliar territory for me!

In reply to Katie Fraser

Re: Question Page Title Formatting in Moodle 2.0.1

Mike Holzer - ން

Hi Katie,

Sorry for the delay in response.  We're actually talking about modifying the Moodle source code. You'll need to either have admin access to your server or be able to FTP to the Moodle Directory (so you could edit the code on your local system then replace it live).  I do not believe you can make this changes via the Moodle interface.

Hope this helps ހިނިތުން ވުން

In reply to Mike Holzer

Re: Question Page Title Formatting in Moodle 2.0.1

Clarence Prudhoe - ން

Hi Mike and Joseph,

I am having the same problem with lessons in IE.

What's the word about getting your fix into the source code?  If this fix will happen soon, I will wait for it.

Thanks,

Clarence

In reply to Clarence Prudhoe

Re: Question Page Title Formatting in Moodle 2.0.1

Mike Holzer - ން

Hi Clarence,

I'm not sure what the priority of this issue is to the core developers, but it helps if the issue gets a lot of votes.

http://tracker.moodle.org/browse/MDL-25899

 

If you need the fix ASAP, I'd be happy to walk you or your system admin through the process of implementing the fix.

In reply to Mike Holzer

Re: Question Page Title Formatting in Moodle 2.0.1

Joseph Rézeau - ން
ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ ފޮޓޯ

@Mike (and fellow moodlers)

Please note that when quoting a bug tracker reference in a message on these forums it is not necessary to provide the full URL. Simply type the tracker reference and its URL will be automatically added, as in/ MDL-25899.

Joseph

In reply to Katie Fraser

Re: Question Page Title Formatting in Moodle 2.0.1

Katie Fraser - ން

For those who are not hackers (like me!) and are reading through this thread in it's entirety......please note that in order to change the code as needed on your local server, you would look for the files in your C: drive and not as I mention in above post. Mike H. was kind enough to point me in the right direction, but it is not posted in this thread so I wanted to make that clarification.  Good luck!