File tree Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change 16
16
*/
17
17
class ComTagsDatabaseBehaviorTaggable extends KDatabaseBehaviorAbstract
18
18
{
19
+ protected function _initialize (KObjectConfig $ config )
20
+ {
21
+ $ config ->append (array ('strict ' => false ));
22
+
23
+ parent ::_initialize ($ config );
24
+ }
25
+
19
26
/**
20
27
* Get a list of tags
21
28
*
@@ -48,9 +55,21 @@ protected function _beforeSelect(KDatabaseContext $context)
48
55
{
49
56
$ package = $ this ->getMixer ()->getIdentifier ()->package ;
50
57
51
- $ query ->join ($ package .'_tags_relations AS tags_relations ' , 'tags_relations.row = tbl.uuid ' );
52
- $ query ->join ($ package .'_tags AS tags ' , 'tags.tag_id = tags_relations.tag_id ' );
53
- $ query ->where ('tags.slug IN :tag ' );
58
+
59
+ if ($ this ->getConfig ()->strict )
60
+ {
61
+ $ tags = KObjectConfig::unbox ($ this ->getConfig ()->tags );
62
+
63
+ for ($ i = 0 ; $ i < count ($ tags ); $ i ++) {
64
+ $ query ->join ("{$ package }_tags_relations AS tags_relations {$ i }" , "tags_relations {$ i }.row = tbl.uuid " )
65
+ ->join ("{$ package }_tags AS tags {$ i }" , "tags {$ i }.tag_id = tags_relations {$ i }.tag_id " , 'INNER ' )
66
+ ->where ("tags {$ i }.slug = :tag {$ i }" )
67
+ ->bind (array ("tag {$ i }" => $ tags [$ i ]));
68
+ }
69
+ }
70
+ else $ query ->join ($ package . '_tags_relations AS tags_relations ' , 'tags_relations{$i}.row = tbl.uuid ' )
71
+ ->join ($ package . '_tags AS tags ' , 'tags.tag_id = tags_relations.tag_id ' )
72
+ ->where ('tags.slug IN :tag ' );
54
73
}
55
74
}
56
75
}
Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ public function __construct(KObjectConfig $config)
38
38
protected function _initialize (KObjectConfig $ config )
39
39
{
40
40
$ config ->append (array (
41
- 'priority ' => KBehaviorAbstract::PRIORITY_HIGH
41
+ 'priority ' => KBehaviorAbstract::PRIORITY_HIGH ,
42
+ 'strict ' => false
42
43
));
43
44
44
45
parent ::_initialize ($ config );
@@ -65,7 +66,11 @@ public function onMixin(KObjectMixable $mixer)
65
66
protected function _makeTaggable (KModelContextInterface $ context )
66
67
{
67
68
$ model = $ context ->getSubject ();
68
- $ model ->getTable ()->addBehavior ('com:tags.database.behavior.taggable ' );
69
+
70
+ $ model ->getTable ()->addBehavior ('com:tags.database.behavior.taggable ' , array (
71
+ 'tags ' => $ model ->getState ()->tag ,
72
+ 'strict ' => $ this ->getConfig ()->strict
73
+ ));
69
74
}
70
75
71
76
/**
You can’t perform that action at this time.
0 commit comments