21307 Posts in 5737 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 271 Views |
-
Multiple DateFiled or TimeFiled or DateTimeField

2 March 2012 at 6:49am
hi guys,
I'm doing weekyl opening hours on a directory site, so have 14 time fields required:
Monday opening time, Monday closing time
Tuesday opening... etcI wanna add the dropwdown to each field, but cant seem to work out how to do that without repeating LOTS of code?
here's what I have:
Statc $db = array (
'MonStart' => 'Time',
'MonFinish' => 'Time',
'MonClosed' => 'Boolean',
'TueStart' => 'Time',
'TueFinish' => 'Time',
'TueClosed' => 'Boolean',............
$TimeField = new Timefield('MonStart', 'Monday Opening time');
$TimeField->setConfig('showdropdown', true);
$TimeField->setConfig('timeformat', 'h:m a');
$TimeField->setLocale('en_GB');new $TimeField
any ideas?
thanks.
-
Re: Multiple DateFiled or TimeFiled or DateTimeField

2 March 2012 at 6:57am Last edited: 2 March 2012 6:57am
you could create a DaylyOpeningHours object, then do a CTF with a record for each day. That would get rid of the code repetition.
Seems like a bit of an overkill - unless of course you want to do something special with these data beside showing them on the page... Else you could just use a table in the content area - but I guess you thought of that
-
Re: Multiple DateFiled or TimeFiled or DateTimeField

2 March 2012 at 7:01am
yeah well the idea is, business owners will be entering their own opening hours, so i will be using the "dropdown" on the front end, rather than having to type in lots of times manually, plus this ensures all date formats are the same. (although I guess I could do front end validating....)
sorry I have no idea what you mean by CTF, any chance of an example?
-
Re: Multiple DateFiled or TimeFiled or DateTimeField

2 March 2012 at 9:18am
OK, sorry, a CTF isa complexTableField...
But I was thinking: since a week only ever has the 7 days, you could just as well create the fields all at once, then use some sort of loop to keep from duplicating code, like the following (haven't tested, but might give you an idea:
Suppose you call the fields:
MondayOpenAt,
MondayCloseAt
MondayClosed
TuesdayOpenAt
...Then you could do something like (just copied your fieldsettings):
$arrayWeek = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' );
$arraySettings = array('OpenAt' => 'open at', 'CloseAt' => 'close at', 'Closed' => 'closed all day');foreach ($arrayWeek as $day) {
foreach ($arraySettings as $setting => $label) {$fieldName = $day . $setting;
if ($setting != 'Closed') {
$field = new Timefield($fieldName, _t("OpeningHours.$label", "$day $label"));
$field->setConfig('showdropdown', true);
$field->setConfig('timeformat', 'h:m a');
$field->setLocale('en_GB');
}
else {
$field = new CheckboxField($fieldName, _t("OpeningHours.$label", "$day $label"));
}
$fields->push($field);
}
}
| 271 Views | ||
|
Page:
1
|
Go to Top |

