Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/fact/storage/PhabricatorFactChart.php
12256 views
1
<?php
2
3
final class PhabricatorFactChart
4
extends PhabricatorFactDAO
5
implements PhabricatorPolicyInterface {
6
7
protected $chartKey;
8
protected $chartParameters = array();
9
10
private $datasets = self::ATTACHABLE;
11
12
protected function getConfiguration() {
13
return array(
14
self::CONFIG_SERIALIZATION => array(
15
'chartParameters' => self::SERIALIZATION_JSON,
16
),
17
self::CONFIG_COLUMN_SCHEMA => array(
18
'chartKey' => 'bytes12',
19
),
20
self::CONFIG_KEY_SCHEMA => array(
21
'key_chart' => array(
22
'columns' => array('chartKey'),
23
'unique' => true,
24
),
25
),
26
) + parent::getConfiguration();
27
}
28
29
public function setChartParameter($key, $value) {
30
$this->chartParameters[$key] = $value;
31
return $this;
32
}
33
34
public function getChartParameter($key, $default = null) {
35
return idx($this->chartParameters, $key, $default);
36
}
37
38
public function newChartKey() {
39
$digest = serialize($this->chartParameters);
40
$digest = PhabricatorHash::digestForIndex($digest);
41
return $digest;
42
}
43
44
public function save() {
45
if ($this->getID()) {
46
throw new Exception(
47
pht(
48
'Chart configurations are not mutable. You can not update or '.
49
'overwrite an existing chart configuration.'));
50
}
51
52
$this->chartKey = $this->newChartKey();
53
54
return parent::save();
55
}
56
57
public function attachDatasets(array $datasets) {
58
assert_instances_of($datasets, 'PhabricatorChartDataset');
59
$this->datasets = $datasets;
60
return $this;
61
}
62
63
public function getDatasets() {
64
return $this->assertAttached($this->datasets);
65
}
66
67
public function getURI() {
68
return urisprintf('/fact/chart/%s/', $this->getChartKey());
69
}
70
71
/* -( PhabricatorPolicyInterface )----------------------------------------- */
72
73
public function getCapabilities() {
74
return array(
75
PhabricatorPolicyCapability::CAN_VIEW,
76
);
77
}
78
79
public function getPolicy($capability) {
80
return PhabricatorPolicies::getMostOpenPolicy();
81
}
82
83
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
84
return false;
85
}
86
87
88
}
89
90