/** * @return array of available attributes in category */ public function getEavAttributes() { if (is_array($this->_eavAttributes)) { return $this->_eavAttributes; } // Find category types /*$model = new Products(null); $criteria = $model ->applyCategories($this->model) ->active() ->withcity() ->getDbCriteria(); unset($model); $builder = new CDbCommandBuilder(Yii::app()->db->getSchema()); $criteria->select = 'type_id'; $criteria->group = 'type_id'; $criteria->distinct = true; $typesUsed = $builder->createFindCommand(Products::model()->tableName(), $criteria)->queryColumn();*/ $typesUsed[] = 1; $typesUsed[] = 2; // Find attributes by type $criteria = new CDbCriteria(); // $criteria->addInCondition('types.type_id', $typesUsed); $query = EavOptions::model()->with(array('options'))->findAll($criteria); $this->_eavAttributes = array(); if (!empty($query)) { foreach ($query as $attr) { $this->_eavAttributes[$attr->id] = $attr; } } return $this->_eavAttributes; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return City the loaded model * @throws CHttpException */ public function loadModel($id) { $model=EavOptions::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }
/** * @param $attributeId * @param $value * @param Objects $product * @return bool */ public function store($attributeId, $value, Objects $product, $forcheck = false) { $attribute = null; if (!isset($this->attributes[$attributeId])) { $attribute = EavOptions::model()->findByPk($attributeId); $this->attributes[$attributeId] = $attribute; } else { $attribute = $this->attributes[$attributeId]; } switch ($attribute->type) { case EavOptions::TYPE_DROPDOWN: $this->option_id = empty($value) ? null : (int)$value; break; case EavOptions::TYPE_CHECKBOX_LIST: $this->option_id = empty($value) ? null : (int)$value; $this->value = $this->option_id; break; /* case EavOptions::TYPE_CHECKBOX: $this->value = (bool)$value; break; case EavOptions::TYPE_NUMBER: $this->number_value = empty($value) ? null : (float)$value; break;*/ case EavOptions::TYPE_TEXT: $this->value = $value; break; /* case EavOptions::TYPE_SHORT_TEXT: $this->string_value = $value; break;*/ default: throw new InvalidArgumentException('Error attribute!'); } $this->product_id = $product->id; $this->attribute_id = $attribute->id; if($forcheck == true){ return $this->validate(); } else { return $this->save(); } }
/** * @return array of used attribute models */ public function getModels() { if(is_array($this->_models)) return $this->_models; $this->_models = array(); $cr = new CDbCriteria; $cr->addInCondition('t.id', array_keys($this->_attributes)); $query = EavOptions::model() // ->displayOnFront() ->with(array('options')) ->findAll($cr); foreach($query as $m){ $this->_models[$m->name] = $m; } return $this->_models; }
$selected = in_array($item->id, $selectedAttributes); if (!$selected) { $groupHasNotSelectedAttribute = true; } $items[] = ['text' => CHtml::tag('div', ['class' => 'checkbox treecheck'], CHtml::label(CHtml::checkBox('attributes[]', $selected, ['value' => $item->id]) . $item->title, null))]; } $tree[] = [ 'text' => CHtml::tag( 'div', ['class' => 'checkbox treecheck'], CHtml::label(CHtml::checkBox('', count($groupItems) && !$groupHasNotSelectedAttribute, ['class' => 'group-checkbox']) . $group->name, null) ), 'children' => $items ]; } foreach ((array)EavOptions::model()->findAllByAttributes(array('group_id' => null),array('order'=>'title')) as $attribute) { $tree[] = array( 'text' => CHtml::tag( 'div', array('class' => 'checkbox treecheck'), CHtml::label(CHtml::checkBox('attributes[]', in_array($attribute->id, $selectedAttributes), ['value' => $attribute->id]) . $attribute->title, null) ) ); } ?> <div class="col-md-1 col-sm-2"></div> <div class="col-md-11 col-sm-10"> <div class="panel panel-default"> <div class="panel-heading"> <?php echo 'Атрибуты'; ?> </div>
protected function checkUniqueUrl($unique){ // Check if url available if($this->isNewRecord) { $test = EavOptions::model() ->withName($unique) ->count(); } else { $test = EavOptions::model() ->withName($unique) ->count('id!=:id', array(':id'=>$this->id)); } return $test; }