Giter Club home page Giter Club logo

doctrine-extensions-taggable's Introduction

Doctrine2 taggable behavior extension

Build Status SensioLabsInsight

Installation

    "require": {
        "anh/doctrine-extensions-taggable": "~1.0"
    }

Symfony

There is bundle for that โ€” AnhTaggableBundle

Basic integration

edit app/config/config.yml:

doctrine:
    dbal:
# ...

    orm:
# ...
        mappings:
            taggable:
                type: annotation
                alias: AnhTaggable
                prefix: Anh\Taggable\Entity
                dir: "%kernel.root_dir%/../vendor/anh/doctrine-extensions-taggable/lib/Anh/Taggable/Entity"

edit Acme/DemoBundle/Resources/config/services.yml to add a service and event subscriber

# ...
services:
# ...
    anh_taggable.manager:
        class: Anh\Taggable\TaggableManager
        arguments:
            - @doctrine.orm.entity_manager
            - Anh\Taggable\Entity\Tag
            - Anh\Taggable\Entity\Tagging

    anh_taggable.subscriber:
        class: Anh\TaggableBundle\TaggableSubscriber
        arguments:
            - @service_container
        tags:
            - { name: doctrine.event_subscriber }

Example

Create taggable entity

<?php

use Anh\Taggable\TaggableInterface;
use Anh\Taggable\AbstractTaggable;

class Article extends AbstractTaggable implements TaggableInterface
{
    // ...

    public function getTaggableType()
    {
        return 'article';
    }
}

Using taggable extension

<?php

use Anh\Taggable\TaggableManager;
use Anh\Taggable\TaggableSubscriber;

// create entity manager
// $em = EntityManager::create(...);

// create taggable manager
$taggableManager = new TaggableManager(
    $em, 'Anh\Taggable\Entity\Tag', 'Anh\Taggable\Entity\Tagging'
);

// add event subscriber
$em->getEventManager()->addEventSubscriber(
    new TaggableSubscriber($taggableManager)
);

// create and fill entity
$article = new Article();
// $article->setTitle(...);

// add tag
$tag = $taggableManager->loadOrCreateTag('This is a tag');
$article->addTag($tag);

// or add multiple tags
$tags = $taggableManager->loadOrCreateTags(array('tag1', 'tag2', 'tag3'));
$article->addTags($tags);

// see Anh\Taggable\AbstractTaggable for more

$em->persist($article);
$em->flush();

// ...

// getting tagged resources
$repository = $taggableManager->getTaggingRepository();

$tag = $taggableManager->loadOrCreateTag('Some tag')
// returns all resources tagged with tag 'Some tag'
$resources = $repository->getResourcesWithTag($tag);
// returns only articles with tag 'Some tag'
$articles = $repository->getResourcesWithTypeAndTag('article', $tag);

doctrine-extensions-taggable's People

Contributors

filoz avatar hilobok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

doctrine-extensions-taggable's Issues

Doctrine 2.5

Does this extension work with doctrine ORM 2.5 or doctrine common 2.5 ?
I use doctrine 2.4.* in my composer.json but it installs doctrine common 2.5 and it is not compatible with your requirements (<2.5 for orm and common)

Any way to query tags?

Is there any way to query tags using a Doctrine query builder for example?

I need to present a table of data and show the tags for each entry, so need to eager load them.

taggable form element doctrine hydration

Hi all,
I am trying to insert into a form hydrated with doctrineObject a field for tag insertion using taggable extension, but it is not clear at all how to accomplish this.

doctrine-extensions-resource

Hi,
do you think that "anh/doctrine-extensions-resource" is really necessary?

I'm trying to understand where is actually used, I found only one reference here:
https://github.com/hilobok/doctrine-extensions-taggable/blob/master/lib/Anh/Taggable/Entity/TagRepository.php
and here
https://github.com/hilobok/doctrine-extensions-taggable/blob/master/lib/Anh/Taggable/Entity/TaggingRepository.php

removing this dependency, this library would become easier to maintain and improve.

What do you think?

anyway, great work!!!

Thankyou

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.