2016-01-12 10:27:39 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProfilePanelConfiguration
|
|
|
|
extends PhabricatorSearchDAO
|
|
|
|
implements
|
|
|
|
PhabricatorPolicyInterface,
|
2016-01-12 15:06:43 -08:00
|
|
|
PhabricatorExtendedPolicyInterface,
|
|
|
|
PhabricatorApplicationTransactionInterface {
|
2016-01-12 10:27:39 -08:00
|
|
|
|
|
|
|
protected $profilePHID;
|
|
|
|
protected $panelKey;
|
|
|
|
protected $builtinKey;
|
|
|
|
protected $panelOrder;
|
2016-01-12 15:06:43 -08:00
|
|
|
protected $visibility;
|
2016-01-12 10:27:39 -08:00
|
|
|
protected $panelProperties = array();
|
|
|
|
|
|
|
|
private $profileObject = self::ATTACHABLE;
|
|
|
|
private $panel = self::ATTACHABLE;
|
|
|
|
|
2016-01-22 05:33:21 -08:00
|
|
|
const VISIBILITY_DEFAULT = 'default';
|
2016-01-12 15:06:43 -08:00
|
|
|
const VISIBILITY_VISIBLE = 'visible';
|
|
|
|
const VISIBILITY_DISABLED = 'disabled';
|
|
|
|
|
|
|
|
public static function initializeNewBuiltin() {
|
|
|
|
return id(new self())
|
|
|
|
->setVisibility(self::VISIBILITY_VISIBLE);
|
|
|
|
}
|
|
|
|
|
2016-01-12 10:27:39 -08:00
|
|
|
public static function initializeNewPanelConfiguration(
|
2016-01-14 05:59:25 -08:00
|
|
|
$profile_object,
|
2016-01-12 10:27:39 -08:00
|
|
|
PhabricatorProfilePanel $panel) {
|
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
return self::initializeNewBuiltin()
|
2016-01-12 10:27:39 -08:00
|
|
|
->setProfilePHID($profile_object->getPHID())
|
|
|
|
->setPanelKey($panel->getPanelKey())
|
|
|
|
->attachPanel($panel)
|
|
|
|
->attachProfileObject($profile_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
|
|
|
self::CONFIG_SERIALIZATION => array(
|
|
|
|
'panelProperties' => self::SERIALIZATION_JSON,
|
|
|
|
),
|
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
|
|
|
'panelKey' => 'text64',
|
2016-01-12 15:06:43 -08:00
|
|
|
'builtinKey' => 'text64?',
|
|
|
|
'panelOrder' => 'uint32?',
|
|
|
|
'visibility' => 'text32',
|
2016-01-12 10:27:39 -08:00
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_profile' => array(
|
|
|
|
'columns' => array('profilePHID', 'panelOrder'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
public function generatePHID() {
|
|
|
|
return PhabricatorPHID::generateNewPHID(
|
|
|
|
PhabricatorProfilePanelPHIDType::TYPECONST);
|
|
|
|
}
|
|
|
|
|
2016-01-12 10:27:39 -08:00
|
|
|
public function attachPanel(PhabricatorProfilePanel $panel) {
|
|
|
|
$this->panel = $panel;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPanel() {
|
|
|
|
return $this->assertAttached($this->panel);
|
|
|
|
}
|
|
|
|
|
2016-01-14 05:59:25 -08:00
|
|
|
public function attachProfileObject($profile_object) {
|
2016-01-12 10:27:39 -08:00
|
|
|
$this->profileObject = $profile_object;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProfileObject() {
|
|
|
|
return $this->assertAttached($this->profileObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPanelProperty($key, $value) {
|
|
|
|
$this->panelProperties[$key] = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPanelProperty($key, $default = null) {
|
|
|
|
return idx($this->panelProperties, $key, $default);
|
|
|
|
}
|
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
public function buildNavigationMenuItems() {
|
|
|
|
return $this->getPanel()->buildNavigationMenuItems($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPanelTypeName() {
|
|
|
|
return $this->getPanel()->getPanelTypeName();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDisplayName() {
|
|
|
|
return $this->getPanel()->getDisplayName($this);
|
|
|
|
}
|
|
|
|
|
2016-01-22 05:33:21 -08:00
|
|
|
public function canMakeDefault() {
|
|
|
|
return $this->getPanel()->canMakeDefault($this);
|
|
|
|
}
|
|
|
|
|
2016-01-13 09:40:27 -08:00
|
|
|
public function getSortKey() {
|
|
|
|
$order = $this->getPanelOrder();
|
|
|
|
if ($order === null) {
|
|
|
|
$order = 'Z';
|
|
|
|
} else {
|
|
|
|
$order = sprintf('%020d', $order);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf(
|
|
|
|
'~%s%020d',
|
|
|
|
$order,
|
|
|
|
$this->getID());
|
|
|
|
}
|
|
|
|
|
2016-01-13 10:40:31 -08:00
|
|
|
public function isDisabled() {
|
|
|
|
return ($this->getVisibility() === self::VISIBILITY_DISABLED);
|
|
|
|
}
|
|
|
|
|
2016-01-22 05:33:21 -08:00
|
|
|
public function isDefault() {
|
|
|
|
return ($this->getVisibility() === self::VISIBILITY_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2016-01-12 10:27:39 -08:00
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
return PhabricatorPolicies::getMostOpenPolicy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return $this->getProfileObject()->hasAutomaticCapability(
|
|
|
|
$capability,
|
|
|
|
$viewer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
$this->getProfileObject(),
|
|
|
|
$capability,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
|
|
|
|
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getApplicationTransactionEditor() {
|
|
|
|
return new PhabricatorProfilePanelEditor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionObject() {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionTemplate() {
|
|
|
|
return new PhabricatorProfilePanelConfigurationTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function willRenderTimeline(
|
|
|
|
PhabricatorApplicationTransactionView $timeline,
|
|
|
|
AphrontRequest $request) {
|
|
|
|
|
|
|
|
return $timeline;
|
|
|
|
}
|
|
|
|
|
2016-01-12 10:27:39 -08:00
|
|
|
}
|