always load details in the same query

This commit is contained in:
Gilles Crettenand
2015-05-20 15:22:51 +02:00
parent bb7c99e190
commit c897f2c9c6
3 changed files with 114 additions and 312 deletions

View File

@@ -230,35 +230,28 @@ class NetBiblio extends WebService
public function AddWish($bookNr)
{
$bookNr = intval($bookNr);
$bookId = AudioBook::findIdByCode($bookNr);
$this->data[] = $this->getUser()->addWish($bookId);
$id = AudioBook::findIdByCode(intval($bookNr));
$this->data[] = $this->getUser()->addWish($id);
}
public function DeleteWish($bookNr)
{
$bookNr = intval($bookNr);
$bookId = AudioBook::findIdByCode($bookNr);
$this->getUser()->deleteWish($bookId);
$id = AudioBook::findIdByCode(intval($bookNr));
$this->getUser()->deleteWish($id);
}
public function FindBooks($codes)
{
$this->CheckSession();
$codeList = array_map('intval', json_decode($codes, true));
foreach ($codeList as $code) {
if ($code != 0) {
$id = AudioBook::findIdByCode($code);
$this->data[] = $this->AddFiles(AudioBook::find($id));
}
}
$codes = json_decode($codes, true);
$codes = array_map('intval', $codes);
$books = AudioBook::findBy('NoticeNr', $codes, true);
$this->data = array_map(array($this, 'AddFiles'), $books);
}
private function AddFiles(AudioBook $book)
private function AddFiles(array $book)
{
$book = $book->toArray();
$uri = sprintf("%s%s",
Configuration::get('checkfile_url'),
http_build_query(array(
@@ -286,8 +279,8 @@ class NetBiblio extends WebService
$this->CheckSession();
$code = intval($code);
$id = AudioBook::findIdByCode($code);
$this->data = $this->AddFiles(AudioBook::find($id));
$book = AudioBook::findBy('NoticeNr', $code, true);
$this->data = $this->AddFiles($book);
}
public function Search($query, $start, $limit)
@@ -361,7 +354,7 @@ class NetBiblio extends WebService
$this->data['facets'] = $results['facet_counts']['facet_fields'];
foreach ($results['response']['docs'] as $doc) {
$book = AudioBook::find($doc['id']);
$book = AudioBook::findBy('NoticeID', $doc['id'], true);
if($book) {
$this->data[] = $this->AddFiles($book);
}