Example #1
0
 /**
  * @return string
  */
 public function run()
 {
     if (Yii::$app->request->isPost) {
         $setting = Yii::$app->request->post('Setting');
         if (isset($_FILES['Setting'])) {
             foreach ($_FILES['Setting']['name'] as $key => $value) {
                 $model = Setting::findOne(['code' => $key]);
                 $model->file = UploadedFile::getInstance($model, $key);
                 if ($model->file != null && $model->upload()) {
                     $model->updateAttributes(['value' => $value]);
                 }
             }
         }
         if ($setting != null) {
             foreach ($setting as $key => $value) {
                 if ($value !== '' || $value != null) {
                     if (is_array($value)) {
                         Setting::updateAll(['value' => implode(",", $value)], ['code' => $key]);
                     } else {
                         Setting::updateAll(['value' => $value], ['code' => $key]);
                     }
                 }
             }
         }
         Yii::$app->session->setFlash('alert', ['body' => Yii::t('setting', 'Settings has been successfully saved'), 'options' => ['class' => 'alert-success']]);
     }
     if (Module::hasMultiLanguage()) {
         $title = Translate::setting();
     } else {
         $title = Yii::t('setting', 'Setting');
     }
     $currentSetting = Setting::findOne(['code' => $this->id]);
     return $this->controller->render('index', ['title' => $title, 'code' => $currentSetting !== null ? $currentSetting->code : null]);
 }
Example #2
0
 /**
  * Return Icon class name
  *
  * @param string $code
  * @param string $default
  *
  * @return string
  * @throws InvalidConfigException
  */
 public function getIcon($code, $default = '')
 {
     if (!$code) {
         return $default;
     }
     $setting = SettingModel::findOne(['code' => $code]);
     if ($setting && in_array($setting->type, [SettingModel::TYPE_ACTION, SettingModel::TYPE_GROUP])) {
         return $setting->icon;
     } else {
         return $default;
     }
 }
 public function safeUp()
 {
     $this->alterColumn('{{%setting}}', 'type', \yii\db\mysql\Schema::TYPE_STRING . '(255) NOT NULL');
     /**@var Setting[] $settings */
     $settings = Setting::find()->all();
     $type = array_keys(Setting::TYPE);
     foreach ($settings as $setting) {
         foreach ($type as $key => $item) {
             if ($setting->type == $key - 1) {
                 $setting->updateAttributes(['type' => $item]);
             }
         }
     }
 }
Example #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Setting::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'type' => $this->type, 'sort_order' => $this->sort_order]);
     $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'desc', $this->desc])->andFilterWhere(['like', 'store_range', $this->store_range])->andFilterWhere(['like', 'store_dir', $this->store_dir])->andFilterWhere(['like', 'value', $this->value]);
     return $dataProvider;
 }
Example #5
0
 /**
  * @param null $code
  *
  * @return array
  */
 public static function getItems($code = null)
 {
     /**@var $parentSettings self[] */
     $items = [];
     if ($code == null) {
         $parentSettings = Setting::find()->where(['parent_id' => 0, 'type' => self::TYPE_GROUP])->orderBy(['sort_order' => SORT_ASC])->all();
     } else {
         $currentSetting = self::findOne(['code' => $code]);
         if ($currentSetting !== null) {
             $parentSettings = Setting::find()->where(['parent_id' => $currentSetting->id, 'type' => self::TYPE_GROUP])->orderBy(['sort_order' => SORT_ASC])->all();
         } else {
             $parentSettings = Setting::find()->where(['parent_id' => 0, 'type' => self::TYPE_GROUP])->orderBy(['sort_order' => SORT_ASC])->all();
         }
     }
     foreach ($parentSettings as $parentSetting) {
         $content = Html::beginForm('', 'POST', ['class' => 'form-horizontal', 'id' => 'nava-setting-form', 'enctype' => 'multipart/form-data']);
         $content .= $parentSetting->getContent();
         $content .= Html::beginTag('div', ['class' => 'form-group']);
         $content .= Html::beginTag('div', ['class' => 'col-sm-9 col-sm-offset-3']);
         $content .= Html::submitButton(Yii::t('setting', 'Save'), ['class' => 'btn btn-success']);
         $content .= Html::endTag('div');
         $content .= Html::endTag('div');
         $content .= Html::endForm();
         $items[] = ['label' => ($parentSetting->icon != '' ? '<span class="glyphicon ' . $parentSetting->icon . '"></span> ' : '') . $parentSetting->getName(), 'content' => $content];
     }
     return $items;
 }
Example #6
0
/**
 * @var $this  View
 * @var $title string
 * @var $code  string
 */
AwesomeBootstrapCheckboxAsset::register($this);
$this->title = $title;
$this->params['breadcrumbs'][] = $this->title;
$items = [];
if (Yii::$app->session->hasFlash('alert')) {
    echo Alert::widget(Yii::$app->session->getFlash('alert'));
}
?>
<div class="navatech-setting">
	<div class="col-sm-12">
		<?php 
if (YII_ENV_DEV) {
    ?>
			<p class="pull-right">
				<?php 
    echo Html::a(Yii::t('setting', 'Setting'), ['config/index'], ['class' => 'btn btn-primary']);
    ?>
			</p>
		<?php 
}
?>
		<?php 
echo TabsX::widget(['items' => Setting::getItems($code), 'bordered' => true, 'position' => TabsX::POS_ABOVE, 'encodeLabels' => false]);
?>
	</div>
</div>
Example #7
0
use navatech\setting\models\Setting;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model Setting */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="setting-form">

	<?php 
$form = ActiveForm::begin();
?>

	<?php 
echo $form->field($model, 'parent_id')->widget(Select2::className(), ['data' => Setting::parentDependent(), 'options' => ['placeholder' => Yii::t('setting', 'Select a parent tab ...')], 'pluginOptions' => ['allowClear' => true]]);
?>

	<?php 
echo $form->field($model, 'code')->textInput(['maxlength' => true, 'placeholder' => Yii::t('setting', 'Code key of setting')]);
?>
	<?php 
echo $form->beginField($model, 'name');
?>
	<?php 
echo Html::activeLabel($model, 'name', ['class' => 'control-label']);
?>
	<?php 
if (in_array($model->type, [Setting::TYPE_GROUP, Setting::TYPE_ACTION])) {
    ?>
		<div class="input-group">
 /**
  * Finds the Setting model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Setting the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Setting::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #9
0
use yii\web\View;
$this->title = Yii::t('setting', 'Setting');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="navatech-setting">
	<div class="col-sm-12">
		<div class="setting-index">
			<h1><?php 
echo Html::encode($this->title);
?>
</h1>
			<p>
				<?php 
echo Html::a(Yii::t('setting', 'Create Setting'), ['create'], ['class' => 'btn btn-success']);
?>
			</p>
			<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'export' => false, 'pjax' => true, 'hover' => true, 'bordered' => true, 'striped' => true, 'condensed' => true, 'responsive' => true, 'persistResize' => false, 'panel' => ['type' => 'primary', 'heading' => Yii::t('setting', 'Setting configure')], 'containerOptions' => ['style' => 'overflow: auto'], 'headerRowOptions' => ['class' => 'kartik-sheet-style'], 'filterRowOptions' => ['class' => 'kartik-sheet-style'], 'columns' => [['class' => 'kartik\\grid\\SerialColumn'], ['class' => 'kartik\\grid\\ExpandRowColumn', 'value' => function (Setting $model, $key, $index, $column) {
    return GridView::ROW_COLLAPSED;
}, 'detail' => function (Setting $model, $key, $index, $column) {
    return Yii::$app->controller->renderPartial('_view', ['model' => $model]);
}, 'headerOptions' => ['class' => 'kartik-sheet-style'], 'expandOneOnly' => true], ['attribute' => 'parent_id', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Setting::find()->where(['type' => 0, 'parent_id' => 0])->orderBy(['sort_order' => SORT_ASC])->all(), 'id', 'name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => Yii::t('setting', 'Parent tab')], 'value' => function (Setting $data) {
    $parent = $data->findOne($data->parent_id);
    return $parent !== null ? $parent->getName() : '';
}], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'code'], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'name'], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'type', 'filterType' => GridView::FILTER_SELECT2, 'filter' => Setting::TYPE, 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => Yii::t('setting', 'Type')], 'value' => function (Setting $data) {
    return Setting::TYPE[$data->type];
}, 'refreshGrid' => true, 'editableOptions' => ['inputType' => Editable::INPUT_DROPDOWN_LIST, 'data' => Setting::TYPE]], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'sort_order'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update}&nbsp;{delete}']]]);
?>
		</div>
	</div>
</div>