Skip to content

Commit

Permalink
MDL-19799 upgraded calls to print_table, print_single_button, print_u…
Browse files Browse the repository at this point in the history
…ser_picture, print_container* and notice_yesno
  • Loading branch information
nicolasconnault committed Aug 20, 2009
1 parent f2f085e commit 642816a
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 78 deletions.
4 changes: 2 additions & 2 deletions comment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function print_comments($page=0) {
$this->perpage = 10;
$count = $DB->count_records_sql('SELECT COUNT(*) FROM {comments} c');
$comments = $this->get_comments($page);
$table = new stdclass;
$table = new html_table();
$table->head = array ('<input type="checkbox" id="comment_select_all"/>', 'author', 'content', 'action');
$table->align = array ('left', 'left', 'left', 'left');
$table->width = "95%";
Expand All @@ -101,7 +101,7 @@ function print_comments($page=0) {
}
$table->data[] = array($checkbox, $c->username, $c->content, $action);
}
print_table($table);
echo $OUTPUT->table($table);
echo $OUTPUT->paging_bar(moodle_paging_bar::make($count, $page, $this->perpage, $CFG->wwwroot.'/comment/index.php'));
}

Expand Down
2 changes: 1 addition & 1 deletion files/draftfiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
echo $OUTPUT->notification(get_string('deletecheckwarning').': '.s($file->get_filepath().$file->get_filename()));
$optionsno = array('itemid'=>$itemid, 'filepath'=>$filepath, 'subdirs'=>$subdirs);
$optionsyes = array('itemid'=>$itemid, 'filepath'=>$filepath, 'delete'=>$delete, 'sesskey'=>sesskey(), 'subdirs'=>$subdirs);
notice_yesno (get_string('deletecheckfiles'), 'draftfiles.php', 'draftfiles.php', $optionsyes, $optionsno, 'post', 'get');
echo $OUTPUT->confirm(get_string('deletecheckfiles'), new moodle_url('draftfiles.php', $optionsyes), new moodle_url('draftfiles.php', $optionsno));
echo $OUTPUT->footer();
die;

Expand Down
2 changes: 1 addition & 1 deletion files/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
$optionsyes['delete'] = 1;
$optionsyes['sesskey'] = sesskey();

notice_yesno (get_string('deletecheckfiles'), 'index.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
echo $OUTPUT->confirm(get_string('deletecheckfiles'), new moodle_url( 'index.php', $optionsyes), new moodle_url('index.php', $optionsno));
echo $OUTPUT->footer();
die;
}
Expand Down
28 changes: 14 additions & 14 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4550,7 +4550,7 @@ public function output_html($data, $query='') {
$return = $OUTPUT->heading(get_string('actauthhdr', 'auth'), 3, 'main');
$return .= $OUTPUT->box_start('generalbox authsui');

$table = new object();
$table = new html_table();
$table->head = array($txt->name, $txt->enable, $txt->updown, $txt->settings);
$table->align = array('left', 'center', 'center', 'center');
$table->width = '90%';
Expand Down Expand Up @@ -4620,7 +4620,7 @@ public function output_html($data, $query='') {
// add a row to the table
$table->data[] =array($displayname, $hideshow, $updown, $settings);
}
$return .= print_table($table, true);
$return .= $OUTPUT->table($table);
$return .= get_string('configauthenticationplugins', 'admin').'<br />'.get_string('tablenosave', 'filters');
$return .= $OUTPUT->box_end();
return highlight($query, $return);
Expand Down Expand Up @@ -4727,7 +4727,7 @@ public function output_html($data, $query='') {
$return = $OUTPUT->heading(get_string('acteditorshhdr', 'editor'), 3, 'main', true);
$return .= $OUTPUT->box_start('generalbox editorsui');

$table = new object();
$table = new html_table();
$table->head = array($txt->name, $txt->enable, $txt->updown, $txt->settings);
$table->align = array('left', 'center', 'center', 'center');
$table->width = '90%';
Expand Down Expand Up @@ -4784,7 +4784,7 @@ public function output_html($data, $query='') {
// add a row to the table
$table->data[] =array($displayname, $hideshow, $updown, $settings);
}
$return .= print_table($table, true);
$return .= $OUTPUT->table($table);
$return .= get_string('configeditorplugins', 'editor').'<br />'.get_string('tablenosave', 'filters');
$return .= $OUTPUT->box_end();
return highlight($query, $return);
Expand Down Expand Up @@ -4939,7 +4939,7 @@ public function output_html($data, $query='') {
$output .= portfolio_report_insane($insane, null, true);
$output .= portfolio_report_insane($insaneinstances, $instances, true);

$table = new StdClass;
$table = new html_table();
$table->head = array($namestr, $pluginstr, '');
$table->data = array();

Expand All @@ -4959,7 +4959,7 @@ public function output_html($data, $query='') {
}
}

$output .= print_table($table, true);
$output .= $OUTPUT->table($table);

$instancehtml = '<br /><br />' . get_string('addnewportfolio', 'portfolio') . ': <br /><br />';
$addable = 0;
Expand Down Expand Up @@ -5047,7 +5047,7 @@ function admin_externalpage_setup($section, $extrabutton = '',
* @param string $focus focus element
*/
function admin_externalpage_print_header($focus='') {
global $CFG, $PAGE, $SITE, $THEME;
global $CFG, $PAGE, $SITE, $THEME, $OUTPUT;

if (!is_string($focus)) {
$focus = ''; // BC compatibility, there used to be adminroot parameter
Expand Down Expand Up @@ -5079,7 +5079,7 @@ function admin_externalpage_print_header($focus='') {
$caption = get_string('blocksediton');
$options['adminedit'] = 'on';
}
$buttons = print_single_button($PAGE->url->out(false), $options, $caption, 'get', '', true);
$buttons = $OUTPUT->button(html_form::make_button($PAGE->url->out(false), $options, $caption, 'get'));
}

$navlinks = array();
Expand Down Expand Up @@ -5793,7 +5793,7 @@ public function output_html($data, $query='') {
$instances = repository::get_types();
$instancesnumber = count($instances);
$alreadyplugins = array();
$table = new StdClass;
$table = new html_table();
$table->head = array($namestr, $updownstr, $hiddenstr, $deletestr, $settingsstr);
$table->align = array('left', 'center', 'center','center','center');
$table->data = array();
Expand Down Expand Up @@ -5865,7 +5865,7 @@ public function output_html($data, $query='') {
$alreadyplugins[] = $i->get_typename();
}
}
$output .= print_table($table, true);
$output .= $OUTPUT->table($table);
$instancehtml = '<div><h3>';
$instancehtml .= get_string('addplugin', 'repository');
$instancehtml .= '</h3><ul>';
Expand Down Expand Up @@ -5941,7 +5941,7 @@ public function output_html($data, $query='') {
$hiddenstr = get_string('hiddenshow', 'repository');
require_once("../webservice/lib.php");
$protocols = webservice_lib::get_list_protocols();
$table = new StdClass;
$table = new html_table();
$table->head = array($namestr, $hiddenstr, $settingsstr);
$table->align = array('left', 'center', 'center');
$table->data = array();
Expand Down Expand Up @@ -5971,7 +5971,7 @@ public function output_html($data, $query='') {
$table->rowclasses[] = '';
}
}
$output = print_table($table, true);
$output = $OUTPUT->table($table);

return highlight($query, $output);
}
Expand Down Expand Up @@ -6027,7 +6027,7 @@ public function output_html($data, $query='') {
//search all web service users
$users = get_users(true, '', false, null, 'firstname ASC','', '', '', 1000);

$table = new StdClass;
$table = new html_table();
$table->head = array('username', 'whitelist');
$table->align = array('left', 'center');
$table->data = array();
Expand All @@ -6044,7 +6044,7 @@ public function output_html($data, $query='') {
}
}

$output .= print_table($table, true);
$output .= $OUTPUT->table($table);
return highlight($query, $output);
}
}
10 changes: 5 additions & 5 deletions lib/commentlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,7 @@ public function get_comments($page = '') {
$user->lastname = $c->lastname;
$user->imagealt = $c->imagealt;
$c->content = format_text($c->content, $c->format);
$userpic = new moodle_user_picture();
$userpic->user = $user;
$userpic->courseid = $this->course->id;
$userpic = moodle_user_picture::make($user, $this->course->id);
$userpic->link = true;
$userpic->size = 18;
$userpic->alttext = true;
Expand Down Expand Up @@ -443,7 +441,7 @@ public function get_pagination($page = 0) {
* @return mixed
*/
public function add($content) {
global $CFG, $DB, $USER;
global $CFG, $DB, $USER, $OUTPUT;
if (empty($this->postcap)) {
return COMMENT_ERROR_INSUFFICIENT_CAPS;
}
Expand Down Expand Up @@ -471,7 +469,9 @@ public function add($content) {
$newcmt->time = userdate($now, get_string('strftimerecent', 'langconfig'));
$newcmt->username = fullname($USER);
$newcmt->content = format_text($newcmt->content);
$newcmt->avatar = print_user_picture($USER, $this->course->id, NULL, 16, true);
$userpic = moodle_user_picture::make($USER, $this->course->id);
$userpic->size = 16;
$newcmt->avatar = $OUTPUT->user_picture($userpic);
return $newcmt;
} else {
return COMMENT_ERROR_DB;
Expand Down
25 changes: 9 additions & 16 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2401,7 +2401,7 @@ function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinne
function print_table($table, $return=false) {
global $OUTPUT;
// TODO MDL-19755 turn debugging on once we migrate the current core code to use the new API
// debugging('print_table() has been deprecated. Please change your code to use $OUTPUT->table().');
debugging('print_table() has been deprecated. Please change your code to use $OUTPUT->table().');
$newtable = new html_table();
foreach ($table as $property => $value) {
if (property_exists($newtable, $property)) {
Expand Down Expand Up @@ -2589,7 +2589,7 @@ function print_single_button($link, $options, $label='OK', $method='get', $notus
$return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
global $OUTPUT;

// debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->button().');
debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->button().');

// Cast $options to array
$options = (array) $options;
Expand Down Expand Up @@ -2679,7 +2679,7 @@ function print_file_picture($path, $courseid=0, $height='', $width='', $link='',
function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
global $CFG, $DB, $OUTPUT;

// debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, $courseid).');
debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, $courseid).');

$userpic = new moodle_user_picture();
$userpic->user = $user;
Expand Down Expand Up @@ -2802,7 +2802,7 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
* @return string|void Depending on value of $return
*/
function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
// debugging('helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_icon().');
debugging('helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_icon().');

global $OUTPUT;

Expand Down Expand Up @@ -2967,21 +2967,14 @@ function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page
*/
function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {

// debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');
debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');

global $OUTPUT;

$formcontinue = new html_form();
$formcontinue->url = new moodle_url($linkyes, $optionsyes);
$formcontinue->button->text = get_string('yes');
$formcontinue->method = $methodyes;
$buttoncontinue = html_form::make_button($linkyes, $optionsyes, get_string('yes'), $methodyes);
$buttoncancel = html_form::make_button($linkno, $optionsno, get_string('no'), $methodno);

$formcancel = new html_form();
$formcancel->url = new moodle_url($linkno, $optionsno);
$formcancel->button->text = get_string('no');
$formcancel->method = $methodno;

echo $OUTPUT->confirm($message, $formcontinue, $formcancel);
echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
}

/**
Expand Down Expand Up @@ -3428,7 +3421,7 @@ function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '',
*/
function print_textfield ($name, $value, $alt = '',$size=50,$maxlength=0, $return=false) {

// debugging('print_textfield() has been deprecated. Please change your code to use $OUTPUT->textfield($field).');
debugging('print_textfield() has been deprecated. Please change your code to use $OUTPUT->textfield($field).');

global $OUTPUT;

Expand Down
12 changes: 6 additions & 6 deletions lib/environmentlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,23 @@ function print_moodle_environment($result, $environment_results) {
$strrestricted = get_string('restricted');
$strenvironmenterrortodo = get_string('environmenterrortodo', 'admin');
/// Table headers
$servertable = new stdClass;//table for server checks
$servertable = new html_table();//table for server checks
$servertable->head = array ($strname, $strinfo, $strreport, $strstatus);
$servertable->align = array ('center', 'center', 'left', 'center');
$servertable->wrap = array ('nowrap', '', '', 'nowrap');
$servertable->size = array ('10', 10, '100%', '10');
$servertable->width = '90%';
$servertable->class = 'environmenttable generaltable';
$servertable->add_class('environmenttable generaltable');

$serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());

$othertable = new stdClass;//table for custom checks
$othertable = new html_table();//table for custom checks
$othertable->head = array ($strinfo, $strreport, $strstatus);
$othertable->align = array ('center', 'left', 'center');
$othertable->wrap = array ('', '', 'nowrap');
$othertable->size = array (10, '100%', '10');
$othertable->width = '90%';
$othertable->class = 'environmenttable generaltable';
$othertable->add_class('environmenttable generaltable');

$otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());

Expand Down Expand Up @@ -309,10 +309,10 @@ function print_moodle_environment($result, $environment_results) {

/// Print table
echo $OUTPUT->heading(get_string('serverchecks', 'admin'));
print_table($servertable);
echo $OUTPUT->table($servertable);
if (count($othertable->data)){
echo $OUTPUT->heading(get_string('customcheck', 'admin'));
print_table($othertable);
echo $OUTPUT->table($othertable);
}

/// Finally, if any error has happened, print the summary box
Expand Down
21 changes: 14 additions & 7 deletions lib/formslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1330,17 +1330,24 @@ function setHelpButtons($buttons, $suppresscheck=false, $function='helpbutton'){
* @param string $function
*/
function setHelpButton($elementname, $button, $suppresscheck=false, $function='helpbutton'){
global $OUTPUT;
if (array_key_exists($elementname, $this->_elementIndex)){
//_elements has a numeric index, this code accesses the elements by name
$element=&$this->_elements[$this->_elementIndex[$elementname]];
if (method_exists($element, 'setHelpButton')){
$element->setHelpButton($button, $function);
}else{
$a=new object();
$a->name=$element->getName();
$a->classname=get_class($element);
print_error('nomethodforaddinghelpbutton', 'form', '', $a);
$buttonparams = array('page', 'text', 'module', 'image', 'linktext', 'text', 'return', 'imagetext');
$helpiconoptions = array('page' => null, 'text' => null, 'module' => 'moodle', 'image' => null, 'linktext' => false);

foreach ($button as $key => $val) {
if (isset($button[$key])) {
$helpiconoptions[$buttonparams[$key]] = $val;
}
}
$helpicon = moodle_help_icon::make($helpiconoptions['page'], $helpiconoptions['text'], $helpiconoptions['module'], $helpiconoptions['linktext']);
if (!$helpiconoptions['image']) {
$helpicon->image = false;
}

$element->_helpbutton = $OUTPUT->help_icon($helpicon);
}elseif (!$suppresscheck){
print_error('nonexistentformelements', 'form', '', $elementname);
}
Expand Down
19 changes: 18 additions & 1 deletion lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ class moodle_html_component {
* @return array the class names as an array.
*/
public static function clean_classes($classes) {
if (is_array($classes)) {
if (empty($classes)) {
return '';
} else if (is_array($classes)) {
return $classes;
} else {
return explode(' ', trim($classes));
Expand Down Expand Up @@ -1424,6 +1426,14 @@ public function prepare() {

parent::prepare();
}

public static function make_button($url, $options, $label='OK', $method='post') {
$form = new html_form();
$form->url = new moodle_url($url, $options);
$form->button->text = $label;
$form->method = $method;
return $form;
}
}

/**
Expand Down Expand Up @@ -1845,6 +1855,13 @@ public function prepare() {

parent::prepare();
}

public static function make($user, $courseid) {
$userpic = new moodle_user_picture();
$userpic->user = $user;
$userpic->courseid = $courseid;
return $userpic;
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/portfolio/exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,13 @@ public function process_stage_confirm() {
$isummary = array();
}
$mainsummary = array_merge($mainsummary, $csummary, $isummary);
$table = new StdClass;
$table = new html_table();
$table->data = array();
foreach ($mainsummary as $string => $value) {
$table->data[] = array($string, $value);
}
print_table($table);
notice_yesno($strconfirm, $yesurl, $nourl);
echo $OUTPUT->table($table);
echo $OUTPUT->confirm($strconfirm, $yesurl, $nourl);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
return false;
Expand Down
Loading

0 comments on commit 642816a

Please sign in to comment.