/** * Creates a group of dropdown boxes for date selection * * @param string comma seperated list of parts to be included * @param string form element name prefix example: user_ * @param array variables to be used within the function * @return string html for specified elements */ public static function date_dropdown($parts = 'month,day,year,time', $prefix = '', $other = array(), $selected = array()) { if (!is_array($parts)) { $parts = explode(',', $parts); } // Blank HTML string. $html = ''; foreach ($parts as $part) { switch ($part) { case 'month': if (!isset($selected['month'])) { $selected['month'] = date('n'); } $html .= form::dropdown($prefix . 'month', date::months(), $selected['month']); break; case 'day': if (!isset($selected['month'])) { $selected['day'] = date('j'); } $html .= form::dropdown($prefix . 'day', date::days(date('n')), $selected['day']); break; case 'year': if (!isset($selected['year'])) { $selected['year'] = date('Y'); } if (!isset($other['year']['start'])) { $other['year']['start'] = false; } if (!isset($other['year']['end'])) { $other['year']['end'] = false; } $html .= form::dropdown($prefix . 'year', date::years($other['year']['start'], $other['year']['end']), $selected['year']); break; case 'time': if (!isset($selected['hour'])) { $selected['hour'] = date('g'); } $html .= form::dropdown($prefix . 'hour', date::hours(), $selected['hour']); if (!isset($selected['min'])) { $selected['min'] = date('i'); } $html .= form::dropdown($prefix . 'min', date::minutes(1), $selected['min']); if (!isset($selected['ampm'])) { $selected['ampm'] = date('a'); } $html .= form::dropdown($prefix . 'ampm', array('am' => 'am', 'pm' => 'pm'), $selected['ampm']); } } return $html; }
/** * Number of months in a year * * @return array A mirrored (foo => foo) array from 1-12. */ public static function months() { return date::hours(); }