예제 #1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getWidgetAreas()
 {
     return $this->hasMany(WidgetArea::className(), ['template_id' => 'id']);
 }
예제 #2
0
/* @var $model im\cms\models\widgets\WidgetArea */
/* @var $widgetArea im\cms\backend\widgets\WidgetArea */
/* @var $form yii\widgets\ActiveForm|im\forms\components\DynamicActiveForm */
$model->id = $model->isNewRecord ? $model->code : $model->id;
?>

<h4><?php 
echo $model->title;
?>
</h4>

<?php 
if ($model->display == WidgetArea::DISPLAY_ALWAYS) {
    echo $form->field($model, "[{$model->id}]display")->hiddenInput()->label(false);
} else {
    echo $form->field($model, "[{$model->id}]display")->dropDownList(WidgetArea::getDisplayOptions(), ['data-action' => 'display']);
}
?>

<?php 
echo $form->field($model, "[{$model->id}]code")->hiddenInput()->label(false);
?>

<?php 
echo Html::beginTag('div', $widgetArea->dropAreaOptions);
if ($widgets = $model->widgets) {
    foreach ($widgets as $index => $widget) {
        echo $this->render('/widget-area/_selected_widget', ['widget' => $widget, 'form' => $form, 'widgetArea' => $model, 'index' => $index + 1]);
    }
} else {
    ?>
예제 #3
0
 /**
  * Gets widgets areas from data array.
  *
  * @param array $data
  * @param string $formName
  * @return WidgetArea[]
  */
 protected function getWidgetAreas($data, $formName = null)
 {
     if ($formName === null) {
         $area = new WidgetArea();
         $formName = $area->formName();
     }
     $areas = [];
     if (!empty($data[$formName])) {
         $pks = [];
         foreach ($data[$formName] as $key => $areaData) {
             if (is_string($key)) {
                 $areas[$key] = new WidgetArea();
             } else {
                 $pks[] = $key;
             }
         }
         if ($pks) {
             $areas = $areas + WidgetArea::find()->where(['id' => $pks])->indexBy('id')->all();
         }
     }
     return $areas;
 }
예제 #4
0
 /**
  * @return \im\cms\models\widgets\WidgetArea
  */
 protected function loadModel()
 {
     $condition = ['code' => $this->code];
     $condition['template_id'] = $this->template ? $this->template->id : null;
     return WidgetAreaModel::findOne($condition);
 }