2016-04-21 22:58:49 +02:00
< ? php
App :: uses ( 'AppController' , 'Controller' );
2020-09-03 15:24:03 +02:00
/**
* @ property Warninglist $Warninglist
*/
2018-07-19 11:48:22 +02:00
class WarninglistsController extends AppController
{
public $components = array ( 'Session' , 'RequestHandler' );
2016-04-21 22:58:49 +02:00
2018-07-19 11:48:22 +02:00
public $paginate = array (
2021-02-10 21:04:06 +01:00
'limit' => 60 ,
'maxLimit' => 9999 , // LATER we will bump here on a problem once we have more than 9999 events <- no we won't, this is the max a user can view/page.
'contain' => array (
'WarninglistType'
),
'order' => array (
'Warninglist.id' => 'DESC'
),
'recursive' => - 1 ,
2018-07-19 11:48:22 +02:00
);
2016-04-21 22:58:49 +02:00
2018-07-19 11:48:22 +02:00
public function index ()
{
2021-02-10 21:04:06 +01:00
$filters = $this -> IndexFilter -> harvestParameters ([ 'value' , 'enabled' ]);
2020-11-10 13:30:32 +01:00
if ( ! empty ( $filters [ 'value' ])) {
$this -> paginate [ 'conditions' ] = [
'OR' => [
'LOWER(Warninglist.name) LIKE' => '%' . strtolower ( $filters [ 'value' ]) . '%' ,
'LOWER(Warninglist.description) LIKE' => '%' . strtolower ( $filters [ 'value' ]) . '%' ,
'LOWER(Warninglist.type)' => strtolower ( $filters [ 'value' ]),
2021-06-01 17:49:45 +02:00
]
];
2020-11-10 13:30:32 +01:00
}
2021-02-10 21:04:06 +01:00
if ( isset ( $filters [ 'enabled' ])) {
$this -> paginate [ 'conditions' ][] = [ 'Warninglist.enabled' => $filters [ 'enabled' ]];
}
2021-06-01 17:49:45 +02:00
$this -> Warninglist -> addCountField (
'warninglist_entry_count' ,
$this -> Warninglist -> WarninglistEntry ,
[ 'WarninglistEntry.warninglist_id = Warninglist.id' ]
);
2018-07-19 11:48:22 +02:00
$warninglists = $this -> paginate ();
foreach ( $warninglists as & $warninglist ) {
2021-02-10 21:04:06 +01:00
$validAttributes = array_column ( $warninglist [ 'WarninglistType' ], 'type' );
$warninglist [ 'Warninglist' ][ 'valid_attributes' ] = implode ( ', ' , $validAttributes );
2018-07-19 11:48:22 +02:00
unset ( $warninglist [ 'WarninglistType' ]);
}
if ( $this -> _isRest ()) {
2021-02-10 21:04:06 +01:00
return $this -> RestResponse -> viewData ([ 'Warninglists' => $warninglists ], $this -> response -> type ());
2018-07-19 11:48:22 +02:00
}
2021-06-02 14:54:29 +02:00
$this -> set ( 'warninglists' , $warninglists );
$this -> set ( 'passedArgsArray' , $filters );
$this -> set ( 'possibleCategories' , $this -> Warninglist -> categories ());
2018-07-19 11:48:22 +02:00
}
2016-06-04 01:08:16 +02:00
2018-07-19 11:48:22 +02:00
public function update ()
{
if ( ! $this -> request -> is ( 'post' )) {
2019-04-03 03:52:18 +02:00
throw new MethodNotAllowedException ( __ ( 'This action is only accessible via POST requests.' ));
2018-07-19 11:48:22 +02:00
}
$result = $this -> Warninglist -> update ();
$this -> Log = ClassRegistry :: init ( 'Log' );
$fails = 0 ;
$successes = 0 ;
if ( ! empty ( $result )) {
if ( isset ( $result [ 'success' ])) {
foreach ( $result [ 'success' ] as $id => $success ) {
if ( isset ( $success [ 'old' ])) {
$change = $success [ 'name' ] . ': updated from v' . $success [ 'old' ] . ' to v' . $success [ 'new' ];
} else {
$change = $success [ 'name' ] . ' v' . $success [ 'new' ] . ' installed' ;
}
$this -> Log -> create ();
$this -> Log -> save ( array (
2021-06-01 17:49:45 +02:00
'org' => $this -> Auth -> user ( 'Organisation' )[ 'name' ],
'model' => 'Warninglist' ,
'model_id' => $id ,
'email' => $this -> Auth -> user ( 'email' ),
'action' => 'update' ,
'user_id' => $this -> Auth -> user ( 'id' ),
'title' => __ ( 'Warning list updated' ),
'change' => $change ,
2018-07-19 11:48:22 +02:00
));
$successes ++ ;
}
}
if ( isset ( $result [ 'fails' ])) {
foreach ( $result [ 'fails' ] as $id => $fail ) {
$this -> Log -> create ();
$this -> Log -> save ( array (
2021-06-01 17:49:45 +02:00
'org' => $this -> Auth -> user ( 'Organisation' )[ 'name' ],
'model' => 'Warninglist' ,
'model_id' => $id ,
'email' => $this -> Auth -> user ( 'email' ),
'action' => 'update' ,
'user_id' => $this -> Auth -> user ( 'id' ),
'title' => __ ( 'Warning list failed to update' ),
'change' => __ ( '%s could not be installed/updated. Error: %s' , $fail [ 'name' ], $fail [ 'fail' ]), // TODO: needs to be optimized for non-SVO languages
2018-07-19 11:48:22 +02:00
));
$fails ++ ;
}
}
} else {
$this -> Log -> create ();
$this -> Log -> save ( array (
2021-06-01 17:49:45 +02:00
'org' => $this -> Auth -> user ( 'Organisation' )[ 'name' ],
'model' => 'Warninglist' ,
'model_id' => 0 ,
'email' => $this -> Auth -> user ( 'email' ),
'action' => 'update' ,
'user_id' => $this -> Auth -> user ( 'id' ),
'title' => __ ( 'Warninglist update (nothing to update)' ),
'change' => __ ( 'Executed an update of the warning lists, but there was nothing to update.' ),
2018-07-19 11:48:22 +02:00
));
}
if ( $successes == 0 && $fails == 0 ) {
$flashType = 'info' ;
2019-04-03 03:52:18 +02:00
$message = __ ( 'All warninglists are up to date already.' );
2018-07-19 11:48:22 +02:00
} elseif ( $successes == 0 ) {
$flashType = 'error' ;
2019-04-03 03:52:18 +02:00
$message = __ ( 'Could not update any of the warning lists' );
2018-07-19 11:48:22 +02:00
} else {
$flashType = 'success' ;
2020-09-07 12:03:04 +02:00
$message = __ ( 'Successfully updated %s warninglists.' , $successes );
2018-07-19 11:48:22 +02:00
if ( $fails != 0 ) {
2020-09-07 12:03:04 +02:00
$message .= __ ( ' However, could not update %s warninglists.' , $fails ); // TODO: non-SVO languages need to be considered
2018-07-19 11:48:22 +02:00
}
}
if ( $this -> _isRest ()) {
return $this -> RestResponse -> saveSuccessResponse ( 'Warninglist' , 'update' , false , $this -> response -> type (), $message );
} else {
$this -> Flash -> { $flashType }( $message );
$this -> redirect ( array ( 'controller' => 'warninglists' , 'action' => 'index' ));
}
}
2016-06-04 01:08:16 +02:00
2021-06-01 17:49:45 +02:00
public function add ()
{
$types = array_combine ( $this -> Warninglist -> validate [ 'type' ][ 'rule' ][ 1 ], $this -> Warninglist -> validate [ 'type' ][ 'rule' ][ 1 ]);
$this -> set ( 'possibleTypes' , $types );
$this -> set ( 'possibleCategories' , $this -> Warninglist -> categories ());
$this -> loadModel ( 'Attribute' );
$this -> set ( 'matchingAttributes' , array_combine ( array_keys ( $this -> Attribute -> typeDefinitions ), array_keys ( $this -> Attribute -> typeDefinitions )));
$this -> CRUD -> add ([
'beforeSave' => function ( array $warninglist ) {
if ( isset ( $warninglist [ 'Warninglist' ][ 'entries' ])) {
$entries = $this -> Warninglist -> parseFreetext ( $warninglist [ 'Warninglist' ][ 'entries' ]);
unset ( $warninglist [ 'Warninglist' ][ 'entries' ]);
$warninglist [ 'WarninglistEntry' ] = $entries ;
}
if ( isset ( $warninglist [ 'Warninglist' ][ 'matching_attributes' ]) && is_array ( $warninglist [ 'Warninglist' ][ 'matching_attributes' ])) {
$warninglist [ 'WarninglistType' ] = [];
foreach ( $warninglist [ 'Warninglist' ][ 'matching_attributes' ] as $attribute ) {
$warninglist [ 'WarninglistType' ][] = [ 'type' => $attribute ];
}
}
$warninglist [ 'Warninglist' ][ 'default' ] = 0 ;
return $warninglist ;
},
]);
if ( $this -> restResponsePayload ) {
return $this -> restResponsePayload ;
}
}
public function edit ( $id = null )
{
$types = array_combine ( $this -> Warninglist -> validate [ 'type' ][ 'rule' ][ 1 ], $this -> Warninglist -> validate [ 'type' ][ 'rule' ][ 1 ]);
$this -> set ( 'possibleTypes' , $types );
$this -> set ( 'possibleCategories' , $this -> Warninglist -> categories ());
$this -> loadModel ( 'Attribute' );
$this -> set ( 'matchingAttributes' , array_combine ( array_keys ( $this -> Attribute -> typeDefinitions ), array_keys ( $this -> Attribute -> typeDefinitions )));
$this -> CRUD -> edit ( $id , [
'conditions' => [ 'default' => 0 ], // it is not possible to edit default warninglist
'contain' => [ 'WarninglistEntry' , 'WarninglistType' ],
'fields' => [ 'name' , 'description' , 'type' , 'category' , 'entries' , 'matching_attributes' ],
'redirect' => [ 'action' => 'view' , $id ],
'beforeSave' => function ( array $warninglist ) {
if ( isset ( $warninglist [ 'Warninglist' ][ 'entries' ])) {
$entries = $this -> Warninglist -> parseFreetext ( $warninglist [ 'Warninglist' ][ 'entries' ]);
unset ( $warninglist [ 'Warninglist' ][ 'entries' ]);
$warninglist [ 'WarninglistEntry' ] = $entries ;
}
if ( isset ( $warninglist [ 'Warninglist' ][ 'matching_attributes' ]) && is_array ( $warninglist [ 'Warninglist' ][ 'matching_attributes' ])) {
$warninglist [ 'WarninglistType' ] = [];
foreach ( $warninglist [ 'Warninglist' ][ 'matching_attributes' ] as $attribute ) {
$warninglist [ 'WarninglistType' ][] = [ 'type' => $attribute ];
}
}
$warninglist [ 'Warninglist' ][ 'version' ] ++ ;
return $warninglist ;
},
]);
if ( $this -> restResponsePayload ) {
return $this -> restResponsePayload ;
}
if ( isset ( $this -> request -> data [ 'WarninglistEntry' ])) {
$entries = [];
foreach ( $this -> request -> data [ 'WarninglistEntry' ] as $entry ) {
$value = $entry [ 'value' ];
if ( $entry [ 'comment' ]) {
$value .= ' # ' . $entry [ 'comment' ];
}
$entries [] = $value ;
}
$this -> request -> data [ 'Warninglist' ][ 'entries' ] = implode ( " \n " , $entries );
}
if ( isset ( $this -> request -> data [ 'WarninglistType' ])) {
$attributes = array_column ( $this -> request -> data [ 'WarninglistType' ], 'type' );
$this -> request -> data [ 'Warninglist' ][ 'matching_attributes' ] = $attributes ;
}
$this -> render ( 'add' );
}
2018-11-23 14:11:33 +01:00
/*
* toggle warninglists on or offset
* Simply POST an ID or a list of IDs to toggle the current state
* To control what state the warninglists should have after execution instead of just blindly toggling them , simply pass the enabled flag
* Example :
* { " id " : [ 5 , 8 ], " enabled " : 1 }
2018-09-24 23:10:40 +02:00
* Alternatively search by a substring in the warninglist ' s named , such as :
* { " name " : [ " %alexa% " , " %iana% " ], " enabled " : 1 }
2018-11-23 14:11:33 +01:00
*/
2018-07-19 11:48:22 +02:00
public function toggleEnable ()
{
2018-11-23 14:11:33 +01:00
if ( ! $this -> request -> is ( 'post' )) {
2019-04-03 03:52:18 +02:00
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => __ ( 'This function only accepts POST requests.' ))), 'status' => 200 , 'type' => 'json' ));
2018-11-23 14:11:33 +01:00
}
if ( isset ( $this -> request -> data [ 'Warninglist' ][ 'data' ])) {
$id = $this -> request -> data [ 'Warninglist' ][ 'data' ];
} else {
if ( ! empty ( $this -> request -> data [ 'id' ])) {
$id = $this -> request -> data [ 'id' ];
} elseif ( ! empty ( $this -> request -> data [ 'name' ])) {
if ( ! is_array ( $this -> request -> data [ 'name' ])) {
$names = array ( $this -> request -> data [ 'name' ]);
} else {
$names = $this -> request -> data [ 'name' ];
}
$conditions = array ();
2021-06-01 17:49:45 +02:00
foreach ( $names as $name ) {
2018-11-23 14:11:33 +01:00
$conditions [ 'OR' ][] = array ( 'LOWER(Warninglist.name) LIKE' => strtolower ( $name ));
}
2021-06-01 17:49:45 +02:00
$id = $this -> Warninglist -> find ( 'column' , array (
2018-11-23 14:11:33 +01:00
'conditions' => $conditions ,
2021-06-01 17:49:45 +02:00
'fields' => array ( 'Warninglist.id' )
2018-11-23 14:11:33 +01:00
));
}
}
if ( isset ( $this -> request -> data [ 'enabled' ])) {
$enabled = $this -> request -> data [ 'enabled' ];
}
2018-09-19 12:20:59 +02:00
if ( empty ( $id )) {
2019-04-03 03:52:18 +02:00
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => __ ( 'Warninglist not found.' ))), 'status' => 200 , 'type' => 'json' ));
2018-07-19 11:48:22 +02:00
}
2018-09-19 12:20:59 +02:00
$currentState = $this -> Warninglist -> find ( 'all' , array ( 'conditions' => array ( 'id' => $id ), 'recursive' => - 1 ));
2018-07-19 11:48:22 +02:00
if ( empty ( $currentState )) {
2019-04-03 03:52:18 +02:00
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => __ ( 'Warninglist(s) not found.' ))), 'status' => 200 , 'type' => 'json' ));
2018-07-19 11:48:22 +02:00
}
2018-11-23 14:11:33 +01:00
$success = 0 ;
foreach ( $currentState as $warningList ) {
if ( isset ( $enabled )) {
$warningList [ 'Warninglist' ][ 'enabled' ] = $enabled ;
$message = $enabled ? 'enabled' : 'disabled' ;
} else {
if ( $warningList [ 'Warninglist' ][ 'enabled' ]) {
$warningList [ 'Warninglist' ][ 'enabled' ] = 0 ;
$message = 'disabled' ;
} else {
$warningList [ 'Warninglist' ][ 'enabled' ] = 1 ;
$message = 'enabled' ;
}
if ( ! isset ( $enabled ) && count ( $currentState ) > 1 ) {
$message = 'toggled' ;
}
}
if ( $this -> Warninglist -> save ( $warningList )) {
$success += 1 ;
}
$this -> Warninglist -> regenerateWarninglistCaches ( $warningList [ 'Warninglist' ][ 'id' ]);
}
2018-09-19 12:20:59 +02:00
if ( $success ) {
2019-04-03 03:52:18 +02:00
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => true , 'success' => $success . __ ( ' warninglist(s) ' ) . $message )), 'status' => 200 , 'type' => 'json' )); // TODO: non-SVO lang considerations
2018-07-19 11:48:22 +02:00
} else {
2019-04-03 03:52:18 +02:00
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => __ ( 'Warninglist(s) could not be toggled.' ))), 'status' => 200 , 'type' => 'json' ));
2018-07-19 11:48:22 +02:00
}
}
2016-06-04 01:08:16 +02:00
2018-07-19 11:48:22 +02:00
public function enableWarninglist ( $id , $enable = false )
{
$this -> Warninglist -> id = $id ;
if ( ! $this -> Warninglist -> exists ()) {
2019-04-03 03:52:18 +02:00
throw new NotFoundException ( __ ( 'Invalid Warninglist.' ));
2018-07-19 11:48:22 +02:00
}
// DBMS interoperability: convert boolean false to integer 0 so cakephp doesn't try to insert an empty string into the database
if ( $enable === false ) {
$enable = 0 ;
}
$this -> Warninglist -> saveField ( 'enabled' , $enable );
$this -> Warninglist -> regenerateWarninglistCaches ( $id );
2019-04-02 15:57:41 +02:00
if ( $enable === 0 ) {
$this -> Flash -> success ( __ ( 'Warninglist disabled' ));
}
else {
$this -> Flash -> success ( __ ( 'Warninglist enabled' ));
}
2018-07-19 11:48:22 +02:00
$this -> redirect ( array ( 'controller' => 'warninglists' , 'action' => 'view' , $id ));
}
2016-06-04 01:08:16 +02:00
2018-07-19 11:48:22 +02:00
public function getToggleField ()
{
if ( ! $this -> request -> is ( 'ajax' )) {
2019-04-03 03:52:18 +02:00
throw new MethodNotAllowedException ( __ ( 'This action is available via AJAX only.' ));
2018-07-19 11:48:22 +02:00
}
$this -> layout = 'ajax' ;
$this -> render ( 'ajax/getToggleField' );
}
2016-06-04 01:08:16 +02:00
2018-07-19 11:48:22 +02:00
public function view ( $id )
{
if ( ! is_numeric ( $id )) {
2019-04-03 03:52:18 +02:00
throw new NotFoundException ( __ ( 'Invalid ID.' ));
2018-07-19 11:48:22 +02:00
}
2021-06-01 17:49:45 +02:00
$warninglist = $this -> Warninglist -> find ( 'first' , array (
'contain' => array ( 'WarninglistEntry' , 'WarninglistType' ),
'conditions' => array ( 'id' => $id ))
);
2018-07-19 11:48:22 +02:00
if ( empty ( $warninglist )) {
2019-04-03 03:52:18 +02:00
throw new NotFoundException ( __ ( 'Warninglist not found.' ));
2021-06-02 15:26:20 +02:00
}
if ( $this -> IndexFilter -> isCsv ()) {
$csv = [];
foreach ( $warninglist [ 'WarninglistEntry' ] as $entry ) {
$line = $entry [ 'value' ];
if ( $entry [ 'comment' ]) {
$line .= ';' . $entry [ 'comment' ];
}
$csv [] = $line ;
}
return $this -> RestResponse -> viewData ( implode ( " \n " , $csv ), 'csv' );
2018-07-19 11:48:22 +02:00
}
if ( $this -> _isRest ()) {
$warninglist [ 'Warninglist' ][ 'WarninglistEntry' ] = $warninglist [ 'WarninglistEntry' ];
$warninglist [ 'Warninglist' ][ 'WarninglistType' ] = $warninglist [ 'WarninglistType' ];
2021-07-12 13:38:30 +02:00
return $this -> RestResponse -> viewData ([ 'Warninglist' => $warninglist [ 'Warninglist' ]], $this -> response -> type ());
2018-07-19 11:48:22 +02:00
}
2021-06-02 14:54:29 +02:00
$this -> set ( 'warninglist' , $warninglist );
$this -> set ( 'possibleCategories' , $this -> Warninglist -> categories ());
}
2021-06-12 17:59:17 +02:00
public function import ()
{
if ( ! $this -> request -> is ( 'post' )) {
throw new MethodNotAllowedException ( __ ( 'This function only accepts POST requests.' ));
}
if ( empty ( $this -> request -> data )) {
throw new BadRequestException ( __ ( 'No valid data received.' ));
}
foreach ([ 'name' , 'type' , 'version' , 'description' , 'matching_attributes' , 'list' ] as $filed ) {
if ( ! isset ( $this -> request -> data [ $filed ])) {
throw new BadRequestException ( __ ( 'No valid data received: field `%s` is missing.' , $filed ));
}
}
if ( ! is_array ( $this -> request -> data [ 'list' ])) {
throw new BadRequestException ( __ ( 'No valid data received: `list` field is not array' ));
}
$id = $this -> Warninglist -> import ( $this -> request -> data );
if ( is_int ( $id )) {
return $this -> RestResponse -> saveSuccessResponse ( 'Warninglist' , 'import' , $id , false , __ ( 'Warninglist imported' ));
} else {
return $this -> RestResponse -> saveFailResponse ( 'Warninglist' , 'import' , false , $id );
}
}
2021-06-02 14:54:29 +02:00
public function export ( $id = null )
{
if ( empty ( $id )) {
throw new NotFoundException ( __ ( 'Warninglist not found.' ));
}
$warninglist = $this -> Warninglist -> find ( 'first' , [
'contain' => [ 'WarninglistType' ],
'conditions' => [ 'id' => $id ],
]);
if ( empty ( $warninglist )) {
throw new NotFoundException ( __ ( 'Warninglist not found.' ));
}
$matchingAttributes = array_column ( $warninglist [ 'WarninglistType' ], 'type' );
$list = $this -> Warninglist -> WarninglistEntry -> find ( 'column' , [
'conditions' => [ 'warninglist_id' => $warninglist [ 'Warninglist' ][ 'id' ]],
'fields' => [ 'value' ],
]);
$output = [
'name' => $warninglist [ 'Warninglist' ][ 'name' ],
2021-06-12 17:59:17 +02:00
'type' => $warninglist [ 'Warninglist' ][ 'type' ],
2021-06-02 14:54:29 +02:00
'version' => $warninglist [ 'Warninglist' ][ 'version' ],
'description' => $warninglist [ 'Warninglist' ][ 'description' ],
'matching_attributes' => $matchingAttributes ,
'list' => $list ,
];
return $this -> RestResponse -> viewData ( $output , 'json' );
2018-07-19 11:48:22 +02:00
}
2017-12-22 13:15:22 +01:00
2018-07-19 11:48:22 +02:00
public function delete ( $id )
{
if ( $this -> request -> is ( 'post' )) {
$id = intval ( $id );
$result = $this -> Warninglist -> quickDelete ( $id );
if ( $result ) {
2021-06-01 17:49:45 +02:00
$this -> Flash -> success ( __ ( 'Warninglist successfully deleted.' ));
2018-07-19 11:48:22 +02:00
$this -> redirect ( array ( 'controller' => 'warninglists' , 'action' => 'index' ));
} else {
2019-04-02 15:57:41 +02:00
$this -> Flash -> error ( __ ( 'Warninglists could not be deleted.' ));
2018-07-19 11:48:22 +02:00
$this -> redirect ( array ( 'controller' => 'warninglists' , 'action' => 'index' ));
}
} else {
if ( $this -> request -> is ( 'ajax' )) {
$this -> set ( 'id' , $id );
$this -> render ( 'ajax/delete_confirmation' );
} else {
2019-04-03 03:52:18 +02:00
throw new MethodNotAllowedException ( __ ( 'This function can only be reached via AJAX.' ));
2018-07-19 11:48:22 +02:00
}
}
}
2018-10-16 17:57:14 +02:00
2018-11-23 14:11:33 +01:00
public function checkValue ()
{
if ( $this -> request -> is ( 'post' )) {
if ( empty ( $this -> request -> data )) {
2019-04-03 03:52:18 +02:00
throw new NotFoundException ( __ ( 'No valid data received.' ));
2018-11-23 14:11:33 +01:00
}
$data = $this -> request -> data ;
2021-05-03 16:53:04 +02:00
if ( is_array ( $data ) && isset ( $data [ 'Warninglist' ])) {
$data = $data [ 'Warninglist' ];
}
2018-11-23 14:11:33 +01:00
if ( ! is_array ( $data )) {
$data = array ( $data );
}
2018-11-06 16:54:17 +01:00
if ( array_key_exists ( '[]' , $data )) {
$data = $data [ '[]' ];
}
2020-09-03 15:24:03 +02:00
2020-09-07 12:03:04 +02:00
$hits = array ();
$warninglists = $this -> Warninglist -> getEnabled ();
2018-11-23 14:11:33 +01:00
foreach ( $data as $dataPoint ) {
foreach ( $warninglists as $warninglist ) {
2020-09-07 12:03:04 +02:00
$values = $this -> Warninglist -> getFilteredEntries ( $warninglist );
$result = $this -> Warninglist -> quickCheckValue ( $values , $dataPoint , $warninglist [ 'Warninglist' ][ 'type' ]);
2020-09-03 15:24:03 +02:00
if ( $result !== false ) {
2018-11-23 14:11:33 +01:00
$hits [ $dataPoint ][] = array ( 'id' => $warninglist [ 'Warninglist' ][ 'id' ], 'name' => $warninglist [ 'Warninglist' ][ 'name' ]);
}
}
}
2021-05-03 16:53:04 +02:00
if ( $this -> _isRest ()) {
return $this -> RestResponse -> viewData ( $hits , $this -> response -> type ());
}
$this -> set ( 'hits' , $hits );
$this -> set ( 'data' , $data );
2018-10-16 17:57:14 +02:00
} else {
2021-05-03 16:53:04 +02:00
if ( $this -> _isRest ()) {
return $this -> RestResponse -> describe ( 'Warninglists' , 'checkValue' , false , $this -> response -> type ());
}
2018-10-16 17:57:14 +02:00
}
2018-11-23 14:11:33 +01:00
}
2016-06-06 10:09:55 +02:00
}