franzholz / table

multiple language support for the usage of database tables in TYPO3
0 stars 2 forks source link

Wrong WHERE clause for products with many FE groups in fe_group field #9

Open webian opened 1 week ago

webian commented 1 week ago

This line https://github.com/franzholz/table/blob/bd46cb51c1c029a6b49742b2722b19f525d9434b/lib/class.tx_table_db.php#L792 only considers the first element of fe_group field.

Example 1: if fe_group = '2,3', the record is shown only to users in group 2 and not to users in group 3. Example 2: if fe_group = '3,2', the record is shown only to users in group 3 and not to users in group 2.

franzholz commented 6 days ago

It is not supported to have products in more than one FE user group. fe_group can only be either 3 or 2.

franzholz commented 6 days ago

Maybe the code could be enhanced like here

No Table No Function No Loop

Building on the idea of parsing your list into a table our DBA suggested using XML.

Declare @Ids varchar(50)
Set @Ids = ‘1,2,3,5,4,6,7,98,234’

DECLARE @XML XML
SET @XML = CAST('<i>' + REPLACE(@Ids, ',', '</i><i>') + '</i>' AS XML)

SELECT * 
FROM
    SomeTable 
    INNER JOIN @XML.nodes('i') x(i) 
        ON  SomeTable .Id = x.i.value('.', 'VARCHAR(MAX)')