mirror of https://github.com/MISP/MISP
chg: [internal] Move getting sightings range to one place
parent
ea5a819064
commit
ce47d32df1
|
@ -5480,18 +5480,14 @@ class Event extends AppModel
|
|||
);
|
||||
}
|
||||
|
||||
public function getSightingData($event)
|
||||
public function getSightingData(array $event)
|
||||
{
|
||||
$this->Sighting = ClassRegistry::init('Sighting');
|
||||
if (!empty($event['Sighting'])) {
|
||||
$attributeSightings = array();
|
||||
$attributeOwnSightings = array();
|
||||
$attributeSightingsPopover = array();
|
||||
$sightingsData = array();
|
||||
$sparklineData = array();
|
||||
$startDates = array();
|
||||
$range = (!empty(Configure::read('MISP.Sightings_range')) && is_numeric(Configure::read('MISP.Sightings_range'))) ? Configure::read('MISP.Sightings_range') : 365;
|
||||
$range = strtotime("-" . $range . " days", time());
|
||||
$range = $this->Sighting->getMaximumRange();
|
||||
foreach ($event['Sighting'] as $sighting) {
|
||||
$type = $this->Sighting->type[$sighting['type']];
|
||||
if (!isset($sightingsData[$sighting['attribute_id']][$type])) {
|
||||
|
@ -5533,22 +5529,21 @@ class Event extends AppModel
|
|||
}
|
||||
}
|
||||
$csv = array();
|
||||
$today = strtotime(date('Y-m-d', time()));
|
||||
foreach ($startDates as $k => $v) {
|
||||
$startDates[$k] = date('Y-m-d', $v);
|
||||
}
|
||||
$range = (!empty(Configure::read('MISP.Sightings_range')) && is_numeric(Configure::read('MISP.Sightings_range'))) ? Configure::read('MISP.Sightings_range') : 365;
|
||||
foreach ($sparklineData as $aid => $data) {
|
||||
if (!isset($startDates[$aid])) {
|
||||
continue;
|
||||
}
|
||||
$startDate = $startDates[$aid];
|
||||
if (strtotime($startDate) < strtotime('-' . $range . ' days', time())) {
|
||||
if (strtotime($startDate) < $range) {
|
||||
$startDate = date('Y-m-d');
|
||||
}
|
||||
$startDate = date('Y-m-d', strtotime("-3 days", strtotime($startDate)));
|
||||
$to = date('Y-m-d', time());
|
||||
$sighting = $data;
|
||||
for ($date = $startDate; strtotime($date) <= strtotime($to); $date = date('Y-m-d', strtotime("+1 day", strtotime($date)))) {
|
||||
for ($date = $startDate; strtotime($date) <= $today; $date = date('Y-m-d', strtotime("+1 day", strtotime($date)))) {
|
||||
if (!isset($csv[$aid])) {
|
||||
$csv[$aid] = 'Date,Close\n';
|
||||
}
|
||||
|
|
|
@ -472,9 +472,8 @@ class Sighting extends AppModel
|
|||
|
||||
public function getSightingsForTag($user, $tag_id, $sgids = array(), $type = false)
|
||||
{
|
||||
$range = (!empty(Configure::read('MISP.Sightings_range')) && is_numeric(Configure::read('MISP.Sightings_range'))) ? Configure::read('MISP.Sightings_range') : 365;
|
||||
$conditions = array(
|
||||
'Sighting.date_sighting >' => strtotime("-" . $range . " days"),
|
||||
'Sighting.date_sighting >' => $this->getMaximumRange(),
|
||||
'EventTag.tag_id' => $tag_id
|
||||
);
|
||||
if ($type !== false) {
|
||||
|
@ -511,9 +510,8 @@ class Sighting extends AppModel
|
|||
|
||||
public function getSightingsForObjectIds($user, $tagList, $context = 'event', $type = '0')
|
||||
{
|
||||
$range = (!empty(Configure::read('MISP.Sightings_range')) && is_numeric(Configure::read('MISP.Sightings_range'))) ? Configure::read('MISP.Sightings_range') : 365;
|
||||
$conditions = array(
|
||||
'Sighting.date_sighting >' => strtotime("-" . $range . " days"),
|
||||
'Sighting.date_sighting >' => $this->getMaximumRange(),
|
||||
ucfirst($context) . 'Tag.tag_id' => $tagList
|
||||
|
||||
);
|
||||
|
@ -845,4 +843,14 @@ class Sighting extends AppModel
|
|||
}
|
||||
return $saved;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function getMaximumRange()
|
||||
{
|
||||
$rangeInDays = Configure::read('MISP.Sightings_range');
|
||||
$rangeInDays = (!empty($rangeInDays) && is_numeric($rangeInDays)) ? $rangeInDays : 365;
|
||||
return strtotime("-$rangeInDays days");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue