Lesson

 
 
Training
New Role View for PDF production
 

Hi,

I've been using the lesson module in excess of 7 years now with great success.

Even included 6 new questions types based on hotpot (thanks go to Gordon Bateson for his programming skills) to add jumbled sentence, drag and drop exercised and more in a 1.8 moodle (heavily custom)
I'm not recreating a replacement eLearning Moodle site, all courses have been recreated from scratch due to heavy customisations over the years.

All is going well...

I'd like to make some modifications to Moodle 2 as a mimimal level (perhaps create a patch).

So firstly here's the AIM: We neeed PDF's of our complete lessons

The PDF must not contain all the rubbish like: web theme style, must not show the questions, jump to details and other technical details when viewing the entire lesson as a whole page (i.e. in editing mode).

Note: We currently use editing mode, strip out the rubbish and place the actual content in a pdf.

Here's the problem:

Now the single biggest problem with the Lesson Module for us is that students have requested PDF copies for the entire time I've been using the Lesson Mod.

PDF's of lessons Without a doubt It's the SINGLE MOST WANTED FEATURE to our website and achieving this programmatically has been a complete nightmare (for many moodlers).

Our current method to produce PDF's Manually - This process was easier in Pre moodle 2.0 versions and a few more steps have been added as per Moodle 2+

What we currently do is this in Moodle 2.3.8+

  1. Login and Visit the Course in question
  2. Select 'Switch role to' and choose 'Non-editing teacher'
  3. Visit the required lesson for PDF production.
  4. The lesson appears with restrictions on editing and only the Jump to and 'content' labels appear just below the actual lesson full contents. It do not display icons or links to edit pages.
  5. Save the page locally (complete web page) - this is important!
  6. Visit the saved page/or view the source.
  7. Edit/Copy the html source to something like 'Dreamweaver' html editor.
  8. Perform a search and replace for the common html to remove, i.e. the jump to's. For me it's the same over and over (mostly)
    Something like replace the following html with nothing, so bulk replace/delete this code:
    <tr class="r1">
    <td class="cell c0 lastcol" style="text-align:right;text-align:center" colspan="2"><strong>Content</strong></td>
    </tr>
    <tr class="r0">
    <td class="cell c0" style="text-align:right;"><span class="label">Content 1<span>: </span></span></td>
    <td class="cell c1 lastcol" style="text-align:left;">Previous</td>
    </tr>
    <tr class="r1">
    <td class="cell c0" style="text-align:right;width:20%;"><span class="label">Jump 1<span>: </span></span></td>
    <td class="cell c1 lastcol" style="text-align:left;">Previous page</td>
    </tr>
    <tr class="r0">
    <td class="cell c0" style="text-align:right;"><span class="label">Content 2<span>: </span></span></td>
    <td class="cell c1 lastcol" style="text-align:left;">Next</td>
    </tr>
    <tr class="r1 lastrow">
    <td class="cell c0" style="text-align:right;"><span class="label">Jump 2<span>: </span></span></td>
    <td class="cell c1 lastcol" style="text-align:left;">Next page</td>
    </tr>

    This gets rid of the annoying table contents that shows the 'Contents' 'Jump to' labels when in editing view as a non-editing tutor.
  9. Then delete all code but the main contents, i.e. delete the unnecessary style of the website, remove side blocks, header/footer etc. and save the html page.
  10. Now I can visit this locally saved page, select all the contents and paste in to a word document, change the layout margins to 'narrow' and save the document as a PDF.

I would then upload the PDF's for that lesson as a resource or within a popup attached to that lesson.

Only problem is this method takes a while if you have 1,000 A4 pages within each lesson (which we do!)

This produces extremely nice looking PDF's documents, we can even include additional pages using something like PDFsam to add extra pages for better styling and instructions.

The problem is THIS METHOD TAKES TOO LONG! Also PDF's have to be reproduced constantly whenever a change to lesson contents is made.

My Suggested Solution:

So my solutions for this is to simply create a new role, i.e. Mod/LessonPDFview

Program this in to the lesson code where the restriction for non-editing tutor exist based on capabilities.

Strip out the display of the annoying part that display the kind of code below based on the role capability views:

<tr class="r1">
<td class="cell c0 lastcol" style="text-align:right;text-align:center" colspan="2"><strong>Content</strong></td>
</tr>
<tr class="r0">
<td class="cell c0" style="text-align:right;"><span class="label">Content 1<span>: </span></span></td>
<td class="cell c1 lastcol" style="text-align:left;">Previous</td>
</tr>
<tr class="r1">
<td class="cell c0" style="text-align:right;width:20%;"><span class="label">Jump 1<span>: </span></span></td>
<td class="cell c1 lastcol" style="text-align:left;">Previous page</td>
</tr>
<tr class="r0">
<td class="cell c0" style="text-align:right;"><span class="label">Content 2<span>: </span></span></td>
<td class="cell c1 lastcol" style="text-align:left;">Next</td>
</tr>
<tr class="r1 lastrow">
<td class="cell c0" style="text-align:right;"><span class="label">Jump 2<span>: </span></span></td>
<td class="cell c1 lastcol" style="text-align:left;">Next page</td>
</tr>

Also strip out the code which displays questions to the user....

I don't have an example of this code to show you right now. I'll have to dig through the lesson php code to find an example. Bjut essentially it strips out the options shown to a normal 'Tutor' role or the role that has the capability to 'edit lesson' and is not 'non-editing-tutor'.

So it would seem by creating an additional role, tweaking the lesson code to include this role capability and to only display the raw contents on the page for the 'lessonPDFview' role.

I can then quickly save the lesson locally as before, copy and paste to word and save as PDF without all the messing around with code.


I could even allow Students to login as this role somehow if they want a complete view.

BTW  - no need to mention print.css - It's a behavioural issue where students just don't use the print button - they want a searchable PDF and don't want to produce it themselves or at least struggle to.

 

Does this seem like a reasonable method to force lesson pages in 'edit' mode to display as I desire? So I can then make very pretty PDF's.

BTW if printing directly from the web and an image is displaying smaller than it;s original size this is not reflected within the produced PDF and images as set to the default dimensions which often does not fit on page.

This is the same for any tables with a defined width in excess of 600px.

Saving the HTML locally ALWAYS gets around this issue as files are referenced locally, not view browser cache.

 
Average of ratings: -
Training
Re: New Role View for PDF production
 

Ok,

So I decided to hack up the lesson code in renderer.php around line(s) 290 to 303

AIM: To NOT display the annoying 'contents' , 'next page / jumpto', 'answers' table cells that mess up the display.... remember I'm trying to get a clean page output without all the tutor (technical) data.

Below I've highlighted the code changes and commented out the original 3 lines.

            $pageheading->style = 'text-align:center';
            $pageheading->colspan = 2;
            $pageheading->scope = 'col';
            $pagetable->head = array($pageheading);

            $cell = new html_table_cell();
            $cell->colspan = 2;
            $cell->style = 'text-align:left';
            $cell->text = $page->contents;
            $pagetable->data[] = new html_table_row(array($cell));

            $cell = new html_table_cell();
            $cell->colspan = 2;
            $cell->style = 'text-align:center';
            //$cell->text = '<strong>'.$qtypes[$page->qtype] . $page->option_description_string().'</strong>';
            if ($canedit) {
                $cell->text = '<strong>'.$qtypes[$page->qtype] . $page->option_description_string().'</strong>';
            }
            //$pagetable->data[] = new html_table_row(array($cell));
            if ($canedit) {
                $pagetable->data[] = new html_table_row(array($cell));
            }
            //$pagetable = $page->display_answers($pagetable);
            if ($canedit) {
                $pagetable = $page->display_answers($pagetable);
            }
            $content .= html_writer::table($pagetable);

            if ($canedit) {
                $content .= $this->add_page_links($lesson, $pageid);
            }

---------------------------------

So this now display a very clean page to a 'non-editing tutor' or anyone with the permission to 'manage' a lesson. Edit overrides this change and displays all previous displayed data and edit links etc.

Now I want to selectively display ONLY contents pages and NOT question pages.

Within the database normal pages are designated in the 'Qtype' field as '20' - all other values for Qtypes are different kinds of questions.

I do not require any questions to be displayed so I am looking to modify the lesson code to only show contents pages that match 'qtype = 20'

Does anyone know how I can achieve this?

I'm guessing it's something along the lines of:

if (qtype = 20) { display;}

Remember it's only for the effective permissions of 'manage' lesson - so the non-editing teacher role is what I'm using a test with.

Hope someone can point me in the right direction.

Thanks

Steve

 
Average of ratings: -