| Current Path : /var/www/html/dosm/backend/controllers/ |
| Current File : /var/www/html/dosm/backend/controllers/ContentNsdpController.php |
<?php
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use backend\models\ContentNsdp;
use backend\models\ContentNsdpSearch;
use backend\models\ContentNsdpcategory;
use backend\models\ContentNsdpcategorySearch;
use backend\models\ContentNsdpsubcategory;
use backend\models\ContentNsdpsubcategorySearch;
use kartik\mpdf\Pdf;
use yii\filters\AccessControl;
error_reporting(0);
class ContentNsdpController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all ContentPhotoGallery models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ContentNsdpSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
]);
}
public function actionCreate()
{
$model = new ContentNsdp();
$model->created_at = date("Y-m-d H:i:s");
$model->created_by = Yii::$app->user->identity->id;
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = Yii::$app->user->identity->id;
if ($model->load(Yii::$app->request->post())) {
// $model->image_main = UploadedFile::getInstance($model, 'image_main');
// if (!empty($model->image_main)) {
// $image_main = 'images/icon/contentNsdpimage_' . date("YmdHis") . '.' . $model->image_main->extension;
// if ($model->image_main->saveAs($image_main))
// $model->image_main = $image_main;
// }
if ($model->save())
return $this->redirect(['index']);
}
return $this->render('create', ['model' => $model,]);
}
public function actionUpdate($id)
{
$model = $this->findModel($id);
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = Yii::$app->user->identity->id;
// $image_main = $model->image_main;
if ($model->load(Yii::$app->request->post())) {
// $model->image_main = UploadedFile::getInstance($model, 'image_main');
// if (!empty($model->image_main)) {
// $image_main = 'images/icon/contentNsdpimage_' . date("YmdHis") . '.' . $model->image_main->extension;
// if ($model->image_main->saveAs($image_main))
// $model->image_main = $image_main;
// } else {
// $model->image_main = $image_main;
// }
if ($model->save()) {
return $this->redirect(['index']);
}
}
return $this->render('update', [
'model' => $model,
]);
}
public function actionDelete($id)
{
$model = $this->findModel($id);
$model->delete();
return $this->redirect(['index']);
}
public function actionAddcategory($id)
{
$searchModel = new ContentNsdpcategorySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams, $id);
return $this->render('addcategory', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
]);
}
public function actionCreate_category($id)
{
$model = new ContentNsdpcategory();
// $model->created_at = date("Y-m-d H:i:s");
// $model->created_by = Yii::$app->user->identity->id;
// $model->updated_at = date("Y-m-d H:i:s");
// $model->updated_by = Yii::$app->user->identity->id;
if ($model->load(Yii::$app->request->post())) {
if (isset($_POST['new_themes_translation_no']) && !empty($_POST['new_themes_translation_no'])) {
foreach ($_POST['new_themes_translation_no'] as $new_themes_translation_no) {
$modelAddTranslation = new ContentNsdpcategory();
$modelAddTranslation->data_category = $_POST['ContentNsdpcategory']['data_category'];
$modelAddTranslation->unit_description = $_POST['unit_description_' . $new_themes_translation_no];
$modelAddTranslation->period_of_latest = $_POST['period_of_latest_' . $new_themes_translation_no];
$modelAddTranslation->latest_data = $_POST['latest_data_' . $new_themes_translation_no];
$modelAddTranslation->data_for_previous_period = $_POST['data_for_previous_period_' . $new_themes_translation_no];
$modelAddTranslation->dsbb = $_POST['dsbb_' . $new_themes_translation_no];
$modelAddTranslation->new_label = $_POST['new_label_' . $new_themes_translation_no];
$modelAddTranslation->publish_date_start = $_POST['ContentNsdpcategory']['publish_date_start'];
$modelAddTranslation->publish_time_start = $_POST['ContentNsdpcategory']['publish_time_start'];
$modelAddTranslation->publish_date_end = $_POST['ContentNsdpcategory']['publish_date_end'];
$modelAddTranslation->publish_time_end = $_POST['ContentNsdpcategory']['publish_time_end'];
$modelAddTranslation->created_at = date("Y-m-d H:i:s");
$modelAddTranslation->created_by = Yii::$app->user->identity->id;
$modelAddTranslation->updated_at = date("Y-m-d H:i:s");
$modelAddTranslation->updated_by = Yii::$app->user->identity->id;
$modelAddTranslation->nsdp_id = $id;
$modelAddTranslation->sorting = 0;
$modelAddTranslation->save(false);
}
}
// if ($model->save())
return $this->redirect(['addcategory?id=' . $id]);
}
return $this->render('create_category', ['model' => $model,]);
}
public function actionUpdate_category($id)
{
$model = ContentNsdpcategory::find()->where(['content_nsdp_categories_id' => $id])->one();
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = Yii::$app->user->identity->id;
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
return $this->redirect(['addcategory?id=' . $model->nsdp_id]);
}
}
return $this->render('update_category', [
'model' => $model,
]);
}
public function actionDelete_category($id)
{
$model = ContentNsdpcategory::find()->where(['content_nsdp_categories_id' => $id])->one();
$model->delete();
return $this->redirect(['addcategory?id=' . $model->nsdp_id]);
}
protected function findModel($id)
{
if (($model = ContentNsdp::findOne($id)) !== null) {
return $model;
}
}
public function actionAdd_subcategory($id)
{
$searchModel = new ContentNsdpsubcategorySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams, $id);
return $this->render('add_subcategory', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
]);
}
public function actionCreate_sub_category($id)
{
$model = new ContentNsdpsubcategory();
// $model->created_at = date("Y-m-d H:i:s");
// $model->created_by = Yii::$app->user->identity->id;
// $model->updated_at = date("Y-m-d H:i:s");
// $model->updated_by = Yii::$app->user->identity->id;
// $model->content_nsdp_categories_id = $id;
if ($model->load(Yii::$app->request->post())) {
// $model->image_sub_category = UploadedFile::getInstance($model, 'image_sub_category');
// if (!empty($model->image_sub_category)) {
// $image_sub_category = 'images/icon/contentNsdp_' . date("YmdHis") . '.' . $model->image_sub_category->extension;
// if ($model->image_sub_category->saveAs($image_sub_category))
// $model->image_sub_category = $image_sub_category;
// }
// if ($model->save())
if (isset($_POST['new_themes_translation_no']) && !empty($_POST['new_themes_translation_no'])) {
foreach ($_POST['new_themes_translation_no'] as $new_themes_translation_no) {
$modelAddTranslation = new ContentNsdpsubcategory();
$modelAddTranslation->data_category = $_POST['ContentNsdpsubcategory']['data_category'];
$modelAddTranslation->unit_description = $_POST['unit_description_' . $new_themes_translation_no];
$modelAddTranslation->period_of_latest = $_POST['period_of_latest_' . $new_themes_translation_no];
$modelAddTranslation->latest_data = $_POST['latest_data_' . $new_themes_translation_no];
$modelAddTranslation->data_for_previous_period = $_POST['data_for_previous_period_' . $new_themes_translation_no];
$modelAddTranslation->new_label = $_POST['new_label_' . $new_themes_translation_no];
$modelAddTranslation->publish_date_start = $_POST['ContentNsdpsubcategory']['publish_date_start'];
$modelAddTranslation->publish_time_start = $_POST['ContentNsdpsubcategory']['publish_time_start'];
$modelAddTranslation->publish_date_end = $_POST['ContentNsdpsubcategory']['publish_date_end'];
$modelAddTranslation->publish_time_end = $_POST['ContentNsdpsubcategory']['publish_time_end'];
$modelAddTranslation->created_at = date("Y-m-d H:i:s");
$modelAddTranslation->created_by = Yii::$app->user->identity->id;
$modelAddTranslation->updated_at = date("Y-m-d H:i:s");
$modelAddTranslation->updated_by = Yii::$app->user->identity->id;
$modelAddTranslation->content_nsdp_categories_id = $id;
$modelAddTranslation->save(false);
}
}
return $this->redirect(['add_subcategory?id=' . $id]);
}
return $this->render('create_sub_category', ['model' => $model,]);
}
public function actionUpdate_sub_category($id)
{
$model = ContentNsdpsubcategory::find()->where(['content_nsdp_sub_categories_id' => $id])->one();
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = Yii::$app->user->identity->id;
$image_sub_category = $model->image_sub_category;
if ($model->load(Yii::$app->request->post())) {
// $model->image_sub_category = UploadedFile::getInstance($model, 'image_sub_category');
// if (!empty($model->image_sub_category)) {
// $image_sub_category = 'images/icon/contentNsdp_' . date("YmdHis") . '.' . $model->image_sub_category->extension;
// if ($model->image_sub_category->saveAs($image_sub_category))
// $model->image_sub_category = $image_sub_category;
// } else {
// $model->image_sub_category = $image_sub_category;
// }
if ($model->save()) {
return $this->redirect(['add_subcategory?id=' . $model->content_nsdp_categories_id]);
}
}
return $this->render('update_sub_category', [
'model' => $model,
]);
}
public function actionDelete_sub_category($id)
{
$model = ContentNsdpsubcategory::find()->where(['content_nsdp_sub_categories_id' => $id])->one();
$model->delete();
return $this->redirect(['add_subcategory?id=' . $model->content_nsdp_categories_id]);
}
public function actionExport_excel($id)
{
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=nsdp.xls");
$output = '';
$output .= '
<table width="100%"><tr><td style="text-align:center;"><img src="https://www.dosm.gov.my/assets/img/logo-dosm-English.png" height="150"></td></tr></table>
<br><br><br><br><br><br><br>
<table class="table table-bordered table-lg" id="nsdpdata" cellpadding="5" cellspacing="0">
<tbody>
<tr class="table-active">
<th style="border: 1px solid black; background:#15818d; color:white;" class="text-center" rowspan="2" width="43%">SDDS Data Category and Component</th>
<th style="border: 1px solid black; background:#15818d; color:white;" class="text-center" rowspan="2" width="9%">Unit Description</th>
<th style="border: 1px solid black; background:#15818d; color:white;" class="text-center" colspan="3" width="45%">Observations</th>
</tr>
<tr class="table-active">
<th style="border: 1px solid black;background:#15818d;color:white;" class="text-center">Period of latest</th>
<th style="border: 1px solid black;background:#15818d;color:white;" class="text-center">Latest data</th>
<th style="border: 1px solid black;background:#15818d;color:white;" class="text-center">Data for previous period</th>
</tr>
';
$sql = "SELECT * FROM content_nsdp_categories WHERE nsdp_id=" . $id . " ORDER BY updated_at DESC";
$categories = Yii::$app->db->createCommand($sql)->queryAll();
foreach ($categories as $ct) {
$start = date('Y-m-d H:i:s', strtotime($ct['publish_date_start'] . " " . $ct['publish_time_start'] . ":00"));
$end = date('Y-m-d H:i:s', strtotime($ct['publish_date_end'] . " " . $ct['publish_time_end'] . ":00"));
$today = date('Y-m-d H:i:s');
if ($today >= $start && $today <= $end) {
$output .= '<tr>';
$output .= '
<td class="text-left" width="43%" style="border:1px solid black;">
';
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $ct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$output .= '
<b style="color:black">' . $refCat['descr_en'] . '</b>
</td>
';
$output .= '
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $ct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['data_for_previous_period'] . '</td>
';
// if ($ct['dsbb'] == 1) {
// $output .= '
// <a href="https://dsbb.imf.org/" class="btn btn-warning">DSBB</a></p></td>
// ';
// }
$output .= '</tr>';
} else if ($start >= $today) {
$output .= '<tr>';
$output .= '
<td style="border:1px solid black" class="text-left" width="43%">
';
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $ct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$output .= '
<b style="color:black">' . $refCat['descr_en'] . '</b>
</td>
';
$output .= '
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $ct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['data_for_previous_period'] . '</td>
';
// if ($ct['dsbb'] == 1) {
// $output .= '
// <a href="https://dsbb.imf.org/" class="btn btn-warning">DSBB</a></p></td>
// ';
// }
$output .= '</tr>';
}
if ($ct['publish_date_start'] == "" && $ct['publish_date_end'] == "") {
$output .= '<tr>';
$output .= '
<td style="border:1px solid black" class="text-left" width="43%">
';
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $ct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$output .= '
<b style="color:black">' . $refCat['descr_en'] . '</b></td>
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $ct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['data_for_previous_period'] . '</td>
';
// if ($ct['dsbb'] == 1) {
// $output .= '
// <a href="https://dsbb.imf.org/" class="btn btn-warning">DSBB</a>
// </p></td>
// ';
// }
$output .= '</tr>';
}
$sql = "SELECT * FROM content_nsdp_sub_categories WHERE content_nsdp_categories_id=" . $ct['content_nsdp_categories_id'] . " ORDER BY updated_at DESC";
$subcategories = Yii::$app->db->createCommand($sql)->queryAll();
foreach ($subcategories as $sct) {
$start = date('Y-m-d H:i:s', strtotime($sct['publish_date_start'] . " " . $sct['publish_time_start'] . ":00"));
$end = date('Y-m-d H:i:s', strtotime($sct['publish_date_end'] . " " . $sct['publish_time_end'] . ":00"));
$today = date('Y-m-d H:i:s');
if ($today >= $start && $today <= $end) {
$output .= '
<tr id="child" style="text-indent:15px">
<td style="border:1px solid black; padding-left:20px" width="43%" class="text-left">
';
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $sct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$output .= '
<p>' . $refCat['descr_en'] . '</p></td>
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $sct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['data_for_previous_period'] . '</td>
</tr>
';
} else if ($start >= $today) {
$output .= '
<tr id="child" style="text-indent:15px">
<td style="border:1px solid black;padding-left:20px" width="43%" class="text-left">
';
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $sct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$output .= '
<p>' . $refCat['descr_en'] . '</p></td>
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $sct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['data_for_previous_period'] . '</td>
</tr>
';
}
if ($sct['publish_date_start'] == "" && $sct['publish_date_end'] == "") {
$output .= '
<tr id="child" style="text-indent:15px">
<td style="border:1px solid black;padding-left:20px" width="43%" class="text-left">
';
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $sct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$output .= '
<p>' . $refCat['descr_en'] . '</p></td>
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $sct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['data_for_previous_period'] . '</td>
</tr>
';
}
}
}
$output .= '
</tbody>
</table>
<br>
<table width="100%">
<tr>
<td style="text-align:center;">
Copyright©' . date('Y') . '<br>
Department of Statistics Malaysia Official Portal.<br>
All rights reserved.
</td>
</tr>
</table>
';
echo $output;
exit;
}
public function actionExport_pdf($id)
{
$mpdf = new \Mpdf\Mpdf(['allow_html_optional_endtags' => true, 'orientation' => Pdf::ORIENT_LANDSCAPE, 'default_font' => 'arial']);
$mpdf->WriteHTML('
<table width="100%"><tr><td style="text-align:center;"><img src="/assets/img/article/JATA-Eng.png" height="150"></td></tr></table>
<table class="table table-bordered table-lg" id="nsdpdata" cellpadding="5" cellspacing="0">
<tbody>
<tr class="table-active">
<th style="border: 1px solid black; background:#15818d; color:white;" class="text-center" rowspan="2" width="43%">SDDS Data Category and Component</th>
<th style="border: 1px solid black; background:#15818d; color:white;" class="text-center" rowspan="2" width="9%">Unit Description</th>
<th style="border: 1px solid black; background:#15818d; color:white;" class="text-center" colspan="3" width="45%">Observations</th>
</tr>
<tr class="table-active">
<th style="border: 1px solid black;background:#15818d;color:white;" class="text-center">Period of latest</th>
<th style="border: 1px solid black;background:#15818d;color:white;" class="text-center">Latest data</th>
<th style="border: 1px solid black;background:#15818d;color:white;" class="text-center">Data for previous period</th>
</tr>
');
$sql = "SELECT * FROM content_nsdp_categories WHERE nsdp_id=" . $id . " ORDER BY sorting ASC";
$categories = Yii::$app->db->createCommand($sql)->queryAll();
foreach ($categories as $ct) {
$start = date('Y-m-d H:i:s', strtotime($ct['publish_date_start'] . " " . $ct['publish_time_start'] . ":00"));
$end = date('Y-m-d H:i:s', strtotime($ct['publish_date_end'] . " " . $ct['publish_time_end'] . ":00"));
$today = date('Y-m-d H:i:s');
if ($today >= $start && $today <= $end) {
$mpdf->WriteHTML('<tr>');
$mpdf->WriteHTML('<td class="text-left" width="43%" style="border:1px solid black;">');
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $ct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$mpdf->WriteHTML('<b style="color:black">' . $refCat['descr_en'] . '</b></td>');
$mpdf->WriteHTML('
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $ct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['data_for_previous_period'] . '</td>
');
//if ($ct['dsbb'] == 1) {
// $mpdf->WriteHTML('<a href="https://dsbb.imf.org/" class="btn btn-warning">DSBB</a></p></td>');
//}
$mpdf->WriteHTML('</tr>');
} else if ($start >= $today) {
$mpdf->WriteHTML('<tr>');
$mpdf->WriteHTML('<td style="border:1px solid black" class="text-left" width="43%">');
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $ct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$mpdf->WriteHTML('<b style="color:black">' . $refCat['descr_en'] . '</b></td>');
$mpdf->WriteHTML('
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $ct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['data_for_previous_period'] . '</td>
');
//if ($ct['dsbb'] == 1) {
// $mpdf->WriteHTML('<a href="https://dsbb.imf.org/" class="btn btn-warning">DSBB</a></p></td>');
//}
$mpdf->WriteHTML('</tr>');
}
if ($ct['publish_date_start'] == "" && $ct['publish_date_end'] == "") {
$mpdf->WriteHTML('<tr>');
$mpdf->WriteHTML('<td style="border:1px solid black" class="text-left" width="43%">');
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $ct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$mpdf->WriteHTML('
<b style="color:black">' . $refCat['descr_en'] . '</b></td>
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $ct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $ct['data_for_previous_period'] . '</td>
');
//if ($ct['dsbb'] == 1) {
// $mpdf->WriteHTML('
// <a href="https://dsbb.imf.org/" class="btn btn-warning">DSBB</a></p></td></tr>
// ');
//}
}
$sql = "SELECT * FROM content_nsdp_sub_categories WHERE content_nsdp_categories_id=" . $ct['content_nsdp_categories_id'] . " ORDER BY updated_at DESC";
$subcategories = Yii::$app->db->createCommand($sql)->queryAll();
foreach ($subcategories as $sct) {
$start = date('Y-m-d H:i:s', strtotime($sct['publish_date_start'] . " " . $sct['publish_time_start'] . ":00"));
$end = date('Y-m-d H:i:s', strtotime($sct['publish_date_end'] . " " . $sct['publish_time_end'] . ":00"));
$today = date('Y-m-d H:i:s');
if ($today >= $start && $today <= $end) {
$mpdf->WriteHTML('
<tr id="child" style="text-indent:15px">
<td style="border:1px solid black; padding-left:20px" width="43%" class="text-left">
');
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $sct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$mpdf->WriteHTML('
<p>' . $refCat['descr_en'] . '</p></td>
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $sct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['data_for_previous_period'] . '</td>
</tr>
');
} else if ($start >= $today) {
$mpdf->WriteHTML('<tr id="child" style="text-indent:15px">
<td style="border:1px solid black;padding-left:20px" width="43%" class="text-left">');
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $sct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$mpdf->WriteHTML('
<p>' . $refCat['descr_en'] . '</p></td>
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $sct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['data_for_previous_period'] . '</td>
</tr>
');
}
if ($sct['publish_date_start'] == "" && $sct['publish_date_end'] == "") {
$mpdf->WriteHTML('<tr id="child" style="text-indent:15px">
<td style="border:1px solid black;padding-left:20px" width="43%" class="text-left">');
$refCat = "SELECT * FROM ref WHERE cat = 'NSDPCAT' AND code=" . $sct['data_category'];
$refCat = Yii::$app->db->createCommand($refCat)->queryOne();
$mpdf->WriteHTML('
<p>' . $refCat['descr_en'] . '</p></td>
<td style="border:1px solid black; text-align:center" class="text-right" width="9%">' . $sct['unit_description'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['period_of_latest'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['latest_data'] . '</td>
<td style="border:1px solid black; text-align:center" class="text-center" width="10%">' . $sct['data_for_previous_period'] . '</td>
</tr>
');
}
}
}
$mpdf->WriteHTML('
</tbody>
</table>
<br>
<table width="100%">
<tr>
<td style="text-align:center;">
Copyright©' . date('Y') . '<br>
Department of Statistics Malaysia Official Portal.<br>
All rights reserved.
</td>
</tr>
</table>
');
$mpdf->Output();
}
public function actionSorting($data = '')
{
$count = 0;
$data_arr = explode(',', $data);
if (!empty($data_arr)) {
foreach ($data_arr as $slider_id) {
$model = ContentNsdpcategory::findOne($slider_id);
if (!empty($model)) {
$count++;
$model->sorting = $count;
$model->save(false);
}
}
}
return $data;
}
public function actionAddnewtranslation($count)
{
$language_arr = ArrayHelper::map((new \yii\db\Query())->from('ref')->where(['=', 'cat', 'CONTENT_LANGUAGE'])->orderBy(['descr' => SORT_ASC])->all(), 'code', 'descr');
return '<div class="row" style="margin-top:1em;" id="new_translation_wrapper_' . $count . '">
' . Html::input('hidden', 'new_themes_translation_no[]', $count) . '
<div class="col-sm-4">' . Html::input('text', 'unit_description_' . $count, '', $options = ['class' => 'form-control', 'placeholder' => 'Unit Description']) . '</div>
<div class="col-sm-4">' . Html::input('text', 'period_of_latest_' . $count, '', $options = ['class' => 'form-control', 'placeholder' => 'Period of latest']) . '</div>
<div class="col-sm-4">' . Html::input('text', 'latest_data_' . $count, '', $options = ['class' => 'form-control', 'placeholder' => 'Latest data']) . '</div>
<div class="col-sm-4">' . Html::input('text', 'data_for_previous_period_' . $count, '', $options = ['class' => 'form-control', 'placeholder' => 'Data for previous period']) . '</div>
<div class="col-sm-4">' . Html::dropDownList('dsbb_' . $count, null, ['1' => 'YES', '2' => 'NO'], ['class' => 'form-control', 'prompt' => '-- Please choose dsbb--']) . '</div>
<div class="col-sm-4">' . Html::dropDownList('new_label_' . $count, null, ['1' => 'YES', '2' => 'NO'], ['class' => 'form-control', 'prompt' => '-- Please choose new label --']) . '</div>
<div class="col-sm-1"><br><br>' . Html::button('Delete', ['class' => 'btn btn-danger btn-block', 'onclick' => 'deletenewtranslation(' . $count . ')']) . '</div>
</div>';
}
public function actionDeletetranslation($id)
{
if (($model = ContentNsdpcategory::findOne($id)) !== null) {
$model->delete();
}
}
public function actionAddnewtranslation1($count)
{
$language_arr = ArrayHelper::map((new \yii\db\Query())->from('ref')->where(['=', 'cat', 'CONTENT_LANGUAGE'])->orderBy(['descr' => SORT_ASC])->all(), 'code', 'descr');
return '<div class="row" style="margin-top:1em;" id="new_translation_wrapper_' . $count . '">
' . Html::input('hidden', 'new_themes_translation_no[]', $count) . '
<div class="col-sm-4">' . Html::input('text', 'unit_description_' . $count, '', $options = ['class' => 'form-control', 'placeholder' => 'Unit Description']) . '</div>
<div class="col-sm-4">' . Html::input('text', 'period_of_latest_' . $count, '', $options = ['class' => 'form-control', 'placeholder' => 'Period of latest']) . '</div>
<div class="col-sm-4">' . Html::input('text', 'latest_data_' . $count, '', $options = ['class' => 'form-control', 'placeholder' => 'Latest data']) . '</div>
<div class="col-sm-4">' . Html::input('text', 'data_for_previous_period_' . $count, '', $options = ['class' => 'form-control', 'placeholder' => 'Data for previous period']) . '</div>
<div class="col-sm-4">' . Html::dropDownList('new_label_' . $count, null, ['1' => 'YES', '2' => 'NO'], ['class' => 'form-control', 'prompt' => '-- Please choose new label --']) . '</div>
<div class="col-sm-1"><br><br>' . Html::button('Delete', ['class' => 'btn btn-danger btn-block', 'onclick' => 'deletenewtranslation(' . $count . ')', 'style' => 'margin-left: -959px']) . '</div>
</div>';
}
public function actionDeletetranslation1($id)
{
if (($model = ContentNsdpsubcategory::findOne($id)) !== null) {
$model->delete();
}
}
public function actionUpdate_multiple_data($id)
{
$searchModel = new ContentNsdpcategorySearch();
$dataProvider = $searchModel->search1(Yii::$app->request->queryParams, $id);
return $this->render('update_multiple_data', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
]);
}
public function actionUpdate_category_multiple_page($nsdp_id, $data_category)
{
$checking = ContentNsdpcategory::find()->where(['nsdp_id' => $nsdp_id, 'data_category' => $data_category])->all();
$model = ContentNsdpcategory::find()->where(['nsdp_id' => $nsdp_id, 'data_category' => $data_category])->one();
return $this->render('update_category_multiple_page', [
'checking' => $checking,
'model' => $model
]);
}
public function actionUpdate_category_multiple_page1($nsdp_id, $data_category)
{
if (isset($_POST['new_themes_translation_no']) && !empty($_POST['new_themes_translation_no'])) {
foreach ($_POST['new_themes_translation_no'] as $new_themes_translation_no) {
$modelAddTranslation = new ContentNsdpcategory();
$modelAddTranslation->data_category = $_POST['ContentNsdpcategory']['data_category'];
$modelAddTranslation->unit_description = $_POST['unit_description_' . $new_themes_translation_no];
$modelAddTranslation->period_of_latest = $_POST['period_of_latest_' . $new_themes_translation_no];
$modelAddTranslation->latest_data = $_POST['latest_data_' . $new_themes_translation_no];
$modelAddTranslation->data_for_previous_period = $_POST['data_for_previous_period_' . $new_themes_translation_no];
$modelAddTranslation->dsbb = $_POST['dsbb_' . $new_themes_translation_no];
$modelAddTranslation->new_label = $_POST['new_label_' . $new_themes_translation_no];
$modelAddTranslation->publish_date_start = $_POST['ContentNsdpcategory']['publish_date_start'];
$modelAddTranslation->publish_time_start = $_POST['ContentNsdpcategory']['publish_time_start'];
$modelAddTranslation->publish_date_end = $_POST['ContentNsdpcategory']['publish_date_end'];
$modelAddTranslation->publish_time_end = $_POST['ContentNsdpcategory']['publish_time_end'];
$modelAddTranslation->created_at = date("Y-m-d H:i:s");
$modelAddTranslation->created_by = Yii::$app->user->identity->id;
$modelAddTranslation->updated_at = date("Y-m-d H:i:s");
$modelAddTranslation->updated_by = Yii::$app->user->identity->id;
$modelAddTranslation->nsdp_id = $nsdp_id;
$modelAddTranslation->sorting = 0;
$modelAddTranslation->save(false);
}
}
if (isset($_POST['old_themes_translation_no']) && !empty($_POST['old_themes_translation_no'])) {
foreach ($_POST['old_themes_translation_no'] as $old_themes_translation_no) {
if (($modelUpdateTranslation = ContentNsdpcategory::findOne($old_themes_translation_no)) !== null) {
$modelUpdateTranslation->data_category = $_POST['ContentNsdpcategory']['data_category'];
$modelUpdateTranslation->unit_description = $_POST['old_unit_description_' . $old_themes_translation_no];
$modelUpdateTranslation->period_of_latest = $_POST['old_period_of_latest_' . $old_themes_translation_no];
$modelUpdateTranslation->latest_data = $_POST['old_latest_data_' . $old_themes_translation_no];
$modelUpdateTranslation->data_for_previous_period = $_POST['old_data_for_previous_period_' . $old_themes_translation_no];
$modelUpdateTranslation->dsbb = $_POST['old_dsbb_' . $old_themes_translation_no];
$modelUpdateTranslation->new_label = $_POST['old_new_label_' . $old_themes_translation_no];
$modelUpdateTranslation->publish_date_start = $_POST['ContentNsdpcategory']['publish_date_start'];
$modelUpdateTranslation->publish_time_start = $_POST['ContentNsdpcategory']['publish_time_start'];
$modelUpdateTranslation->publish_date_end = $_POST['ContentNsdpcategory']['publish_date_end'];
$modelUpdateTranslation->publish_time_end = $_POST['ContentNsdpcategory']['publish_time_end'];
$modelUpdateTranslation->created_at = date("Y-m-d H:i:s");
$modelUpdateTranslation->created_by = Yii::$app->user->identity->id;
$modelUpdateTranslation->updated_at = date("Y-m-d H:i:s");
$modelUpdateTranslation->updated_by = Yii::$app->user->identity->id;
$modelUpdateTranslation->nsdp_id = $nsdp_id;
$modelUpdateTranslation->sorting = 0;
$modelUpdateTranslation->save(false);
}
}
}
Yii::$app->session->setFlash('success', "Successful Updated");
return $this->redirect(['update_multiple_data?id=' . $nsdp_id]);
}
public function actionUpdate_multiple_data_sub($id)
{
$searchModel = new ContentNsdpsubcategorySearch();
$dataProvider = $searchModel->search1(Yii::$app->request->queryParams, $id);
return $this->render('update_multiple_data_sub', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
]);
}
public function actionUcmps($content_nsdp_categories_id, $data_category)
{
$checking = ContentNsdpsubcategory::find()->where(['content_nsdp_categories_id' => $content_nsdp_categories_id, 'data_category' => $data_category])->all();
$model = ContentNsdpsubcategory::find()->where(['content_nsdp_categories_id' => $content_nsdp_categories_id, 'data_category' => $data_category])->one();
return $this->render('update_category_multiple_page_sub', [
'checking' => $checking,
'model' => $model
]);
}
public function actionUpdate_category_multiple_page2($content_nsdp_categories_id, $data_category)
{
if (isset($_POST['new_themes_translation_no']) && !empty($_POST['new_themes_translation_no'])) {
foreach ($_POST['new_themes_translation_no'] as $new_themes_translation_no) {
$modelAddTranslation = new ContentNsdpsubcategory();
$modelAddTranslation->data_category = $_POST['ContentNsdpsubcategory']['data_category'];
$modelAddTranslation->unit_description = $_POST['unit_description_' . $new_themes_translation_no];
$modelAddTranslation->period_of_latest = $_POST['period_of_latest_' . $new_themes_translation_no];
$modelAddTranslation->latest_data = $_POST['latest_data_' . $new_themes_translation_no];
$modelAddTranslation->data_for_previous_period = $_POST['data_for_previous_period_' . $new_themes_translation_no];
$modelAddTranslation->new_label = $_POST['new_label_' . $new_themes_translation_no];
$modelAddTranslation->publish_date_start = $_POST['ContentNsdpsubcategory']['publish_date_start'];
$modelAddTranslation->publish_time_start = $_POST['ContentNsdpsubcategory']['publish_time_start'];
$modelAddTranslation->publish_date_end = $_POST['ContentNsdpsubcategory']['publish_date_end'];
$modelAddTranslation->publish_time_end = $_POST['ContentNsdpsubcategory']['publish_time_end'];
$modelAddTranslation->created_at = date("Y-m-d H:i:s");
$modelAddTranslation->created_by = Yii::$app->user->identity->id;
$modelAddTranslation->updated_at = date("Y-m-d H:i:s");
$modelAddTranslation->updated_by = Yii::$app->user->identity->id;
$modelAddTranslation->content_nsdp_categories_id = $content_nsdp_categories_id;
$modelAddTranslation->save(false);
}
}
if (isset($_POST['old_themes_translation_no']) && !empty($_POST['old_themes_translation_no'])) {
foreach ($_POST['old_themes_translation_no'] as $old_themes_translation_no) {
if (($modelUpdateTranslation = ContentNsdpsubcategory::findOne($old_themes_translation_no)) !== null) {
$modelUpdateTranslation->data_category = $_POST['ContentNsdpsubcategory']['data_category'];
$modelUpdateTranslation->unit_description = $_POST['old_unit_description_' . $old_themes_translation_no];
$modelUpdateTranslation->period_of_latest = $_POST['old_period_of_latest_' . $old_themes_translation_no];
$modelUpdateTranslation->latest_data = $_POST['old_latest_data_' . $old_themes_translation_no];
$modelUpdateTranslation->data_for_previous_period = $_POST['old_data_for_previous_period_' . $old_themes_translation_no];
$modelUpdateTranslation->new_label = $_POST['old_new_label_' . $old_themes_translation_no];
$modelUpdateTranslation->publish_date_start = $_POST['ContentNsdpsubcategory']['publish_date_start'];
$modelUpdateTranslation->publish_time_start = $_POST['ContentNsdpsubcategory']['publish_time_start'];
$modelUpdateTranslation->publish_date_end = $_POST['ContentNsdpsubcategory']['publish_date_end'];
$modelUpdateTranslation->publish_time_end = $_POST['ContentNsdpsubcategory']['publish_time_end'];
$modelUpdateTranslation->created_at = date("Y-m-d H:i:s");
$modelUpdateTranslation->created_by = Yii::$app->user->identity->id;
$modelUpdateTranslation->updated_at = date("Y-m-d H:i:s");
$modelUpdateTranslation->updated_by = Yii::$app->user->identity->id;
$modelUpdateTranslation->content_nsdp_categories_id = $content_nsdp_categories_id;
$modelUpdateTranslation->save(false);
}
}
}
Yii::$app->session->setFlash('success', "Successful Updated");
return $this->redirect(['update_multiple_data_sub?id=' . $content_nsdp_categories_id]);
}
}