0

値を簡単Zend_Formに統合できる要素を探してい ます。Zend_Date

たとえば、フォームに時間ピッカーと曜日ピッカーが必要です。たとえば、時間ピッカーは午前 12:00 から午後 11:00 までのすべての時間の値を表示し、曜日ピッカーは利用可能なすべての曜日を表示する必要があります。

Zend_Form_Element_Selectとの間の何らかの統合を探していましたZend_Dateが、すぐに使用できる要素が見つかりませんでした。zend_date を使用したいので、既に使用しているローカリゼーション設定をここで使用します。

理想的には、これは次のような必要な値のタイプを設定できる zend フォーム要素である必要があります。

    $hour = new Form_Element_DateSelect('hour');
    $hour->setDateFormat(Zend_Date:HOUR);

また

    $weekday = new Form_Element_DateSelect('hour');
    $hour->setDateFormat(Zend_Date:DAYOFWEEK);

標準Zend_Form_Element_Selectを使用して値を事前に入力することでそれを達成できますが、誰かがこれらのケースの要素を作成したか、これらの要素を再利用可能にし、複数の日付形式をサポートするアイデアを持っているかどうかに興味があります.

    $hour = new Zend_Form_Element_Select('hour');
    $hour->setRequired(true)
    ->setLabel('Hour:')
    $this->addElement($hour);

    $time = new Zend_Date();
    $time->setTime('00:00:00');
    for ($i=0;$i<=23;$i++) {
        $hour->addMultiOption($time->get('HH:mm'), $time->toString(Zend_Date::TIME_SHORT));
        $time->addHour(1);
    }
4

1 に答える 1

2

Zend_Dojoを見てみましょう。これには、探しているものに近い要素が含まれている可能性があります。

具体的には、dijit.form.TimeTextBox、おそらくdijit.Calendarで、週末の日付の選択を無効にすることができます。または、dijit.form.selectZend_Formは、Zend_Translate平日を入れることができる拡張選択ボックスです。ユーザーの言語に簡単に翻訳できます。

同じことを行うためのjQueryウィジェットがたくさん利用できると確信しています。その方法をとった場合、必要に応じて緊密に結合するためにもう少し作業を行うZend_Form必要がありますが、独自のデコレータと要素を作成することもできます。

Zend Framework リファレンス ガイドには、Dojo フォーム要素のTimeTextBoxDateTextBox、およびCombo/Select Boxesに関するいくつかの基本的な例があります。

これらの豊富な UI 要素を使用するのはやり過ぎかもしれません。その場合、要素を事前に入力して目的を達成するための簡単な方法は、値の配列 (曜日または時間) を返すヘルパー メソッドを作成することです。に簡単にフィードできますZend_Form_Element_Select::setMultiOptions()

例えば

public function getWeekdays()
{
    $locale = new Zend_Locale('en_US'); // or get from registry
    $days = Zend_Locale::getTranslationList('Days', $locale);

    return $days['format']['wide'];
}

public function getTimes($options = array())
{
    $start     = null;  // time to start
    $end       = null;  // time to end
    $increment = 900;   // increment in seconds
    $format    = Zend_Date::TIME_SHORT;  // date/time format

    if (is_array($options)) {
        if (isset($options['start']) && $options['start'] instanceof Zend_Date) {
            $start = $options['start'];
        }
        if (isset($options['end']) && $options['end'] instanceof Zend_Date) {
            $end = $options['end'];
        }
        if (isset($options['increment']) && is_int($options['increment']) && (int)$options['increment'] > 0) {
            $increment = (int)$options['increment'];
        }
        if (isset($options['format']) && is_string($options['format'])) {
            $format = $options['format'];
        }
    }

    if ($start == null) {
        $start = new Zend_Date('00:00:00', Zend_Date::TIME_LONG);
    }
    if ($end == null) {
        $end   = new Zend_Date('23:59:00', Zend_Date::TIME_LONG);
    }

    $times = array();

    $time = new Zend_Date($start);

    while($time < $end) {  // TODO: check $end > $time
        $times[] = $time->toString($format);
        $time->add($increment, Zend_Date::SECOND);
    }

    return $times;
}

それらを呼び出す:

$opts = array('start' => new Zend_Date('07:00:00', Zend_Date::TIME_LONG),
              'end'   => new Zend_Date('20:00:00', Zend_Date::TIME_LONG),
              'increment' => 3600);
$element->setMultiOptions($form->getTimes($opts));

$element2->setMultiOptions($form->getWeekdays());
于 2012-02-28T07:08:33.983 に答える