mirror of https://github.com/MISP/MISP
52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Common functions for the 3 analyst objects
|
|
*/
|
|
class AnalystDataParentBehavior extends ModelBehavior
|
|
{
|
|
private $__currentUser = null;
|
|
|
|
public $User;
|
|
|
|
|
|
|
|
public function attachAnalystData(array $object, array $types = ['Note', 'Opinion', 'Relationship'])
|
|
{
|
|
// No uuid, nothing to attach
|
|
if (empty($object['uuid'])) {
|
|
return $object;
|
|
}
|
|
if (empty($this->__currentUser)) {
|
|
$user_id = Configure::read('CurrentUserId');
|
|
$this->User = ClassRegistry::init('User');
|
|
if ($user_id) {
|
|
$this->__currentUser = $this->User->getAuthUser($user_id);
|
|
}
|
|
}
|
|
$data = [];
|
|
foreach ($types as $type) {
|
|
$this->{$type} = ClassRegistry::init($type);
|
|
$temp = $this->{$type}->fetchForUuid($object['uuid'], $this->__currentUser);
|
|
if (!empty($temp)) {
|
|
foreach ($temp as $k => $temp_element) {
|
|
$data[$type][] = $temp_element[$type];
|
|
}
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function afterFind(Model $model, $results, $primary = false)
|
|
{
|
|
if (!empty($model->includeAnalystData)) {
|
|
foreach ($results as $k => $item) {
|
|
if (isset($item[$model->alias])) {
|
|
$results[$k] = array_merge($results[$k], $this->attachAnalystData($item[$model->alias]));
|
|
}
|
|
}
|
|
}
|
|
return $results;
|
|
}
|
|
}
|