Skip to content

Commit

Permalink
move dateFormat to traits
Browse files Browse the repository at this point in the history
  • Loading branch information
PutraSudaryanto committed Jul 9, 2018
1 parent f1d7485 commit 42b3760
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
33 changes: 25 additions & 8 deletions GridViewTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* Contains many function that most used :
* keyIndex
* activeDefaultColumns
* filterYesNo
* quickAction
* filterDatepicker
*
*/

Expand Down Expand Up @@ -93,23 +96,20 @@ public function quickAction($url, $id, $type=null, $single=false)
*
* @return string input
*/
public function filterDatepicker($model, $attribute)
public function filterDatepicker($model, $attribute, $filter=true)
{
$class = trim(get_class($model));
$attrValue = Yii::app()->getRequest()->getParam($class)[$attribute];
if(Yii::app()->params['grid-view']['JuiDatepicker'])
{
return Yii::app()->controller->widget('zii.widgets.jui.CJuiDatePicker', array(
$options = array(
'model'=>$model,
'attribute'=>$attribute,
'language' => 'en',
'i18nScriptFile' => 'jquery-ui-i18n.min.js',
//'mode'=>'datetime',
'htmlOptions' => array(
'value' => $attrValue,
'id' => $attribute.'_filter',
'on_datepicker' => 'on',
'placeholder' => Yii::t('phrase', 'filter'),
),
'options'=>array(
'showOn' => 'focus',
Expand All @@ -120,9 +120,26 @@ public function filterDatepicker($model, $attribute)
'changeYear' => true,
'showButtonPanel' => true,
),
), true);
);
if($filter == true) {
$options['htmlOptions']['id'] = $attribute.'_filter';
$options['htmlOptions']['on_datepicker'] = 'on';
$options['htmlOptions']['placeholder'] = Yii::t('phrase', 'filter');
} else
$options['htmlOptions']['class'] = 'form-control';

} else
return CHtml::activeDateField($model, $attribute, array('value'=>$attrValue, 'placeholder'=>'filter'));
return Yii::app()->controller->widget('zii.widgets.jui.CJuiDatePicker', $options, true);

} else {
$options = array(
'value'=>$attrValue,
);
if($filter == true)
$options['placeholder'] = Yii::t('phrase', 'filter');
else
$options['class'] = 'form-control';

return CHtml::activeDateField($model, $attribute, $options);
}
}
}
21 changes: 21 additions & 0 deletions UtilityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* flashMessage
* uniqueCode
* licenseCode
* dateFormat
*
*/

Expand Down Expand Up @@ -125,4 +126,24 @@ public function licenseCode($source='1234567890', $length=16, $char=4)

return $license;
}

/**
* Get format date from locale setting
*
* @return string
*/
public function dateFormat($date, $time=false)
{
if(is_numeric($date) && (int)$date == $date)
$date = date('Y-m-d H:i:s', $date);

$setting = OmmuSettings::model()->findByPk(1, array(
'select' => 'site_dateformat, site_timeformat',
));

if($time == true)
return date($setting->site_dateformat, strtotime($date)).' '.date($setting->site_timeformat, strtotime($date)).' WIB';
else
return date($setting->site_dateformat, strtotime($date));
}
}

0 comments on commit 42b3760

Please sign in to comment.