Пример #1
0
 public function run($id)
 {
     $model = EavAttributeExtended::model()->findByPk($id);
     if (is_null($model)) {
         throw new CHttpException(404);
     }
     $request = Yii::app()->request;
     $formName = get_class($model);
     $validator = new BaseValidatorForm();
     $validator->setAttribute($model);
     if (is_null($request->getPost($formName))) {
         $this->controller->render('update', array('model' => $model, 'validator' => $validator));
         Yii::app()->end();
     }
     $validator->setValidatorInputs($_POST);
     $attributes = $request->getPost($formName);
     $model->attributes = $attributes;
     $model->setRules($validator->getRules());
     $model->setValues($attributes['values']);
     if ($model->validate() && empty($model->validatorErrors)) {
         $model->assignPossibleValues();
         if ($model->save(false)) {
             Yii::app()->getComponent('user')->setFlash('success', Yii::t('EavModule.eavactiverecord', 'The attribute has been successfully updated'));
             $this->controller->render('update', array('model' => $model, 'validator' => $validator));
             Yii::app()->end();
         }
     }
     Yii::app()->getComponent('user')->setFlash('error', Yii::t('EavModule.eavactiverecord', 'A validation error has occurred while processing your request'));
     $this->controller->render('update', array('model' => $model, 'validator' => $validator));
 }
 public function loadModel($id)
 {
     if (($model = EavAttributeExtended::model()->findByPk($id)) === null) {
         throw new CHttpException(404, Yii::t('EavModule.eav', 'Page was not found!'));
     }
     return $model;
 }
 public function loadModel($id)
 {
     if (($model = EavAttributeExtended::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }
Пример #4
0
 public function run()
 {
     $criteria = new CDbCriteria();
     $pages = new CPagination(EavAttributeExtended::model()->count());
     $pages->pageSize = $this->getController()->getModule()->getItemsPerPage();
     $pages->applyLimit($criteria);
     $sort = new CSort('EavAttributeExtended');
     $sort->attributes = array('id', 'name', 'label', 'type', 'data_type');
     $sort->applyOrder($criteria);
     $model = EavAttributeExtended::model()->findAll($criteria);
     $this->controller->render('index', array('model' => $model, 'sort' => $sort, 'pages' => $pages));
 }
Пример #5
0
 public function actionAjaxAttributeValues($attrs, $term, $typeId = 0)
 {
     if (Yii::app()->request->isAjaxRequest) {
         // Получаем список доступных атрибутов для поиска
         $searchAddressAttributes = [];
         foreach (RealtyItem::$searchAddressAttributes as $section) {
             $searchAddressAttributes = array_merge($searchAddressAttributes, $section['attributes']);
         }
         // Проверяем переданный список атрибутов на корректность
         $attrs = explode(',', $attrs);
         foreach ($attrs as &$attr) {
             $attr = trim($attr);
             if (!in_array($attr, $searchAddressAttributes)) {
                 unset($attr);
             }
         }
         $criteria = new CDbCriteria();
         $criteria->addInCondition('t.name', $attrs);
         $attributes = EavAttributeExtended::model()->findAll($criteria);
         $values = [];
         foreach ($attributes as $attribute) {
             $class = EavValue::model($attribute->data_type);
             $valueField = $class->valueField;
             $criteria = new CDbCriteria();
             $criteria->join = 'LEFT JOIN ' . RealtyItem::model()->tableName() . ' r ON t.entity_id = r.id';
             $criteria->distinct = true;
             $criteria->select = 't.' . $valueField;
             if (!empty($typeId)) {
                 $criteria->compare('r.type_id', (int) $typeId);
             }
             $criteria->compare('t.eav_attribute_id', $attribute->id);
             $criteria->compare('r.status', RealtyItem::STATUS_ACTIVE);
             $criteria->addCondition('t.' . $valueField . ' LIKE :term');
             $criteria->params[':term'] = '%' . $term . '%';
             $criteria->order = 't.' . $valueField . ' ASC';
             $models = EavValue::model()->findAll($criteria);
             foreach ($models as $model) {
                 $values[] = $model->{$valueField};
             }
         }
         sort($values);
         echo CJSON::encode($values);
         Yii::app()->end();
     }
 }
Пример #6
0
<div class="row">
    <div class="col-sm-<?php 
echo isset($width) ? $width : 4;
?>
">
        <?php 
if ($attr->isMultivalued()) {
    $value = is_array($model->{$attr->name}) ? implode(", ", $model->{$attr->name}) : $model->{$attr->name};
    $model->{$attr->name} = $value;
    echo $form->select2Group($model, $attr->name, ['widgetOptions' => ['asDropDownList' => false, 'options' => ['tags' => []]]]);
} else {
    if ($attr->autocomplete) {
        echo $form->typeAheadGroup($model, $attr->name, ['widgetOptions' => ['datasets' => ['source' => EavAttributeExtended::model()->getValuesList($attr->id)]]]);
    } else {
        echo $form->textFieldGroup($model, $attr->name);
    }
}
?>
    </div>
</div>
Пример #7
0
<?php 
echo $form->errorSummary($model);
?>

<div class="row">
    <div class="col-sm-7">
        <?php 
echo $form->textFieldGroup($model, 'name');
?>
    </div>
</div>
<div class="row">
    <div class="col-sm-7">
        <?php 
echo $form->checkBoxListGroup($model, 'attachedEavAttributes', ['widgetOptions' => ['data' => EavAttributeExtended::model()->list]]);
?>
    </div>
</div>

<br/><br/>

<?php 
$this->widget('bootstrap.widgets.TbButton', ['buttonType' => 'submit', 'context' => 'primary', 'label' => $model->isNewRecord ? Yii::t('EavModule.eav', 'Create and continue') : Yii::t('EavModule.eav', 'Save and continue')]);
?>

<?php 
$this->widget('bootstrap.widgets.TbButton', ['buttonType' => 'submit', 'htmlOptions' => ['name' => 'submit-type', 'value' => 'index'], 'label' => $model->isNewRecord ? Yii::t('EavModule.eav', 'Create and close') : Yii::t('EavModule.eav', 'Save and close')]);
?>

<?php 
Пример #8
0
            <span class="help-block">
            <?php 
echo $form->error($model, 'attachedEavAttributes', array('class' => 'label label-danger'));
?>
            </span>
        </div>
    </div>

<?php 
if (!empty($model->eavAttributes)) {
    ?>
    <?php 
    $counter = 0;
    ?>
    <?php 
    $attributeExtended = EavAttributeExtended::model();
    ?>
    <br>
    <h5><?php 
    echo Yii::t('EavModule.eavactiverecord', 'Attached EAV attributes');
    ?>
</h5>
    <span class="h6 text-muted"><span class="glyphicon glyphicon-info-sign"></span>  &nbsp;<?php 
    echo Yii::t('EavModule.eavactiverecord', 'You can reorder attributes by simply dragging them with your mouse');
    ?>
</span>
    <div class="clearfix"></div>
    <hr>
    <table class="table table-striped">
        <thead>
        <th class="col-md-1">#</th>
Пример #9
0
    <?php 
echo $form->errorSummary($model);
?>

    <div class='control-group <?php 
echo $model->hasErrors("name") ? "error" : "";
?>
'>
        <?php 
echo $form->textFieldRow($model, 'name', array('class' => 'span7', 'maxlength' => 250));
?>
    </div>

    <div class='row-fluid control-group'>
        <?php 
echo $form->checkBoxListRow($model, 'attachedEavAttributes', EavAttributeExtended::model()->list);
?>
    </div>

    <?php 
if (!$model->isNewRecord && !empty($model->eavAttributes)) {
    ?>
        <?php 
    $dataProvider = new CArrayDataProvider($model->eavAttributes, array('pagination' => false));
    $this->widget('zii.widgets.grid.CGridView', array('id' => 'attributes-grid', 'dataProvider' => $dataProvider, 'rowCssClassExpression' => '"items[]_{$data->id}"', 'columns' => array(array('header' => 'Атрибут', 'name' => 'name'), array('header' => 'Название', 'name' => 'label'))));
    ?>
        <?php 
    echo $this->renderPartial('_sortable', array('model' => $model));
    ?>
    <?php 
}
 public function getValuesList($attributeId)
 {
     $attribute = EavAttributeExtended::model()->findByPK($attributeId);
     if (is_null($attribute)) {
         return [];
     }
     $class = EavValue::model($attribute->data_type);
     $valueField = $class->valueField;
     $models = EavValue::model()->findAllByAttributes(['eav_attribute_id' => $attributeId], ['select' => 't.' . $valueField, 'order' => 't.' . $valueField . ' ASC', 'distinct' => true]);
     $values = [];
     foreach ($models as $model) {
         $values[] = $model->{$valueField};
     }
     return $values;
 }