Passed
Push — master ( 60c4f2...db8d73 )
by Georgi
02:28
created

FileStorageList::getModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Epesi\FileStorage;
4
5
use Epesi\Core\System\Integration\Modules\ModuleView;
6
use Illuminate\Support\Facades\Auth;
7
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...
8
use Epesi\FileStorage\Seeds\FileModal;
9
use Epesi\Core\System\User\Database\Models\User;
10
11
class FileStorageList extends ModuleView
12
{
13
	protected $label = 'File Storage';
14
	
15
	public static function access()
16
	{
17
		return Auth::user()->can('modify system settings');
18
	}
19
	
20
	public function body()
21
	{	
22
		$this->grid = $this->add([
0 ignored issues
show
Bug Best Practice introduced by
The property grid does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
				'CRUD',
24
				'canCreate' => false,
25
				'canUpdate' => false,
26
				'canDelete' => false,
27
				'quickSearch' => [
28
						'name'
29
				]
30
		]);
31
32
		$this->grid->menu->addItem([__('Back'), 'icon'=>'arrow left'])->link(url('view/system'));
33
		
34
		$this->grid->setModel($this->getModel());
35
		
36
		$this->grid->addDecorator('name', ['Multiformat', function($row, $column) {
1 ignored issue
show
Bug introduced by
The method addDecorator() 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 or atk4\ui\Table. ( Ignorable by Annotation )

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

36
		$this->grid->/** @scrutinizer ignore-call */ 
37
               addDecorator('name', ['Multiformat', function($row, $column) {
Loading history...
37
			return [['Template', '<a href="#" class="file-modal" data-id="' . $row['id'] . '">' . $row[$column]  . '</a>']];
38
		}]);
39
		
40
		$this->grid->addDecorator('created_by', ['Multiformat', function($row, $column) {
41
			if (! $user = User::find($row[$column])) return '';
42
			
43
			return [['Template', $user->name]];
44
		}]);
45
46
		$modal = $this->add(new FileModal());
47
		
48
		$this->grid->on('click', '.file-modal', $modal->show());
49
50
		return $this;
51
	}
52
	
53
	public function getModel()
54
	{
55
		$atkDb = app()->make(SQL::class);
56
		
57
		$model = new \atk4\data\Model($atkDb, 'filestorage_files');
58
		
59
		$model->addFields(['created_at', 'created_by', 'name', 'link']);
60
61
		return $model;
62
	}
63
}
64