-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #417 from pantheon-systems/site_tags
Added site tags add|delete
- Loading branch information
Showing
13 changed files
with
1,127 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
php/Terminus/Collections/SiteOrganizationMemberships.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
namespace Terminus\Collections; | ||
use Terminus\Request; | ||
use Terminus\Session; | ||
use Terminus\SiteOrganizationMembership; | ||
use \TerminusCommand; | ||
|
||
class SiteOrganizationMemberships { | ||
private $site; | ||
private $models = array(); | ||
private $workflows; | ||
|
||
/** | ||
* Object constructor. Saves site object | ||
* | ||
* @return [SiteOrganizationMemberships] $this | ||
*/ | ||
public function __construct($options = array()) { | ||
$this->site = $options['site']; | ||
} | ||
|
||
/** | ||
* Adds this org as a member to the site | ||
* | ||
* @param [string] $site Name of site to add org to | ||
* @return [Workflow] $workflow | ||
**/ | ||
public function add($name, $role) { | ||
$workflow = $this->site->workflows->create( | ||
'add_site_organization_membership', | ||
array('params' => array('organization_name' => $name, 'role' => $role)) | ||
); | ||
return $workflow; | ||
} | ||
|
||
/** | ||
* Lists all organizational members | ||
* | ||
* @return [array] $org_memberships SiteOrganizationMembership objects for each org member | ||
*/ | ||
public function all() { | ||
$org_memberships = array_values($this->models); | ||
return $org_memberships; | ||
} | ||
|
||
/** | ||
* Retrieves organization with given UUID or name, if such exists | ||
* | ||
* @param [string] $id User UUID or name | ||
* @return [SiteOrganizationMembership] $this->models[$id] Org or null | ||
*/ | ||
public function get($id) { | ||
if(isset($this->models[$id])) { | ||
return $this->models[$id]; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Retrieves and fills in team member data | ||
* | ||
* @return [SiteOrganizationMemberships] $this | ||
*/ | ||
public function fetch() { | ||
$results = TerminusCommand::paged_request( | ||
'sites/' . $this->site->get('id') . '/memberships/organizations' | ||
); | ||
|
||
foreach($results['data'] as $id => $org_membership_data) { | ||
$org_membership_data = (array)$org_membership_data; | ||
$org_membership_data['id'] = $org_membership_data['organization_id']; | ||
$org_membership_data['site'] = $this->site; | ||
$this->models[$id] = new SiteOrganizationMembership( | ||
$this->site, | ||
$org_membership_data | ||
); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Returns UUID of organization with given name | ||
* | ||
* @param [string] $email A name to search for | ||
* @return [SiteOrganizationMembership] $orgs[$name] | ||
*/ | ||
public function findByName($name) { | ||
$orgs = array(); | ||
foreach($this->models as $org_member) { | ||
$org = $org_member->getName(); | ||
if($org->name == $org) { | ||
return $org_member; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Lists IDs of all organizational members of this site | ||
* | ||
* @return [array] $ids Array of organization UUIDs | ||
*/ | ||
public function ids() { | ||
$ids = array_keys($this->models); | ||
return $ids; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace Terminus; | ||
use \ReflectionClass; | ||
use \Terminus\Request; | ||
use \Terminus\Collections\Bindings; | ||
|
||
class SiteOrganizationMembership { | ||
private $id; | ||
private $attributes; | ||
private $site; | ||
private $organization; | ||
|
||
/** | ||
* Object constructor | ||
* | ||
* @param [stdClass] $attributes | ||
* @param [array] $options | ||
* @return [SiteOrganizationMembership] $this | ||
*/ | ||
public function __construct($attributes, $options = array()) { | ||
if(!is_array($options)) { | ||
$options = get_object_vars($options); | ||
} | ||
foreach($options as $var_name => $value) { | ||
$this->$var_name = $value; | ||
} | ||
$this->attributes = $attributes; | ||
} | ||
|
||
/** | ||
* Returns attribute of given name | ||
* | ||
* @param [string] $attribute Name of attribute to retrieve | ||
* @return [mixed] $this->attributes->$attribute or null | ||
*/ | ||
public function get($attribute) { | ||
if(isset($this->attributes->$attribute)) { | ||
return $this->attributes->$attribute; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns organization object within SiteOrganizationMembership object | ||
* | ||
* @return [Organization] $this->organization Org associated with this SiteOrganizationMembership | ||
*/ | ||
public function getOrganization() { | ||
if (!isset($this->organization)) { | ||
$this->organization = new Organization($this->id); | ||
} | ||
return $this->organization; | ||
} | ||
/** | ||
* Remove membership of organization | ||
* | ||
* @return [Workflow] $workflow | ||
**/ | ||
public function remove() { | ||
$workflow = $this->site->workflows->create( | ||
'remove_site_organization_membership', | ||
array('params' => array('organization_id' => $this->id)) | ||
); | ||
return $workflow; | ||
} | ||
|
||
/** | ||
* Changes the role of the given member | ||
* | ||
* @param [string] $role Desired role for this organization | ||
* @return [Workflow] $workflow | ||
*/ | ||
public function setRole($role) { | ||
$workflow = $this->site->workflows->create( | ||
'update_site_organization_membership', | ||
array('params' => array('organization_id' => $this->id, 'role' => $role))); | ||
return $workflow; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.