|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Serverfireteam\Panel; |
|
4
|
|
|
|
|
5
|
|
|
use Serverfireteam\Panel\CrudController; |
|
6
|
|
|
|
|
7
|
|
|
class LinkController extends CrudController { |
|
8
|
|
|
|
|
9
|
|
View Code Duplication |
public function all($entity) { |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
parent::all($entity); |
|
12
|
|
|
|
|
13
|
|
|
$this->filter = \DataFilter::source(new Link()); |
|
14
|
|
|
$this->filter->add('id', 'ID', 'text'); |
|
15
|
|
|
$this->filter->add('display', 'Display', 'text'); |
|
16
|
|
|
$this->filter->submit('search'); |
|
17
|
|
|
$this->filter->reset('reset'); |
|
18
|
|
|
$this->filter->build(); |
|
19
|
|
|
|
|
20
|
|
|
$this->grid = \DataGrid::source($this->filter); |
|
21
|
|
|
$this->grid->add('id', 'ID', true)->style("width:100px"); |
|
22
|
|
|
$this->grid->add('display', 'Display'); |
|
23
|
|
|
$this->grid->add('url', 'Model'); |
|
24
|
|
|
$this->grid->add('show_menu','Show in Menu')->cell( function( $value, $row) { |
|
|
|
|
|
|
25
|
|
|
return ($value) ? "True" : "False"; |
|
26
|
|
|
}); |
|
27
|
|
|
|
|
28
|
|
|
$this->addStylesToGrid(); |
|
29
|
|
|
|
|
30
|
|
|
return $this->returnView(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function edit($entity) { |
|
34
|
|
|
|
|
35
|
|
|
parent::edit($entity); |
|
36
|
|
|
|
|
37
|
|
|
$this->edit = \DataEdit::source(new Link()); |
|
38
|
|
|
|
|
39
|
|
|
Link::creating(function($link) |
|
40
|
|
|
{ |
|
41
|
|
|
$appHelper = new libs\AppHelper(); |
|
42
|
|
|
return ( class_exists( $appHelper->getModel($link['url']) )); |
|
43
|
|
|
}); |
|
44
|
|
|
|
|
45
|
|
|
$helpMessage = \Lang::get('panel::fields.links_help'); |
|
46
|
|
|
|
|
47
|
|
|
$this->edit->label('Edit Links'); |
|
48
|
|
|
$this->edit->link("rapyd-demo/filter", "Articles", "TR")->back(); |
|
49
|
|
|
$this->edit->add('display', 'Display', 'text')->rule('required'); |
|
50
|
|
|
$this->edit->add('url', 'link', 'text')->rule('required'); |
|
51
|
|
|
$this->edit->add('show_menu','Show in Menu','checkbox'); |
|
52
|
|
|
|
|
53
|
|
|
$this->edit->saved(function () use ($entity) { |
|
54
|
|
|
$this->edit->message(\Lang::get('panel::fields.dataSavedSuccessfull')); |
|
55
|
|
|
$this->edit->link('panel/Permission/all', \Lang::get('panel::fields.back')); |
|
56
|
|
|
}); |
|
57
|
|
|
$this->addHelperMessage($helpMessage); |
|
58
|
|
|
|
|
59
|
|
|
return $this->returnEditView(); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.