Skip to content

Commit 5d3fe41

Browse files
committed
3.0.4 merge
sorry made a mesh off the merges.
1 parent 57968c2 commit 5d3fe41

File tree

3 files changed

+176
-144
lines changed

3 files changed

+176
-144
lines changed

cblisthelper.php

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
defined('_JEXEC') or die;
4+
5+
/* this file will build the query to get the profiles in the same way as the cblist.
6+
* By seperating it it can be easier used in other applications.
7+
* @copyright 2022
8+
* @author Tazzios
9+
* @license GNU General Public License version 2 or later; see LICENSE.txt
10+
*/
11+
12+
13+
14+
function createcblistquerymod($cblistid,$cblistname) {
15+
$where = '' ;
16+
if (!empty($cblistid)) {
17+
$where = 'listid = '. $cblistid ;
18+
}
19+
else {
20+
$where = 'title = \''. $cblistname . '\'';
21+
}
22+
23+
24+
25+
// Obtain a database connection
26+
$db = JFactory::getDbo();
27+
// Retrieve the selected list
28+
$query = $db->getQuery(true)
29+
->select('params')
30+
->select('usergroupids')
31+
->from('#__comprofiler_lists')
32+
->where($where . ' AND published=1');
33+
//->order('ordering ASC');
34+
$db->setQuery($query);
35+
36+
// Load the List row.
37+
$row = $db->loadAssoc();
38+
$select_sql_raw = $row['params'];
39+
$select_sql =""; //declare variable
40+
41+
// Process the filterfields to make it usefull for SQL query
42+
$json_a=json_decode($select_sql_raw,true);
43+
if (isset($json_a['filter_basic'])) $filters_basic = $json_a['filter_basic'];
44+
45+
if ($json_a['filter_mode'] == 0) {
46+
$i = 0;
47+
foreach ($filters_basic as $filter) {
48+
if ($filter['column']<>'') {
49+
// If it is not the first filter add AND
50+
if ($i>0) {
51+
$select_sql .= " AND " ;
52+
}
53+
54+
// add qoutes if value is text.
55+
if (!is_numeric($filter['value'])) {
56+
$value = "'".$filter['value']."'";
57+
} else {
58+
$value = $filter['value'];
59+
}
60+
61+
// Replace operators from json if needed else default
62+
switch ($filter['operator']) {
63+
case "<>||ISNULL": // CB Not equal to
64+
$select_sql .= "(".$filter['column'] . "<> ".$value ." OR ". $filter['column'] . " IS NULL)";
65+
break;
66+
67+
case "NOT REGEXP||ISNULL": // CB is not regexp
68+
$select_sql .= "(".$filter['column'] . " NOT REGEXP ".$value ." OR ". $filter['column'] . " IS NULL)";
69+
break;
70+
71+
case "NOT LIKE||ISNULL"; //CB Does not contain
72+
$value = "'%" . trim($value,'\'"') . "%'"; // any combination of ' and "
73+
$select_sql .= "(".$filter['column'] . " NOT LIKE ".$value ." OR ". $filter['column'] . " IS NULL)";
74+
break;
75+
76+
case "LIKE"; //CB Does contain
77+
$value = "'%" . trim($value,'\'"') . "%'"; // any combination of ' and "
78+
$select_sql = "(".$filter['column'] . " LIKE " . $value . ")" ;
79+
break;
80+
81+
case "IN"; //CB IN
82+
$i = 0;
83+
$include = "";
84+
//loop al the values from the in filter value. Fetch original value so no aurrounding qoutes are present
85+
foreach ((explode(",",$filter['value'])) as $value) {
86+
// Start with separator is not first one.
87+
if ($i>0) {
88+
$include .= ", " ;
89+
}
90+
91+
// place quotes if text
92+
if (!is_numeric($value)) {
93+
$value = "'".$filter['value']."'";
94+
}
95+
96+
$include .= "".$value."";
97+
$i++;
98+
}
99+
$select_sql .= "".$filter['column'] . " IN (". $include .") ";
100+
break;
101+
102+
default:
103+
// Default way to process json values to query
104+
$select_sql .= "(".$filter['column']." ".$filter['operator']." ".$value.")";
105+
break;
106+
}
107+
$i++;
108+
}
109+
}
110+
}
111+
112+
else if ($json_a['filter_mode'] == 1) {
113+
$select_sql = $json_a['filter_advanced'];
114+
}
115+
116+
117+
// Set a base-sql for connecting users, fields and lists
118+
$usergroupids = str_replace("|*|", ",", $row['usergroupids']); //CMJ ADDED
119+
$usergroupids = trim($usergroupids,','); // prevent that the range starts (or ends) with a comma if you also have selected '--- Select User group (CTR/CMD-Click: multiple)---' at the usergroups
120+
121+
$list_show_unapproved = $json_a['list_show_unapproved'];
122+
$list_show_blocked = $json_a['list_show_blocked'];
123+
$list_show_unconfirmed = $json_a['list_show_unconfirmed'];
124+
$fetch_sql = "SELECT DISTINCT ue.id FROM #__users u JOIN #__user_usergroup_map g ON g.`user_id` = u.`id` JOIN #__comprofiler ue ON ue.`id` = u.`id` WHERE g.group_id IN (".$usergroupids.")";
125+
if ($list_show_blocked == 0) {$fetch_sql.=" AND u.block = 0 ";}
126+
if ($list_show_unapproved == 0) {$fetch_sql.=" AND ue.approved = 1 ";}
127+
if ($list_show_unconfirmed == 0) {$fetch_sql.=" AND ue.confirmed = 1 ";}
128+
129+
130+
// add CB list filters only if there are any
131+
if ($select_sql <>'') $fetch_sql = $fetch_sql . " AND (" . $select_sql . ")";
132+
$cblistquery['cblistselect'] = $fetch_sql;
133+
134+
//Add ordering if list is configured for that
135+
// order will be given seperates so it can be overwritten
136+
$cblistquery['cblistsortby'] = $json_a['sort_basic'][0]['column'];
137+
$cblistquery['cblistsortorder'] = $json_a['sort_basic'][0]['direction'];
138+
139+
140+
return $cblistquery;
141+
142+
}
143+
?>
144+

0 commit comments

Comments
 (0)