use improved method for get(Old)Circulations
This commit is contained in:
@@ -157,7 +157,7 @@ class AudioBook extends DbMapping
|
|||||||
$row['cover'] = 'http://ecx.images-amazon.com/images/I/'.$row['cover'].'._SL320_.jpg';
|
$row['cover'] = 'http://ecx.images-amazon.com/images/I/'.$row['cover'].'._SL320_.jpg';
|
||||||
}
|
}
|
||||||
|
|
||||||
$books[] = $raw ? $row : new AudioBook($row);
|
$books[$row['id']] = $raw ? $row : new AudioBook($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $multiple ? $books : reset($books);
|
return $multiple ? $books : reset($books);
|
||||||
|
|||||||
84
lib/User.php
84
lib/User.php
@@ -121,74 +121,44 @@ class User extends DbMapping
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function reload()
|
public function reload()
|
||||||
{
|
{
|
||||||
$this->setAttributes(User::find($this->login)->toArray());
|
$this->setAttributes(User::find($this->login)->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function _getCirculations($table, $sort = "ItemNr ASC") {
|
||||||
|
$sql = sprintf("SELECT
|
||||||
|
NoticeID,
|
||||||
|
CheckOutDate,
|
||||||
|
ItemNr
|
||||||
|
FROM %s AS c, Items
|
||||||
|
WHERE
|
||||||
|
c.UseraccountId = %s
|
||||||
|
AND Items.ItemId=c.ItemId
|
||||||
|
ORDER BY %s", $table, $this->id, $sort);
|
||||||
|
|
||||||
|
$result = Connection::execute($sql);
|
||||||
|
|
||||||
|
$circulations = $result->to_array();
|
||||||
|
$books = array_map(function($c) { return $c['NoticeID']; }, $circulations);
|
||||||
|
$books = AudioBook::findBy('NoticeID', $books, true);
|
||||||
|
|
||||||
|
foreach($circulations as $c) {
|
||||||
|
$books[$c['NoticeID']]['date'] = $c['CheckOutDate'];
|
||||||
|
$books[$c['NoticeID']]['itemNr'] = $c['ItemNr'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $books;
|
||||||
|
}
|
||||||
|
|
||||||
public function getCirculations()
|
public function getCirculations()
|
||||||
{
|
{
|
||||||
if (!$this->circulations) {
|
return $this->_getCirculations('Circulations');
|
||||||
$strSQL = "SELECT NoticeId, CheckOutDate, ItemNr FROM Circulations, Items " .
|
|
||||||
"WHERE Circulations.UseraccountId = $this->id and Items.ItemId=Circulations.ItemId " .
|
|
||||||
"ORDER BY ItemNr asc";
|
|
||||||
|
|
||||||
$result = Connection::execute($strSQL);
|
|
||||||
|
|
||||||
$ids = array();
|
|
||||||
$checkOutDates = array();
|
|
||||||
$itemNrs = array();
|
|
||||||
|
|
||||||
while ($row = $result->next()) {
|
|
||||||
$ids[] = $row['NoticeId'];
|
|
||||||
$checkOutDates[] = $row['CheckOutDate'];
|
|
||||||
$itemNrs[] = $row['ItemNr'];
|
|
||||||
}
|
|
||||||
$this->circulations = AudioBook::find($ids);
|
|
||||||
|
|
||||||
// ici je remplace le champs date du livre par la date du prêt
|
|
||||||
$counter = 0;
|
|
||||||
foreach ($this->circulations as &$circulation) {
|
|
||||||
|
|
||||||
$circulation->date = substr($checkOutDates[$counter], 0, 10);
|
|
||||||
$circulation->itemNr = $itemNrs[$counter];
|
|
||||||
|
|
||||||
$counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->circulations;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOldCirculations()
|
public function getOldCirculations()
|
||||||
{
|
{
|
||||||
|
return $this->_getCirculations('OldCirculations', 'CheckOutDate DESC');
|
||||||
//if(!$this->oldCirculations){
|
|
||||||
$strSQL = "SELECT NoticeId, CheckOutDate FROM OldCirculations, Items " .
|
|
||||||
"WHERE OldCirculations.UseraccountId = $this->id and Items.ItemId=OldCirculations.ItemId " .
|
|
||||||
"ORDER BY CheckOutDate desc";
|
|
||||||
|
|
||||||
|
|
||||||
$result = Connection::execute($strSQL);
|
|
||||||
$ids = array();
|
|
||||||
$checkOutDates = array();
|
|
||||||
while ($row = $result->next()) {
|
|
||||||
$ids[] = $row['NoticeId'];
|
|
||||||
$checkOutDates[] = $row['CheckOutDate'];
|
|
||||||
}
|
|
||||||
$this->oldCirculations = AudioBook::find($ids);
|
|
||||||
|
|
||||||
// ici je remplace le champs date du livre par la date du prêt
|
|
||||||
$counter = 0;
|
|
||||||
foreach ($this->oldCirculations as &$circulation) {
|
|
||||||
|
|
||||||
$circulation->date = substr($checkOutDates[$counter], 0, 10);
|
|
||||||
$counter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
return $this->oldCirculations;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user