Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CharacteristicModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'idCategory' => $this->idCategory]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'value', $this->value]);
     return $dataProvider;
 }
Пример #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCharacteristics()
 {
     return $this->hasMany(CharacteristicModel::className(), ['idCategory' => 'id']);
 }
Пример #3
0
/* @var $model app\models\CharacteristicValueModel */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="characteristic-value-model-form">

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

    <?php 
echo $form->field($model, 'idProduct')->dropDownList(ArrayHelper::map(ProductModel::find()->all(), 'id', 'name'));
?>

    <?php 
echo $form->field($model, 'idCharacteristic')->dropDownList(ArrayHelper::map(CharacteristicModel::find()->all(), 'id', 'name'));
?>

    <?php 
echo $form->field($model, 'value')->textInput(['maxlength' => 50]);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>
Пример #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdCharacteristic0()
 {
     return $this->hasOne(CharacteristicModel::className(), ['id' => 'idCharacteristic']);
 }
Пример #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdCharacteristics()
 {
     return $this->hasMany(CharacteristicModel::className(), ['id' => 'idCharacteristic'])->viaTable('{characteristic_value}', ['idProduct' => 'id']);
 }
Пример #6
0
    <!-- <?php 
echo $form->field($model, 'amountRated')->textInput();
?>
 -->

    <?php 
echo $form->field($model, 'idCategory')->dropDownList(ArrayHelper::map(CategoryModel::find()->all(), 'id', 'name'), ['readonly' => isset($model['idCategory'])]);
?>

    <?php 
if (isset($model['idCategory']) && isset($model['id'])) {
    if (isset($model->idCategory)) {
        $characteristics = CharacteristicModel::find()->where(['idCategory' => $model['idCategory']])->all();
        $category = CategoryModel::find()->where(['id' => $model['idCategory']])->one();
        while ($category['parentId'] != null) {
            $temp = CharacteristicModel::find()->where(['idCategory' => $category['parentId']])->all();
            foreach ($temp as $temp_char) {
                $characteristics[] = $temp_char;
            }
            $category = CategoryModel::find()->where(['id' => $category['parentId']])->one();
        }
    }
    $counter = 0;
    foreach ($characteristics as $characteristic) {
        $char_model = CharacteristicValueModel::find()->where(['idProduct' => $model['id'], 'idCharacteristic' => $characteristic->id])->one();
        if ($char_model == null) {
            $char_model = new CharacteristicValueModel();
            $char_model->idProduct = $model['id'];
            $char_model->idCharacteristic = $characteristic->id;
        }
        echo Html::activeHiddenInput($char_model, "[{$counter}]idProduct");
Пример #7
0
 /**
  * Finds the CharacteristicModel model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CharacteristicModel the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CharacteristicModel::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }