From 42b3760b59a715f0355173c5fa5508150eeb6cca Mon Sep 17 00:00:00 2001 From: Putra Sudaryanto Date: Mon, 9 Jul 2018 15:38:25 +0700 Subject: [PATCH] move dateFormat to traits --- GridViewTrait.php | 33 +++++++++++++++++++++++++-------- UtilityTrait.php | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/GridViewTrait.php b/GridViewTrait.php index d037110..cf6f658 100644 --- a/GridViewTrait.php +++ b/GridViewTrait.php @@ -11,6 +11,9 @@ * Contains many function that most used : * keyIndex * activeDefaultColumns + * filterYesNo + * quickAction + * filterDatepicker * */ @@ -93,13 +96,13 @@ 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', @@ -107,9 +110,6 @@ public function filterDatepicker($model, $attribute) //'mode'=>'datetime', 'htmlOptions' => array( 'value' => $attrValue, - 'id' => $attribute.'_filter', - 'on_datepicker' => 'on', - 'placeholder' => Yii::t('phrase', 'filter'), ), 'options'=>array( 'showOn' => 'focus', @@ -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); + } } } diff --git a/UtilityTrait.php b/UtilityTrait.php index 02749ea..c361c89 100644 --- a/UtilityTrait.php +++ b/UtilityTrait.php @@ -13,6 +13,7 @@ * flashMessage * uniqueCode * licenseCode + * dateFormat * */ @@ -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)); + } }