public function actionSort($id) { $set = $this->loadModel($id); if (isset($_POST['items']) && is_array($_POST['items'])) { $i = 10; foreach ($_POST['items'] as $item) { $elem = EavAttributeToSet::model()->findByPk(array('eav_attribute_id' => $item, 'eav_set_id' => $id)); $elem->weight = $i; $elem->save(); $i += 10; } } }
/** * Метод выполняемый перед удалением: * * @return void */ public function beforeDelete() { EavAttributeToSet::model()->deleteAllByAttributes(array('set_id' => $this->id)); return parent::beforeDelete(); }
<?php $this->breadcrumbs = [Yii::t('EavModule.eav', 'EAV'), Yii::t('EavModule.eav', 'Группы') => ['/eav/setBackend/index'], Yii::t('EavModule.eav', 'Атрибуты EAV')]; $this->pageTitle = Yii::t('EavModule.eav', 'Группы - атрибуты'); $this->menu = $this->getModule()->getSetModelNavigation($model); ?> <div class="page-header"> <h1> <?php echo Yii::t('EavModule.eav', 'Атрибуты группы'); ?> <br /> <small>«<?php echo $model->name; ?> »</small> </h1> </div> <?php if (!$model->isNewRecord) { ?> <?php $this->widget('yupe\\widgets\\BackendGridView', ['id' => 'attributes-grid', 'type' => 'condensed', 'dataProvider' => $attrToSet->search(), 'actionsButtons' => false, 'columns' => [['header' => 'Атрибут', 'name' => 'name', 'type' => 'raw', 'value' => '$data->eavAttribute->name'], ['header' => 'Название', 'name' => 'label', 'type' => 'raw', 'value' => '$data->eavAttribute->label'], ['class' => 'yupe\\widgets\\columns\\EditableStatusColumn', 'name' => 'inshort', 'source' => EavAttributeToSet::model()->booleanStatusList, 'url' => $this->createUrl('/eav/setBackend/inlineAttributes'), 'sortable' => false, 'options' => [EavAttributeToSet::BOOLEAN_YES => ['class' => 'label-success'], EavAttributeToSet::BOOLEAN_NO => ['class' => 'label-default']]], ['class' => 'yupe\\widgets\\columns\\EditableStatusColumn', 'name' => 'inmedium', 'source' => EavAttributeToSet::model()->booleanStatusList, 'url' => $this->createUrl('/eav/setBackend/inlineAttributes'), 'sortable' => false, 'options' => [EavAttributeToSet::BOOLEAN_YES => ['class' => 'label-success'], EavAttributeToSet::BOOLEAN_NO => ['class' => 'label-default']]], ['class' => 'yupe\\widgets\\columns\\EditableStatusColumn', 'name' => 'infull', 'source' => EavAttributeToSet::model()->booleanStatusList, 'url' => $this->createUrl('/eav/setBackend/inlineAttributes'), 'sortable' => false, 'options' => [EavAttributeToSet::BOOLEAN_YES => ['class' => 'label-success'], EavAttributeToSet::BOOLEAN_NO => ['class' => 'label-default']]], ['class' => 'yupe\\widgets\\columns\\EditableStatusColumn', 'name' => 'in_main_filter', 'source' => EavAttributeToSet::model()->booleanStatusList, 'url' => $this->createUrl('/eav/setBackend/inlineAttributes'), 'sortable' => false, 'options' => [EavAttributeToSet::BOOLEAN_YES => ['class' => 'label-success'], EavAttributeToSet::BOOLEAN_NO => ['class' => 'label-default']]], ['class' => 'yupe\\widgets\\columns\\EditableStatusColumn', 'name' => 'in_advanced_filter', 'source' => EavAttributeToSet::model()->booleanStatusList, 'url' => $this->createUrl('/eav/setBackend/inlineAttributes'), 'sortable' => false, 'options' => [EavAttributeToSet::BOOLEAN_YES => ['class' => 'label-success'], EavAttributeToSet::BOOLEAN_NO => ['class' => 'label-default']]], ['class' => 'yupe.widgets.columns.CustomEditableColumn', 'name' => 'weight', 'htmlOptions' => ['style' => 'width:80px'], 'sortable' => false, 'editable' => ['url' => $this->createUrl('/eav/setBackend/inlineAttributes'), 'success' => 'js: function(response, newValue) { $.fn.yiiGridView.update("attributes-grid"); }']]]]); ?> <?php }
/** * Метод выполняемый перед удалением: * * @return void */ public function beforeDelete() { // Удаляем связь с группами EavAttributeToSet::model()->deleteAllByAttributes(['eav_attribute_id' => $this->id]); // Удаляем значения атрибутов EavValue::model()->deleteAllByAttributes(['eav_attribute_id' => $this->id]); foreach ($this->variants as $variant) { $variant->delete(); } return parent::beforeDelete(); }