Get the list of readers from Solr
This commit is contained in:
@@ -64,6 +64,22 @@ class BookSearch
|
|||||||
$this->query->addSortField($field, $order);
|
$this->query->addSortField($field, $order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addFacetField($field)
|
||||||
|
{
|
||||||
|
$this->query->addFacetField($field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFacetLimits($limit = null, $count = null)
|
||||||
|
{
|
||||||
|
if(! is_null($limit)) {
|
||||||
|
$this->query->setFacetLimit($limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(! is_null($count)) {
|
||||||
|
$this->query->setFacetMinCount($count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $start
|
* @param int $start
|
||||||
* @param int $count
|
* @param int $count
|
||||||
|
|||||||
@@ -4,33 +4,6 @@ namespace BSR\Lib\db;
|
|||||||
|
|
||||||
class DbHelper
|
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.
|
* Retrieve the list of all type available in the database.
|
||||||
* @param boolean $withJeunesse add 'Jeunesse' to the list
|
* @param boolean $withJeunesse add 'Jeunesse' to the list
|
||||||
|
|||||||
@@ -662,7 +662,30 @@ class NetBiblio extends WebService
|
|||||||
*/
|
*/
|
||||||
public function ListOfReaders()
|
public function ListOfReaders()
|
||||||
{
|
{
|
||||||
return DBHelper::ListOfReaders();
|
$s = new BookSearch();
|
||||||
|
$s->addQuery(1, 'visible');
|
||||||
|
$s->addFacetField('reader');
|
||||||
|
$s->setFacetLimits(2000, 10);
|
||||||
|
$results = $s->getResults(0, 0);
|
||||||
|
|
||||||
|
$readers = array();
|
||||||
|
foreach($results['facets']['facets']['reader'] as $name => $count) {
|
||||||
|
$parts = explode(" ", $name);
|
||||||
|
$firstname = array_shift($parts);
|
||||||
|
$lastname = implode(" ", $parts);
|
||||||
|
|
||||||
|
$fullname = trim($lastname.' '.$firstname);
|
||||||
|
$readers[$fullname] = array(
|
||||||
|
'lastname' => $lastname,
|
||||||
|
'firstname' => $firstname,
|
||||||
|
'count' => $count,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort readers by lastname
|
||||||
|
ksort($readers);
|
||||||
|
|
||||||
|
return array_values($readers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user