9
9
abstract class VIEW implements VIEWInterface {
14
var $min_width, $min_height;
17
var $caches; // CacheSet
18
var $ivl; // CacheSet Interval
20
const MERGE_START = 1;
22
const ALLOW_SAME_CHANNEL = 1;
23
const FORBID_MULTIPLE_GROUPS = 2;
25
const GET_RAW_DATA = 1;
13
27
function __construct(REQUEST $req = NULL, $options) {
28
$this->req = $req?$req:new REQUEST();
15
29
$this->options = $options;
31
$this->object = $this->req->GetProp("view_object", false);
34
$this->max_points = $this->GetOption('max_points', 500);
36
$this->max_points = $this->GetOption('max_points', 5000);
39
$this->aggregation = $this->GetOption('aggregation', false);
40
$this->min_width = $this->GetOption('min_width', 0);
41
$this->min_height = $this->GetOption('min_height', 0);
43
$this->DetectImageDimensions();
44
$this->CreateCacheSet();
47
function GetProp($prop, $default = false) {
48
if (!preg_match("/^view_/", $prop))
49
$prop = "view_" . $prop;
51
return $this->req->GetProp($prop, $default);
54
function GetOption($opt, $default = false) {
55
if (isset($this->options[$opt])) return $this->options[$opt];
18
59
function IsApplicable() {
21
63
function GetOptions() {
67
function DetectImageDimensions() {
69
$width = $this->req->GetProp($this->object . "_width", $this->min_width + 20) - 20;
70
if ($width < $this->min_width) $width = $this->min_width;
71
$height = $width - 40;//$this->req->GetProp($this->object . "_height", $this->min_height);
73
$width = $this->req->GetProp("page_width", $this->min_width + 5) - 5;
74
$height = $this->req->GetProp("page_height", $this->min_height);
75
if ($width < $this->min_width) $width = $this->min_width;
76
if ($height < $this->min_height) $height = $this->min_height;
79
$this->width = $width;
80
$this->height = $height;
83
function CreateCacheSet() {
85
$req = $this->req->CreateDataRequest();
87
$rdr = $req->CreateReader();
88
$group = $rdr->CreateGroup();
89
$caches = $rdr->CreateCacheSet($group, $mask);
90
$iv = $caches->CreateInterval($req, true);
92
$this->caches = $caches;
98
function ParseDataOptions($params, $ignore_missing = false) {
101
foreach ($params as $param) {
102
$x = $this->GetProp($param, false);
104
list($x_gid, $x_id) = explode(":", $x);
105
} else if (!$ignore_missing) {
106
throw new ADEIException(translate("Parameter $param is not set"));
109
if (!is_array($ids[$x_gid]))
110
$ids[$x_gid] = array();
111
array_push($ids[$x_gid], $x_id);
117
function GetDataVariants($params, $flags = 0) {
118
$this->CreateCacheSet();
120
if (!is_array($params))
121
$params = array($params);
124
for ($i = 0; $i < sizeof($params); $i++) {
125
$result[$i] = array();
130
foreach ($this->caches as $key => $cachewrap) {
131
for ($i = 0; $i < sizeof($params); $i++) {
132
array_push($result[$i], array("label" => $cachewrap->GetGroupTitle(), "disabled" => 1));
136
$list = $cachewrap->GetItemList();
138
foreach ($list as $id => $info) {
139
$title = $info['name'];
140
for ($i = 0; $i < sizeof($params); $i++) {
141
$selected_chan = false;
143
$idx = array_search("$gid:$id", $values);
144
if ($idx === false) {
145
// free we can assign
146
if (!isset($values[$i])) {
147
$setval = $this->GetProp($params[$i], false);
149
// What if it invalid value? It will be just left unselected.
150
$values[$i] = $setval;
152
$values[$i] ="$gid:$id";
155
} else if ($idx < $i) {
156
// Already used before
157
if (($flags&VIEW::ALLOW_SAME_CHANNEL) == 0)
160
// Even if it set for later input, we can use it here and override...
161
// If it is invalid, the earlier is also set to something valid/invalid anyway...
165
if ($fixed_gid !== false) {
166
if ($gid != $fixed_gid)
170
if (($flags&VIEW::FORBID_MULTIPLE_GROUPS)&&(isset($values[$i]))) {
171
list($fixed_gid, $tmp) = explode(":", $values[$i]);
175
array_push($result[$i], array("value" => "$gid:$id", "label" => " $title"));
185
function GetDataOptions($params, $flags = 0) {
186
$result = $this->GetDataVariants($params, $flags);
188
if (!is_array($params))
189
$params = array($params);
192
for ($i = 0; $i < sizeof($params); $i++) {
193
array_push($res, array("select" => array("label" => $params[$i], "id" => $params[$i], "options" => $result[$i])));
194
array_push($res, array("xml"=>"<br/>"));
200
function GetData($params, INTERVAL $iv = NULL, $flags = 0) {
201
$this->CreateCacheSet();
202
if (!$iv) $iv = $this->ivl;
204
if (!is_array($params))
205
$params = array($params);
207
$ids = $this->ParseDataOptions($params);
209
$window_size = $iv->GetWindowSize();
210
$window_start = $iv->GetWindowStart();
211
$window_end = $iv->GetWindowEnd();
214
'limit' => $this->max_points,
220
foreach ($this->caches as $key => $cachewrap) {
221
if (!isset($ids[$gid])) {
228
if ($flags&VIEW::GET_RAW_DATA) {
229
$points = $cachewrap->GetAllPoints($this->ivl, $this->max_points);
230
$operation_info = array("resolution" => 0);
232
$resolution = $cachewrap->GetResolution();
233
if ($this->aggregation === false) {
234
$r = $resolution->Get($iv, $this->width);
235
$size = $resolution->GetWindowSize($r);
237
if (($size > 0)&&(($window_size / $size) > $this->max_points)) {
238
$new_r = $resolution->Larger($r);
239
if ($new_r !== false) $r = $new_r;
242
$r = $resolution->GetByWindowSize($this->aggregation);
244
$rescfg['resolution'] = $r;
245
$points = $cachewrap->GetIntervals($iv, $rescfg, CACHE::TRUNCATE_INTERVALS);
246
$operation_info = $points->GetOperationInfo();
250
foreach ($ids[$gid] as $i => $id) {
251
$info[$i] = $operation_info;
254
foreach($points as $t => $v) {
255
foreach ($ids[$gid] as $i => $id) {
256
if ($flags&VIEW::GET_RAW_DATA) $val = $v[$id];
257
else $val = $v['mean'.$id];
259
if (is_numeric($val)) {
260
if (!is_array($data[$t])) $data[$t] = array();
261
$data[$t][$gpos + $i] = $val;
267
$gpos += sizeof($ids[$i]);
270
return array("info" => $info, "data" => $data);
273
function MergeViewInfo(&$view, $info, $flags = 0) {
275
foreach ($view as &$v) {
276
if (isset($v['info'])) {
277
if ($flags&VIEW::MERGE_START)
278
$v['info'] = array_merge($info, $v['info']);
280
$v['info'] = array_merge($v['info'], $info);
288
array_push($view, array("info" => $info));
b'\\ No newline at end of file'