yiiext / eav-behavior Goto Github PK
View Code? Open in Web Editor NEWImplements entity-attribute-value pattern.
Implements entity-attribute-value pattern.
Action for create an object::view
<?php
if(!$model->isNewRecord) $model->getEavAttributes();
foreach (['attr1', 'attr2', 'attr3'] as $name){?>
<?= $form->textAreaGroup($model,'eavAttributes['.$name.']', array('widgetOptions'=>array(
'htmlOptions'=>array('rows'=>6, 'cols'=>50)
))); ?>
<?}?>
calling this:
public function loadEavAttributes($attributes)
and now we have smth like this on empty object primary key (new entity adding):
SELECT * FROM `project_eav` `t` WHERE (object_id = ) AND (attribute IN (:ycp0, :ycp1, :ycp2))
The solution is to fix EEavBehavior:
public function loadEavAttributes($attributes) {
if(is_null($this->getModelId())){ //[+]
return $this->getOwner(); //[+]
} //[+]
I have used to getEavAttributes() function and I am not getting returned a full array if I have many rows with the same entity and attribute. The most I get in an array is 2 and then its getting overwritten with the next result as it itterate through on loadEavAttributes().
Any ideas?
Hi! I'm using this behavior but i can't make it works with OR logic.
If i want to find items with several different values of attribute at the same time, i get empty result
I think it's because several values of one attribute work like AND logic. How to switch it to OR logic?
EEavBehavior.php:211
должно быть Yii::t('yiiext', ...
а сейчас self::t('yii',...
что естественно вызывает Exception т.к. EEavBehavior::t не существует.
Сделайте чтоб getEavAttribute возвращал массив значений как в Eximus, а не первое.
How to reproduce:
$model = Model::model()->findByPk($pk);
$model->setEavAttribute('attribute', 'value');
$model->save();
Now there's two records at the EavAttr table for the same entity and attibute.
Any guidance?
TIA!
is this an active extension?
any updates?
is this good approach to design applications?
Model.php:
'eavAttr' => array(
'class' => 'application.components.behaviors.EEavBehavior',
'tableName' => 'project_eav',
'entityField' => 'project_id',
'safeAttributes' => [], //empty array! btw, I have three eav-fields for this model
'preload' => false, //preload false!
'cacheId' => 'cache'
)
i have three attributes stored in db for Model->id instance:
attribute1=OK
attribute2=OK
attribute3=OK
Now, you should turn on CMemCache etc,
then make flush_all; //!important
and use in template smth like this:
$appealText = $this->project->getEavAttribute('attribute1'); //it's OK!
$appealText = $this->project->getEavAttribute('attribute2'); //it's NULL!
$appealText = $this->project->getEavAttribute('attribute3'); //it's NULL!
Thats all folks! you have a broken cache data!
The possible solution are following:
$eavAttributes = $this->project->getEavAttributes(['attribute1','attribute2','attribute3']);
before getting the first one!
The root of evil is:
public function getEavAttribute($attribute) {
$values = $this->getEavAttributes(array($attribute)); //storing to cache only the first value!
return $this->attributes->itemAt($attribute);
}
Доброе утро!
Работаю с движком Eximus. И недавно исправлял баг Множественного выбора. Вот описание исправленного бага из трекера багов и задач Eximus'а:
После выбора множественных атрибутов, движок ищет все товары по критерию. Однако, в расширении EEavBehavior было немного другое трактование условия множественного выбора. Если пришел массив со значениями для одного атрибута, то EEavBehavior делал составной JOIN, в котором по всем значениям из массива делал склейку - т.е. это даже не точное соответствие товара всем значениям при перечислении через AND, а сложный запрос с пропорциональным количеством JOIN'ов, в каждом из которых идет проверка на соответствие.
Решение: если в EEavBehavior приходит массив со значениям для атрибута, то сделал проверку на вхождение в массив через IN.
Вот изменение в функции protected function getFindByEavAttributesCriteria($attributes){:
Было:
foreach ($values as $value) {
$value = $conn->quoteValue($value);
$criteria->join .= "\nJOIN {$this->tableName} eavb$i"
. "\nON t.{$pk} = eavb$i.{$this->entityField}"
. "\nAND eavb$i.{$this->attributeField} = $attribute"
. "\nAND eavb$i.{$this->valueField} = $value";
$i++;
}
Стало:
$valueTmpArr = array();
foreach ($values as $value) {
$valueTmpArr[] = $conn->quoteValue($value);
}
$valueInCondition = implode(',',$valueTmpArr);
$criteria->join .= "\nJOIN {$this->tableName} eavb$i"
. "\nON t.{$pk} = eavb$i.{$this->entityField}"
. "\nAND eavb$i.{$this->attributeField} = $attribute"
. "\nAND eavb$i.{$this->valueField} IN ($valueInCondition)";
$i++;
Правильно ли я понял, что именно здесь нужно было исправить и что здесь планировался такой критерий? :)
Hi, excellent extension but how we can define the attribute type?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.