2020-06-28 02:11:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zoomyboy\LaravelNami;
|
|
|
|
|
2020-07-04 21:23:10 +02:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Illuminate\Support\LazyCollection;
|
2020-06-28 02:11:23 +02:00
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
|
|
|
|
class Group implements Arrayable {
|
|
|
|
|
|
|
|
public $name;
|
|
|
|
public $id;
|
|
|
|
|
2020-07-04 17:50:55 +02:00
|
|
|
public static function fromResponse($response, $parent) {
|
2020-06-28 02:11:23 +02:00
|
|
|
$group = new self();
|
|
|
|
$group->name = $response['descriptor'];
|
|
|
|
$group->id = $response['id'];
|
2020-07-04 17:50:55 +02:00
|
|
|
$group->parent_id = $parent;
|
2020-06-28 02:11:23 +02:00
|
|
|
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toArray() {
|
2020-07-04 17:50:55 +02:00
|
|
|
return [ 'id' => $this->id, 'name' => $this->name, 'parent_id' => $this->parent_id ];
|
2020-06-28 02:11:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-07-04 21:23:10 +02:00
|
|
|
public function activities(): Collection {
|
|
|
|
return Nami::activities($this->id);
|
|
|
|
}
|
|
|
|
|
2020-06-28 02:11:23 +02:00
|
|
|
}
|