Get the list of readers from Solr

This commit is contained in:
Gilles Crettenand
2015-06-11 14:42:12 +02:00
parent 1894212a5c
commit 0143374ae1
3 changed files with 40 additions and 28 deletions

View File

@@ -4,33 +4,6 @@ namespace BSR\Lib\db;
class DbHelper
{
/**
* Retrieve the list of all readers (volunteers) having read at least 4 books (2 notices per book).
* Returns an associative array containing $lastname and $firstname
*/
public static function ListOfReaders()
{
$sql = "SELECT
count(*),
ContentShortPart AS name
FROM NoticeFields
WHERE Tag=901
GROUP BY ContentShortPart
HAVING count(*) > 6
ORDER BY SUBSTRING(ContentShortPart, CHARINDEX(' ', ContentShortPart)+1, 15);";
$results = Connection::execute($sql);
return array_map(function($row) {
$fullname = str_replace("*", "", $row['name']);
$parts = explode(" ", $fullname);
$firstname = array_shift($parts);
$lastname = implode(" ", $parts);
return array(
'lastname' => $lastname,
'firstname' => $firstname);
}, $results->to_array());
}
/**
* Retrieve the list of all type available in the database.
* @param boolean $withJeunesse add 'Jeunesse' to the list