Commit ffcb9c04 by Junaid Rahman pv

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

# Conflicts:
#	composer.json
parents 0a66f601 8e5dab8a
......@@ -2,14 +2,15 @@
namespace backend\modules\theme\controllers;
use common\models\CategoryFiles;
use Yii;
use common\models\Category;
use backend\modules\theme\models\search\CategorySearch;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\Model;
use yii\helpers\ArrayHelper;
/**
* CategoryController implements the CRUD actions for Category model.
......@@ -125,4 +126,119 @@ class CategoryController extends Controller
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
* @return mixed
*/
public function actionFiles($id)
{
// $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)
);
}
// validate all models
$valid = $model->validate();
$valid = Model::validateMultiple($modelFiles) && $valid;
if ($valid) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($flag = $model->save(false)) {
if (! empty($deletedIDs)) {
CategoryFiles::deleteAll(['id' => $deletedIDs]);
}
foreach ($modelFiles as $modelFiles) {
$modelFiles->customer_id = $model->id;
if (! ($flag = $modelFiles->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($modelFiles)) ? [new CategoryFiles()] : $modelFiles
]);
}
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();
}
}
}
return $this->render('file', [
'model' => $model,
'modelFiles' => (empty($modelFiles)) ? [new CategoryFiles()] : $modelFiles
]);
}
}
<?php
namespace backend\modules\theme\controllers;
use Yii;
use common\models\Theme;
use backend\modules\theme\models\search\ThemeSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* ThemeController implements the CRUD actions for Theme model.
*/
class ThemeController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all Theme models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ThemeSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Theme model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Theme model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Theme();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing Theme model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing Theme model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Theme model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Theme the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Theme::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\modules\theme\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Theme;
/**
* ThemeSearch represents the model behind the search form about `common\models\Theme`.
*/
class ThemeSearch extends Theme
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'category_id', 'status', 'created_at', 'updated_at'], 'integer'],
[['code', 'slug', 'name', 'description'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Theme::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'category_id' => $this->category_id,
'status' => $this->status,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'code', $this->code])
->andFilterWhere(['like', 'slug', $this->slug])
->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'description', $this->description]);
return $dataProvider;
}
}
......@@ -12,23 +12,11 @@ use trntv\filekit\widget\Upload;
<div class="category-form">
<?php $form = ActiveForm::begin(); ?>
<!-- <ul id="myTab" class="nav nav-tabs">-->
<!-- <li class="active">-->
<!-- <a href="#info" data-toggle="tab">-->
<!-- Info-->
<!-- </a>-->
<!-- </li>-->
<!-- <li>-->
<!-- <a href="#files" data-toggle="tab">-->
<!-- Files-->
<!-- </a>-->
<!-- </li>-->
<!-- </ul>-->
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="info">
<div class="page-header">
<h3>Info</h3>
<h3> <?= Yii::t('backend', 'Info') ?> </h3>
</div>
<div class="row">
<div class="col-md-6">
......
<?php
/* @var $this yii\web\View */
/* @var $model common\models\Category */
/* @var $modelFiles common\models\CategoryFiles */
$this->params['categoryId'] = false;
$this->title = 'Create Category File';
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Categories'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="category-create">
<?= $this->render('..\file\_form', [
'model' => $model,
'modelFiles' => $modelFiles,
]) ?>
</div>
......@@ -11,17 +11,15 @@ Menu::widget([
'items' => [
[
'label' => 'Info',
'url' => $this->params['categoryId'] ? [
'category/update',
'id' => $this->params['categoryId']
] : ['category/create'],
'url' => $this->params['categoryId'] ?
['category/update', 'id' => $this->params['categoryId']]
: ['category/create'],
],
[
'label' => 'Files',
'url' => $this->params['categoryId'] ? [
'category/files',
'category_id' => $this->params['categoryId']
] : '#',
'url' => $this->params['categoryId'] ?
['category/files', 'id' => $this->params['categoryId']]
: '#',
'options' => ['class' => $this->params['categoryId'] ? '' : 'disabled']
],
],
......
<?php
?>
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use wbraganca\dynamicform\DynamicFormWidget;
?>
<div class="customer-form">
<?php $form = ActiveForm::begin(['id' => 'dynamic-form']); ?>
<div class="panel panel-default">
<div class="panel-heading">
<h4><i class="glyphicon glyphicon-envelope"></i> Addresses</h4>
</div>
<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],
'formId' => 'dynamic-form',
'formFields' => [
'name',
'code',
'type',
],
]); ?>
<div class="container-items"><!-- widgetContainer -->
<?php foreach ($modelFiles as $i => $modelFile): ?>
<div class="item panel panel-default"><!-- widgetBody -->
<div class="panel-heading">
<h3 class="panel-title pull-left">Category Files</h3>
<div class="pull-right">
<button type="button" class="add-item btn btn-success btn-xs"><i
class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item btn btn-danger btn-xs"><i
class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (!$modelFile->isNewRecord) {
echo Html::activeHiddenInput($modelFile, "[{$i}]category_id");
}
?>
<div class="row">
<div class="col-sm-4">
<?= $form->field($modelFile, "[{$i}]name")->textInput(['maxlength' => true]) ?>
</div>
<div class="col-sm-4">
<?= $form->field($modelFile, "[{$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' => '']) ?>
</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(); ?>
</div>
<?php
?>
<div id="panel-option-values" class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-check-square-o"></i> Option values</h3>
</div>
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper',
'widgetBody' => '.form-options-body',
'widgetItem' => '.form-options-item',
'min' => 1,
'insertButton' => '.add-item',
'deleteButton' => '.delete-item',
'model' => $modelsOptionValue[0],
'formId' => 'dynamic-form',
'formFields' => [
'name',
'img'
],
]); ?>
<table class="table table-bordered table-striped margin-b-none">
<thead>
<tr>
<th style="width: 90px; text-align: center"></th>
<th class="required">Option value name</th>
<th style="width: 188px;">Image</th>
<th style="width: 90px; text-align: center">Actions</th>
</tr>
</thead>
<tbody class="form-options-body">
<?php foreach ($modelsOptionValue as $index => $modelOptionValue): ?>
<tr class="form-options-item">
<td class="sortable-handle text-center vcenter" style="cursor: move;">
<i class="fa fa-arrows"></i>
</td>
<td class="vcenter">
<?= $form->field($modelOptionValue, "[{$index}]name")->label(false)->textInput(['maxlength' => 128]); ?>
</td>
<td>
<?php if (!$modelOptionValue->isNewRecord): ?>
<?= Html::activeHiddenInput($modelOptionValue, "[{$index}]id"); ?>
<?= Html::activeHiddenInput($modelOptionValue, "[{$index}]image_id"); ?>
<?= Html::activeHiddenInput($modelOptionValue, "[{$index}]deleteImg"); ?>
<?php endif; ?>
<?php
$modelImage = Image::findOne(['id' => $modelOptionValue->image_id]);
$initialPreview = [];
if ($modelImage) {
$pathImg = Yii::$app->fileStorage->baseUrl . '/' . $modelImage->path;
$initialPreview[] = Html::img($pathImg, ['class' => 'file-preview-image']);
}
?>
<?= $form->field($modelOptionValue, "[{$index}]img")->label(false)->widget(FileInput::classname(), [
'options' => [
'multiple' => false,
'accept' => 'image/*',
'class' => 'optionvalue-img'
],
'pluginOptions' => [
'previewFileType' => 'image',
'showCaption' => false,
'showUpload' => false,
'browseClass' => 'btn btn-default btn-sm',
'browseLabel' => ' Pick image',
'browseIcon' => '<i class="glyphicon glyphicon-picture"></i>',
'removeClass' => 'btn btn-danger btn-sm',
'removeLabel' => ' Delete',
'removeIcon' => '<i class="fa fa-trash"></i>',
'previewSettings' => [
'image' => ['width' => '138px', 'height' => 'auto']
],
'initialPreview' => $initialPreview,
'layoutTemplates' => ['footer' => '']
]
]) ?>
</td>
<td class="text-center vcenter">
<button type="button" class="delete-item btn btn-danger btn-xs"><i class="fa fa-minus"></i></button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<td colspan="3"></td>
<td><button type="button" class="add-item btn btn-success btn-sm"><span class="fa fa-plus"></span> New</button></td>
</tr>
</tfoot>
</table>
<?php DynamicFormWidget::end(); ?>
</div>
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $model common\models\Theme */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div class="theme-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->errorSummary($model); ?>
<?= $form->field($model, 'category_id')->textInput() ?>
<?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'status')->textInput() ?>
<?= $form->field($model, 'created_at')->textInput() ?>
<?= $form->field($model, 'updated_at')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\theme\models\search\ThemeSearch */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div class="theme-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'category_id') ?>
<?= $form->field($model, 'code') ?>
<?= $form->field($model, 'slug') ?>
<?= $form->field($model, 'name') ?>
<?php // echo $form->field($model, 'description') ?>
<?php // echo $form->field($model, 'status') ?>
<?php // echo $form->field($model, 'created_at') ?>
<?php // echo $form->field($model, 'updated_at') ?>
<div class="form-group">
<?= Html::submitButton(Yii::t('backend', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('backend', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Theme */
$this->title = Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'Theme',
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Themes'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="theme-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\theme\models\search\ThemeSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend', 'Themes');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="theme-index">
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'Theme',
]), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'category_id',
'code',
'slug',
'name',
// 'description',
// 'status',
// 'created_at',
// 'updated_at',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Theme */
$this->title = Yii::t('backend', 'Update {modelClass}: ', [
'modelClass' => 'Theme',
]) . ' ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Themes'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('backend', 'Update');
?>
<div class="theme-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\Theme */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Themes'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="theme-view">
<p>
<?= Html::a(Yii::t('backend', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('backend', 'Delete'), ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('backend', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'category_id',
'code',
'slug',
'name',
'description',
'status',
'created_at',
'updated_at',
],
]) ?>
</div>
......@@ -28,7 +28,7 @@ class m160830_105840_category extends Migration
'id' => $this->primaryKey(),
'category_id' => $this->integer()->notNull(),
'code' => $this->string(32)->notNull(),
'type' => $this->string(32)->notNull(),
'type' => $this->integer()->notNull(),
'name' => $this->string(32)->notNull(),
'created_at' => $this->integer(),
'updated_at' => $this->integer()
......
<?php
use yii\db\Migration;
class m160903_101233_theme extends Migration
{
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable('{{%theme}}', [
'id' => $this->primaryKey(),
'category_id' => $this->integer()->notNull(),
'code' => $this->string(32)->notNull(),
'slug' => $this->string(32)->notNull(),
'name' => $this->string(32)->notNull(),
'description' => $this->string(512),
'status' => $this->smallInteger()->notNull(),//->defaultValue(Category::STATUS_ACTIVE),
'created_at' => $this->integer(),
'updated_at' => $this->integer()
], $tableOptions);
$this->createTable('{{%theme_files}}', [
'id' => $this->primaryKey(),
'theme_id' => $this->integer()->notNull(),
'file_id' => $this->string(32)->notNull(),
'base_url' => $this->string(1024),
'base_path' => $this->string(1024),
'created_at' => $this->integer(),
'updated_at' => $this->integer()
], $tableOptions);
$this->addForeignKey('fk_theme_category', '{{%theme}}', 'category_id', '{{%category}}', 'id', 'cascade', 'cascade');
$this->addForeignKey('fk_theme_files_theme', '{{%theme_files}}', 'theme_id', '{{%theme}}', 'id', 'cascade', 'cascade');
}
public function safeDown()
{
$this->dropForeignKey('fk_theme_files_theme', '{{%theme_files}}');
$this->dropForeignKey('fk_theme_category', '{{%theme}}');
$this->dropTable('{{%theme_files}}');
$this->dropTable('{{%theme}}');
}
}
......@@ -19,6 +19,10 @@ use Yii;
*/
class CategoryFiles extends \yii\db\ActiveRecord
{
const TYPE_JS = 1;
const TYPE_CSS = 2;
const TYPE_HTML = 3;
const TYPE_HTML_BLOCK = 4;
/**
* @inheritdoc
*/
......@@ -72,4 +76,14 @@ class CategoryFiles extends \yii\db\ActiveRecord
{
return new \common\models\query\CategoryFilesQuery(get_called_class());
}
public static function getfiles()
{
return [
self::TYPE_JS => Yii::t('common', 'JS'),
self::TYPE_CSS => Yii::t('common', 'CSS'),
self::TYPE_HTML => Yii::t('common', 'HTML'),
self::TYPE_HTML_BLOCK => Yii::t('common', 'HTML BLOCK'),
];
}
}
<?php
/**
* Created by PhpStorm.
* User: dianc
* Date: 03-09-2016
* Time: 11:21
*/
namespace common\models;
use Yii;
use yii\helpers\ArrayHelper;
class Model extends \yii\base\Model
{
/**
* Creates and populates a set of models.
*
* @param string $modelClass
* @param array $multipleModels
* @return array
*/
public static function createMultiple($modelClass, $multipleModels = [])
{
$model = new $modelClass;
$formName = $model->formName();
$post = Yii::$app->request->post($formName);
$models = [];
if (! empty($multipleModels)) {
$keys = array_keys(ArrayHelper::map($multipleModels, 'id', 'id'));
$multipleModels = array_combine($keys, $multipleModels);
}
if ($post && is_array($post)) {
foreach ($post as $i => $item) {
if (isset($item['id']) && !empty($item['id']) && isset($multipleModels[$item['id']])) {
$models[] = $multipleModels[$item['id']];
} else {
$models[] = new $modelClass;
}
}
}
unset($model, $formName, $post);
return $models;
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "{{%theme}}".
*
* @property integer $id
* @property integer $category_id
* @property string $code
* @property string $slug
* @property string $name
* @property string $description
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
*
* @property Category $category
* @property ThemeFiles[] $themeFiles
*/
class Theme extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%theme}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['category_id', 'code', 'slug', 'name', 'status'], 'required'],
[['category_id', 'status', 'created_at', 'updated_at'], 'integer'],
[['code', 'slug', 'name'], 'string', 'max' => 32],
[['description'], 'string', 'max' => 512],
[['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'category_id' => Yii::t('app', 'Category ID'),
'code' => Yii::t('app', 'Code'),
'slug' => Yii::t('app', 'Slug'),
'name' => Yii::t('app', 'Name'),
'description' => Yii::t('app', 'Description'),
'status' => Yii::t('app', 'Status'),
'created_at' => Yii::t('app', 'Created At'),
'updated_at' => Yii::t('app', 'Updated At'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCategory()
{
return $this->hasOne(Category::className(), ['id' => 'category_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getThemeFiles()
{
return $this->hasMany(ThemeFiles::className(), ['theme_id' => 'id']);
}
/**
* @inheritdoc
* @return \common\models\query\ThemeQuery the active query used by this AR class.
*/
public static function find()
{
return new \common\models\query\ThemeQuery(get_called_class());
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "{{%theme_files}}".
*
* @property integer $id
* @property integer $theme_id
* @property string $file_id
* @property string $base_url
* @property string $base_path
* @property integer $created_at
* @property integer $updated_at
*
* @property Theme $theme
*/
class ThemeFiles extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%theme_files}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['theme_id', 'file_id'], 'required'],
[['theme_id', 'created_at', 'updated_at'], 'integer'],
[['file_id'], 'string', 'max' => 32],
[['base_url', 'base_path'], 'string', 'max' => 1024],
[['theme_id'], 'exist', 'skipOnError' => true, 'targetClass' => Theme::className(), 'targetAttribute' => ['theme_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'theme_id' => Yii::t('app', 'Theme ID'),
'file_id' => Yii::t('app', 'File ID'),
'base_url' => Yii::t('app', 'Base Url'),
'base_path' => Yii::t('app', 'Base Path'),
'created_at' => Yii::t('app', 'Created At'),
'updated_at' => Yii::t('app', 'Updated At'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTheme()
{
return $this->hasOne(Theme::className(), ['id' => 'theme_id']);
}
/**
* @inheritdoc
* @return \common\models\query\ThemeFilesQuery the active query used by this AR class.
*/
public static function find()
{
return new \common\models\query\ThemeFilesQuery(get_called_class());
}
}
<?php
namespace common\models\query;
/**
* This is the ActiveQuery class for [[\common\models\ThemeFiles]].
*
* @see \common\models\ThemeFiles
*/
class ThemeFilesQuery extends \yii\db\ActiveQuery
{
/*public function active()
{
return $this->andWhere('[[status]]=1');
}*/
/**
* @inheritdoc
* @return \common\models\ThemeFiles[]|array
*/
public function all($db = null)
{
return parent::all($db);
}
/**
* @inheritdoc
* @return \common\models\ThemeFiles|array|null
*/
public function one($db = null)
{
return parent::one($db);
}
}
<?php
namespace common\models\query;
/**
* This is the ActiveQuery class for [[\common\models\Theme]].
*
* @see \common\models\Theme
*/
class ThemeQuery extends \yii\db\ActiveQuery
{
/*public function active()
{
return $this->andWhere('[[status]]=1');
}*/
/**
* @inheritdoc
* @return \common\models\Theme[]|array
*/
public function all($db = null)
{
return parent::all($db);
}
/**
* @inheritdoc
* @return \common\models\Theme|array|null
*/
public function one($db = null)
{
return parent::one($db);
}
}
......@@ -49,6 +49,8 @@
"bower-asset/flot": "^0.8",
"symfony/process": "^3.0",
"petrabarus/yii2-googleplacesautocomplete": "dev-master"
"symfony/process": "^3.0",
"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