username = $oname; $this->owner = $owner; } /** * @see Base * @throws Exception\InvalidMethodRequestException when owner is not set * @throws Exception\RequestErrorException when missing organization data */ protected function set_scope(string $method) { switch ($method) { case "create": if ($this->owner == null) throw new Exception\InvalidMethodRequestException("Cant create organization without a related User"); $this->scope = "/admin/users/" . $this->owner->username . "/orgs"; return true; case "get": if (!$this->username) throw new Exception\RequestErrorException("Missing organization-data 'username'."); $this->scope = "/orgs/" . $this->username; return true; } return false; } /** * @see Base */ public function search(string $q) { $searchable = sprintf("%s %s %s", $this->full_name, $this->username, $this->description); return stripos($searchable, $q) !== false; } /** * Create a new user * * Valid parameters: * * 1. username * 2. full_name * 3. description * 4. website * 5. location * * This reflects the API v1 doc, but is in an order * where the required fields is first. * * @todo Create team within org with user * @param ...$args The parameter values. * @return bool */ public function create(...$args) { $params = array( "username" => isset($args[0]) && is_string($args[0]) ? $args[0] : null, "full_name" => isset($args[1]) && is_string($args[1]) ? $args[1] : null, "description" => isset($args[2]) && is_string($args[2]) ? $args[2] : null, "website" => isset($args[3]) && is_string($args[3]) ? $args[3] : null, "location" => isset($args[4]) && is_string($args[4]) ? $args[4] : null ); $params = array_filter($params, function($val) { return $val != null; }); Base::create($params); } } } ?>