2020-06-28 02:11:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zoomyboy\LaravelNami;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
|
|
|
|
class Group implements Arrayable {
|
|
|
|
|
|
|
|
public $name;
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
public static function fromResponse($response) {
|
|
|
|
$group = new self();
|
|
|
|
$group->name = $response['descriptor'];
|
|
|
|
$group->id = $response['id'];
|
|
|
|
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toArray() {
|
|
|
|
return [ 'id' => $this->id, 'name' => $this->name ];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function subgroups() {
|
|
|
|
return Nami::subgroupsOf($this->id);
|
|
|
|
}
|
|
|
|
|
2020-06-29 00:30:57 +02:00
|
|
|
public function members(): MemberCollection {
|
2020-07-04 02:11:30 +02:00
|
|
|
$members = Nami::membersOf($this->id);
|
|
|
|
|
|
|
|
return MemberCollection::make(function() use ($members) {
|
|
|
|
foreach ($members as $member) {
|
|
|
|
yield $this->member($member['id']);
|
|
|
|
}
|
|
|
|
});
|
2020-06-29 00:30:57 +02:00
|
|
|
return new MemberCollection(Nami::membersOf($this->id)->map(function($member) {
|
|
|
|
return $this->member($member['id']);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function member($id): Member {
|
|
|
|
return Member::fromNami(Nami::member($this->id, $id));
|
|
|
|
}
|
|
|
|
|
2020-06-28 02:11:23 +02:00
|
|
|
}
|