| Current Path : /var/www/html/dosm_backup/backend/controllers/ |
| Current File : /var/www/html/dosm_backup/backend/controllers/ContentDirectoryController.php |
<?php
namespace backend\controllers;
use Yii;
use backend\models\ReleaseThemes1;
use backend\models\ReleaseThemesSearch1;
use backend\models\ReleaseThemesTranslation1;
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\modules\refdynawebv2\models\Ref;
/**
* ContentDirectoryController implements the CRUD actions for ContentDirectory model.
*/
class ContentDirectoryController extends Controller {
/**
* {@inheritdoc}
*/
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['GET'],
],
],
];
}
/**
* Lists all ReleaseThemes models.
* @return mixed
*/
public function actionIndex() {
$searchModel = new ReleaseThemesSearch1();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single ReleaseThemes model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new ReleaseThemes model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($parent_id = '') {
$model = new ReleaseThemes1();
$model->theme_parent_id = $parent_id;
$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->theme_thumbnail = UploadedFile::getInstance($model, 'theme_thumbnail');
if (!empty($model->theme_thumbnail)) {
$theme_thumbnail = 'images/icon/icon_' . date("YmdHis") . '.' . $model->theme_thumbnail->extension;
if ($model->theme_thumbnail->saveAs($theme_thumbnail))
$model->theme_thumbnail = $theme_thumbnail;
}
// $model->theme_background = UploadedFile::getInstance($model, 'theme_background');
// if (!empty($model->theme_background)) {
// $theme_background = 'uploads/release-themes/background_' . date("YmdHis") . '.' . $model->theme_background->extension;
// if ($model->theme_background->saveAs('../' . $theme_background))
// $model->theme_background = $theme_background;
// }
$model->theme_status = $_POST['ReleaseThemes1']['theme_status'];
if(!empty($parent_id))
{
$chekcing = ReleaseThemes1::find()->where(['theme_id' => $parent_id])->one();
$chekcing->theme_father = 0;
$chekcing->save();
}
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 ReleaseThemesTranslation1();
$modelAddTranslation->themes_translation_parent_id = $model->theme_id;
$modelAddTranslation->themes_translation_language = $_POST['new_themes_translation_language_' . $new_themes_translation_no];
$modelAddTranslation->themes_translation = $_POST['new_themes_translation_' . $new_themes_translation_no];
$modelAddTranslation->save(false);
}
}
return $this->redirect(['index']);
}
}
return $this->render('create', ['model' => $model,]);
}
/**
* Updates an existing ReleaseThemes model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
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;
$original_theme_thumbnail = $model->theme_thumbnail;
// $original_theme_background = $model->theme_background;
if ($model->load(Yii::$app->request->post())) {
$model->theme_thumbnail = UploadedFile::getInstance($model, 'theme_thumbnail');
if (!empty($model->theme_thumbnail)) {
$theme_thumbnail = 'images/icon/icon_' . date("YmdHis") . '.' . $model->theme_thumbnail->extension;
if ($model->theme_thumbnail->saveAs($theme_thumbnail))
$model->theme_thumbnail = $theme_thumbnail;
} else {
$model->theme_thumbnail = $original_theme_thumbnail;
}
// $model->theme_background = UploadedFile::getInstance($model, 'theme_background');
// if (!empty($model->theme_background)) {
// $theme_background = 'uploads/release-themes/background_' . date("YmdHis") . '.' . $model->theme_background->extension;
// if ($model->theme_background->saveAs('../' . $theme_background))
// $model->theme_background = $theme_background;
// } else {
// $model->theme_background = $original_theme_background;
// }
$model->theme_status = $_POST['ReleaseThemes1']['theme_status'];
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 ReleaseThemesTranslation1();
$modelAddTranslation->themes_translation_parent_id = $model->theme_id;
$modelAddTranslation->themes_translation_language = $_POST['new_themes_translation_language_' . $new_themes_translation_no];
$modelAddTranslation->themes_translation = $_POST['new_themes_translation_' . $new_themes_translation_no];
$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 = ReleaseThemesTranslation1::findOne($old_themes_translation_no)) !== null) {
$modelUpdateTranslation->themes_translation_language = $_POST['old_themes_translation_language_' . $old_themes_translation_no];
$modelUpdateTranslation->themes_translation = $_POST['old_themes_translation_' . $old_themes_translation_no];
$modelUpdateTranslation->save(false);
}
}
}
return $this->redirect(['index']);
}
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing ReleaseThemes model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id) {
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the ReleaseThemes model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return ReleaseThemes the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = ReleaseThemes1::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
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::dropDownList('new_themes_translation_language_' . $count, null, $language_arr, ['class' => 'form-control', 'prompt' => '-- Please choose language --']) . '</div>
<div class="col-sm-7">' . Html::input('text', 'new_themes_translation_' . $count, '', $options = ['class' => 'form-control', 'placeholder' => 'Themes Name']) . '</div>
<div class="col-sm-1">' . Html::button('Delete', ['class' => 'btn btn-danger btn-block', 'onclick' => 'deletenewtranslation(' . $count . ')']) . '</div>
</div>';
}
public function actionDeletetranslation($id) {
if (($model = ReleaseThemesTranslation1::findOne($id)) !== null) {
$model->delete();
}
}
}