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\Contracts\Auth\Guard; |
15
|
|
|
use Illuminate\Support\Collection; |
16
|
|
|
use Tinyissue\Model\Message; |
17
|
|
|
use Tinyissue\Model\Project; |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* UserMessagesSettings is a class to defines fields & rules for edit user message settings form. |
21
|
|
|
* |
22
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class UserMessagesSettings extends FormAbstract |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var Collection |
28
|
|
|
*/ |
29
|
|
|
protected $projects; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var \Illuminate\Contracts\Auth\Authenticatable|null |
33
|
|
|
*/ |
34
|
|
|
protected $user; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param Guard $model |
38
|
|
|
*/ |
39
|
|
|
public function __construct(Guard $model) |
40
|
|
|
{ |
41
|
|
|
$this->user = $model->user(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param Collection $projects |
46
|
|
|
* |
47
|
|
|
* @return $this |
48
|
|
|
*/ |
49
|
|
|
public function setProjects(Collection $projects) |
50
|
|
|
{ |
51
|
|
|
$this->projects = $projects; |
52
|
|
|
|
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
public function actions() |
60
|
|
|
{ |
61
|
|
|
return [ |
62
|
|
|
'submit' => 'update', |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
public function fields() |
70
|
|
|
{ |
71
|
|
|
$fields = []; |
72
|
|
|
|
73
|
|
|
// Change label widths |
74
|
|
|
\Former::setOption('TwitterBootstrap3.labelWidths', ['large' => 4, 'small' => 4]); |
75
|
|
|
|
76
|
|
|
/** @var Collection $messages Available message options */ |
77
|
|
|
$messages = Message::orderBy('id')->lists('name', 'id'); |
78
|
|
|
|
79
|
|
|
// Create field for each project |
80
|
|
|
$this->projects->each(function (Project $project) use (&$fields, $messages) { |
81
|
|
|
$messageId = $project->projectUsers->first()->message_id; |
|
|
|
|
82
|
|
|
$fields['projects[' . $project->id . ']'] = [ |
83
|
|
|
'type' => 'select', |
84
|
|
|
'label' => $project->name, |
85
|
|
|
'options' => $messages, |
86
|
|
|
'value' => $messageId, |
87
|
|
|
'help' => trans('tinyissue.messages_' . strtolower($messages->get($messageId) . '_help')), |
88
|
|
|
]; |
89
|
|
|
}); |
90
|
|
|
|
91
|
|
|
return $fields; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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: