Add activities and subactivities
This commit is contained in:
parent
08fbb731a8
commit
3e34540227
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Activity extends Model {
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public static function fromNami($item) {
|
||||
$item = collect($item)
|
||||
->only(['descriptor', 'id'])
|
||||
->mapWithKeys(function($item,$key) {
|
||||
if ($key == 'id') { return ['id' => $item]; }
|
||||
return ['name' => $item];
|
||||
})->toArray();
|
||||
|
||||
return (new self($item));
|
||||
}
|
||||
|
||||
public function subactivities() {
|
||||
return Nami::subactivitiesOf($this->id);
|
||||
}
|
||||
|
||||
}
|
20
src/Api.php
20
src/Api.php
|
@ -73,6 +73,12 @@ class Api {
|
|||
return collect($this->http()->get(self::$url.'/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/'.$memberId.'/flist')->json()['data']);
|
||||
}
|
||||
|
||||
public function subactivitiesOf($activityId) {
|
||||
return collect($this->http()->get(self::$url.'/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/'.$activityId)->json()['data'])->map(function($subactivity) {
|
||||
return Subactivity::fromNami($subactivity);
|
||||
});;
|
||||
}
|
||||
|
||||
public function membership($memberId, $membershipId) {
|
||||
$url = self::$url.'/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/'.$memberId.'/'.$membershipId;
|
||||
$response = $this->http()->get($url);
|
||||
|
@ -148,6 +154,12 @@ class Api {
|
|||
});
|
||||
}
|
||||
|
||||
public function activities($groupId) {
|
||||
return collect($this->http()->get(self::$url."/ica/rest/nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/".$groupId)['data'])->map(function($activity) {
|
||||
return Activity::fromNami($activity);
|
||||
});
|
||||
}
|
||||
|
||||
private function singleMemberFallback($groupId, $memberId) {
|
||||
$url = self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist';
|
||||
$response = $this->http()->get($url);
|
||||
|
@ -190,14 +202,6 @@ class Api {
|
|||
return json_decode((string)$response->getBody());
|
||||
}
|
||||
|
||||
public function activities() {
|
||||
$response = $this->client->get("/ica/rest/nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/{$this->user->getNamiGroupId()}", [
|
||||
'cookies' => $this->cookie
|
||||
]);
|
||||
|
||||
return json_decode((string)$response->getBody());
|
||||
}
|
||||
|
||||
public function groupForActivity($activityId) {
|
||||
|
||||
$response = $this->client->get("/ica/rest//nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/{$activityId}", [
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Zoomyboy\LaravelNami;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\LazyCollection;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
|
||||
class Group implements Arrayable {
|
||||
|
@ -43,4 +45,8 @@ class Group implements Arrayable {
|
|||
return Member::fromNami(Nami::member($this->id, $id));
|
||||
}
|
||||
|
||||
public function activities(): Collection {
|
||||
return Nami::activities($this->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Subactivity extends Model {
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public static function fromNami($item) {
|
||||
$item = collect($item)
|
||||
->only(['descriptor', 'id'])
|
||||
->mapWithKeys(function($item,$key) {
|
||||
if ($key == 'id') { return ['id' => $item]; }
|
||||
return ['name' => $item];
|
||||
})->toArray();
|
||||
|
||||
return (new self($item));
|
||||
}
|
||||
|
||||
public function getNameAttribute() {
|
||||
return ucfirst($this->attributes['name']);
|
||||
}
|
||||
|
||||
public function getIsNullAttribute() {
|
||||
return $this->attributes['id'] == self::getNullValue();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Zoomyboy\LaravelNami\Group;
|
||||
|
||||
class PullActivitiesTest extends TestCase
|
||||
{
|
||||
|
||||
public $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":103}],"responseType":"OK"}';
|
||||
|
||||
public function test_get_all_activities() {
|
||||
Http::fake(array_merge($this->login(),[
|
||||
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/103' => Http::response($this->fakeJson('activities.json'), 200)
|
||||
]));
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
|
||||
$this->assertSame([
|
||||
[ 'name' => 'Ac1', 'id' => 4 ],
|
||||
[ 'name' => 'Ac2', 'id' => 3 ]
|
||||
], Nami::group(103)->activities()->toArray());
|
||||
|
||||
Http::assertSentCount(4);
|
||||
}
|
||||
|
||||
public function test_get_all_subactivities() {
|
||||
Http::fake(array_merge($this->login(),[
|
||||
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/103' => Http::response($this->fakeJson('activities.json'), 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/4' => Http::response($this->fakeJson('subactivities-4.json'), 200)
|
||||
]));
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
|
||||
$this->assertSame([
|
||||
[ 'name' => 'Biber', 'id' => 40 ],
|
||||
[ 'name' => 'Wölfling', 'id' => 30 ]
|
||||
], Nami::group(103)->activities()->first()->subactivities()->toArray());
|
||||
|
||||
Http::assertSentCount(5);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"descriptor": "Ac1",
|
||||
"name": "",
|
||||
"representedClass": "de.iconcept.nami.entity.taetigkeit.FunktionsTaetigkeit",
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"descriptor": "Ac2",
|
||||
"name": "",
|
||||
"representedClass": "de.iconcept.nami.entity.taetigkeit.FunktionsTaetigkeit",
|
||||
"id": 3
|
||||
}
|
||||
],
|
||||
"responseType": "OK"
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"descriptor": "Biber",
|
||||
"name": "",
|
||||
"representedClass": "de.iconcept.nami.entity.taetigkeit.Stufe",
|
||||
"id": 40
|
||||
},
|
||||
{
|
||||
"descriptor": "Wölfling",
|
||||
"name": "",
|
||||
"representedClass": "de.iconcept.nami.entity.taetigkeit.Stufe",
|
||||
"id": 30
|
||||
}
|
||||
],
|
||||
"responseType": "OK"
|
||||
}
|
Loading…
Reference in New Issue