3 final class AlmanacProperty
5 implements PhabricatorPolicyInterface
{
10 protected $fieldValue;
12 private $object = self
::ATTACHABLE
;
14 protected function getConfiguration() {
16 self
::CONFIG_TIMESTAMPS
=> false,
17 self
::CONFIG_SERIALIZATION
=> array(
18 'fieldValue' => self
::SERIALIZATION_JSON
,
20 self
::CONFIG_COLUMN_SCHEMA
=> array(
21 'fieldIndex' => 'bytes12',
22 'fieldName' => 'text128',
24 self
::CONFIG_KEY_SCHEMA
=> array(
25 'objectPHID' => array(
26 'columns' => array('objectPHID', 'fieldIndex'),
30 ) + parent
::getConfiguration();
33 public function getObject() {
34 return $this->assertAttached($this->object);
37 public function attachObject(PhabricatorLiskDAO
$object) {
38 $this->object = $object;
42 public static function newPropertyUpdateTransactions(
43 AlmanacPropertyInterface
$object,
45 $only_builtins = false) {
47 $template = $object->getApplicationTransactionTemplate();
48 $builtins = $object->getAlmanacPropertyFieldSpecifications();
51 foreach ($properties as $name => $property) {
52 if ($only_builtins && empty($builtins[$name])) {
56 $xactions[] = id(clone $template)
57 ->setTransactionType($object->getAlmanacPropertySetTransactionType())
58 ->setMetadataValue('almanac.property', $name)
59 ->setNewValue($property);
65 public static function newPropertyRemoveTransactions(
66 AlmanacPropertyInterface
$object,
69 $template = $object->getApplicationTransactionTemplate();
72 foreach ($properties as $property) {
73 $xactions[] = id(clone $template)
74 ->setTransactionType($object->getAlmanacPropertyDeleteTransactionType())
75 ->setMetadataValue('almanac.property', $property)
82 public function save() {
83 $hash = PhabricatorHash
::digestForIndex($this->getFieldName());
84 $this->setFieldIndex($hash);
86 return parent
::save();
90 /* -( PhabricatorPolicyInterface )----------------------------------------- */
93 public function getCapabilities() {
95 PhabricatorPolicyCapability
::CAN_VIEW
,
96 PhabricatorPolicyCapability
::CAN_EDIT
,
100 public function getPolicy($capability) {
101 return $this->getObject()->getPolicy($capability);
104 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
105 return $this->getObject()->hasAutomaticCapability($capability, $viewer);
108 public function describeAutomaticCapability($capability) {
109 return pht('Properties inherit the policies of their object.');