1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tinyissue\Form; |
13
|
|
|
|
14
|
|
|
use Illuminate\Support\Collection; |
15
|
|
|
use Tinyissue\Model\Message; |
16
|
|
|
use Tinyissue\Model\Project; |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* UserMessagesSettings is a class to defines fields & rules for edit user message settings form. |
20
|
|
|
* |
21
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class UserMessagesSettings extends FormAbstract |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var Collection |
27
|
|
|
*/ |
28
|
|
|
protected $projects; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param Collection $projects |
32
|
|
|
* |
33
|
|
|
* @return $this |
34
|
|
|
*/ |
35
|
|
|
public function setProjects(Collection $projects) |
36
|
|
|
{ |
37
|
|
|
$this->projects = $projects; |
38
|
|
|
|
39
|
|
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function actions() |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
'submit' => 'update', |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
public function fields() |
56
|
|
|
{ |
57
|
|
|
$fields = []; |
58
|
|
|
|
59
|
|
|
// Change label widths |
60
|
|
|
\Former::setOption('TwitterBootstrap3.labelWidths', ['large' => 4, 'small' => 4]); |
61
|
|
|
|
62
|
|
|
/** @var Collection $messages Available message options */ |
63
|
|
|
$messages = Message::orderBy('id')->lists('name', 'id'); |
64
|
|
|
|
65
|
|
|
// Create field for each project |
66
|
|
|
$this->projects->each(function (Project $project) use (&$fields, $messages) { |
67
|
|
|
$messageId = $project->projectUsers->first()->message_id; |
|
|
|
|
68
|
|
|
$fields['projects[' . $project->id . ']'] = [ |
69
|
|
|
'type' => 'select', |
70
|
|
|
'label' => $project->name, |
71
|
|
|
'options' => $messages, |
72
|
|
|
'value' => $messageId, |
73
|
|
|
'help' => trans('tinyissue.messages_' . strtolower($messages->get($messageId) . '_help')), |
74
|
|
|
]; |
75
|
|
|
}); |
76
|
|
|
|
77
|
|
|
return $fields; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: