2021-01-07 09:31:38 +01:00
< ? php
App :: uses ( 'AppController' , 'Controller' );
/**
2021-04-25 19:49:08 +02:00
* @ property CorrelationExclusion $CorrelationExclusion
2021-01-07 09:31:38 +01:00
*/
class CorrelationExclusionsController extends AppController
{
public $components = array (
'CRUD' ,
'RequestHandler'
);
public $paginate = array (
'limit' => 60 ,
'order' => array (
'CorrelationExclusion.value' => 'ASC' ,
)
);
public function index ( $id = false )
{
$this -> CRUD -> index ([
2021-04-27 10:52:53 +02:00
'filters' => [ 'value' , 'comment' ],
'quickFilters' => [ 'value' , 'comment' ]
2021-01-07 09:31:38 +01:00
]);
if ( $this -> IndexFilter -> isRest ()) {
return $this -> restResponsePayload ;
}
$this -> set ( 'title_for_layout' , __ ( 'Correlation Exclusions index' ));
$this -> set ( 'menuData' , [
'menuList' => 'correlationExclusions' ,
'menuItem' => 'index'
]);
}
public function delete ( $id )
{
$this -> CRUD -> delete ( $id );
if ( $this -> IndexFilter -> isRest ()) {
return $this -> restResponsePayload ;
}
}
2021-04-25 17:36:29 +02:00
public function add ()
2021-01-07 09:31:38 +01:00
{
2021-04-25 17:36:29 +02:00
$options = [
2021-04-27 10:52:53 +02:00
'filters' => [ 'value' , 'redirect' , 'redirect_controller' , 'comment' ]
2021-04-25 17:36:29 +02:00
];
$params = $this -> IndexFilter -> harvestParameters ( $options [ 'filters' ]);
if ( ! empty ( $params [ 'value' ])) {
$this -> request -> data [ 'CorrelationExclusion' ][ 'value' ] = $params [ 'value' ];
}
2021-04-27 10:52:53 +02:00
if ( ! empty ( $params [ 'comment' ])) {
2021-09-15 09:34:36 +02:00
$this -> request -> data [ 'CorrelationExclusion' ][ 'comment' ] = $params [ 'comment' ];
2021-04-27 10:52:53 +02:00
}
2021-01-07 09:31:38 +01:00
$this -> CRUD -> add ( $params );
if ( $this -> IndexFilter -> isRest ()) {
return $this -> restResponsePayload ;
}
$dropdownData = [];
$this -> set ( compact ( 'dropdownData' ));
$this -> set ( 'menuData' , [
'menuList' => 'correlationExclusions' ,
'menuItem' => 'add' ,
]);
}
2021-04-27 10:52:53 +02:00
public function edit ( $id )
{
$this -> set ( 'menuData' , [
'menuList' => 'correlationExclusions' ,
'menuItem' => 'edit' ,
]);
$this -> set ( 'id' , $id );
$params = [
'fields' => [ 'comment' ]
];
$this -> CRUD -> edit ( $id , $params );
if ( $this -> IndexFilter -> isRest ()) {
return $this -> restResponsePayload ;
}
$this -> loadModel ( 'Organisation' );
$orgs = $this -> Organisation -> find ( 'list' , [
'recursive' => - 1 ,
'fields' => [ 'id' , 'name' ],
'order' => [ 'lower(name)' => 'ASC' ]
]);
$dropdownData = [
'org_id' => $orgs
];
$this -> set ( compact ( 'dropdownData' ));
$this -> render ( 'add' );
}
2021-01-07 09:31:38 +01:00
public function view ( $id = false )
{
$this -> CRUD -> view ( $id );
if ( $this -> IndexFilter -> isRest ()) {
return $this -> restResponsePayload ;
}
$this -> set ( 'title_for_layout' , __ ( 'Correlation Exclusion' ));
$this -> set ( 'menuData' , [
'menuList' => 'correlationExclusions' ,
'menuItem' => 'view' ,
]);
}
public function clean ()
{
if ( $this -> request -> is ( 'post' )) {
$this -> CorrelationExclusion -> cleanRouter ( $this -> Auth -> user ());
$message = __ ( 'Correlations cleanup initiated, based on the exclusion rules.' );
if ( $this -> _isRest ()) {
return $this -> RestResponse -> saveSuccessResponse ( 'CorrelationExclusion' , 'clean' , false , false , $message );
} else {
$this -> Flash -> success ( $message );
$this -> redirect ( $this -> referer ());
}
} else {
$this -> set ( 'title' , __ ( 'Clean up correlations' ));
$this -> set ( 'question' , __ ( 'Execute the cleaning of all correlations that are at odds with the exclusion rules? This will delete all matching correlations.' ));
2022-05-09 14:34:38 +02:00
$this -> set ( 'actionName' , __ ( 'Clean' ));
2022-04-28 14:51:21 +02:00
$this -> layout = false ;
2021-01-07 09:31:38 +01:00
$this -> render ( '/genericTemplates/confirm' );
}
}
}