public function saveWidgets($model)
 {
     if (isset($_POST['widgets'])) {
         foreach ($model->layout_widgets as $lw) {
             if (!array_key_exists($lw->id, $_POST['widgets'])) {
                 $lw->delete();
             }
         }
         $count = count($_POST['widgets']);
         foreach ($_POST['widgets'] as $index => $widget) {
             if ($index == 'copyMe') {
                 continue;
             }
             $layoutWidget = SystemLayoutsWidgets::model()->findByPk($index, 'layout_id = :layout_id', array(':layout_id' => $model->id));
             if ($layoutWidget) {
                 $layoutWidget->attributes = $widget;
                 $layoutWidget->save();
             } else {
                 $newLayoutWidget = new SystemLayoutsWidgets();
                 $newLayoutWidget->attributes = $widget;
                 $newLayoutWidget->layout_id = $model->id;
                 $newLayoutWidget->save();
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function runLayout($position)
 {
     $route = $this->module->id . "/" . $this->id . "/" . $this->action->id;
     $layout = SystemLayouts::model()->orderById()->find(':route LIKE route', array(':route' => $route));
     $layoutWidgets = SystemLayoutsWidgets::model()->sort()->findAll('layout_id = :layout_id AND position = :position', array(':layout_id' => $layout->id, ':position' => $position));
     foreach ($layoutWidgets as $layoutWidget) {
         $widget = $layoutWidget->widget;
         if ($widget) {
             $this->widget($widget->class, $widget->getParams());
         }
     }
 }
Ejemplo n.º 3
0
<?php

// Register scripts
Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/admin/layouts.widgets.js', CClientScript::POS_END);
$newWidget = new SystemLayoutsWidgets();
?>

<style type="text/css">
    table.widgetsEditTable td,th {
        padding: 3px;
    }
    table.widgetsEditTable th{
        font-weight: bold;
    }
    table.widgetsEditTable input[type="text"] {
        width: 200px;
    }
    table.widgetsEditTable tr.copyMe {
        display: none;
    }
    table.widgetsEditTable {
    }
    table.widgetsEditTable td.desc-column{
        width: 35%;
    }
</style>

<div class="row">
    <button class="btn j-widget-add"><?php 
echo Yii::t('main', 'Добавить');
?>