Hi there. I've dreamed to start to write some small tricks for change the code and this is my first howto.
If you want to know how to change any another functions, you can ask us. Please, use the contact form.
For add this feature, you need to add some new code.
Please, follow the steps bellow:
1) Frontend part
Open this file - modules/mod_k2_filter/assets/js/jquery.multiselect.filter.js
Find this line:
// wrapper elem
var wrapper = (this.wrapper = ......
Then, add this code bellow:
1
2
3
4
5
6
7
8
9
10
11
12
//added
var elem_name = elem.attr("name").replace(']', '').replace('[', '');
var wrap_cond = $("<div class='conditionSelect' style='clear: both;' />");
wrap_cond.append($("<span style='float:left; margin-right:10px;'><label style='border: none; background: none; color: #fff;'>AND <input type='radio' value='AND' name='condition_"+elem_name+"' style='margin-top: -2px;'></label></span>"));
wrap_cond.append($("<span style='float:left;'><label style='border: none; background: none; color: #fff;'>OR <input type='radio' value='OR' name='condition_"+elem_name+"' style='margin-top: -2px;'></label></span>"));
wrap_cond.appendTo(this.header);
$('form[name='+elem.parents('form').attr("name")+']').append($("<input type='hidden' name='condition_"+elem_name+"' value='' />"));
this.header.find("input[name='condition_"+elem_name+"']").each(function() {
$(this).on("click", function() {
$('form[name='+elem.parents('form').attr("name")+']').find("input[name='condition_"+elem_name+"']").val($(this).val());
});
});
Maybe you will need to clear the browser cache for see the changes.
2) Backend part
You need to modify the filter plugin file - plugins/system/k2filter/K2Filter/models/itemlistfilter.php
Find this part of code (two match on line ~582 and line ~1658):
$query .= " AND i.id IN (SELECT itemID FROM #__k2_tags_xref WHERE (";
$query .= "tagID IN (".implode(",", $taga).")";
$query .= "))";
Then, replace this code with the following:
if(JRequest::getVar("condition_taga") == "AND") {
foreach($taga as $tag_id) {
$query .= " AND {$tag_id} IN (SELECT tagID FROM #__k2_tags_xref WHERE itemID = i.id)";
}
}
else {
$query .= " AND i.id IN (SELECT itemID FROM #__k2_tags_xref WHERE (";
$query .= "tagID IN (".implode(",", $taga).")";
$query .= "))";
}
For extrafield type fields, you will need to modify this code (line ~2162):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
else if ($slider == 0 and $array == 1) {
$sql = "";
foreach($search as $j=>$word) {
foreach($slarray as $k=>$value) {
if($word == $value) {
if($j == 0) {
$sql .= " AND (i.extra_fields REGEXP '^.*\"$i_slider\",\"value(.[^}]*\"{$k}";
}
else {
$sql .= "|.[^}]*\"{$k}";
}
if(($j+1) == count($search)) {
$sql .= ")\".*$')";
}
}
}
}
}
And replace it with the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
else if ($slider == 0 and $array == 1) {
$sql = "";
foreach($search as $j=>$word) {
foreach($slarray as $k=>$value) {
if($word == $value) {
if(JRequest::getVar("condition_array".$i_slider) == "AND") {
$sql .= " AND i.extra_fields REGEXP '^.*\"$i_slider\",\"value(.[^}]*\"{$k})\".*$'";
}
else {
if($j == 0) {
$sql .= " AND (i.extra_fields REGEXP '^.*\"$i_slider\",\"value(.[^}]*\"{$k}";
}
else {
$sql .= "|.[^}]*\"{$k}";
}
if(($j+1) == count($search)) {
$sql .= ")\".*$')";
}
}
}
}
}
}
That's all. You can use it now and have fun.