From 398be7c897f37ea87eef4664cdc1e984f5250dbd Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 4 Nov 2016 11:30:11 +0800 Subject: [PATCH] MDL-56725 mod_data: coding style Fixes from lines in the previous commit. --- mod/data/edit.php | 13 ++++++++---- mod/data/export_form.php | 13 ++++++++---- mod/data/field/checkbox/field.class.php | 9 ++++---- mod/data/field/file/field.class.php | 3 ++- mod/data/field/latlong/field.class.php | 24 +++++++++++++++------ mod/data/field/multimenu/field.class.php | 3 ++- mod/data/field/number/field.class.php | 3 ++- mod/data/field/picture/field.class.php | 13 +++++++----- mod/data/field/text/field.class.php | 4 +++- mod/data/field/textarea/field.class.php | 3 ++- mod/data/field/url/field.class.php | 20 +++++++++++------- mod/data/lib.php | 27 ++++++++++++++++-------- mod/data/renderer.php | 10 +++++---- mod/data/templates.php | 25 ++++++++++++++++------ 14 files changed, 114 insertions(+), 56 deletions(-) diff --git a/mod/data/edit.php b/mod/data/edit.php index 39af5e2bc8f..4dcf608e573 100644 --- a/mod/data/edit.php +++ b/mod/data/edit.php @@ -352,12 +352,17 @@ foreach ($generalnotifications as $notification) { } echo $newtext; -echo '
'; +echo '
'; if ($rid) { - echo ' '; + echo ' '; } else { - if ((!$data->maxentries) || has_capability('mod/data:manageentries', $context) || (data_numentries($data) < ($data->maxentries - 1))) { - echo ' '; + if ((!$data->maxentries) || + has_capability('mod/data:manageentries', $context) || + (data_numentries($data) < ($data->maxentries - 1))) { + echo ' '; } } echo '
'; diff --git a/mod/data/export_form.php b/mod/data/export_form.php index a5abd773015..1377e6c73a6 100644 --- a/mod/data/export_form.php +++ b/mod/data/export_form.php @@ -41,7 +41,8 @@ class mod_data_export_form extends moodleform { unset($choices[$key]); } $typesarray = array(); - $typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('csvwithselecteddelimiter', 'data') . ' ', 'csv'); + $str = get_string('csvwithselecteddelimiter', 'data'); + $typesarray[] = $mform->createElement('radio', 'exporttype', null, $str . ' ', 'csv'); $typesarray[] = $mform->createElement('select', 'delimiter_name', null, $choices); //temporarily commenting out Excel export option. See MDL-19864 //$typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('excel', 'data'), 'xls'); @@ -59,12 +60,16 @@ class mod_data_export_form extends moodleform { $mform->addElement('header', 'notice', get_string('chooseexportfields', 'data')); foreach($this->_datafields as $field) { if($field->text_export_supported()) { - $mform->addElement('advcheckbox', 'field_'.$field->field->id, '
' . $field->field->name . '
', ' (' . $field->name() . ')', array('group'=>1)); - $mform->setDefault('field_'.$field->field->id, 1); + $html = '
' . $field->field->name . '
'; + $name = ' (' . $field->name() . ')'; + $mform->addElement('advcheckbox', 'field_' . $field->field->id, $html, $name, array('group' => 1)); + $mform->setDefault('field_' . $field->field->id, 1); } else { $a = new stdClass(); $a->fieldtype = $field->name(); - $mform->addElement('static', 'unsupported'.$field->field->id, $field->field->name, get_string('unsupportedexport', 'data', $a)); + $str = get_string('unsupportedexport', 'data', $a); + $mform->addElement('static', 'unsupported' . $field->field->id, $field->field->name, $str); } } $this->add_checkbox_controller(1, null, null, 1); diff --git a/mod/data/field/checkbox/field.class.php b/mod/data/field/checkbox/field.class.php index f1b46dbe24c..4a871c44843 100644 --- a/mod/data/field/checkbox/field.class.php +++ b/mod/data/field/checkbox/field.class.php @@ -95,13 +95,13 @@ class data_field_checkbox extends data_field_base { $str = ''; $found = false; + $marginclass = ['class' => 'm-r-1']; foreach (explode("\n",$this->field->param1) as $checkbox) { $checkbox = trim($checkbox); - if (in_array($checkbox, $content)) { - $str .= html_writer::checkbox('f_'.$this->field->id.'[]', s($checkbox), true, $checkbox, array('class' => 'm-r-1')); + $str .= html_writer::checkbox('f_'.$this->field->id.'[]', s($checkbox), true, $checkbox, $marginclass); } else { - $str .= html_writer::checkbox('f_'.$this->field->id.'[]', s($checkbox), false, $checkbox, array('class' => 'm-r-1')); + $str .= html_writer::checkbox('f_'.$this->field->id.'[]', s($checkbox), false, $checkbox, $marginclass); } $str .= html_writer::empty_tag('br'); $found = true; @@ -110,7 +110,8 @@ class data_field_checkbox extends data_field_base { return ''; } - $str .= html_writer::checkbox('f_'.$this->field->id.'_allreq', null, $allrequired, get_string('selectedrequired', 'data'), array('class' => 'm-r-1')); + $requiredstr = get_string('selectedrequired', 'data'); + $str .= html_writer::checkbox('f_'.$this->field->id.'_allreq', null, $allrequired, $requiredstr, $marginclass); return $str; } diff --git a/mod/data/field/file/field.class.php b/mod/data/field/file/field.class.php index 522e11f52fe..363fe847c35 100644 --- a/mod/data/field/file/field.class.php +++ b/mod/data/field/file/field.class.php @@ -104,7 +104,8 @@ class data_field_file extends data_field_base { function display_search_field($value = '') { return '' . - ''; + ''; } function generate_sql($tablealias, $value) { diff --git a/mod/data/field/latlong/field.class.php b/mod/data/field/latlong/field.class.php index cbe567567bc..ce9fba78423 100644 --- a/mod/data/field/latlong/field.class.php +++ b/mod/data/field/latlong/field.class.php @@ -62,20 +62,27 @@ class data_field_latlong extends data_field_base { $str = '
'; $str .= '
'.$this->field->name.''; $str .= ''; - $str .= ''; $str .= ''; $str .= '
'; - $str .= 'field->id.'_0" value="'; $str .= s($lat).'" size="10" />°N
field->id.'_1" id="field_'.$this->field->id.'_1" value="'; $str .= s($long).'" size="10" />°E
'; @@ -103,8 +110,10 @@ class data_field_latlong extends data_field_base { } $latlongsrs->close(); - $return = html_writer::label(get_string('latlong', 'data'), 'menuf_'.$this->field->id, false, array('class' => 'accesshide')); - $return .= html_writer::select($options, 'f_'.$this->field->id, $value, null, array('class' => 'custom-select')); + $classes = array('class' => 'accesshide'); + $return = html_writer::label(get_string('latlong', 'data'), 'menuf_'.$this->field->id, false, $classes); + $classes = array('class' => 'custom-select'); + $return .= html_writer::select($options, 'f_'.$this->field->id, $value, null, $classes); return $return; } @@ -185,7 +194,8 @@ class data_field_latlong extends data_field_base { } // NB! If you are editing this, make sure you don't break the javascript reference "previousSibling" // which allows the "Go" button to refer to the drop-down selector. - $str .= "\n"; + $str .= '\n'; $str .= ''; } else { $str = "$compasslat, $compasslong"; diff --git a/mod/data/field/multimenu/field.class.php b/mod/data/field/multimenu/field.class.php index 333375b1ee2..7ab1405a377 100644 --- a/mod/data/field/multimenu/field.class.php +++ b/mod/data/field/multimenu/field.class.php @@ -140,7 +140,8 @@ class data_field_multimenu extends data_field_base { $str .= ''; - $str .= html_writer::checkbox('f_'.$this->field->id.'_allreq', null, $allrequired, get_string('selectedrequired', 'data'), array('class' => 'm-r-1')); + $str .= html_writer::checkbox('f_'.$this->field->id.'_allreq', null, $allrequired, + get_string('selectedrequired', 'data'), array('class' => 'm-r-1')); return $str; diff --git a/mod/data/field/number/field.class.php b/mod/data/field/number/field.class.php index ea01aa5e6f5..dc116156101 100644 --- a/mod/data/field/number/field.class.php +++ b/mod/data/field/number/field.class.php @@ -71,7 +71,8 @@ class data_field_number extends data_field_base { function display_search_field($value = '') { return '' . - ''; + ''; } function parse_search_field() { diff --git a/mod/data/field/picture/field.class.php b/mod/data/field/picture/field.class.php index f620a6747c4..8007b905794 100644 --- a/mod/data/field/picture/field.class.php +++ b/mod/data/field/picture/field.class.php @@ -109,9 +109,11 @@ class data_field_picture extends data_field_base { $str .= $output->render($fm); $str .= '
'; - $str .= ''; - $str .= ' '; + $str .= ''; + $str .= ' '; $str .= '
'; $str .= '
'; @@ -139,8 +141,9 @@ class data_field_picture extends data_field_base { } function display_search_field($value = '') { - return '' . - ''; + return '' . + ''; } function parse_search_field() { diff --git a/mod/data/field/text/field.class.php b/mod/data/field/text/field.class.php index fea218508dd..4c255953c3e 100644 --- a/mod/data/field/text/field.class.php +++ b/mod/data/field/text/field.class.php @@ -33,7 +33,9 @@ class data_field_text extends data_field_base { protected static $priority = self::MAX_PRIORITY; function display_search_field($value = '') { - return '' . ''; + return '' . + ''; } function parse_search_field() { diff --git a/mod/data/field/textarea/field.class.php b/mod/data/field/textarea/field.class.php index ec9b6610fa7..0fbd34ca352 100644 --- a/mod/data/field/textarea/field.class.php +++ b/mod/data/field/textarea/field.class.php @@ -172,7 +172,8 @@ class data_field_textarea extends data_field_base { function display_search_field($value = '') { return '' . - ''; + ''; } function parse_search_field() { diff --git a/mod/data/field/url/field.class.php b/mod/data/field/url/field.class.php index fb32bdb888c..38b719474b3 100644 --- a/mod/data/field/url/field.class.php +++ b/mod/data/field/url/field.class.php @@ -87,11 +87,13 @@ class data_field_url extends data_field_base { } $str .= ''; $str .= $label; - $str .= ''; - $str .= ''; - $str .= ''.get_string('text', 'data').':'; - $str .= 'field->id . '_0" id="' . $fieldid . '" value="' . s($url) . '" ' . + 'size="40" class="form-control d-inline"/>'; + $str .= ''; + $str .= '' . get_string('text', 'data') . ':'; + $str .= ''; $str .= ''; } else { // Just the URL field @@ -99,7 +101,8 @@ class data_field_url extends data_field_base { $str .= 'repositories) > 0) { - $str .= ''; + $str .= ''; } } @@ -113,8 +116,9 @@ class data_field_url extends data_field_base { } function display_search_field($value = '') { - return '' . - ''; + return '' . + ''; } function parse_search_field() { diff --git a/mod/data/lib.php b/mod/data/lib.php index 0fc5b0f4a5d..2d859c30989 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -308,8 +308,9 @@ class data_field_base { // Base class for Database Field Types (see field/*/ array('class' => 'req', 'title' => get_string('requiredelement', 'form'))); $str .= html_writer::div($image, 'inline-req'); } - $str .= 'field->id . '" value="'.s($content).'" />'; + $str .= ''; $str .= '
'; return $str; @@ -1663,7 +1664,7 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order=' echo ' '; $pagesizes = array(2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10,15=>15, 20=>20,30=>30,40=>40,50=>50,100=>100,200=>200,300=>300,400=>400,500=>500,1000=>1000); - echo html_writer::select($pagesizes, 'perpage', $perpage, false, array('id'=>'pref_perpage', 'class' => 'custom-select')); + echo html_writer::select($pagesizes, 'perpage', $perpage, false, array('id' => 'pref_perpage', 'class' => 'custom-select')); if ($advanced) { $regsearchclass = 'search_none'; @@ -1673,7 +1674,8 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order=' $advancedsearchclass = 'search_none'; } echo ''; + echo ' '; echo '    '; // foreach field, print the option echo ''; echo ' '; - echo ' '; - echo ' '; + echo ' ' . + ''; + echo ' '; echo '
'; echo '
'; @@ -1781,9 +1785,11 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order=' $fn = !empty($search_array[DATA_FIRSTNAME]->data) ? $search_array[DATA_FIRSTNAME]->data : ''; $ln = !empty($search_array[DATA_LASTNAME]->data) ? $search_array[DATA_LASTNAME]->data : ''; $patterns[] = '/##firstname##/'; - $replacement[] = ''; + $replacement[] = '' . + ''; $patterns[] = '/##lastname##/'; - $replacement[] = ''; + $replacement[] = '' . + ''; // actual replacement of the tags $newtext = preg_replace($patterns, $replacement, $data->asearchtemplate); @@ -1795,7 +1801,10 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order=' echo format_text($newtext, FORMAT_HTML, $options); echo ''; - echo '
'; + echo '
' . + '' . + '' . + ''; echo ''; echo '
'; echo ''; diff --git a/mod/data/renderer.php b/mod/data/renderer.php index 1b065354fc3..2056e6e462b 100644 --- a/mod/data/renderer.php +++ b/mod/data/renderer.php @@ -40,7 +40,8 @@ class mod_data_renderer extends plugin_renderer_base { foreach ($newfields as $nid => $newfield) { $row = array(); $row[0] = html_writer::tag('label', $newfield->name, array('for'=>'id_'.$newfield->name)); - $row[1] = html_writer::start_tag('select', array('name'=>'field_'.$nid, 'id'=>'id_'.$newfield->name, 'class' => 'custom-select')); + $attrs = array('name' => 'field_' . $nid, 'id' => 'id_' . $newfield->name, 'class' => 'custom-select'); + $row[1] = html_writer::start_tag('select', $attrs); $selected = false; foreach ($currentfields as $cid => $currentfield) { @@ -71,10 +72,11 @@ class mod_data_renderer extends plugin_renderer_base { } $html .= html_writer::start_tag('div', array('class'=>'overwritesettings')); - $html .= html_writer::tag('label', get_string('overwritesettings', 'data'), array('for'=>'overwritesettings')); - $html .= html_writer::empty_tag('input', array('type'=>'checkbox', 'name'=>'overwritesettings', 'id'=>'overwritesettings', 'class'=>'m-l-1')); + $html .= html_writer::tag('label', get_string('overwritesettings', 'data'), array('for' => 'overwritesettings')); + $attrs = array('type' => 'checkbox', 'name' => 'overwritesettings', 'id' => 'overwritesettings', 'class' => 'm-l-1'); + $html .= html_writer::empty_tag('input', $attrs); $html .= html_writer::end_tag('div'); - $html .= html_writer::empty_tag('input', array('type'=>'submit', 'class'=>'btn btn-primary', 'value'=>$strcontinue)); + $html .= html_writer::empty_tag('input', array('type' => 'submit', 'class' => 'btn btn-primary', 'value' => $strcontinue)); $html .= html_writer::end_tag('div'); $html .= html_writer::end_tag('form'); diff --git a/mod/data/templates.php b/mod/data/templates.php index 704bfa5eadb..4d68d9fe127 100644 --- a/mod/data/templates.php +++ b/mod/data/templates.php @@ -300,7 +300,8 @@ if ($mode != 'csstemplate' and $mode != 'jstemplate') { echo ''; echo ''; - echo '



'; + echo '



'; + echo ''; echo '

'; if ($usehtmleditor) { $switchlink = new moodle_url($PAGE->url, ['useeditor' => false]); @@ -315,7 +316,8 @@ if ($mode != 'csstemplate' and $mode != 'jstemplate') { ]); } } else { - echo '



'; + echo '



'; + echo ''; } echo ''; @@ -329,7 +331,10 @@ if ($mode == 'listtemplate'){ $field = 'template'; $editor->set_text($data->{$mode}); $editor->use_editor($field, $options); -echo '
'; +echo '
'; +echo ''; +echo '
'; echo ''; echo ''; @@ -342,19 +347,27 @@ if ($mode == 'listtemplate'){ $field = 'listtemplatefooter'; $editor->set_text($data->listtemplatefooter); $editor->use_editor($field, $options); - echo '
'; + echo '
'; + echo ''; + echo '
'; echo ''; echo ''; } else if ($mode == 'rsstemplate') { echo ''; echo ' '; echo ''; - echo '
'; + echo '
'; + echo ''; + echo '
'; $field = 'rsstitletemplate'; $editor->set_text($data->rsstitletemplate); $editor->use_editor($field, $options); - echo '
'; + echo '
'; + echo ''; + echo '
'; echo ''; echo ''; }