/** * List an organization's sites * * ## OPTIONS * * [--org=<id>] * : Organization id * * [--tag=<tag>] * : Tag name to filter sites list by * * [--add=<site>] * : Site to add to organization * * [--remove=<site>] * : Site to remove from organization * * @subcommand sites * */ public function sites($args, $assoc_args) { $org_id = Input::orgid($assoc_args, 'org', null, array('allow_none' => false)); $org = new Organization($org_id); if (isset($assoc_args['add'])) { $add = SiteFactory::instance(Input::sitename($assoc_args, 'add')); Terminus::confirm("Are you sure you want to add %s to %s ?", $assoc_args, array($add->getName(), $org->name)); $org->addSite($add); Terminus::success("Added site!"); return true; } if (isset($assoc_args['remove'])) { $remove = SiteFactory::instance(Input::sitename($assoc_args, 'remove')); Terminus::confirm("Are you sure you want to remove %s to %s ?", $assoc_args, array($remove->getName(), $org->name)); $org->removeSite($remove); Terminus::success("Removed site!"); return true; } $org->siteMemberships->fetch(); $memberships = $org->siteMemberships->all(); foreach ($memberships as $membership) { if (isset($assoc_args['tag']) && !in_array($assoc_args['tag'], $membership->get('tags'))) { continue; } $site = $membership->get('site'); $data[] = array('name' => $site->name, 'id' => $site->id, 'service_level' => $site->service_level, 'framework' => $site->framework, 'created' => date('Y-m-d H:i:s', $site->created), 'tags' => $membership->get('tags')); } $this->handleDisplay($data); }
/** * List an organizations sites * * ## OPTIONS * * [--org=<org>] * : Organization name or Id * * [--add=<site>] * : Site to add to organization * * [--remove=<site>] * : Site to remove from organization * * @subcommand sites * */ public function sites($args, $assoc_args) { $orgs = array(); $user = new User(); foreach ($user->organizations() as $id => $org) { $orgs[$id] = $org->name; } if (!isset($assoc_args['org']) or empty($assoc_args['org'])) { $selected_org = Terminus::menu($orgs, false, "Choose an organization"); } else { $selected_org = $assoc_args['org']; } $org = new Organization($selected_org); if (isset($assoc_args['add'])) { $add = SiteFactory::instance(Input::site($assoc_args, 'add')); Terminus::confirm("Are you sure you want to add %s to %s ?", $assoc_args, array($add->getName(), $org->name)); $org->addSite($add); Terminus::success("Added site!"); return true; } if (isset($assoc_args['remove'])) { $remove = SiteFactory::instance(Input::site($assoc_args, 'remove')); Terminus::confirm("Are you sure you want to remove %s to %s ?", $assoc_args, array($remove->getName(), $org->name)); $org->removeSite($remove); Terminus::success("Removed site!"); return true; } $sites = $org->getSites(); $data = array(); foreach ($sites as $site) { $data[] = array('name' => $site->site->name, 'service level' => isset($site->site->service_level) ? $site->site->service_level : '', 'framework' => isset($site->site->framework) ? $site->site->framework : '', 'created' => date('Y-m-d H:i:s', $site->site->created)); } $this->handleDisplay($data); }