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
}
/**
* 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.
* If record exists, the browser will be redirected to the 'view' page.
* @param integer $id
......@@ -135,110 +119,119 @@ class CategoryController extends Controller
*/
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);
$modelFiles = $model->categoryFiles;
// $modelFiles->type = $modelFiles::TYPE_JS;
if ($model->load(Yii::$app->request->post())) { //&& $model->save()
$oldIDs = ArrayHelper::map($modelFiles, 'id', 'id');
$modelFiles = Model::createMultiple(CategoryFiles::classname(), $modelFiles);
Model::loadMultiple($modelFiles, Yii::$app->request->post());
$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)
);
}
$categoryModel = $this->findModel($id);
$models = $categoryModel->categoryFiles;
if (Yii::$app->request->isPost) {
$oldIDs = ArrayHelper::map($models, 'id', 'id');
$models = Model::createMultiple(CategoryFiles::classname(), $models);
if (Model::loadMultiple($models, Yii::$app->request->post())) {
$deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($models, 'id', 'id')));
// validate all models
$valid = $model->validate();
$valid = Model::validateMultiple($modelFiles) && $valid;
if (Model::validateMultiple($models)) {
$transaction = \Yii::$app->db->beginTransaction();
if ($valid) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($flag = $model->save(false)) {
if (! empty($deletedIDs)) {
try {
$flag = true;
if (!empty($deletedIDs)) {
CategoryFiles::deleteAll(['id' => $deletedIDs]);
}
foreach ($modelFiles as $modelFiles) {
$modelFiles->customer_id = $model->id;
if (! ($flag = $modelFiles->save(false))) {
foreach ($models as $model) {
$model->category_id = $categoryModel->id;
if (!($flag = $model->save(false))) {
$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', [
'model' => $model,
'modelFiles' => (empty($modelFiles)) ? [new CategoryFiles()] : $modelFiles
'categoryModel' => $categoryModel,
'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();
$valid = Model::validateMultiple($modelFiles) && $valid;
if ($valid) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($flag = $model->save(false)) {
foreach ($modelFiles 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();
}
}
/**
* 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.');
}
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
/* @var $this yii\web\View */
/* @var $model common\models\Category */
/* @var $modelFiles common\models\CategoryFiles */
/* @var $categoryModel common\models\Category */
/* @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'][] = $this->title;
$this->params['categoryId'] = $categoryModel->id;
?>
<div class="category-create">
<?= $this->render('..\file\_form', [
'model' => $model,
'modelFiles' => $modelFiles,
'categoryModel' => $categoryModel,
'models' => $models,
]) ?>
</div>
......@@ -20,7 +20,7 @@ Menu::widget([
'url' => $this->params['categoryId'] ?
['category/files', 'id' => $this->params['categoryId']]
: '#',
'options' => ['class' => $this->params['categoryId'] ? '' : 'disabled']
'options' => $this->params['categoryId'] ? [] : ['class' => 'disabled'],
],
],
'options' => [
......
<?php
/* @var $this yii\web\View */
/* @var $model common\models\Category */
$this->params['categoryId'] = $model->id;
$this->title = Yii::t('backend', 'Update {modelClass}: ', [
'modelClass' => 'Category',
]) . ' ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Categories'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('backend', 'Update');
$this->params['categoryId'] = $model->id;
?>
<div class="category-update">
......
<?php
?>
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use wbraganca\dynamicform\DynamicFormWidget;
/* @var $this yii\web\View */
/* @var $categoryModel common\models\Category */
/* @var $models common\models\CategoryFiles[] */
?>
<div class="customer-form">
......@@ -14,14 +15,21 @@ use wbraganca\dynamicform\DynamicFormWidget;
<div class="panel panel-default">
<div class="panel-body">
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 4, // 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' => $modelFiles[0],
'widgetContainer' => 'dynamicform_wrapper',
// required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items',
// required: css class selector
'widgetItem' => '.item',
// required: css class
'limit' => 4,
// 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',
'formFields' => [
'name',
......@@ -31,7 +39,9 @@ use wbraganca\dynamicform\DynamicFormWidget;
]); ?>
<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="panel-heading">
<h3 class="panel-title pull-left">Category Files</h3>
......@@ -44,34 +54,48 @@ use wbraganca\dynamicform\DynamicFormWidget;
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (!$modelFile->isNewRecord) {
echo Html::activeHiddenInput($modelFile, "[{$i}]category_id");
if (!$model->isNewRecord) {
echo Html::activeHiddenInput($model, "[{$i}]category_id");
}
?>
<div class="row">
<div class="col-sm-4">
<?= $form->field($modelFile, "[{$i}]name")->textInput(['maxlength' => true]) ?>
<?= $form->field($model, "[{$i}]name")->textInput(['maxlength' => true]) ?>
</div>
<div class="col-sm-4">
<?= $form->field($modelFile, "[{$i}]code")->textInput(['maxlength' => true]) ?>
<?= $form->field($model, "[{$i}]code")->textInput(['maxlength' => true]) ?>
</div>
<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>
<?php endforeach; ?>
</div>
<?php DynamicFormWidget::end(); ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
......
......@@ -17,13 +17,13 @@ if (YII_DEBUG) {
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'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) {
$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
const TYPE_CSS = 2;
const TYPE_HTML = 3;
const TYPE_HTML_BLOCK = 4;
/**
* @inheritdoc
*/
......@@ -37,10 +38,16 @@ class CategoryFiles extends \yii\db\ActiveRecord
public function rules()
{
return [
[['category_id', 'code'], 'required'],
[['code'], 'required'],
[['category_id', 'created_at', 'updated_at'], 'integer'],
[['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 @@
"bower-asset/flot": "^0.8",
"petrabarus/yii2-googleplacesautocomplete": "dev-master",
"symfony/process": "^3.0",
"yiisoft/yii2-httpclient": "*"
"yiisoft/yii2-httpclient": "*",
"wbraganca/yii2-dynamicform": "*"
},
"require-dev": {
"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