function GetGroupRequest(LOGGROUP $grp, MASK $mask = NULL) { if (!isset($this->list[$grp->gid])) { throw new ADEIException(translate("Unknown group (%s) is requested in SOURCETree::GetGroupRequest", $grp->gid)); } $info = $this->list[$grp->gid]; if ($mask && is_array($mask->ids)) { if ($info['items'] === false) { $info['props']['db_mask'] = $mask->GetProp(); } else { $ires = array(); foreach ($mask->ids as $id) { if (isset($info['items'][$id])) { array_push($ires, $info['items'][$id]); } else { throw new ADEIException(translate("Invalid mask, item (%s) is not present in group", $id)); } } if ($ires) { $info['props']['db_mask'] = implode(",", $ires); } else { $info['props']['db_mask'] = false; } } } /* if ($this->props_cast) { call_user_func($this->props_cast, $info['props'], $grp->gid); } */ return new GROUPRequest($info['props']); }
function FindColumns(LOGGROUP $grp, MASK $mask = NULL) { $sql_filters = false; if (!$this->time_column || !$this->time_column[$grp->gid]) { $time_column_base = $this->columns['time']; if ($this->time_module) { $time_column = $this->db->col_quote . $time_column_base . $this->db->col_quote; } else { // This will never work. We always create time_module in the constructor. Why we have it here? $time_column = $this->db->GetTimeRequest($time_column_base); } if ($this->time_module && !$this->use_db_slicer) { $slicer_column = $this->db->col_quote . $time_column_base . $this->db->col_quote; } else { $slicer_column = $this->db->GetSlicerRequest($time_column_base); } $sql_filters = $this->req->GetGroupOption("sql_filters", $grp, array()); $data_columns = array(); $msk = $this->CreateMask($grp, $info = array()); // if ($msk->IsFull()) $flags = 0; // else $flags = REQUEST::LIST_CUSTOM; $items = $this->GetItemList($grp, $msk); foreach ($items as $item) { $col = $this->db->col_quote . $item['column'] . $this->db->col_quote; foreach ($sql_filters as $re => $sqlflt) { if (preg_match($re, $item['column'])) { $col = $this->ApplySqlFilters($col, $sqlflt); break; } } array_push($data_columns, $col); } $this->data_columns[$grp->gid] = $data_columns; $this->time_column[$grp->gid] = $time_column; $this->slicer_column[$grp->gid] = $slicer_column; } if ($mask && is_array($ids = $mask->GetIDs())) { if (!isset($time_column)) { $data_columns =& $this->data_columns[$grp->gid]; $time_column = $this->time_column[$grp->gid]; } $data_request = ""; $custom_columns = false; foreach ($ids as $id) { if (isset($data_columns[$id])) { $data_request .= "{$data_columns[$id]}, "; } else { if ($custom_columns === false) { if ($sql_filters === false) { $sql_filters = $this->req->GetGroupOption("sql_filters", $grp, array()); } if (isset($this->custom_columns[$grp->gid])) { $custom_columns =& $this->custom_columns[$grp->gid]; } else { $items = $this->GetItemList($grp, $msk = $this->CreateMask($grp, $minfo = array()), REQUEST::LIST_CUSTOM); $custom_columns = array(); $i = 0; foreach ($items as $item) { if ($item['custom']) { $col = $this->db->col_quote . $item['column'] . $this->db->col_quote; foreach ($sql_filters as $re => $sqlflt) { if (preg_match($re, $item['column'])) { $col = $this->ApplySqlFilters($col, $sqlflt); break; } } $custom_columns["c" . $i++] = $col; } } $this->custom_columns[$grp->gid] = $custom_columns; } } if (isset($custom_columns[$id])) { $data_request .= "{$custom_columns[$id]}, "; } else { throw new ADEIException(translate("Invalid item mask is supplied. The ID:%s refers non-existing item.", $id)); } } } return "{$data_request}{$time_column}"; } elseif ($this->data_request[$grp->gid]) { return $this->data_request[$grp->gid]; } else { $this->data_request[$grp->gid] = implode(", ", $this->data_columns[$grp->gid]) . ", " . $this->time_column[$grp->gid]; return $this->data_request[$grp->gid]; } }
function Superpose(MASK $mask = NULL) { if (!$mask || $mask->IsFull()) { return $this; } else { if ($this->IsFull()) { return $mask; } } $res = array(); foreach ($mask->ids as $id) { if (isset($this->ids[$id])) { array_push($res, $this->ids[$id]); } else { throw new ADEIException(translate("Invalid mask (%s) is passed for supperposing. The base mask is (%s)", $mask->GetProp(), $this->GetProp())); } } $mask = new MASK(); $mask->SetIDs($res); return $mask; }
function CreateSimpleRequestSet(MASK $mask = NULL, LOGGROUP $grp = NULL, $type = "GROUPRequest") { $props = array(); if ($grp) { $props['db_group'] = $grp->GetProp(); } if ($mask) { $props['db_mask'] = $mask->GetProp(); } return new REQUESTList($this->props, $list = array($props), $type); }
function CreateDataFilter(LOGGROUP $grp = NULL, MASK $mask = NULL, $resample = false, $limit = 0, $additional_filter = NULL) { $grp = $this->CheckGroup($grp); $filters = $this->GetGroupOption($grp, "data_filters"); if (!$filters && isset($this->data_filters)) { $filters = $this->data_filters; } $exts = $this->GetGroupOption($grp, "data_extractors"); if ($exts) { $list = $this->GetItemList($grp, $mask); $extra = array(); $ids = array(); $extractors = array(); $mapping = array(); foreach ($list as &$item) { $id = $item['id']; if ($item['item_type']) { if (isset($item['item_dependency'])) { $dep = $item['item_dependency']; if (!$mask || !$mask->CheckStandard($dep)) { array_push($extra, $dep); } } if (!isset($extractors[$item['item_extractor_id']])) { $extractors[$item['item_extractor_id']] = array(); } if (!isset($extractors[$item['item_extractor_id']][$item['item_dependency']])) { $extractors[$item['item_extractor_id']][$item['item_dependency']] = array(); } array_push($extractors[$item['item_extractor_id']][$item['item_dependency']], $item['extractor_item']); $mapping[$id] = array($item['item_extractor_id'], $item['item_dependency'], $item['extractor_item']); } else { array_push($ids, $item['id']); //$mapping[$id] = true; } } if ($extractors) { if ($filters) { if ($additional_filter) { $additional_filter = new READER_SUPERDataFilter($additional_filter, $this, $grp, $filters, $mask, $resample, $limit); } else { $additional_filter = new READER_DATAFilter($this, $grp, $filters, $mask, $resample, $limit); } } $new_mask = new MASK(); $new_mask->SetIDs(array_merge($ids, array_unique($extra))); $extra_filter = array("class" => "EXTRACTORFilter", "mask" => $mask, "config" => $exts, "extractors" => $extractors, "mappings" => $mapping); $filters = array($extra_filter); $mask = $new_mask; } } if ($mask) { $custom_filters = $this->GetGroupOption($grp, "custom_data_filters"); if ($custom_filters && $mask->IsCustom()) { if ($filters) { $filters = array_merge($custom_filters, $filters); } else { $filters = $custom_filters; } } } if ($resample === false) { $resample = $this->GetGroupOption($grp, "resample", 0); } if ($filters || $mask || $resample || $limit) { if ($additional_filter) { $filter = new READER_SUPERDataFilter($additional_filter, $this, $grp, $filters, $mask, $resample, $limit); } else { $filter = new READER_DATAFilter($this, $grp, $filters, $mask, $resample, $limit); } return $filter; } return $additional_filter; }
function GetAlarmList(LOGGROUP $grp = NULL, MASK $mask = NULL, $flags = 0) { $masktest = ""; if ($mask) { $ids = $mask->GetIDs(); if ($ids) { $lastid = array_pop($ids); foreach ($ids as $id) { $masktest .= "(messageid = {$id}) OR "; } $masktest .= "(messageid = {$lastid})"; } } $columns = "messageid AS id, mtype AS severity, name"; $selopts = array(); if ($masktest) { $selopts['condition'] = $masktest; } $query = $this->db->SelectRequest("messages", $columns, $selopts); $resp = $this->db->Query($query); $res = array(); if ($resp) { foreach ($resp as $row) { $res[$row['id']] = $row; } } return $res; }