1
|
|
|
<?php namespace Anomaly\Streams\Platform\Http\Controller; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Addon\Module\ModuleCollection; |
4
|
|
|
use Anomaly\Streams\Platform\Assignment\Form\AssignmentFormBuilder; |
5
|
|
|
use Anomaly\Streams\Platform\Assignment\Table\AssignmentTableBuilder; |
6
|
|
|
use Anomaly\Streams\Platform\Field\Contract\FieldInterface; |
7
|
|
|
use Anomaly\Streams\Platform\Field\Contract\FieldRepositoryInterface; |
8
|
|
|
use Anomaly\Streams\Platform\Stream\Contract\StreamInterface; |
9
|
|
|
use Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class AssignmentsController |
13
|
|
|
* |
14
|
|
|
* @link http://pyrocms.com/ |
15
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
16
|
|
|
* @author Ryan Thompson <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class AssignmentsController extends AdminController |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The stream namespace. |
23
|
|
|
* |
24
|
|
|
* @var null|string |
25
|
|
|
*/ |
26
|
|
|
protected $namespace = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Return an index of existing assignments. |
30
|
|
|
* |
31
|
|
|
* @param AssignmentTableBuilder $table |
32
|
|
|
* @param StreamRepositoryInterface $streams |
33
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
public function index(AssignmentTableBuilder $table, StreamRepositoryInterface $streams) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
/* @var StreamInterface $stream */ |
38
|
|
|
if (!$stream = $streams->find($this->route->parameter('stream'))) { |
39
|
|
|
$stream = $streams->findBySlugAndNamespace( |
40
|
|
|
$this->route->parameter('stream'), |
41
|
|
|
$this->getNamespace() |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $table |
46
|
|
|
->setStream($stream) |
|
|
|
|
47
|
|
|
->render(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Choose a field to assign. |
52
|
|
|
* |
53
|
|
|
* @param FieldRepositoryInterface $fields |
54
|
|
|
* @param StreamRepositoryInterface $streams |
55
|
|
|
* @param ModuleCollection $modules |
56
|
|
|
* @return \Illuminate\Contracts\View\View|mixed |
57
|
|
|
*/ |
58
|
|
|
public function choose( |
59
|
|
|
FieldRepositoryInterface $fields, |
60
|
|
|
StreamRepositoryInterface $streams, |
61
|
|
|
ModuleCollection $modules |
62
|
|
|
) { |
63
|
|
|
$module = $modules->active(); |
64
|
|
|
|
65
|
|
|
/* @var StreamInterface $stream */ |
66
|
|
|
if (!$stream = $streams->find($this->route->parameter('stream'))) { |
67
|
|
|
$stream = $streams->findBySlugAndNamespace($this->route->parameter('stream'), $this->getNamespace()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$fields = $fields |
71
|
|
|
->findAllByNamespace($this->getNamespace()) |
72
|
|
|
->notAssignedTo($stream) |
|
|
|
|
73
|
|
|
->unlocked(); |
74
|
|
|
|
75
|
|
|
return $this->view->make('streams::assignments/choose', compact('fields', 'group', 'module')); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Create a new assignment. |
80
|
|
|
* |
81
|
|
|
* @param AssignmentFormBuilder $builder |
82
|
|
|
* @param StreamRepositoryInterface $streams |
83
|
|
|
* @param FieldRepositoryInterface $fields |
84
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
85
|
|
|
*/ |
86
|
|
|
public function create( |
87
|
|
|
AssignmentFormBuilder $builder, |
88
|
|
|
StreamRepositoryInterface $streams, |
89
|
|
|
FieldRepositoryInterface $fields |
90
|
|
|
) { |
91
|
|
|
/* @var StreamInterface $stream */ |
92
|
|
|
if (!$stream = $streams->find($this->route->parameter('stream'))) { |
93
|
|
|
$stream = $streams->findBySlugAndNamespace($this->route->parameter('stream'), $this->getNamespace()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/* @var FieldInterface $field */ |
97
|
|
|
$field = $fields->find($this->request->get('field')); |
98
|
|
|
|
99
|
|
|
return $builder |
100
|
|
|
->setField($field) |
101
|
|
|
->setStream($stream) |
|
|
|
|
102
|
|
|
->render(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Edit an existing assignment. |
107
|
|
|
* |
108
|
|
|
* @param AssignmentFormBuilder $builder |
109
|
|
|
* @param StreamRepositoryInterface $streams |
110
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
111
|
|
|
*/ |
112
|
|
View Code Duplication |
public function edit(AssignmentFormBuilder $builder, StreamRepositoryInterface $streams) |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
/* @var StreamInterface $stream */ |
115
|
|
|
if (!$stream = $streams->find($this->route->parameter('stream'))) { |
116
|
|
|
$stream = $streams->findBySlugAndNamespace($this->route->parameter('stream'), $this->getNamespace()); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $builder |
120
|
|
|
->setStream($stream) |
|
|
|
|
121
|
|
|
->render($this->route->parameter('id')); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get the namespace. |
126
|
|
|
* |
127
|
|
|
* @return null|string |
128
|
|
|
*/ |
129
|
|
|
public function getNamespace() |
130
|
|
|
{ |
131
|
|
|
return $this->namespace; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
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.