Browse Source

Update minute() method to use datetime widget.

Mark Story 12 years ago
parent
commit
1dbe9f7dc4
2 changed files with 19 additions and 29 deletions
  1. 12 22
      src/View/Helper/FormHelper.php
  2. 7 7
      tests/TestCase/View/Helper/FormHelperTest.php

+ 12 - 22
src/View/Helper/FormHelper.php

@@ -1992,35 +1992,25 @@ class FormHelper extends Helper {
  * - `empty` - If true, the empty select option is shown. If a string,
  *   that string is displayed as the empty element.
  * - `value` The selected value of the input.
+ * - `interval` The interval that minute options should be created at.
+ * - `round` How you want the value rounded when it does not fit neatly into an
+ *   interval. Accepts 'up', 'down', and null.
  *
  * @param string $fieldName Prefix name for the SELECT element
- * @param array $attributes Array of Attributes
+ * @param array $options Array of options.
  * @return string Completed minute select input.
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::minute
  */
-	public function minute($fieldName, $attributes = array()) {
-		$attributes += array('empty' => true, 'value' => null);
-		$attributes = $this->_dateTimeSelected('min', $fieldName, $attributes);
-
-		if (strlen($attributes['value']) > 2) {
-			$date = date_create($attributes['value']);
-			$attributes['value'] = null;
-			if ($date) {
-				$attributes['value'] = $date->format('i');
-			}
-		} elseif ($attributes['value'] === false) {
-			$attributes['value'] = null;
-		}
-		$minuteOptions = array();
+	public function minute($fieldName, $options = []) {
+		$options = $this->_singleDatetime($options, 'minute');
 
-		if (isset($attributes['interval'])) {
-			$minuteOptions['interval'] = $attributes['interval'];
-			unset($attributes['interval']);
+		if (isset($options['val']) && $options['val'] > 0 && $options['val'] <= 60) {
+			$options['val'] = [
+				'hour' => date('H'),
+				'minute' => (int)$options['val'],
+			];
 		}
-		return $this->select(
-			$fieldName . ".min", $this->_generateOptions('minute', $minuteOptions),
-			$attributes
-		);
+		return $this->datetime($fieldName, $options);
 	}
 
 /**

+ 7 - 7
tests/TestCase/View/Helper/FormHelperTest.php

@@ -5602,10 +5602,10 @@ class FormHelperTest extends TestCase {
 	public function testMinute() {
 		extract($this->dateRegex);
 
-		$result = $this->Form->minute('Model.field');
+		$result = $this->Form->minute('Model.field', ['value' => '']);
 		$expected = array(
-			array('select' => array('name' => 'Model[field][min]')),
-			array('option' => array('value' => '')),
+			array('select' => array('name' => 'Model[field][minute]')),
+			array('option' => array('selected' => 'selected', 'value' => '')),
 			'/option',
 			array('option' => array('value' => '00')),
 			'00',
@@ -5624,7 +5624,7 @@ class FormHelperTest extends TestCase {
 		$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
 		$result = $this->Form->minute('Model.field');
 		$expected = array(
-			array('select' => array('name' => 'Model[field][min]')),
+			array('select' => array('name' => 'Model[field][minute]')),
 			array('option' => array('value' => '')),
 			'/option',
 			array('option' => array('value' => '00')),
@@ -5648,8 +5648,8 @@ class FormHelperTest extends TestCase {
 		$this->Form->request->data['Model']['field'] = '';
 		$result = $this->Form->minute('Model.field', array('interval' => 5));
 		$expected = array(
-			array('select' => array('name' => 'Model[field][min]')),
-			array('option' => array('value' => '')),
+			array('select' => array('name' => 'Model[field][minute]')),
+			array('option' => array('selected' => 'selected', 'value' => '')),
 			'/option',
 			array('option' => array('value' => '00')),
 			'00',
@@ -5668,7 +5668,7 @@ class FormHelperTest extends TestCase {
 		$this->Form->request->data['Model']['field'] = '2006-10-10 00:10:32';
 		$result = $this->Form->minute('Model.field', array('interval' => 5));
 		$expected = array(
-			array('select' => array('name' => 'Model[field][min]')),
+			array('select' => array('name' => 'Model[field][minute]')),
 			array('option' => array('value' => '')),
 			'/option',
 			array('option' => array('value' => '00')),