Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/storage/DrydockBlueprint.php
<?php | <?php | ||||
/** | |||||
* @task resource Allocating Resources | |||||
* @task lease Acquiring Leases | |||||
*/ | |||||
final class DrydockBlueprint extends DrydockDAO | final class DrydockBlueprint extends DrydockDAO | ||||
implements | implements | ||||
PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
PhabricatorCustomFieldInterface { | PhabricatorCustomFieldInterface { | ||||
protected $className; | protected $className; | ||||
protected $blueprintName; | protected $blueprintName; | ||||
protected $viewPolicy; | protected $viewPolicy; | ||||
protected $editPolicy; | protected $editPolicy; | ||||
protected $details = array(); | protected $details = array(); | ||||
private $implementation = self::ATTACHABLE; | private $implementation = self::ATTACHABLE; | ||||
private $customFields = self::ATTACHABLE; | private $customFields = self::ATTACHABLE; | ||||
private $fields = null; | |||||
public static function initializeNewBlueprint(PhabricatorUser $actor) { | public static function initializeNewBlueprint(PhabricatorUser $actor) { | ||||
$app = id(new PhabricatorApplicationQuery()) | $app = id(new PhabricatorApplicationQuery()) | ||||
->setViewer($actor) | ->setViewer($actor) | ||||
->withClasses(array('PhabricatorDrydockApplication')) | ->withClasses(array('PhabricatorDrydockApplication')) | ||||
->executeOne(); | ->executeOne(); | ||||
$view_policy = $app->getPolicy( | $view_policy = $app->getPolicy( | ||||
Show All 38 Lines | public function getDetail($key, $default = null) { | ||||
return idx($this->details, $key, $default); | return idx($this->details, $key, $default); | ||||
} | } | ||||
public function setDetail($key, $value) { | public function setDetail($key, $value) { | ||||
$this->details[$key] = $value; | $this->details[$key] = $value; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getFieldValue($key) { | |||||
$key = "std:drydock:core:{$key}"; | |||||
$fields = $this->loadCustomFields(); | |||||
$field = idx($fields, $key); | |||||
if (!$field) { | |||||
throw new Exception( | |||||
pht( | |||||
'Unknown blueprint field "%s"!', | |||||
$key)); | |||||
} | |||||
return $field->getBlueprintFieldValue(); | |||||
} | |||||
private function loadCustomFields() { | |||||
if ($this->fields === null) { | |||||
$field_list = PhabricatorCustomField::getObjectFields( | |||||
$this, | |||||
PhabricatorCustomField::ROLE_VIEW); | |||||
$field_list->readFieldsFromStorage($this); | |||||
$this->fields = $field_list->getFields(); | |||||
} | |||||
return $this->fields; | |||||
} | |||||
/* -( Allocating Resources )----------------------------------------------- */ | |||||
/** | |||||
* @task resource | |||||
*/ | |||||
public function canEverAllocateResourceForLease(DrydockLease $lease) { | public function canEverAllocateResourceForLease(DrydockLease $lease) { | ||||
return $this->getImplementation()->canEverAllocateResourceForLease( | return $this->getImplementation()->canEverAllocateResourceForLease( | ||||
$this, | $this, | ||||
$lease); | $lease); | ||||
} | } | ||||
/** | |||||
* @task resource | |||||
*/ | |||||
public function canAllocateResourceForLease(DrydockLease $lease) { | public function canAllocateResourceForLease(DrydockLease $lease) { | ||||
return $this->getImplementation()->canAllocateResourceForLease( | return $this->getImplementation()->canAllocateResourceForLease( | ||||
$this, | $this, | ||||
$lease); | $lease); | ||||
} | } | ||||
public function canAllocateLeaseOnResource( | |||||
/** | |||||
* @task resource | |||||
*/ | |||||
public function allocateResource(DrydockLease $lease) { | |||||
return $this->getImplementation()->allocateResource( | |||||
$this, | |||||
$lease); | |||||
} | |||||
/* -( Acquiring Leases )--------------------------------------------------- */ | |||||
/** | |||||
* @task lease | |||||
*/ | |||||
public function canAcquireLeaseOnResource( | |||||
DrydockResource $resource, | DrydockResource $resource, | ||||
DrydockLease $lease) { | DrydockLease $lease) { | ||||
return $this->getImplementation()->canAllocateLeaseOnResource( | return $this->getImplementation()->canAcquireLeaseOnResource( | ||||
$this, | $this, | ||||
$resource, | $resource, | ||||
$lease); | $lease); | ||||
} | } | ||||
/** | |||||
* @task lease | |||||
*/ | |||||
public function acquireLease( | |||||
DrydockResource $resource, | |||||
DrydockLease $lease) { | |||||
return $this->getImplementation()->acquireLease( | |||||
$this, | |||||
$resource, | |||||
$lease); | |||||
} | |||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */ | /* -( PhabricatorApplicationTransactionInterface )------------------------- */ | ||||
public function getApplicationTransactionEditor() { | public function getApplicationTransactionEditor() { | ||||
return new DrydockBlueprintEditor(); | return new DrydockBlueprintEditor(); | ||||
} | } | ||||
public function getApplicationTransactionObject() { | public function getApplicationTransactionObject() { | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |