laravel-nami-api/src/Group.php

39 lines
862 B
PHP
Raw Normal View History

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 {
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
}