new: [fetch] individuals added
parent
3cee213b53
commit
c87f6651dc
|
@ -116,4 +116,25 @@ class BroodsController extends AppController
|
||||||
$this->redirect($this->referer());
|
$this->redirect($this->referer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function downloadIndividual($brood_id, $individual_id)
|
||||||
|
{
|
||||||
|
$result = $this->Broods->downloadIndividual($brood_id, $individual_id);
|
||||||
|
$success = __('Individual fetched from remote.');
|
||||||
|
$fail = __('Could not save the remote individual');
|
||||||
|
if ($this->ParamHandler->isRest()) {
|
||||||
|
if ($result) {
|
||||||
|
return $this->RestResponse->saveSuccessResponse('Brood', 'downloadIndividual', $brood_id, 'json', $success);
|
||||||
|
} else {
|
||||||
|
return $this->RestResponse->saveFailResponse('Brood', 'downloadIndividual', $brood_id, $fail, 'json');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($result) {
|
||||||
|
$this->Flash->success($success);
|
||||||
|
} else {
|
||||||
|
$this->Flash->error($fail);
|
||||||
|
}
|
||||||
|
$this->redirect($this->referer());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,31 @@ class BroodsTable extends AppTable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function downloadAndCapture($brood_id, $object_id, $scope, $path)
|
||||||
|
{
|
||||||
|
$query = $this->find();
|
||||||
|
$brood = $query->where(['id' => $brood_id])->first();
|
||||||
|
if (empty($brood)) {
|
||||||
|
throw new NotFoundException(__('Brood not found'));
|
||||||
|
}
|
||||||
|
$http = new Client();
|
||||||
|
$response = $http->get($brood['url'] . '/' . $scope . '/view/' . $org_id . '/index.json' , [], [
|
||||||
|
'headers' => [
|
||||||
|
'Authorization' => $brood['authkey'],
|
||||||
|
'Accept' => 'Application/json',
|
||||||
|
'Content-type' => 'Application/json'
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
if ($response->isOk()) {
|
||||||
|
$org = $response->getJson();
|
||||||
|
$this->Organisation = TableRegistry::getTableLocator()->get('Organisations');
|
||||||
|
$result = $this->Organisation->captureOrg($org);
|
||||||
|
return $result;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function downloadOrg($brood_id, $org_id)
|
public function downloadOrg($brood_id, $org_id)
|
||||||
{
|
{
|
||||||
$query = $this->find();
|
$query = $this->find();
|
||||||
|
@ -117,4 +142,29 @@ class BroodsTable extends AppTable
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function downloadIndividual($brood_id, $individual_id)
|
||||||
|
{
|
||||||
|
$query = $this->find();
|
||||||
|
$brood = $query->where(['id' => $brood_id])->first();
|
||||||
|
if (empty($brood)) {
|
||||||
|
throw new NotFoundException(__('Brood not found'));
|
||||||
|
}
|
||||||
|
$http = new Client();
|
||||||
|
$response = $http->get($brood['url'] . '/individuals/view/' . $individual_id . '/index.json' , [], [
|
||||||
|
'headers' => [
|
||||||
|
'Authorization' => $brood['authkey'],
|
||||||
|
'Accept' => 'Application/json',
|
||||||
|
'Content-type' => 'Application/json'
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
if ($response->isOk()) {
|
||||||
|
$org = $response->getJson();
|
||||||
|
$this->Individual = TableRegistry::getTableLocator()->get('Individual');
|
||||||
|
$result = $this->Individual->captureIndividual($individual);
|
||||||
|
return $result;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue