kartik\helpers\Enum::dateList PHP Method

dateList() public static method

Example: ~~~ print_r(Enum::dateList(1, 28, 7)); print_r(Enum::dateList(1, 10)); ~~~
public static dateList ( integer $from = 1, integer $to = 31, integer $interval = 1, boolean $intervalFromZero = true, boolean $showLast = true ) : array
$from integer the start day, defaults to 1
$to integer the end day, defaults to 31
$interval integer the date interval, defaults to 1.
$intervalFromZero boolean whether to start incrementing intervals from zero if $from = 1.
$showLast boolean whether to show the last date (set in $to) even if it does not match interval.
return array
    public static function dateList($from = 1, $to = 31, $interval = 1, $intervalFromZero = true, $showLast = true)
    {
        if ($to < 1 || $from < 1) {
            $val = $from < 1 ? "from day '{$from}'" : "to day '{$to}'";
            throw new InvalidConfigException("Invalid value for {$val} passed. Must be greater or equal than 1");
        }
        if ($from > $to) {
            throw new InvalidConfigException("The from day '{$from}' cannot exceed to day '{$to}'.");
        }
        if ($to > 31) {
            throw new InvalidConfigException("Invalid value for to day '{$to}' passed. Must be less than or equal to 31");
        }
        if ($from > 1 || $interval == 1 || !$intervalFromZero) {
            $out = range($from, $to, $interval);
        } else {
            $out = range(0, $to, $interval);
            $out[0] = 1;
        }
        $len = count($out);
        if ($showLast && $out[$len - 1] != $to) {
            $out[$len] = $to;
        }
        return $out;
    }

Usage Example

Example #1
0
$model = new Recurrence();
Modal::begin(['header' => '<h3>' . Yii::t('igolf', 'Repeat Event') . '</h3>', 'id' => 'recurrence-modal']);
?>
<div class="recurrence-form">

	<?php 
echo Form::widget(['model' => $model, 'form' => $form, 'columns' => 12, 'attributes' => ['frequency' => ['label' => Yii::t('igolf', 'Recurrence'), 'type' => Form::INPUT_DROPDOWN_LIST, 'items' => Recurrence::getLocalizedConstants('FREQUENCY_'), 'columnOptions' => ['colspan' => 4]], 'interval' => ['type' => Form::INPUT_WIDGET, 'widgetClass' => TouchSpin::className(), 'options' => ['pluginOptions' => ['initval' => 1, 'min' => 1, 'max' => 30]], 'columnOptions' => ['colspan' => 4]], 'repeat' => ['label' => Yii::t('igolf', 'every'), 'type' => Form::INPUT_STATIC, 'columnOptions' => ['colspan' => 4]]]]);
echo '<div class="recurrence_byweekday">';
echo $form->field($model, 'byweekday')->checkboxButtonGroup(Enum::dayList())->label(false);
echo '</div>';
echo '<div class="recurrence_bymonth">';
echo Form::widget(['model' => $model, 'form' => $form, 'columns' => 12, 'attributes' => ['option' => ['type' => Form::INPUT_RADIO_LIST, 'items' => ['bymonthday' => Yii::t('igolf', 'on day')], 'columnOptions' => ['colspan' => 2], 'label' => false], 'bymonthday' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Enum::dateList(1, 31), 'columnOptions' => ['colspan' => 2], 'label' => false]]]);
echo Form::widget(['model' => $model, 'form' => $form, 'columns' => 12, 'attributes' => ['option' => ['type' => Form::INPUT_RADIO_LIST, 'items' => ['byposday' => Yii::t('igolf', 'on the')], 'columnOptions' => ['colspan' => 2], 'label' => false], 'bypos4month' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Recurrence::getLocalizedConstants('POSITION_'), 'columnOptions' => ['colspan' => 4], 'label' => false], 'weekday4month' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Enum::dayList() + Recurrence::getLocalizedConstants('DAY_'), 'columnOptions' => ['colspan' => 4], 'label' => false]]]);
echo '</div>';
echo '<div class="recurrence_byyear">';
echo Form::widget(['model' => $model, 'form' => $form, 'columns' => 12, 'attributes' => ['option' => ['type' => Form::INPUT_RADIO_LIST, 'items' => ['bymonth' => Yii::t('igolf', 'on')], 'columnOptions' => ['colspan' => 2], 'label' => false], 'bymonth' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Enum::monthList(), 'columnOptions' => ['colspan' => 4], 'label' => false], 'monthday4year' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Enum::dateList(1, 31), 'columnOptions' => ['colspan' => 2], 'label' => false]]]);
echo Form::widget(['model' => $model, 'form' => $form, 'columns' => 12, 'attributes' => ['option' => ['type' => Form::INPUT_RADIO_LIST, 'items' => ['byposmonth' => Yii::t('igolf', 'on the')], 'columnOptions' => ['colspan' => 2], 'label' => false], 'bypos4year' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Recurrence::getLocalizedConstants('POSITION_'), 'columnOptions' => ['colspan' => 3], 'label' => false], 'weekday4year' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Enum::dayList() + Recurrence::getLocalizedConstants('DAY_'), 'columnOptions' => ['colspan' => 3], 'label' => false], 'month4year' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Enum::monthList(), 'columnOptions' => ['colspan' => 4], 'label' => false]]]);
echo '</div>';
echo '<div class="recurrence_until">';
echo Form::widget(['model' => $model, 'form' => $form, 'columns' => 12, 'attributes' => ['until' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Recurrence::getLocalizedConstants('UNTIL_'), 'columnOptions' => ['colspan' => 4]], 'count' => ['type' => Form::INPUT_WIDGET, 'widgetClass' => TouchSpin::className(), 'options' => ['pluginOptions' => ['initval' => 1, 'min' => 1, 'max' => 20]], 'columnOptions' => ['colspan' => 4]], 'date_end' => ['type' => Form::INPUT_WIDGET, 'widgetClass' => DatePicker::className(), 'options' => ['pluginOptions' => ['format' => 'yyyy/mm/dd', 'todayHighlight' => true]], 'columnOptions' => ['colspan' => 4], 'label' => Yii::t('igolf', 'End Date')]]]);
echo '</div>';
?>

	<div class="form-group">
	    <?php 
echo Html::button(Yii::t('igolf', 'Cancel'), ['class' => 'btn btn-danger', 'data' => ['dismiss' => 'modal']]);
?>
	    <?php 
echo Html::button(Yii::t('igolf', 'OK'), ['class' => 'btn btn-success action-ok', 'data' => ['dismiss' => 'modal']]);
?>
	</div>