1 | <?php |
||
22 | class Project extends FormAbstract |
||
23 | { |
||
24 | /** |
||
25 | * @return array |
||
26 | */ |
||
27 | 4 | public function actions() |
|
28 | { |
||
29 | 4 | if ($this->isEditing()) { |
|
30 | return [ |
||
31 | 3 | 'submit' => 'update', |
|
32 | 'delete' => [ |
||
33 | 3 | 'type' => 'danger_submit', |
|
34 | 3 | 'label' => trans('tinyissue.delete_something', ['name' => $this->getModel()->name]), |
|
35 | 3 | 'class' => 'delete-project', |
|
36 | 3 | 'name' => 'delete-project', |
|
37 | 3 | 'data-message' => trans('tinyissue.delete_project_confirm'), |
|
38 | ], |
||
39 | ]; |
||
40 | } |
||
41 | |||
42 | return [ |
||
43 | 1 | 'submit' => 'create_project', |
|
44 | ]; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @return array |
||
49 | */ |
||
50 | 4 | public function fields() |
|
51 | { |
||
52 | $fields = [ |
||
53 | 'name' => [ |
||
54 | 'type' => 'text', |
||
55 | 'label' => 'name', |
||
56 | 4 | ], |
|
57 | 'private' => [ |
||
58 | 4 | 'type' => 'select', |
|
59 | 4 | 'label' => 'visibility', |
|
60 | 'options' => [ |
||
61 | 4 | ProjectModel::INTERNAL_YES => trans('tinyissue.internal'), |
|
62 | 4 | ProjectModel::PRIVATE_YES => trans('tinyissue.private'), |
|
63 | 4 | ProjectModel::PRIVATE_NO => trans('tinyissue.public'), |
|
64 | ], |
||
65 | ], |
||
66 | 'default_assignee' => [ |
||
67 | 'type' => 'hidden', |
||
68 | 'id' => 'default_assignee-id', |
||
69 | ], |
||
70 | ]; |
||
71 | |||
72 | // On create project can assign users |
||
73 | // On edit project can change status or default assignee |
||
74 | 4 | if (!$this->isEditing()) { |
|
75 | 1 | $fields['user'] = [ |
|
76 | 1 | 'type' => 'selectUser', |
|
77 | 1 | 'label' => 'assign_users', |
|
78 | 1 | 'id' => 'add-user-project', |
|
79 | 1 | 'placeholder' => trans('tinyissue.assign_a_user'), |
|
80 | ]; |
||
81 | } else { |
||
82 | 3 | $fields['status'] = [ |
|
83 | 3 | 'type' => 'select', |
|
84 | 3 | 'label' => 'status', |
|
85 | 3 | 'options' => [ProjectModel::STATUS_OPEN => trans('tinyissue.open'), ProjectModel::STATUS_ARCHIVED => trans('tinyissue.archived')], |
|
86 | ]; |
||
87 | 3 | $fields['default_assignee'] = [ |
|
88 | 3 | 'type' => 'select', |
|
89 | 3 | 'label' => 'default_assignee', |
|
90 | 3 | 'options' => [0 => ''] + $this->getModel()->usersCanFixIssue()->get()->lists('fullname', 'id')->all(), |
|
91 | ]; |
||
92 | } |
||
93 | |||
94 | 4 | $fields['kanban_board'] = [ |
|
95 | 'type' => 'legend', |
||
96 | ]; |
||
97 | |||
98 | 4 | $fields += $this->getKanbanColumnsField(); |
|
99 | |||
100 | 4 | return $fields; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * Return Kanban columns field. |
||
105 | * |
||
106 | * @return array |
||
107 | */ |
||
108 | 4 | protected function getKanbanColumnsField() |
|
109 | { |
||
110 | 4 | $fields = []; |
|
111 | |||
112 | // All of the status tags |
||
113 | 4 | $statusTags = (new TagModel())->getStatusTags()->get(); |
|
114 | |||
115 | // Get selected status tags on editing a project |
||
116 | 4 | $selectTags = []; |
|
117 | 4 | if ($this->isEditing()) { |
|
118 | 3 | $selectTags = $this->getModel()->kanbanTags()->get()->lists('id'); |
|
119 | } |
||
120 | |||
121 | // An array for checkboxes |
||
122 | 4 | $options = []; |
|
123 | 4 | foreach ($selectTags as $tagId) { |
|
124 | $tag = $statusTags->find($tagId); |
||
125 | if ($tag) { |
||
126 | $options[ucwords($tag->name)] = $this->getKanbanColumnField($tag, true); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | 4 | foreach ($statusTags as $tag) { |
|
131 | 4 | if (!isset($options[ucwords($tag->name)])) { |
|
132 | 4 | $options[ucwords($tag->name)] = $this->getKanbanColumnField($tag); |
|
133 | } |
||
134 | } |
||
135 | |||
136 | // The checkbox button element |
||
137 | 4 | $fields['columns[]'] = [ |
|
138 | 4 | 'label' => 'columns', |
|
139 | 4 | 'type' => 'checkboxButton', |
|
140 | 4 | 'checkboxes' => $options, |
|
141 | 'grouped' => true, |
||
142 | ]; |
||
143 | |||
144 | 4 | return $fields; |
|
145 | } |
||
146 | |||
147 | /** |
||
148 | * Returns an array structure for a checkbox button in the kanban field. |
||
149 | * |
||
150 | * @param TagModel $tag |
||
151 | * @param bool $checked |
||
152 | * |
||
153 | * @return array |
||
154 | */ |
||
155 | 4 | protected function getKanbanColumnField(TagModel $tag, $checked = false) |
|
164 | |||
165 | /** |
||
166 | * @return array |
||
167 | */ |
||
168 | 4 | public function rules() |
|
177 | |||
178 | /** |
||
179 | * @return string |
||
180 | */ |
||
181 | public function getRedirectUrl() |
||
189 | } |
||
190 |