add property and property definition
This commit is contained in:
@@ -235,6 +235,28 @@ class AdminMenuStructure
|
||||
];
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Group Training
|
||||
/////////////////////////////
|
||||
$items = [];
|
||||
// $items[] = ['label' => 'Felszerelés', 'url' => ['/event-equipment-type'], 'role' => [RoleDefinition::$ROLE_ADMIN]];
|
||||
$items[] = [
|
||||
'label' => 'Beállítások',
|
||||
'url' => ['/settings/index'],
|
||||
'role' => [
|
||||
RoleDefinition::$ROLE_ADMIN,
|
||||
]
|
||||
];
|
||||
$this->menuItems[] = [
|
||||
'label' => 'Beállítások',
|
||||
'url' => $this->emptyUrl,
|
||||
'items' => $items,
|
||||
'role' => [
|
||||
RoleDefinition::$ROLE_ADMIN
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Development
|
||||
/////////////////////////////
|
||||
|
||||
77
backend/controllers/SettingsController.php
Normal file
77
backend/controllers/SettingsController.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace backend\controllers;
|
||||
|
||||
use common\helpers\AppArrayHelper;
|
||||
use common\manager\PropertySettingsManager;
|
||||
use common\models\PropertySettingModel;
|
||||
|
||||
class SettingsController extends BackendController
|
||||
{
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'access' => [
|
||||
'class' => \yii\filters\AccessControl::class,
|
||||
'rules' => [
|
||||
// allow authenticated users
|
||||
[
|
||||
'actions' => [
|
||||
'index',
|
||||
],
|
||||
'allow' => true,
|
||||
'roles' => [
|
||||
'admin',
|
||||
'employee',
|
||||
'reception'
|
||||
]
|
||||
]
|
||||
]
|
||||
// everything else is denied
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Ticket models.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$settingsManager = new PropertySettingsManager();
|
||||
$settings = $settingsManager->getPropertySettings();
|
||||
$settingsMap = AppArrayHelper::objectArrayToMap($settings,
|
||||
function ($setting) {
|
||||
return $setting->definition->id;
|
||||
},
|
||||
function ($setting) {
|
||||
return $setting;
|
||||
});
|
||||
|
||||
$models = AppArrayHelper::mapValues($settings, function ($item) {
|
||||
return PropertySettingModel::fromPropertySetting($item);
|
||||
}
|
||||
);
|
||||
|
||||
if (\Yii::$app->request->isPost) {
|
||||
PropertySettingModel::loadMultiple($models, \Yii::$app->request->post());
|
||||
|
||||
foreach ($models as $model){
|
||||
if ( isset($settingsMap[$model->id_definition])){
|
||||
$setting = $settingsMap[$model->id_definition];
|
||||
$setting->setValue($model->value);
|
||||
}
|
||||
}
|
||||
|
||||
$settingsManager->saveSettings(array_values($settingsMap));
|
||||
}
|
||||
return $this->render('index', [
|
||||
'settings' => $models
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
41
backend/models/SettingsSearch.php
Normal file
41
backend/models/SettingsSearch.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use common\models\Property;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\PropertyDefinition;
|
||||
|
||||
/**
|
||||
* PropertyDefinitionSearch represents the model behind the search form about `common\models\PropertyDefinition`.
|
||||
*/
|
||||
class SettingsSearch extends Model
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
// [['id'], 'integer'],
|
||||
// [['name', 'label', 'type', 'config', 'created_at', 'updated_at'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
*
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search()
|
||||
{
|
||||
|
||||
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
42
backend/views/settings/index.php
Normal file
42
backend/views/settings/index.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/** @var common\models\PropertySettingModel[] $settings */
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
|
||||
?>
|
||||
|
||||
|
||||
<div class="room-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?php
|
||||
$index = 0;
|
||||
foreach ($settings as $setting) {
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-3">
|
||||
<?= $setting->label . ":" ?>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<?= $form->field($setting, "[$index]value")->textInput(['maxlength' => true, 'label' => false])->label(false) ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$index++;
|
||||
} ?>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton("Mentés", ['class' => 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user