sub tags_subselect
{
+ return shift->tags_subselect_and(@_);
+}
+
+sub tags_subselect_and
+{
+ my($self,@constraints)=@_;
+ my ($tags, $tags_vals, $parent)=$self->constraints_tag_list(@constraints);
+ my @tags=@$tags;
+ my @tags_vals=@$tags_vals;;
+ my $cnt=1;
+ my @andclauses=();
+ my $sql='';
+ for my $tag (@tags)
+ {
+ if($cnt == 1)
+ {
+ $sql="\tSELECT fxt" . scalar(@tags) . ".files_id FROM files_x_tags fxt1\n";
+ }
+ else
+ {
+ $sql .= ("\tINNER JOIN files_x_tags fxt$cnt ON fxt" .
+ ($cnt-1) . ".files_id=fxt${cnt}.files_id\n");
+ }
+ push(@andclauses, "\t\tfxt${cnt}.tags_id = $tag");
+ print "AND: @andclauses\n";
+ $cnt++;
+ }
+ if(@andclauses)
+ {
+ $sql .= "\tWHERE\n\t\t";
+ $sql .= join(" AND\n\t\t", @andclauses) . "\n";
+ }
+ $sql .= "\tGROUP BY fxt". scalar(@tags).".files_id\n";
+ return $sql;
+}
+
+sub tags_subselect_or
+{
my($self,@constraints)=@_;
my ($tags, $tags_vals, $parent)=$self->constraints_tag_list(@constraints);
my @tags=@$tags;
"\tINNER JOIN files_x_tags ON t1.id=files_x_tags.tags_id\n");
my @orclauses=();
my @andclauses=();
+ # FIXME: and / or?
if(@tags)
{
- push(@orclauses, "( t1.parents_id=" . (defined($parent) ? $parent : "''") . " )");
- push(@orclauses, "( t1.id IN ( " . join(', ', @tags) ." ) )");
+ push(@andclauses, "( t1.parents_id=" . (defined($parent) ? $parent : "''") . " )");
+ push(@andclauses, "( t1.id IN ( " . join(', ', @tags) ." ) )");
}
for my $pair (@tags_vals)
{