Moodle

reimplement print_table() to use the new rendering engine

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0
  • Component/s: Libraries
  • Labels:
    None
  • Affected Branches:
    MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

table will be hold by class html_table
moodle_core_renderer::table() will be implemented, accepting html_table as a parameter
print_table() becomes deprecated. for BC, it will convert the passed stdClass to the html_table and will print or return the output of moodle_core_renderer::table()

Activity

Hide
David Mudrak added a comment -
  • rowclass property has been deprecated, rowclasses should be used.
  • direct assigning of the class has been deprecated, moodle_html_elements should be used instead. In both cases, debugging message is displayed.
Show
David Mudrak added a comment -
  • rowclass property has been deprecated, rowclasses should be used.
  • direct assigning of the class has been deprecated, moodle_html_elements should be used instead. In both cases, debugging message is displayed.
Hide
Tim Hunt added a comment -

Very much along the right lines. Nice work. but...

1. Please comment out the

debugging('print_table() has been deprecated. Please change your code to use $OUTPUT->table().');

with a TODO to uncomment, until almost all calls in core code have been fixed. See, for example, admin_externalpage_print_footer in lib/adminlib.php

2. I think most of the ifs at the top of function table() should be in html_table::prepare()

3. Same for all the fix-up ifs in the header loop. That should be in prepare too.

4. html_table::__construct should not take arguments. We had a debate about this and decided on a consistent API with argument-less constructors.

5. Please can you move the __set magic for $class to the moodle_html_component class. Very nice and we should have that everywhere.

6. However, I think that it needs to be clearly defined what happens when you do $table->somethingunknown - and of course the PHP docs at http://php.net/manual/en/language.oop5.overloading.php are hopelessly vague. OK, based on a quick experiment it silently does nothing. I think we should either do $this->$name = $value at the end of __call if nothing else matches, or a throw new coding_exception. I am not sure which option is better.

7. I think the comments for the properties on html_table should be made more verbose, to make it clearer how to use the class (basically, give an example of a typical value for each argument). However, I see that you have just copied the existing comments from the old function, which is a natural place to start.

The justification for 2. and 3. is that if someone overrides moodle_core_renderer, they should not have to copy-and-paste this clean-up code, and they will almost certainly have to. That is why we have the prepare method, to avoid that sort of code duplication.

Sorry to be so picky (and I know I have been missing out some PHPdoc comments myself, recently). Anyway, if you fix all (or most) of these, then I am happy for you to commit without further review.

Show
Tim Hunt added a comment - Very much along the right lines. Nice work. but... 1. Please comment out the debugging('print_table() has been deprecated. Please change your code to use $OUTPUT->table().'); with a TODO to uncomment, until almost all calls in core code have been fixed. See, for example, admin_externalpage_print_footer in lib/adminlib.php 2. I think most of the ifs at the top of function table() should be in html_table::prepare() 3. Same for all the fix-up ifs in the header loop. That should be in prepare too. 4. html_table::__construct should not take arguments. We had a debate about this and decided on a consistent API with argument-less constructors. 5. Please can you move the __set magic for $class to the moodle_html_component class. Very nice and we should have that everywhere. 6. However, I think that it needs to be clearly defined what happens when you do $table->somethingunknown - and of course the PHP docs at http://php.net/manual/en/language.oop5.overloading.php are hopelessly vague. OK, based on a quick experiment it silently does nothing. I think we should either do $this->$name = $value at the end of __call if nothing else matches, or a throw new coding_exception. I am not sure which option is better. 7. I think the comments for the properties on html_table should be made more verbose, to make it clearer how to use the class (basically, give an example of a typical value for each argument). However, I see that you have just copied the existing comments from the old function, which is a natural place to start. The justification for 2. and 3. is that if someone overrides moodle_core_renderer, they should not have to copy-and-paste this clean-up code, and they will almost certainly have to. That is why we have the prepare method, to avoid that sort of code duplication. Sorry to be so picky (and I know I have been missing out some PHPdoc comments myself, recently). Anyway, if you fix all (or most) of these, then I am happy for you to commit without further review.
Hide
David Mudrak added a comment -

Committed to HEAD. Hopefully all Tim's comments incorporated.

Show
David Mudrak added a comment - Committed to HEAD. Hopefully all Tim's comments incorporated.
Hide
Tim Hunt added a comment -

Very good. Just one more thing ...

I think that width, tablealign, cellpadding and cellspacing should all be null be default, and when they are null, they should not appear in the HTML. These are all things that should be handled by CSS, and not hard-coded in the HTML.

Note that

$attributes = array('id' => 'test', 'align' => null);
$this->output_tag('p', $attributes, 'Test');

will output

<p id="test">Test</p>

So it is easy to handle nulls.

Show
Tim Hunt added a comment - Very good. Just one more thing ... I think that width, tablealign, cellpadding and cellspacing should all be null be default, and when they are null, they should not appear in the HTML. These are all things that should be handled by CSS, and not hard-coded in the HTML. Note that $attributes = array('id' => 'test', 'align' => null); $this->output_tag('p', $attributes, 'Test'); will output <p id="test">Test</p> So it is easy to handle nulls.
Hide
Tim Hunt added a comment -

I just deprecated those fields.

Show
Tim Hunt added a comment - I just deprecated those fields.
Hide
David Mudrak added a comment -

Checked and closing. Thanks for deprecating those attributes.

Show
David Mudrak added a comment - Checked and closing. Thanks for deprecating those attributes.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: