Passed
Push — master ( bc7b5c...925ca7 )
by Georgi
03:13
created

FileAccessHistory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 60
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getModel() 0 25 1
A displayAccessHistoryGrid() 0 15 1
A displayFileDetails() 0 3 1
A body() 0 7 1
1
<?php
2
3
namespace Epesi\FileStorage;
4
5
use Epesi\Core\System\Integration\Modules\ModuleView;
6
use Epesi\Core\Data\Persistence\SQL;
0 ignored issues
show
Bug introduced by
The type Epesi\Core\Data\Persistence\SQL was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Epesi\FileStorage\Seeds\FileView;
8
use Epesi\Core\Layout\Seeds\ActionBar;
9
10
class FileAccessHistory extends ModuleView
11
{
12
	protected $label = 'File Access History';
13
	
14
	public function body()
15
	{
16
		ActionBar::addButton('back')->link(url()->previous());
17
		
18
		$this->displayFileDetails();
19
		
20
		$this->displayAccessHistoryGrid();
21
	}
22
	
23
	public function displayFileDetails()
24
	{
25
		$this->add(['View', ['ui' => 'segment']])->add([new FileView($this->stickyGet('id')), 'disableActions' => 'history']);
26
	}
27
	
28
	public function displayAccessHistoryGrid()
29
	{	
30
		$grid = $this->add([
31
				'CRUD',
32
				'canCreate' => false,
33
				'canUpdate' => false,
34
				'canDelete' => false,
35
				'quickSearch' => [
36
						'accessed_by_user', 'action', 'ip_address', 'host_name'
37
				]
38
		]);
39
40
		$grid->addItemsPerPageSelector([10, 25, 50, 100], __('Items per page') . ':');
0 ignored issues
show
Bug introduced by
Are you sure __('Items per page') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
		$grid->addItemsPerPageSelector([10, 25, 50, 100], /** @scrutinizer ignore-type */ __('Items per page') . ':');
Loading history...
Bug introduced by
The method addItemsPerPageSelector() does not exist on atk4\ui\View. It seems like you code against a sub-type of atk4\ui\View such as atk4\ui\Grid. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
		$grid->/** @scrutinizer ignore-call */ 
41
         addItemsPerPageSelector([10, 25, 50, 100], __('Items per page') . ':');
Loading history...
41
		
42
		$grid->setModel($this->getModel($this->stickyGet('id')));
43
	}
44
	
45
	public function getModel($fileId)
46
	{
47
		$atkDb = app()->make(SQL::class);
48
49
		$user = new \atk4\data\Model($atkDb, 'users');
50
		
51
		$user->addField('name');
52
53
		$model = new \atk4\data\Model($atkDb, 'filestorage_access_log');
54
		
55
		$model->hasOne('accessed_by', $user)->addTitle(['field' => 'accessed_by_user', 'caption' => __('Accessed By')]);
0 ignored issues
show
Bug introduced by
$user of type atk4\data\Model is incompatible with the type array expected by parameter $defaults of atk4\data\Model::hasOne(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
		$model->hasOne('accessed_by', /** @scrutinizer ignore-type */ $user)->addTitle(['field' => 'accessed_by_user', 'caption' => __('Accessed By')]);
Loading history...
introduced by
The method addTitle() does not exist on atk4\data\Reference_One. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
		$model->hasOne('accessed_by', $user)->/** @scrutinizer ignore-call */ addTitle(['field' => 'accessed_by_user', 'caption' => __('Accessed By')]);
Loading history...
56
		
57
		$model->addFields([
58
				'file_id',
59
				['accessed_at', 'caption' => __('Accessed At')],
60
				['action', 'caption' => __('Action')],
61
				['ip_address', 'caption' => __('IP Address')],
62
				['host_name', 'caption' => __('Host Name')]
63
		]);
64
				
65
		$model->addCondition('file_id', $fileId);
66
		
67
		$model->setOrder('accessed_at desc');
68
		
69
		return $model;
70
	}
71
}
72