Skip to content

Commit

Permalink
Sync: Støtte for å overføre lån fra midlertidig kort til eget
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Sep 8, 2013
1 parent c74cfcc commit 7a90441
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
27 changes: 26 additions & 1 deletion app/controllers/LoansController.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function getSync()
$due = array();
header("Content-type: text/html; charset=utf-8");
echo "Starter sync...<br />\n";
$ncip = new NcipClient();
$ncip = App::make('NcipClient');
$guest_ltid = Config::get('app.guest_ltid');

foreach (Loan::with('document','user')->get() as $loan) {
Expand Down Expand Up @@ -337,6 +337,31 @@ public function getSync()
echo "<br />\n";
}
}
echo "<br />\n";

$users = array();
foreach (User::with('loans.document.thing')->get() as $user) {
foreach ($user->loans as $loan) {
if ($loan->as_guest && $loan->document->thing->id == 1) {
$ltid = $user->ltid;
if (!empty($ltid)) {
echo "Checking loan $loan->id for $ltid : ";
if (!isset($users[$ltid])) {
$response = $ncip->lookupUser($ltid);
$users[$ltid] = $response;
}
if ($users[$ltid]->exists) {
echo " user has been imported, attempt to transfer loan ";
$loan->transfer();
} else {
echo " nope, not yet imported";
}
echo "<br />\n";
}
}
}
}

exit();
}

Expand Down
1 change: 0 additions & 1 deletion app/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public function getNcipLookup($id)
return Response::json(array('exists' => false));
}
$data = $user->ncipLookup();
$data['exists'] = true;

return Response::json($data);
}
Expand Down
21 changes: 20 additions & 1 deletion app/models/Loan.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,23 @@ public function restore()
return true;
}

}
public function transfer()
{
if ($this->as_guest) {
$dokid = $this->document->dokid;
$ltid = $this->user->ltid;
Log::info('Attempting to transfer ' . $dokid . ' to ' . $ltid);
$ncip = App::make('NcipClient');
$ncip->checkInItem($dokid);
$response = $ncip->checkOutItem($ltid, $dokid);
if ($response->success) {
$this->as_guest = false;
$this->save();
} else {
die($response->error);
}
}
return true;
}

}

0 comments on commit 7a90441

Please sign in to comment.