-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
-
5.0
-
MOODLE_500_STABLE
-
MDL-83340-completion-reports-improvements
-
-
Refactor proposal for both the course completion report´s and the course activity completion progress report´s index.php files in order to improve separation between logic and layout.
This refactoring would bring up two new elements for the users:
- The possibility to render reports in pdf.
- The topics or sections of a course are shown in the heading of the report´s table.
The reason for this is that I have found that both files do not separate appropriately the logic from the layout. On top of that in the case of report/completion/index.php html code is hardcoded in the file at different points whereas in report/progress/index.php we use HTML::output class which is more appropriate (specially for accessibility) but yet it is also mixed with logic. The same divergence of approach happens in the case we want to render a csv file with the reports.
imho, This makes the code difficult to read an even more difficult to mantain.
I have successfuly managed to create a new code which separates logic and layout, using template files in order to be able to export the reports to pdf and for this reason I think that this new way of organising code can be beneficial for all moodle users, specially developers, for future developments in these areas.
I send part of the repository where I have elaborated into that idea, which of course is in the process of being built. On this "report/completion" folder that I share here, the index.php is the former version and index.php is the new version together with template/table.mustache and template/links.mustache and classes/engine.php and classes/course_report_pdf.php classes.
These are the main ideas behind this refactoring proposal.
- Both index.php files, at report/completion/ and report/progress/ folders, will show three clear separations
- A place to require classes, define de page, receive the parameters, define access capabilities.
- Data preparation and generation. We generate a big array of data which will contain all the necessary data to generate the reports in the different formats.
- Exportation to different formats, html, csv, excelcsv and pdf.
Depending on the format of the output, we will pick up the data from the array that is necessary to be displayed at each format.
We will generate an html code even for the case of pdf file where the html code will be send to a custom pdf class which extends the TCPDF class
- at the report/progress/classes and the report/completion/classes folders we will create a pdf.php class what will extend moodle´s pdf class (which extends the TCPDF library class).
- at report/progress and report/completion folders we will add a templates folder and within it a table.mustache and a links.mustache files that will render both the html and the pdf results.
I submit as an attachment a screenshot of Course Completion report once this changes have been applied.