mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-20204 legacy time selects converted, please note we should always use mforms if possible
This commit is contained in:
parent
78bdac6449
commit
f83b9b63ae
@ -170,7 +170,9 @@ if (!empty($allowedusers)) {
|
||||
//valid until date selector
|
||||
$contents .= "<div class=\"fitem\"><div class=\"fitemtitle\"><label>".get_string('validuntil','webservice')." </label></div><div class=\"felement\">";
|
||||
// the following date selector needs to have specific day/month/year field ids because we use javascript (enable/disable).
|
||||
$selectors = html_select::make_time_selectors(array('days' => 'fromday'.$user->id,'months' => 'frommonth'.$user->id, 'years' => 'fromyear'.$user->id),$user->validuntil);
|
||||
$selectors = html_writer::select_time('days', 'fromday'.$user->id, $user->validuntil)
|
||||
. html_writer::select_time('months', 'frommonth'.$user->id, $user->validuntil)
|
||||
. html_writer::select_time('years', 'fromyear'.$user->id, $user->validuntil);
|
||||
foreach ($selectors as $select) {
|
||||
if (empty($user->validuntil)) {
|
||||
$select->disabled = true;
|
||||
|
@ -298,11 +298,11 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
|
||||
/// (some formats like main page, social..., haven't it and rolling dates
|
||||
/// from 0 produces crazy dates. MDL-10125
|
||||
if ($form1->startdate) {
|
||||
$dayselector = html_select::make_time_selector('days', "startday", $form1->startdate);
|
||||
$monthselector = html_select::make_time_selector('months', "startmonth", $form1->startdate);
|
||||
$yearselector = html_select::make_time_selector('years', "startyear", $form1->startdate);
|
||||
$dayselector = html_writer::select_time('days', "startday", $form1->startdate);
|
||||
$monthselector = html_writer::select_time('months', "startmonth", $form1->startdate);
|
||||
$yearselector = html_writer::select_time('years', "startyear", $form1->startdate);
|
||||
|
||||
echo $OUTPUT->select($dayselector) . $OUTPUT->select($monthselector) . $OUTPUT->select($yearselector);
|
||||
echo $dayselector . $monthselector . $yearselector;
|
||||
echo $OUTPUT->help_icon("coursestartdate", get_string("startdate"));
|
||||
} else {
|
||||
print_string('notavailable');
|
||||
|
@ -113,9 +113,9 @@ if (!isset($frm->acceptechecktypes)) {
|
||||
<td align="right">an_cutoff:</td>
|
||||
<td><?php
|
||||
$curtime = make_timestamp(2000,1,1,$frm->an_cutoff_hour,$frm->an_cutoff_min);
|
||||
$hourselector = html_select::make_time_selector('hours', 'an_cutoff_hour', $curtime);
|
||||
$minselector = html_select::make_time_selector('minutes', 'an_cutoff_min', $curtime);
|
||||
echo $OUTPUT->select($hourselector) . $OUTPUT->select($minselector);
|
||||
$hourselector = html_writer::select_time('hours', 'an_cutoff_hour', $curtime);
|
||||
$minselector = html_writer::select_time('minutes', 'an_cutoff_min', $curtime);
|
||||
echo $hourselector . $minselector;
|
||||
?><br />
|
||||
<?php print_string("cutofftime", "enrol_authorize") ?></td>
|
||||
</tr>
|
||||
|
@ -3233,11 +3233,11 @@ function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $
|
||||
*/
|
||||
function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
|
||||
debugging('print_time_selector() has been deprecated. Please change your code to use $OUTPUT->select($timeselector).');
|
||||
global $OUTPUT;
|
||||
$hourselector = html_select::make_time_selector('hours', $hour, $currenttime);
|
||||
$minuteselector = html_select::make_time_selector('minutes', $minute, $currenttime, $step);
|
||||
|
||||
$output = $OUTPUT->select($hourselector) . $OUTPUT->select($minuteselector);
|
||||
$hourselector = html_writer::select_time('hours', $hour, $currenttime);
|
||||
$minuteselector = html_writer::select_time('minutes', $minute, $currenttime, $step);
|
||||
|
||||
$output = $hourselector . $$minuteselector;
|
||||
|
||||
if ($return) {
|
||||
return $output;
|
||||
@ -3259,15 +3259,13 @@ function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=fa
|
||||
* @return string|bool Depending on value of $return
|
||||
*/
|
||||
function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
|
||||
|
||||
debugging('print_date_selector() has been deprecated. Please change your code to use $OUTPUT->select($dateselector).');
|
||||
global $OUTPUT;
|
||||
|
||||
$dayselector = html_select::make_time_selector('days', $day, $currenttime);
|
||||
$monthselector = html_select::make_time_selector('months', $month, $currenttime);
|
||||
$yearselector = html_select::make_time_selector('years', $year, $currenttime);
|
||||
$dayselector = html_writer::select_time('days', $day, $currenttime);
|
||||
$monthselector = html_writer::select_time('months', $month, $currenttime);
|
||||
$yearselector = html_writer::select_time('years', $year, $currenttime);
|
||||
|
||||
$output = $OUTPUT->select($dayselector) . $OUTPUT->select($monthselector) . $OUTPUT->select($yearselector);
|
||||
$output = $dayselector . $monthselector . $yearselector;
|
||||
|
||||
if ($return) {
|
||||
return $output;
|
||||
|
@ -788,6 +788,70 @@ class html_writer {
|
||||
return self::tag('optgroup', $attributes, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a shortcut for making an hour selector menu.
|
||||
* @param string $type The type of selector (years, months, days, hours, minutes)
|
||||
* @param string $name fieldname
|
||||
* @param int $currenttime A default timestamp in GMT
|
||||
* @param int $step minute spacing
|
||||
* @param array $attributes - html select element attributes
|
||||
* @return HTML fragment
|
||||
*/
|
||||
public static function select_time($type, $name, $currenttime=0, $step=5, array $attributes=null) {
|
||||
if (!$currenttime) {
|
||||
$currenttime = time();
|
||||
}
|
||||
$currentdate = usergetdate($currenttime);
|
||||
$userdatetype = $type;
|
||||
$timeunits = array();
|
||||
|
||||
switch ($type) {
|
||||
case 'years':
|
||||
for ($i=1970; $i<=2020; $i++) {
|
||||
$timeunits[$i] = $i;
|
||||
}
|
||||
$userdatetype = 'year';
|
||||
break;
|
||||
case 'months':
|
||||
for ($i=1; $i<=12; $i++) {
|
||||
$timeunits[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B");
|
||||
}
|
||||
$userdatetype = 'month';
|
||||
$currentdate['month'] = $currentdate['mon'];
|
||||
break;
|
||||
case 'days':
|
||||
for ($i=1; $i<=31; $i++) {
|
||||
$timeunits[$i] = $i;
|
||||
}
|
||||
$userdatetype = 'mday';
|
||||
break;
|
||||
case 'hours':
|
||||
for ($i=0; $i<=23; $i++) {
|
||||
$timeunits[$i] = sprintf("%02d",$i);
|
||||
}
|
||||
break;
|
||||
case 'minutes':
|
||||
if ($step != 1) {
|
||||
$currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step;
|
||||
}
|
||||
|
||||
for ($i=0; $i<=59; $i+=$step) {
|
||||
$timeunits[$i] = sprintf("%02d",$i);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new coding_exception("Time type $type is not supported by html_writer::select_time().");
|
||||
}
|
||||
|
||||
if (empty($attributes['id'])) {
|
||||
$attributes['id'] = self::random_id('ts_');
|
||||
}
|
||||
$timerselector = self::select($timeunits, $name, $currentdate[$userdatetype], null, array('id'=>$attributes['id']));
|
||||
$label = self::tag('label', array('for'=>$attributes['id'], 'class'=>'accesshide'), get_string(substr($type, 0, -1), 'form'));
|
||||
|
||||
return $label.$timerselector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns hidden input fields created from url parameters.
|
||||
* @param moodle_url $url
|
||||
@ -1374,87 +1438,6 @@ class html_select extends labelled_html_component {
|
||||
return $menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a shortcut for making an hour selector menu.
|
||||
* @param string $type The type of selector (years, months, days, hours, minutes)
|
||||
* @param string $name fieldname
|
||||
* @param int $currenttime A default timestamp in GMT
|
||||
* @param int $step minute spacing
|
||||
* @return html_select A menu initialised with hour options.
|
||||
*/
|
||||
public static function make_time_selector($type, $name, $currenttime=0, $step=5) {
|
||||
|
||||
if (!$currenttime) {
|
||||
$currenttime = time();
|
||||
}
|
||||
$currentdate = usergetdate($currenttime);
|
||||
$userdatetype = $type;
|
||||
|
||||
switch ($type) {
|
||||
case 'years':
|
||||
for ($i=1970; $i<=2020; $i++) {
|
||||
$timeunits[$i] = $i;
|
||||
}
|
||||
$userdatetype = 'year';
|
||||
break;
|
||||
case 'months':
|
||||
for ($i=1; $i<=12; $i++) {
|
||||
$timeunits[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B");
|
||||
}
|
||||
$userdatetype = 'month';
|
||||
$currentdate['month'] = $currentdate['mon'];
|
||||
break;
|
||||
case 'days':
|
||||
for ($i=1; $i<=31; $i++) {
|
||||
$timeunits[$i] = $i;
|
||||
}
|
||||
$userdatetype = 'mday';
|
||||
break;
|
||||
case 'hours':
|
||||
for ($i=0; $i<=23; $i++) {
|
||||
$timeunits[$i] = sprintf("%02d",$i);
|
||||
}
|
||||
break;
|
||||
case 'minutes':
|
||||
if ($step != 1) {
|
||||
$currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step;
|
||||
}
|
||||
|
||||
for ($i=0; $i<=59; $i+=$step) {
|
||||
$timeunits[$i] = sprintf("%02d",$i);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new coding_exception("Time type $type is not supported by html_select::make_time_selector().");
|
||||
}
|
||||
|
||||
$timerselector = self::make($timeunits, $name, $currentdate[$userdatetype]);
|
||||
$timerselector->label = new html_label();
|
||||
|
||||
$timerselector->label->text = get_string(substr($type, 0, -1), 'form');
|
||||
$timerselector->label->for = "menu$timerselector->name";
|
||||
$timerselector->label->add_class('accesshide');
|
||||
$timerselector->nothinglabel = '';
|
||||
|
||||
return $timerselector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an associative array of type => fieldname and an optional timestamp,
|
||||
* returns an array of html_select components representing date/time selectors.
|
||||
* @param array $selectors Arrays of type => fieldname. Selectors will be returned in the order of the types given
|
||||
* @param int $currenttime A UNIX timestamp
|
||||
* @param int $step minute spacing
|
||||
* @return array Instantiated date/time selectors
|
||||
*/
|
||||
public static function make_time_selectors($selectors, $currenttime=0, $step=5) {
|
||||
$selects = array();
|
||||
foreach ($selectors as $type => $name) {
|
||||
$selects[] = html_select::make_time_selector($type, $name, $currenttime, $step);
|
||||
}
|
||||
return $selects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a help icon next to the select menu.
|
||||
*
|
||||
|
@ -44,10 +44,10 @@ class data_field_date extends data_field_base {
|
||||
}
|
||||
|
||||
$str = '<div title="'.s($this->field->description).'">';
|
||||
$dayselector = html_select::make_time_selector('days', 'field_'.$this->field->id.'_day', $content);
|
||||
$monthselector = html_select::make_time_selector('months', 'field_'.$this->field->id.'_month', $content);
|
||||
$yearselector = html_select::make_time_selector('years', 'field_'.$this->field->id.'_year', $content);
|
||||
$str .= $OUTPUT->select($dayselector) . $OUTPUT->select($monthselector) . $OUTPUT->select($yearselector);
|
||||
$dayselector = html_writer::select_time('days', 'field_'.$this->field->id.'_day', $content);
|
||||
$monthselector = html_writer::select_time('months', 'field_'.$this->field->id.'_month', $content);
|
||||
$yearselector = html_writer::select_time('years', 'field_'.$this->field->id.'_year', $content);
|
||||
$str .= $dayselector . $monthselector . $yearselector;
|
||||
$str .= '</div>';
|
||||
|
||||
return $str;
|
||||
|
@ -310,10 +310,12 @@ function forum_print_big_search_form($course) {
|
||||
}
|
||||
|
||||
echo '<input name="timefromrestrict" type="checkbox" value="1" alt="'.get_string('searchdatefrom', 'forum').'" onclick="return lockoptions(\'searchform\', \'timefromrestrict\', timefromitems)" '. $datefromchecked . ' /> ';
|
||||
$selectors = html_select::make_time_selectors(array('days' => 'fromday','months' => 'frommonth', 'years' => 'fromyear', 'hours' => 'fromhour', 'minutes' => 'fromminute'), $datefrom);
|
||||
foreach ($selectors as $select) {
|
||||
echo $OUTPUT->select($select);
|
||||
}
|
||||
$selectors = html_writer::select_time('days', 'fromday', $datefrom)
|
||||
. html_writer::select_time('months', 'frommonth', $datefrom)
|
||||
. html_writer::select_time('years', 'fromyear', $datefrom)
|
||||
. html_writer::select_time('hours', 'fromhour', $datefrom)
|
||||
. html_writer::select_time('minutes', 'fromminute', $datefrom);
|
||||
echo $selectors;
|
||||
echo '<input type="hidden" name="hfromday" value="0" />';
|
||||
echo '<input type="hidden" name="hfrommonth" value="0" />';
|
||||
echo '<input type="hidden" name="hfromyear" value="0" />';
|
||||
@ -334,10 +336,12 @@ function forum_print_big_search_form($course) {
|
||||
}
|
||||
|
||||
echo '<input name="timetorestrict" type="checkbox" value="1" alt="'.get_string('searchdateto', 'forum').'" onclick="return lockoptions(\'searchform\', \'timetorestrict\', timetoitems)" ' .$datetochecked. ' /> ';
|
||||
$selectors = html_select::make_time_selectors(array('days' => 'today','months' => 'tomonth', 'years' => 'toyear', 'hours' => 'tohour', 'minutes' => 'tominute'), $dateto);
|
||||
foreach ($selectors as $select) {
|
||||
echo $OUTPUT->select($select);
|
||||
}
|
||||
$selectors = html_writer::select_time('days', 'fromday', $dateto)
|
||||
. html_writer::select_time('months', 'frommonth', $dateto)
|
||||
. html_writer::select_time('years', 'fromyear', $dateto)
|
||||
. html_writer::select_time('hours', 'fromhour', $dateto)
|
||||
. html_writer::select_time('minutes', 'fromminute', $dateto);
|
||||
echo $selectors;
|
||||
|
||||
echo '<input type="hidden" name="htoday" value="0" />';
|
||||
echo '<input type="hidden" name="htomonth" value="0" />';
|
||||
|
Loading…
x
Reference in New Issue
Block a user