Commit fc5ea308 by Junaid Rahman pv

Merge remote-tracking branch 'origin/development' into development

parents 5bf8bf66 32ec38bf
...@@ -112,22 +112,6 @@ class CategoryController extends Controller ...@@ -112,22 +112,6 @@ class CategoryController extends Controller
} }
/** /**
* Finds the Category model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Category the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Category::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/**
* Files of an existing Category model. * Files of an existing Category model.
* If record exists, the browser will be redirected to the 'view' page. * If record exists, the browser will be redirected to the 'view' page.
* @param integer $id * @param integer $id
...@@ -135,110 +119,119 @@ class CategoryController extends Controller ...@@ -135,110 +119,119 @@ class CategoryController extends Controller
*/ */
public function actionFiles($id) public function actionFiles($id)
{ {
// $this->layout = '@backend/modules/theme/views/category/layout.php'; $this->layout = '@backend/modules/theme/views/category/layout.php';
$model = $this->findModel($id); $categoryModel = $this->findModel($id);
$modelFiles = $model->categoryFiles; $models = $categoryModel->categoryFiles;
// $modelFiles->type = $modelFiles::TYPE_JS;
if (Yii::$app->request->isPost) {
if ($model->load(Yii::$app->request->post())) { //&& $model->save() $oldIDs = ArrayHelper::map($models, 'id', 'id');
$models = Model::createMultiple(CategoryFiles::classname(), $models);
$oldIDs = ArrayHelper::map($modelFiles, 'id', 'id');
$modelFiles = Model::createMultiple(CategoryFiles::classname(), $modelFiles); if (Model::loadMultiple($models, Yii::$app->request->post())) {
Model::loadMultiple($modelFiles, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($models, 'id', 'id')));
$deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelFiles, 'id', 'id')));
// ajax validation
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ArrayHelper::merge(
ActiveForm::validateMultiple($modelFiles),
ActiveForm::validate($model)
);
}
// validate all models if (Model::validateMultiple($models)) {
$valid = $model->validate(); $transaction = \Yii::$app->db->beginTransaction();
$valid = Model::validateMultiple($modelFiles) && $valid;
if ($valid) { try {
$transaction = \Yii::$app->db->beginTransaction(); $flag = true;
try {
if ($flag = $model->save(false)) { if (!empty($deletedIDs)) {
if (! empty($deletedIDs)) {
CategoryFiles::deleteAll(['id' => $deletedIDs]); CategoryFiles::deleteAll(['id' => $deletedIDs]);
} }
foreach ($modelFiles as $modelFiles) {
$modelFiles->customer_id = $model->id; foreach ($models as $model) {
if (! ($flag = $modelFiles->save(false))) { $model->category_id = $categoryModel->id;
if (!($flag = $model->save(false))) {
$transaction->rollBack(); $transaction->rollBack();
break;
} }
} }
if ($flag) {
$transaction->commit();
return $this->redirect(['index']);
}
} catch (Exception $e) {
$transaction->rollBack();
} }
if ($flag) {
$transaction->commit();
return $this->redirect(['file', 'category_id' => $model->id]);
}
} catch (Exception $e) {
$transaction->rollBack();
} }
} }
} }
return $this->render('file', [ return $this->render('file', [
'model' => $model, 'categoryModel' => $categoryModel,
'modelFiles' => (empty($modelFiles)) ? [new CategoryFiles()] : $modelFiles 'models' => (empty($models)) ? [new CategoryFiles(['category_id' => $categoryModel->id])] : $models,
]); ]);
} }
public function actionCreatee()
{
$model = new Category();
$modelFiles = [new CategoryFiles()];
if ($model->load(Yii::$app->request->post())) {
$modelFiles = Model::createMultiple(CategoryFiles::classname());
Model::loadMultiple($modelFiles, Yii::$app->request->post());
// ajax validation
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ArrayHelper::merge(
ActiveForm::validateMultiple($modelFiles),
ActiveForm::validate($model)
);
}
// validate all models /**
$valid = $model->validate(); * Finds the Category model based on its primary key value.
$valid = Model::validateMultiple($modelFiles) && $valid; * If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
if ($valid) { * @return Category the loaded model
$transaction = \Yii::$app->db->beginTransaction(); * @throws NotFoundHttpException if the model cannot be found
try { */
if ($flag = $model->save(false)) { protected function findModel($id)
foreach ($modelFiles as $modelFile) { {
$modelFile->category_id = $model->id; if (($model = Category::findOne($id)) !== null) {
if (! ($flag = $modelFile->save(false))) { return $model;
$transaction->rollBack(); } else {
break; throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
if ($flag) {
$transaction->commit();
return $this->redirect(['file', 'category_id' => $model->id]);
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
} }
return $this->render('file', [
'model' => $model,
'modelFiles' => (empty($modelFiles)) ? [new CategoryFiles()] : $modelFiles
]);
} }
// public function actionCreatee()
// {
// $model = new Category();
// $models = [new CategoryFiles()];
// if ($model->load(Yii::$app->request->post())) {
//
// $models = Model::createMultiple(CategoryFiles::classname());
// Model::loadMultiple($models, Yii::$app->request->post());
//
// // ajax validation
// if (Yii::$app->request->isAjax) {
// Yii::$app->response->format = Response::FORMAT_JSON;
//
// return ArrayHelper::merge(
// ActiveForm::validateMultiple($models),
// ActiveForm::validate($model)
// );
// }
//
// // validate all models
// $valid = $model->validate();
// $valid = Model::validateMultiple($models) && $valid;
//
// if ($valid) {
// $transaction = \Yii::$app->db->beginTransaction();
// try {
// if ($flag = $model->save(false)) {
// foreach ($models as $modelFile) {
// $modelFile->category_id = $model->id;
// if (!($flag = $modelFile->save(false))) {
// $transaction->rollBack();
// break;
// }
// }
// }
// if ($flag) {
// $transaction->commit();
//
// return $this->redirect(['file', 'category_id' => $model->id]);
// }
// } catch (Exception $e) {
// $transaction->rollBack();
// }
// }
// }
//
// return $this->render('file', [
// 'model' => $model,
// 'modelFiles' => (empty($models)) ? [new CategoryFiles()] : $models
// ]);
// }
} }
<?php <?php
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\Category */ /* @var $categoryModel common\models\Category */
/* @var $modelFiles common\models\CategoryFiles */ /* @var $models common\models\CategoryFiles[] */
$this->title = Yii::t('admin', 'Create Category File');
$this->params['categoryId'] = false;
$this->title = 'Create Category File';
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Categories'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Categories'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
$this->params['categoryId'] = $categoryModel->id;
?> ?>
<div class="category-create"> <div class="category-create">
<?= $this->render('..\file\_form', [ <?= $this->render('..\file\_form', [
'model' => $model, 'categoryModel' => $categoryModel,
'modelFiles' => $modelFiles, 'models' => $models,
]) ?> ]) ?>
</div> </div>
...@@ -20,7 +20,7 @@ Menu::widget([ ...@@ -20,7 +20,7 @@ Menu::widget([
'url' => $this->params['categoryId'] ? 'url' => $this->params['categoryId'] ?
['category/files', 'id' => $this->params['categoryId']] ['category/files', 'id' => $this->params['categoryId']]
: '#', : '#',
'options' => ['class' => $this->params['categoryId'] ? '' : 'disabled'] 'options' => $this->params['categoryId'] ? [] : ['class' => 'disabled'],
], ],
], ],
'options' => [ 'options' => [
......
<?php <?php
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\Category */ /* @var $model common\models\Category */
$this->params['categoryId'] = $model->id;
$this->title = Yii::t('backend', 'Update {modelClass}: ', [ $this->title = Yii::t('backend', 'Update {modelClass}: ', [
'modelClass' => 'Category', 'modelClass' => 'Category',
]) . ' ' . $model->name; ]) . ' ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Categories'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Categories'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('backend', 'Update'); $this->params['breadcrumbs'][] = Yii::t('backend', 'Update');
$this->params['categoryId'] = $model->id;
?> ?>
<div class="category-update"> <div class="category-update">
......
<?php <?php
?>
<?php
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use wbraganca\dynamicform\DynamicFormWidget; use wbraganca\dynamicform\DynamicFormWidget;
/* @var $this yii\web\View */
/* @var $categoryModel common\models\Category */
/* @var $models common\models\CategoryFiles[] */
?> ?>
<div class="customer-form"> <div class="customer-form">
...@@ -14,14 +15,21 @@ use wbraganca\dynamicform\DynamicFormWidget; ...@@ -14,14 +15,21 @@ use wbraganca\dynamicform\DynamicFormWidget;
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
<?php DynamicFormWidget::begin([ <?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_] 'widgetContainer' => 'dynamicform_wrapper',
'widgetBody' => '.container-items', // required: css class selector // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetItem' => '.item', // required: css class 'widgetBody' => '.container-items',
'limit' => 4, // the maximum times, an element can be cloned (default 999) // required: css class selector
'min' => 1, // 0 or 1 (default 1) 'widgetItem' => '.item',
'insertButton' => '.add-item', // css class // required: css class
'deleteButton' => '.remove-item', // css class 'limit' => 4,
'model' => $modelFiles[0], // the maximum times, an element can be cloned (default 999)
'min' => 1,
// 0 or 1 (default 1)
'insertButton' => '.add-item',
// css class
'deleteButton' => '.remove-item',
// css class
'model' => $models[0],
'formId' => 'dynamic-form', 'formId' => 'dynamic-form',
'formFields' => [ 'formFields' => [
'name', 'name',
...@@ -31,7 +39,9 @@ use wbraganca\dynamicform\DynamicFormWidget; ...@@ -31,7 +39,9 @@ use wbraganca\dynamicform\DynamicFormWidget;
]); ?> ]); ?>
<div class="container-items"><!-- widgetContainer --> <div class="container-items"><!-- widgetContainer -->
<?php foreach ($modelFiles as $i => $modelFile): ?>
<?php foreach ($models as $i => $model): ?>
<div class="item panel panel-default"><!-- widgetBody --> <div class="item panel panel-default"><!-- widgetBody -->
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title pull-left">Category Files</h3> <h3 class="panel-title pull-left">Category Files</h3>
...@@ -44,34 +54,48 @@ use wbraganca\dynamicform\DynamicFormWidget; ...@@ -44,34 +54,48 @@ use wbraganca\dynamicform\DynamicFormWidget;
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<?php <?php
// necessary for update action. // necessary for update action.
if (!$modelFile->isNewRecord) { if (!$model->isNewRecord) {
echo Html::activeHiddenInput($modelFile, "[{$i}]category_id"); echo Html::activeHiddenInput($model, "[{$i}]category_id");
} }
?> ?>
<div class="row"> <div class="row">
<div class="col-sm-4"> <div class="col-sm-4">
<?= $form->field($modelFile, "[{$i}]name")->textInput(['maxlength' => true]) ?>
<?= $form->field($model, "[{$i}]name")->textInput(['maxlength' => true]) ?>
</div> </div>
<div class="col-sm-4"> <div class="col-sm-4">
<?= $form->field($modelFile, "[{$i}]code")->textInput(['maxlength' => true]) ?>
<?= $form->field($model, "[{$i}]code")->textInput(['maxlength' => true]) ?>
</div> </div>
<div class="col-sm-4"> <div class="col-sm-4">
<!-- <?//= $form->field($modelFile, "[{$i}]type")->textInput(['maxlength' => true]) ?> -->
<?= $form->field($modelFile, "[{$i}]type")->dropDownList($modelFile::getfiles(), ['prompt' => '']) ?> <?= $form->field($model, "[{$i}]type")->dropDownList($model::getfiles(),
['prompt' => '']) ?>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<?php DynamicFormWidget::end(); ?> <?php DynamicFormWidget::end(); ?>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-primary']) ?> <?= Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
......
...@@ -17,13 +17,13 @@ if (YII_DEBUG) { ...@@ -17,13 +17,13 @@ if (YII_DEBUG) {
$config['bootstrap'][] = 'debug'; $config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [ $config['modules']['debug'] = [
'class' => 'yii\debug\Module', 'class' => 'yii\debug\Module',
'allowedIPs' => ['127.0.0.1', '::1', '192.168.33.1', '172.17.42.1', '172.17.0.1'], 'allowedIPs' => ['127.0.0.1', '::1','192.168.1.123'],
]; ];
} }
if (YII_ENV_DEV) { if (YII_ENV_DEV) {
$config['modules']['gii'] = [ $config['modules']['gii'] = [
'allowedIPs' => ['127.0.0.1', '::1', '192.168.33.1', '172.17.42.1', '172.17.0.1'], 'allowedIPs' => ['127.0.0.1', '::1','192.168.1.123'],
]; ];
} }
......
...@@ -23,6 +23,7 @@ class CategoryFiles extends \yii\db\ActiveRecord ...@@ -23,6 +23,7 @@ class CategoryFiles extends \yii\db\ActiveRecord
const TYPE_CSS = 2; const TYPE_CSS = 2;
const TYPE_HTML = 3; const TYPE_HTML = 3;
const TYPE_HTML_BLOCK = 4; const TYPE_HTML_BLOCK = 4;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -37,10 +38,16 @@ class CategoryFiles extends \yii\db\ActiveRecord ...@@ -37,10 +38,16 @@ class CategoryFiles extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['category_id', 'code'], 'required'], [['code'], 'required'],
[['category_id', 'created_at', 'updated_at'], 'integer'], [['category_id', 'created_at', 'updated_at'], 'integer'],
[['code', 'type', 'name'], 'string', 'max' => 32], [['code', 'type', 'name'], 'string', 'max' => 32],
[['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'id']], [
['category_id'],
'exist',
'skipOnError' => true,
'targetClass' => Category::className(),
'targetAttribute' => ['category_id' => 'id']
],
]; ];
} }
......
...@@ -49,7 +49,8 @@ ...@@ -49,7 +49,8 @@
"bower-asset/flot": "^0.8", "bower-asset/flot": "^0.8",
"petrabarus/yii2-googleplacesautocomplete": "dev-master", "petrabarus/yii2-googleplacesautocomplete": "dev-master",
"symfony/process": "^3.0", "symfony/process": "^3.0",
"yiisoft/yii2-httpclient": "*" "yiisoft/yii2-httpclient": "*",
"wbraganca/yii2-dynamicform": "*"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-debug": "^2.0.0", "yiisoft/yii2-debug": "^2.0.0",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment