Open jamespakorn opened 7 years ago
yii2 CreateCommand
$conn = \Yii::$app->db;
$sql = 'คำสั่ง sql';
$cmd = $conn->createCommand($sql);
// $cmd->bindValue(':startdate', $startdate);
// $cmd->bindValue(':enddate', $enddate);
$data = $cmd->queryAll();
composer require miloschuman/yii2-highcharts-widget
composer.json
"miloschuman/yii2-highcharts-widget": "dev-master",
สำหรับเครื่องที่ ใช้งาน yii2 ใหม่ ก่อนใช้งาน composer อื่นใน yii2 composer global require "fxp/composer-asset-plugin:^1.2.0"
use miloschuman\highcharts\Highcharts;
echo Highcharts::widget([
'options' => [
'title' => ['text' => 'Fruit Consumption'],
'xAxis' => [
'categories' => ['Apples', 'Bananas', 'Oranges']
],
'yAxis' => [
'title' => ['text' => 'Fruit eaten']
],
'series' => [
['name' => 'Jane', 'data' => [1, 0, 4]],
['name' => 'John', 'data' => [5, 7, 3]]
]
]
]);
use miloschuman\highcharts\Highcharts;
echo Highcharts::widget([
'options' => [
'chart'=> [
type=> 'column'
],
'title' => ['text' => 'Fruit Consumption'],
'xAxis' => [
'categories' => ['เขต1', 'เขต2', 'เขต3']
],
'yAxis' => [
'title' => ['text' => 'Fruit eaten']
],
'series' => [
['name' => 'ข้อมูล', 'data' => [1, 2, 4]],
]
]
]);
<?php echo Highcharts::widget([
'scripts' => [
'modules/exporting',
'themes/grid-light',
],
'options' => [
'chart'=> [
'type'=> 'column'
],
'title'=> [
'text'=> 'ตัวชีั้วัด'
],
'subtitle'=> [
//'text'=> 'ปีงบประมาณ'
],
'xAxis'=>[
'type' => 'category',
'labels' => [
'rotation' => -45,
'style' => [
'fontSize'=>'13px',
'fontFamily'=>'Verdana, sans-serif'
]
]
],
'yAxis' => [
'min' => 0,
'title' => [
// 'text' => 'ดัชนีมวลกาย'
],
'plotLines' => [[
// 'value' => (int) $kpiTemplateToYear->target_value,
'value' => 5,
'color' => 'red',
'width' => 2,
'label' => [
//'text' => 'Theoretical mean => 932',
'align' => 'center',
'style' => [
'color' => 'gray'
]
]
]]
],
'legend' => [
'enabled' => false
],
'tooltip' => [
'pointFormat' => ''
],
'series' => [
[
'name' => 'Population',
'colorByPoint' => false,
// 'color'=> '#62cb31',
'data' => [["เขต 1",70.17],["เขต 2",65.86],["เขต 3",63.42],["เขต 4",47.93],["เขต 5",63.98],["เขต 6",50.12],["เขต 7",66.1],["เขต 8",75.95],["เขต 9",63.13],["เขต 10",73.2],["เขต 11",68.18],["เขต 12",75.26]],
'dataLabels'=> [
'enabled'=> true,
'rotation'=> -90,
'color'=> 'gray',
'align'=> 'right',
'format'=> '{point.y:.2f}',
'y' => 10,
'style' => [
'fontSize' => '10px',
'fontFamily' => 'Verdana, sans-serif'
]
]
]
]
]
])?>
<table id="datatables" class="table table-striped table-hover table-bordered" cellspacing="0" width="100%">
<thead>
<tr class="warning">
<th>ลำดับ</th>
<th>รหัสหน่วย</th>
<th>กลุ่มหน่วยงาน</th>
</tr>
</thead>
<tbody>
<?php
foreach ($data as $k => $v) {
echo '<tr>';
echo '<td>'.($k+1).'</td>';
echo '<td>'.$v['hostypecode'].'</td>';
echo '<td>'.$v['hostypename'].'</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<div class="content animate-panel">
<div class="row">
<div class="col-lg-12">
<div class="hpanel">
<div class="panel-body h-200">
<!-- Code -->
</div>
<!-- <div class="panel-footer"></div> -->
</div>
</div>
</div>
</div>
public $css = [
....,
//datatables
'datatables/css/datatables.bootstrap.min.css',
'datatables/extensions/buttons/css/buttons.bootstrap.min.css',
]
public $js=[
.......,
//datatables
'js/datatables.js',
'datatables/js/jquery.datatables.min.js',
'datatables/js/datatables.bootstrap.min.js',
'datatables/extensions/buttons/js/datatables.buttons.min.js',
'datatables/extensions/buttons/js/buttons.bootstrap.min.js',
'datatables/js/pdfmake.min.js',
'datatables/js/vfs_fonts.js',
'datatables/js/jszip.min.js',
'datatables/extensions/buttons/js/buttons.html5.min.js',
'datatables/extensions/buttons/js/buttons.print.min.js',
'datatables/extensions/buttons/js/buttons.colVis.min.js',
]
<?php
$script = <<< JS
//Datatables
getDatatable('#datatables');
// getDatatableTotal('#table_total',2);
JS;
$this->registerJs($script);
?>
<?php
foreach ($data as $k => $v) {
echo '<tr>';
echo '<td>'.($k+1).'</td>';
echo '<td>'.$v['areaname'].'</td>';
echo '<td>'.number_format($v['target']).'</td>';
echo '<td>'.number_format($v['result']).'</td>';
echo '</tr>';
}
?>
use miloschuman\highcharts\Highcharts;
<?php
echo Highcharts::widget([
'scripts' => [
'modules/exporting',
'themes/grid-light',
],
'options' => [
'chart'=> [
'type'=> 'column'
],
'title'=> [
'text'=> 'ตัวชีั้วัด'
],
'subtitle'=> [
//'text'=> 'ปีงบประมาณ'
],
'xAxis'=>[
'type' => 'category',
'labels' => [
'rotation' => -45,
'style' => [
'fontSize'=>'13px',
'fontFamily'=>'Verdana, sans-serif'
]
]
],
'yAxis' => [
'min' => 0,
'title' => [
// 'text' => 'ดัชนีมวลกาย'
],
'plotLines' => [[
// 'value' => (int) $kpiTemplateToYear->target_value,
'value' => 50,
'color' => 'red',
'width' => 2,
'label' => [
//'text' => 'Theoretical mean => 932',
'align' => 'center',
'style' => [
'color' => 'gray'
]
]
]]
],
'legend' => [
'enabled' => false
],
'tooltip' => [
'pointFormat' => ''
],
'series' => [
[
'name' => 'Population',
'colorByPoint' => false,
// 'color'=> '#62cb31',
'data' => [["เขต 1",70.17],["เขต 2",65.86],["เขต 3",63.42],["เขต 4",47.93],["เขต 5",63.98],["เขต 6",50.12],["เขต 7",66.1],["เขต 8",75.95],["เขต 9",63.13],["เขต 10",73.2],["เขต 11",68.18],["เขต 12",75.26]],
'dataLabels'=> [
'enabled'=> true,
'rotation'=> -90,
'color'=> 'gray',
'align'=> 'right',
'format'=> '{point.y:.2f}',
'y' => 10,
'style' => [
'fontSize' => '10px',
'fontFamily' => 'Verdana, sans-serif'
]
]
]
]
]
]);
?>
foreach ($data as $k => $v) {
$chartData[]=[$v['areaname'],(float) $v['total_ratio']];
}
<?php
echo Highcharts::widget([
'id'=>'xxx',
'scripts' => [
'highcharts-more',
'modules/exporting',
'themes/grid-light',
],
'options' => [
'chart'=> [
'type' => 'gauge',
'plotBackgroundColor' => null,
'plotBackgroundImage' => null,
'plotBorderWidth' => 0,
'plotShadow' => false
],
'title' => 'ร้อยละ',
'pane' => [
'startAngle' => -150,
'endAngle' => 150,
'background' => [[
'backgroundColor' => [
'linearGradient' => [ x1 => 0, y1 => 0, x2 => 0, y2 => 1 ],
'stops' => [
[0, '#FFF'],
[1, '#333']
]
],
'borderWidth' => 0,
'outerRadius' => '109%'
], [
'backgroundColor' => [
'linearGradient' => [ x1 => 0, y1 => 0, x2 => 0, y2 => 1 ],
'stops' => [
[0, '#333'],
[1, '#FFF']
]
],
'borderWidth' => 1,
'outerRadius' => '107%'
], [
// default background
], [
'backgroundColor' => '#DDD',
'borderWidth' => 0,
'outerRadius' => '105%',
'innerRadius' => '103%'
]]
],
// the value axis
'yAxis'=>[
'min' => 0,
'max' => 100,
'minorTickInterval' => 'auto',
'minorTickWidth' => 1,
'minorTickLength' => 10,
'minorTickPosition' => 'inside',
'minorTickColor' => '#666',
'tickPixelInterval' => 30,
'tickWidth' => 2,
'tickPosition' => 'inside',
'tickLength' => 10,
'tickColor' => '#666',
'labels' => [
'step' => 2,
'rotation' => 'auto'
],
'title' => [
'text' => 'ร้อยละ'
],
// 'plotBands' => $plotBands
'plotBands'=> [[
'from'=> 0,
'to'=> 50,
'color'=> '#55BF3B' // green
], [
'from'=> 51,
'to'=> 80,
'color'=> '#DDDF0D' // yellow
], [
'from'=> 81,
'to'=> 100,
'color'=> '#DF5353' // red
]],
],
'tooltip' => [
'pointFormat' => 'ร้อยละ {point.y:.2f}',
'style' => [
'fontSize' => '18px',
'fontFamily' => 'Verdana, sans-serif'
]
],
'series' => [[
'name' => 'ร้อยละ',
// 'data' => [(int)$chartHdc->percentage],
'data' => [$gaugeData],
'tooltip'=> [
'valueSuffix' => ' '
],
'dataLabels'=> [
'enabled'=> true,
'color'=> 'blue',
'format'=> '{point.y:.2f}',
'style' => [
'fontSize' => '10px',
'fontFamily' => 'Verdana, sans-serif'
]
]
]]
]
])?>
Yii2 CreateCommand http://www.yiiframework.com/doc-2.0/guide-db-dao.html
//Create Connection
$conn = \Yii::$app->db;
//kpi data
$sql = 'select * from kpi_hdc k
left join kpi_template_to_year y on y.kpi_template_id=k.kpi_template_id
where k.kpi_template_id=:kpi_template_id and y.year=:year';
$cmd = $conn->createCommand($sql);
$cmd->bindValue(':kpi_template_id', $kpi_template_id);
$cmd->bindValue(':year', $year);
$q = $cmd->queryOne();
select * from kpi_hdc k
left join kpi i on i.id=k.kpi_template_id
left join kpi_template_to_year y on y.kpi_template_id=k.kpi_template_id
where k.kpi_template_id=6 and y.year="2017"
$request = \Yii::$app->request;
// echo $year = $request->get('year');
// echo $kid=$request->get('kid');
$year=$request->get('year');
$kpi_template_id=$request->get('kid');
$bYear=intval($year)+543;
-- Q1-03. ร้อยละหญิงตั้งครรภ์ที่ได้รับการดูแลก่อนคลอด 4 ครั้ง ตามเกณฑ์คุณภาพ - Trend
SELECT K.b_year,ROUND( SUM(IFNULL(K.result,0))/SUM(IFNULL(K.target,0))*100,2 ) as total_ratio
FROM s_anc4 K
INNER JOIN cchangwat C ON C.changwatcode=LEFT(K.areacode,2)
INNER JOIN cregion Z ON Z.region_code=C.regioncode
WHERE K.id = '0748a96f259f329a83206d40c47df150'
AND K.b_year BETWEEN :queryYearPrev and :queryYear
group by K.b_year
HDC SERVICE Data Dictionary (ตาราง S) DOPHDashboardDataDict-20170910.pdf
//trend
if($kpi['sql_query_trend']){
$cmd = $conn->createCommand($kpi['sql_query_trend']);
$cmd->bindValue(':queryYearPrev',$bYearPrev);
$cmd->bindValue(':queryYear',$bYear);
$trends = $cmd->queryAll();
//จัดรูปแบบ trend chart
foreach ($trends as $t) {
$trendData[]=[$t['b_year'],(float) $t['total_ratio']];
}
}
//แสดงวัน เดือน ปี แบบไทย
<?php
$_month_name = array("01"=>"มกราคม", "02"=>"กุมภาพันธ์", "03"=>"มีนาคม",
"04"=>"เมษายน", "05"=>"พฤษภาคม", "06"=>"มิถุนายน",
"07"=>"กรกฎาคม", "08"=>"สิงหาคม", "09"=>"กันยายน",
"10"=>"ตุลาคม", "11"=>"พฤศจิกายน", "12"=>"ธันวาคม");
$vardate=date('Y-m-d'); $yy=date('Y'); $mm =date('m');$dd=date('d'); if ($dd<10){ $dd=substr($dd,1,2); } $date=$dd ." ".$_month_name[$mm]." ".$yy+= 543; echo 'วันที่ประมวลผล :: '.$date; ?>
<?php
$this->title = 'ระบบบันทึกข้อมูลตัวชี้วัดตัวชีัวัดสิ่งแวดล้อม';
?>
<?=$this->render('//_header')?>
<div class="content animate-panel">
<div class="row">
<div class="col-lg-12">
<div class="hpanel">
<div class="panel-body h-200">
<!-- Code -->
</div>
<!-- <div class="panel-footer"></div> -->
</div>
</div>
</div>
</div>
public static function GetList() {
return yii\helpers\ArrayHelper::map(self::find()->all(), 'changwatcode', 'changwatname');
}
use kartik\select2\Select2;
<?php
echo $form->field($model, 'year_id')->widget(Select2::classname(), [
'data' => KpiFiscalYear::GetList(),
'options' => ['placeholder' => 'กรุณาเลือก...'],
'pluginOptions' => [
'allowClear' => true,
],
]);
?>
"2amigos/yii2-ckeditor-widget": "~1.0"
composer global require "fxp/composer-asset-plugin:^1.2.0"
On running composer update on my Yii2 projects, Composer now reports The "extra.asset-installer-paths" option is deprecated, use the "config.fxp-asset.installer-paths" option.
So should the default composer.json be updated to reflect this?
This modification produces correct results for me...
"config": {
"fxp-asset": {
"installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
},
"process-timeout": 1800
},
"extra": {
},
<?php
echo $form->field($model, 'comment')->widget(\dosamigos\ckeditor\CKEditor::className(), [
'clientOptions' => ['height' => 200],
'preset' => 'advance',
])
?>
<table id="datatables" class="table table-striped table-hover table-bordered" width="100%">
<thead>
<tr class="info">
<th></th>
<th>ลำดับ</th>
<th>จังหวัด</th>
<th>ปี</th>
<th>ไตรมาส</th>
<th>เป้าหมาย(แห่ง)</th>
<th>ประเด็นมีการพัฒนาระบบ
ฐานข้อมูล สถานการณ์
และการเฝ้าระวังด้าน
สิ่งแวดล้อมและสุขภาพ</th>
<th>ประเด็นมีกลไกการจัดการ
ปัจจัยเสี่ยงจากมลพิษ
สิ่งแวดล้อมอย่างบูรณาการ
โดยขับเคลื่อน
การดำเนินงานผ่านกลไก
คณะกรรมการสาธารณสุข
จังหวัด (คสจ.)</th>
<th>ประเด็นมีระบบและกลไก
สนับสนุนการจัดการมูล
ฝอยติดเชื้อของ
โรงพยาบาล รพศ./รพท./
รพช. สังกัดกระทรวง
สาธารณสุขให้ถูกต้อง
ตามกฎหมาย</th>
<th>ประเด็นมีการส่งเสริมให้
ท้องถิ่นมีการจัดบริการ
อนามัยสิ่งแวดล้อมที่ได้
มาตรฐาน (EHA)</th>
<th>ประเด็นมีการดำเนินงาน
เพื่อส่งเสริมสนับสนุน
ให้เกิดตำบลที่มีชุมชน
เข้มแข็ง ด้านอนามัย
สิ่งแวดล้อม</th>
<th>ประเด็นมีการจัดระบบ
เฝ้าระวังสุขภาพจากการ
ประกอบอาชีพและมลพิษ
สิ่งแวดล้อม</th>
<th>สรุปผลการดำาเนินงาน</th>
<th>ไฟล์แนบ</th>
</tr>
</thead>
<!-- <tfoot>
<tr>
<th></th>
<th>รวมทั้งหมด</th>
<th></th>
</tr>
</tfoot>-->
<tbody>
<?php
foreach ($data as $key => $item) {
echo '<tr>';
echo '<td>';
echo Html::a('<i class="fa fa-eye fa-lg text-info"></i>', ['kpienvenvriskmng/view', 'id' => $item['id']]) . ' ';
echo Html::a('<i class="fa fa-pencil-square-o fa-lg text-primary"></i>', ['kpienvenvriskmng/update', 'id' => $item['id']]) . ' ';
echo Html::a('<i class="fa fa-trash fa-lg text-danger"></i>', ['kpienvenvriskmng/delete', 'id' => $item['id']], ['data-method' => "post", 'data-confirm' => "ยืนยันการลบ?"]);
echo '</td>';
echo '<td>' . ($key + 1) . '</td>';
echo '<td>' . $item['changwatname'] . '</td>';
echo '<td>' . $item['year_buddhism'] . '</td>';
echo '<td>' . $item['quater_id'] . '</td>';
echo '<td>' . $item['target'] . '</td>';
echo '<td>' . $item['result1'] . '</td>';
echo '<td>' . $item['result2'] . '</td>';
echo '<td>' . $item['result3'] . '</td>';
echo '<td>' . $item['result4'] . '</td>';
echo '<td>' . $item['result5'] . '</td>';
echo '<td>' . $item['result6'] . '</td>';
echo '<td>' . $item['conclude_result'] . '</td>';
if ($item['file_attachment']) {
echo '<td>' . Html::a('<i class="fa fa-file-text-o text-warning" aria-hidden="true"></i> ', Yii::getAlias('@web') . '/uploads/' . $item['file_attachment']) . '</td>';
} else {
echo '<td></td>';
}
// echo '<td>' . Yii::$app->thaidate->ShortDate($item['book_date']) . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
public function actionIndex()
{
// $searchModel = new KpiEnvEnvriskmngSearch();
// $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$conn = Yii::$app->db;
$sql = 'select e.*,c.changwatname,f.`year`,f.year_buddhism
from kpi_env_envriskmng e
inner join cchangwat c on c.changwatcode=e.areacode
left join kpi_fiscal_year f on f.`year`=e.year_id';
$cmd = $conn->createCommand($sql);
$data =$cmd->queryAll();
return $this->render('index', [
'data'=>$data
// 'searchModel' => $searchModel,
// 'dataProvider' => $dataProvider,
]);
}
<?php
$script = <<< JS
//Datatables
getDatatable('#datatables');
// getDatatableSum('#datatables',2,3);
JS;
$this->registerJs($script);
?>
use kartik\widgets\FileInput;
<?php
echo $form->field($modelfile, 'file')->widget(FileInput::classname(), [
'options' => [
//'multiple' => true
],
'pluginOptions' => [
'initialPreview' => [],
// 'allowedFileExtensions' => ['pdf','doc','docx','xls','xlsx','zip','rar'],
'showPreview' => true,
'showCaption' => true,
'showRemove' => true,
'showUpload' => false,
],
]);
?>
use yii\web\UploadedFile;
//upload file
$modelfile->file = UploadedFile::getInstance($modelfile, 'file');
if ($modelfile->file) {
if ($modelfile->file->saveAs('uploads/files_' . $model->id . '.' . $modelfile->file->extension)) {
$model->file_attachment = 'files_' . $model->id . '.' . $modelfile->file->extension;
$model->save();
}
}
## view form
<div class="form-group">
<?php
echo $model->file_attachment != null ? Html::a('<i class="fa fa-file-text-o fa-lg text-warning" aria-hidden="true"> ไฟล์แนบ</i> ', Yii::getAlias('@web') . '/uploads/' . $model->file_attachment) : '';
?>
<hr>
</div>
public function actionDelete($id)
{
$model = $this->findModel($id);
// $filepath = Yii::getAlias('@web') .'/uploads/' . $model->file_attachment;
$filepath ='uploads/' . $model->file_attachment;
if (file_exists($filepath)) {
unlink($filepath);
$this->findModel($id)->delete();
}
return $this->redirect(['index']);
}
<?php
if (Yii::$app->session->hasFlash('Save')) {
echo kartik\widgets\Alert::widget([
'type' => Alert::TYPE_SUCCESS,
'icon' => 'glyphicon glyphicon-info-sign',
'title' => 'สถานะการบันทึกข้อมูล!',
'titleOptions' => ['icon' => 'info-sign'],
'body' => Yii::$app->session->getFlash('Save'),
'showSeparator' => true,
'delay' => 3000,
]);
}
?>
DOH Dashboard ChiangMai Installation
XAMPP(apache(web server)+php+mysql) >> https://www.apachefriends.org/index.html
composer >> https://getcomposer.org/
git >> https://git-scm.com/
Visual Studio Code >> https://code.visualstudio.com/
Java 8 sdk >> http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Netbeans 8.2 Full >> https://netbeans.org/downloads/
Sign up Account Github >> https://github.com/
Download zip Yii2 Basic Template >> https://github.com/yiisoft/yii2/releases/download/2.0.12/yii-basic-app-2.0.12.tgz
Download zip Yii2 Advanced Template >> https://github.com/yiisoft/yii2/releases/download/2.0.12/yii-advanced-app-2.0.12.tgz
Navicat Premium 11 >> Private