org.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php namespace Client\Request;
  2. class Org extends User {
  3. public $udescription;
  4. public $uwebsite;
  5. public $ulocation;
  6. private $owner;
  7. public function __construct(string $api_url, string $api_token, string $oname = null, User $owner = null) {
  8. $this->ousername = $oname;
  9. $this->owner = $owner;
  10. parent::__construct($api_url, $api_token);
  11. }
  12. protected function set_scope(string $method) {
  13. switch ($method) {
  14. case "create":
  15. if ($this->owner == null);
  16. $this->scope = "/admin/users/" . $this->owner->uusername . "/orgs";
  17. return true;
  18. case "get":
  19. $this->scope = "/orgs/" . $this->uusername;
  20. return true;
  21. }
  22. }
  23. public function search(string $q) {
  24. $searchable = sprintf("%s %s %s", $this->ufull_name, $this->uusername, $this->udescription);
  25. return stripos($searchable, $q) !== false;
  26. }
  27. public function create(...$args) {
  28. $params = array(
  29. "username" => isset($args[0]) && is_string($args[0]) ? $args[0] : null,
  30. "ufull_name" => isset($args[1]) && is_string($args[1]) ? $args[1] : null,
  31. "description" => isset($args[2]) && is_string($args[2]) ? $args[2] : null,
  32. "website" => isset($args[3]) && is_string($args[3]) ? $args[3] : null,
  33. "location" => isset($args[4]) && is_string($args[4]) ? $args[4] : null
  34. );
  35. $params = array_filter($params, function($val) {
  36. return $val != null;
  37. });
  38. parent::create($params);
  39. }
  40. }