123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php namespace Client\Request;
- class Orgs extends Collection {
- protected $owner;
- public function __construct(string $api_url, string $api_token, User $owner) {
- $this->owner = $owner;
- parent::__construct($api_url, $api_token);
- }
- protected function set_scope(string $method) {
- switch ($method) {
- case "get":
- $this->scope = ($this->owner == null || $this->owner->authenticated() ? "/user" : "/users/" . $this->owner->uusername) . "/orgs";
- return true;
- }
- }
- public function create(...$args) {
- $org = new Org($this->url, $this->token, null, $this->owner);
- if (count($args) > 0)
- $org->create(...$args);
- return $org;
- }
- public function get(string $s) {
- if (($org = $this->by_key($s)))
- return $org;
- return new Org($this->url, $this->token, $s, $this->owner);
- }
- public function search(array $params = array()) {
- if (!isset($params["name"]) && !isset($params["q"]))
- throw new SearchParamException("Missing param <name>|<q>");
- $q = isset($params["name"]) ? $params["name"] : $params["q"];
- $l = isset($params["limit"]) ? $params["limit"] : 10;
- $this->load();
- $orgs = new CollectionResult();
- foreach ($this->all() as $key => $org) {
- if ($org->search($q))
- $orgs->set($org);
- if ($orgs->len() == $l)
- break;
- }
- return $orgs;
- }
- protected function json_set_property($obj) {
- foreach($obj as $val) {
- $org = new Org($this->url, $this->token, null, $this->owner);
- $org->json_set_property($val);
- $this->add($org, $val->username);
- }
- }
- }
|