Announcements: rows per page wrong
Current behavior / Resultado actual / Résultat actuel
When announcements are sent to many groups at once, the number of announcements shown is lower than the numRow (page size) specifies.
Expected behavior / Resultado esperado / Résultat attendu
If you select 20, 50 or 100 rows in the announcement tool, that should be the number to show.
Steps to reproduce / Pasos para reproducir / Étapes pour reproduire
Create many announcements to many groups and look at the pages. Numbers are totally wrong. (See picture where 20 is the page size but only 4 rows are shown)
Chamilo Version / Versión de Chamilo / Version de Chamilo
1.11.x latest git checkout 2017-04-22
Caused by changes in function getAnnouncements in main/inc/lib/AnnouncementManager class.


See my Announcements page https://pageshot.net/1cQZlcgZRfPZwfxI/chamilo111x.dev https://pageshot.net/oAuElNlr5DZJ8rbk/chamilo111x.dev
Try replicate this in 1.11.chamilo.org
Will be left open 3 more days for feedback.
Here you go:

Make sure you have some announcements that are sent to many groups at once and to some users. The code to add the "group" label causes the count of the number of announcements to go wrong.
Another way to reproduce it with only 2 announcements:

Steps:
- use fill data to create some users and courses
- create 80 groups with 2 users (use random filler)
- sent 1 announcement to 40 groups.
- sent another one to all 40 groups
These are 2 announcements but the count will be 80 and the list will show one per page even if the page size is set to 20. That is because the single announcement-to-40-groups is counted as 40 announcements.
All because of a change in a SQL select query to add the "group" label to the list...
Announcement bad dead code example: test on 0:

Even on the chamilo campus the issue appears: https://campus.chamilo.org/main/announcements/announcements.php?cidReq=TEST9&id_session=0&gidReq=0&gradebook=0&origin= (you have to login to see announcements)
The root cause of the issue is the SELECT part in AnnouncementManager:getAnnouncements (a terrible piece of code) where multiple rows with the same ID pop up. The "fix" in the while loop where is checked if the announcement has already been displayed is a complex not-working fix because it conflicts with the LIMIT in the SQL statements, causing fewer than the page-size number of items to be displayed. When testing the fix, also keep in mind that the insert-date of similar announcements can be 1 second different from each other. A DISTINCT does not fix this.
campus.chamilo.org is version 1.10, so it shouldn't be used as an example. I'm not sure we're going to be able to fix this one in time for 1.11.4. We'll see, but otherwise we'll move it to 1.11.6.
@jderriks try with the last 1.11.x changes
Considered fixed. Please don't hesitate to report back (we'll reopen it and reschedule for 1.11.6) if it wasn't fixed for you in 1.11.4 (to be released today).
If only this bug was that easy to fix :-)
https://1.11.chamilo.org/main/announcements/announcements.php?cidReq=TESTHVA&gidReq=0&id_session=0
This was already fixed:
https://11.chamilo.org/main/announcements/announcements.php?cidReq=TESTHVA&gidReq=0&id_session=0