GithubHelp home page GithubHelp logo

yii2-taggable's People

Contributors

antonkomarev avatar creocoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-taggable's Issues

Tags i18n

It's just an idea for a far future. Have you ever thought about tags internalization? Because there are a lot of multilingual projects, but tags are usually in one language.

Choosing of package

Hello, Alexander.

I'm now choosing taggable system for a new one project.
What's the main difference between your package and this one?
I saw that you are supporting both of them.

Thanks in advance.

problem in beforeDelete

its better to check whether the owner model has error or not before reducing frequency and deleting all relations. because if some behaviors wants to attach error on owner and they registered before TaggableBehavior and reject deleting for some reasons, when deleting is perform the owner model stay live but all relations gone.
something like this in beforeDelete() :
if ($this->owner->hasErrors()) { return; }
we can also think about doing this afterDelete event.

Array to string conversion

@creocoder I'm not sure about best solution of this issue after last changes: #5

I'm using this behavior config:

[
    'class' => TaggableBehavior::className(),
    'tagNamesAsArray' => true,
],

In view actions everything working well. But it broke my input widget.

Array to string conversion

<?= $form->field($model, 'tagNames')->textInput() ?>

How to change behavior's config only for update/create actions in controller or in model? Or how to deal with it?

Otherwise we need always have tagNamesAsArray => false and only set it in true state when there is a need. Like this:

<?php foreach ($model->getTagNames(true) as $tag) : ?>
    <?= Html::a($tag, ['/tag/' . $tag]) ?>
<?php endforeach ?>

Extension doesn't works if relation is defined by 'via', not 'viaTable'

My AR looks like that:

public function getItemTagRelations()
{
    return $this->hasMany(ItemTagRelation::className(), ['item_id' => 'item_id']);
}

public function getTags()
{
    return $this->hasMany(Tag::className(), ['tag_id' => 'tag_id'])
        ->via('itemTagRelations');
}

and i getting the error below:

screenshot 2016-02-12 15 38 47

Tags with different categories

Such taggable behaviors are a convenient way to store information for attributes that can take an array of values. And sometimes it is convenient to store information about different attributes in the same table using a special column to distinguish, say, category. What would be very useful if this extension allowed to work (save, load, search etc) with multiple tag categories defined for the same model.

This functionality was available in Yii1 through taggable extension by @samdark and was very useful.

You could potentially build on top of existing approach by attaching multiple TaggableBehavior behaviors, one per tag category, and adding a specific where clause like ->where('category = :category', [':category' => $category]); to each relation. But it has certain problems:

  • TaggableQueryBehavior right now does not distinguish between owner's behaviors and uses $model->tagRelation which would reference a relation from the first bahavior it finds instead of the one we need.
  • When saving tags, would be nice if tag category was saved automatically. This was handled by insertValues property in Yii1 taggable extension.
  • Yii1 taggable extension also provided useful methods like getAllTagsWithModelsCount, but this is less critical.

Brainstorm on tag nesting

Is there tags nesting support planned?
Like:

Furniture
|- Table
|  |- Coffee table

And availability to work with tags like with categories. Step-by-step choosing tags: If you have chosen Furniture - you can only choose next tag only from Furniture children.

That way of tags suppose restricting creation of new tags by users automatically (or premoderate them).

Create `TaggableBehavior::relatedByTagNames` scope

MP: lets take this example
Post1 has tag1, tag2, tag3
Post2 has tag1, tag2
post3 has tag1, tag2, tag3
post4 has tag1

post 1 has more in common with post3 then with anything else
then it has partially somethings in common with post2, the last one is post4
if you ever want to show related posts with post1, the order that you need to show is post3, post2, post4

so what I am proposing besides the power of your tag search is to have a related posts relation maybe directly in the behavior, that would take all of the post1 tags, select from the relation table all of the post that have those, make a grouping on post_id and a count on tag_id, order by count(tag_id) and return the posts based on the post_id column
MP: I am not sure it is possible directly in the behavior
AK: I think its possible by TaggableQuery
AK: Just need to think about implementation.
AK: And method name.
AK: I mean it should be scope.
AK: Like tag()
AK: But need to think about that scope name.
AK: Maybe recent()
MP: just some food for thought
AK: Can you create issue with that?
MP: ok, sure
AK: To not forget implement it as future plans.
AK: Because it very serious and interesting feature.
AK: Moreover since behavior is entity related it 100% possible
AK: relatedByTags() maybe...
AK: But we need to think about optimal implementation on SQL level.
MP: we might need too much info put in the behavior...
AK: It will looks like:

Post::find()->relatedByTags(... tags here...)->all();
$post->relatedByTags(... no params here...)->all();

Problems with the new "alias" function (Yii 2.0.7)

Hi,
there is an issue with the new alias() function in Yii 2.0.7.

If you use an alias for the primary table the function anyTagValuesin the class TaggableQueryBehavior returns an error.

I think you should change the function in this way:

public function anyTagValues($values, $attribute = null)
    {
        $model = new $this->owner->modelClass();
        $query = $this->owner;
        $tagClass = $model->getRelation($model->tagRelation)->modelClass;

        $this->owner
            ->innerJoinWith($model->tagRelation, false)
            ->andWhere([$tagClass::tableName() . '.' . ($attribute ?: $model->tagValueAttribute) => $model->filterTagValues($values)])
            ->addGroupBy(array_map(function ($pk) use ($model,$query) {
                return array_search($model->tableName(),$query->from) . '.' . $pk;
            }, $model->primaryKey()));

        return $this->owner;
    }

You don't have to get the table name from $model->tableName()but from the $from variable in the ActiveQuery object.

regards

Taggable behavior to use Redis or any other in-memory database

I just tried to have taggable behavior for an yii/redis/activerecord, but it was clear that it won't work since yii/redis/activerecord does not support viaTable() in queries.

I believe its reasonable to use in-memory databases to implement some features that have m2m relations. Taggable behavior is a good case, since it is a m2m relation, data values are short and also searching for tags is a frequent operation throughout application lifetime.
This will make a huge improvement in application performance, so why not to make it compatible with noSQL?

Probably bug in afterFind() (not populated after find)

It seems to me that here should not be a negation:

 /**
 * @return void
 */
public function afterFind()
{
    if (!$this->owner->isRelationPopulated($this->tagRelation)) {
        return;
    }

    $this->populateTagNames();
}

correct version, without negation in if statement:

 /**
 * @return void
 */
public function afterFind()
{
    if ($this->owner->isRelationPopulated($this->tagRelation)) {
        return;
    }

    $this->populateTagNames();
}

or

/**
 * @return void
 */
public function afterFind()
{
    if (!$this->owner->isRelationPopulated($this->tagRelation)) {
        $this->populateTagNames();
    }
}

problem in aftersave

Hi
In my news module i'm using this behavior . after updating news it will save tags again although it's tags haven't changed . it doesn't need to save a model when it didn't change.
this made some problems for me .
please help me .
tnx.

Composite primary key in Post-model

Hi.
My post-model::primaryKey() returns ['id', 'version'].
And thus in the TaggableBehavior[:177] rows are of the form array:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [version] => 0
                )

            [1] => 6
        )
)

Similarly this is to remove the tags.
What can be done?
Only override methods of afterSave and beforeDelete?

Update: override as I understand it does not help - private $_tagValues; :(

Widget for tag display

Have you planned to create a widget to display tags with links on them in view actions or this repository will contain only TaggableBehavior?
IMHO: Separate repository with require will be better solution.

Case sensitivity

I've had some problems with case sensitivity on inputting tags.

Because of MySQL SELECT statements are not case-sensitive by default: if 'foo' exists as a tag and 'Foo' was inputted, it would would cause a double entry insert statement which because of the composite primary key uniqueness would throw an SQL error and rollback the transaction.

I would suggest adding an attribute or property forcing all incoming tags to lower-case as default.
and when disabled, choose to do a binary mysql statement instead:
SELECT * FROM table WHERE BINARY column = 'value

any ideas on this, or do you have any suggestions on how to filter the $tagValues at the MODEL level?

Advanced usage: generate links on tags

Here is how I'm using tags without SluggableBehavior.

In application config:

'components' => [
    'urlManager' => [
        'class' => 'yii\web\UrlManager',
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules'=> [
            ['pattern'=>'tag/<tag>', 'route'=>'tag/view'],
        ]
    ],
]

In view file:

<?php foreach ($model->getTagNames(true) as $tag) : ?>
    <?= Html::a($tag, ['/tag/view', 'tag' => $tag]) ?>
<?php endforeach ?>

If we have a tag tag with whitespace we will have a generated link:
/tag/tag+with+whitespace

This link will call TagController:actionView() method and bypass tag parameter in Yii::$app->request->queryParams array.

Как получить все посты с похожими тегами?

Как получить все посты с похожими тегами?

relatedByTagValues('Собака') сортирует посты по количеству прикрепленных тегов, а мне нужны в первую очередь посты в которых есть тег 'Собака'.

Post::find()->relatedByTagValues('Собака')->all()

Many 'tags' relations

Is this possible to attach behavior twice or more? For example imagine that base model "post" has more than one 'tags' relation. It can be "tags", "materials", "locations", "dates" etc.

Overwrite afterSave()

Hi.

I have afterSave() implemented in ActiveRecord which use TaggableBehavior.
And afterSave() from TaggableBehavior dones't have any effect. When I comment my TaggableBehavior works normal.

Any fix for this?

Tag update false

Hello, when i update a tag value for post, some data work error
See the image
tag

That error, the id filed not update correct, it update on name filed so create new record.
Thank

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.