| Total Complexity | 18 |
| Total Lines | 299 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | class ProjectReleaseCrudController extends CrudController |
||
| 21 | { |
||
| 22 | //use UsesPolicies; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @throws \Exception |
||
| 26 | */ |
||
| 27 | public function setup() |
||
| 28 | { |
||
| 29 | |||
| 30 | /* |
||
| 31 | |-------------------------------------------------------------------------- |
||
| 32 | | BASIC CRUD INFORMATION |
||
| 33 | |-------------------------------------------------------------------------- |
||
| 34 | */ |
||
| 35 | |||
| 36 | $project_id = Route::current()->parameter('project_id') ?? Route::current()->parameter('project'); |
||
| 37 | |||
| 38 | $this->crud->setModel(Release::class); |
||
| 39 | $this->crud->setEntityNameStrings('Release', 'Releases'); |
||
| 40 | $this->crud->setRoute(config('backpack.base.route_prefix') . '/projects/' . $project_id . '/releases'); |
||
| 41 | |||
| 42 | if ($project_id) { |
||
| 43 | $project = Project::findOrFail($project_id); |
||
| 44 | $this->crud->addClause('where', 'agent_id', $project_id); |
||
| 45 | Vocabulary::addGlobalScope('project_id', function (Builder $builder) use ($project_id) { |
||
| 46 | $builder->where('agent_id', $project_id); |
||
| 47 | }); |
||
| 48 | Elementset::addGlobalScope('project_id', function (Builder $builder) use ($project_id) { |
||
| 49 | $builder->where('agent_id', $project_id); |
||
| 50 | }); |
||
| 51 | } |
||
| 52 | |||
| 53 | /* |
||
| 54 | |-------------------------------------------------------------------------- |
||
| 55 | | BASIC CRUD INFORMATION |
||
| 56 | |-------------------------------------------------------------------------- |
||
| 57 | */ |
||
| 58 | |||
| 59 | $this->crud->setFromDb(); |
||
| 60 | |||
| 61 | // ------ CRUD FIELDS |
||
| 62 | // $this->crud->addField($options, 'update/create/both'); |
||
|
1 ignored issue
–
show
|
|||
| 63 | // $this->crud->addFields($array_of_arrays, 'update/create/both'); |
||
|
1 ignored issue
–
show
|
|||
| 64 | // $this->crud->removeField('name', 'update/create/both'); |
||
|
1 ignored issue
–
show
|
|||
| 65 | $this->crud->removeFields(['user_id', 'agent_id', 'name', 'body', 'github_response', 'tag_name', 'target_commitish', 'is_draft', 'is_prerelease']); |
||
| 66 | $this->crud->addFields([ |
||
| 67 | [ |
||
| 68 | 'name' => 'user_id', |
||
| 69 | 'type' => 'hidden', |
||
| 70 | 'default' => request()->user() ? request()->user()->id : null, |
||
| 71 | ], |
||
| 72 | [ |
||
| 73 | 'name' => 'agent_id', |
||
| 74 | 'type' => 'hidden', |
||
| 75 | 'default' => $project_id, |
||
| 76 | ], |
||
| 77 | [ |
||
| 78 | 'name' => 'name', |
||
| 79 | 'label' => 'Release Title', |
||
| 80 | 'type' => 'text', |
||
| 81 | 'attributes' => [ |
||
| 82 | 'placeholder' => 'The descriptive title of this release', |
||
| 83 | ], |
||
| 84 | ], |
||
| 85 | [ |
||
| 86 | 'name' => 'body', |
||
| 87 | 'label' => 'Release Notes', |
||
| 88 | 'type' => 'textarea', |
||
| 89 | 'attributes' => [ |
||
| 90 | 'placeholder' => 'Add some description of the changes in this release', |
||
| 91 | 'rows' => 10, |
||
| 92 | ], |
||
| 93 | ], |
||
| 94 | [ |
||
| 95 | 'name' => 'tag_name', |
||
| 96 | 'label' => 'Tag Name', |
||
| 97 | 'type' => 'text', |
||
| 98 | 'attributes' => [ |
||
| 99 | 'placeholder' => 'The name of the GIT tag to assign to this release', |
||
| 100 | ], |
||
| 101 | ], |
||
| 102 | [ |
||
| 103 | 'name' => 'is_prerelease', |
||
| 104 | 'label' => 'Pre-Release', |
||
| 105 | 'type' => 'checkbox', |
||
| 106 | 'hint' => 'Notify consuming systems that this release is not final', |
||
| 107 | |||
| 108 | ], |
||
| 109 | [ |
||
| 110 | 'label' => 'Value Vocabularies to publish...', |
||
| 111 | 'type' => 'select_multiple', |
||
| 112 | 'name' => 'vocabularies', // the method that defines the relationship in your Model |
||
| 113 | 'entity' => 'vocabularies', // the method that defines the relationship in your Model |
||
| 114 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
| 115 | 'model' => Vocabulary::class, // foreign key model |
||
| 116 | 'pivot' => true, // on create&update, do you need to add/delete pivot table entries? |
||
| 117 | 'pivotFields' => [], // an array of pivot table fields |
||
| 118 | 'morph' => true, |
||
| 119 | 'allows_null' => false, |
||
| 120 | 'hint' => 'Use shift- or ctrl-click (Windows) or cmd-click (mac) to select.', |
||
| 121 | ], |
||
| 122 | [ |
||
| 123 | 'label' => 'Element Sets to publish...', |
||
| 124 | 'type' => 'select_multiple', |
||
| 125 | 'name' => 'elementsets', // the method that defines the relationship in your Model |
||
| 126 | 'entity' => 'elementsets', // the method that defines the relationship in your Model |
||
| 127 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
| 128 | 'model' => Elementset::class, // foreign key model |
||
| 129 | 'pivot' => true, // on create&update, do you need to add/delete pivot table entries? |
||
| 130 | 'pivotFields' => [], // an array of pivot table fields |
||
| 131 | 'morph' => true, |
||
| 132 | 'allows_null' => false, |
||
| 133 | 'hint' => 'Use shift- or ctrl-click (Windows) or cmd-click (mac) to select.', |
||
| 134 | ], |
||
| 135 | ]); |
||
| 136 | |||
| 137 | // ------ CRUD COLUMNS |
||
| 138 | // $this->crud->addColumn(); // add a single column, at the end of the stack |
||
|
1 ignored issue
–
show
|
|||
| 139 | // $this->crud->addColumns(); // add multiple columns, at the end of the stack |
||
|
1 ignored issue
–
show
|
|||
| 140 | //$this->crud->removeColumn('github_response'); // remove a column from the stack |
||
|
1 ignored issue
–
show
|
|||
| 141 | $this->crud->removeColumns(['user_id', 'agent_id', 'github_response', 'target_commitish', 'is_draft', 'deleted_at']); // remove an array of columns from the stack |
||
| 142 | // $this->crud->setColumnDetails('column_name', ['attribute' => 'value']); // adjusts the properties of the passed in column (by name) |
||
|
1 ignored issue
–
show
|
|||
| 143 | $this->crud->addColumns([ |
||
| 144 | [ |
||
| 145 | // n-n relationship (with pivot table) |
||
| 146 | 'label' => 'Vocabularies', // Table column heading |
||
| 147 | 'type' => 'select_multiple', |
||
| 148 | 'name' => 'vocabularies', // the method that defines the relationship in your Model |
||
| 149 | 'entity' => 'vocabularies', // the method that defines the relationship in your Model |
||
| 150 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
| 151 | 'model' => Vocabulary::class, // foreign key model |
||
| 152 | |||
| 153 | ], |
||
| 154 | [ |
||
| 155 | // n-n relationship (with pivot table) |
||
| 156 | 'label' => 'Element Sets', // Table column heading |
||
| 157 | 'type' => 'select_multiple', |
||
| 158 | 'name' => 'elementsets', // the method that defines the relationship in your Model |
||
| 159 | 'entity' => 'elementsets', // the method that defines the relationship in your Model |
||
| 160 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
| 161 | 'model' => Elementset::class, // foreign key model |
||
| 162 | |||
| 163 | ], |
||
| 164 | [ |
||
| 165 | 'label' => 'Released by', // Table column heading |
||
| 166 | 'type' => 'select', |
||
| 167 | 'name' => 'user', // the method that defines the relationship in your Model |
||
| 168 | 'entity' => 'user', // the method that defines the relationship in your Model |
||
| 169 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
| 170 | 'model' => User::class, // foreign key model |
||
| 171 | |||
| 172 | ], |
||
| 173 | ]); |
||
| 174 | |||
| 175 | $this->crud->setColumnDetails('is_prerelease', |
||
| 176 | [ |
||
| 177 | 'type' => 'boolean', |
||
| 178 | 'label' => 'Pre-release?', |
||
| 179 | |||
| 180 | ]); |
||
| 181 | $this->crud->setColumnDetails('body', |
||
| 182 | [ |
||
| 183 | 'type' => 'markdown', |
||
| 184 | ]); |
||
| 185 | |||
| 186 | $this->crud->setColumnsDetails(['body', 'tag_name'], |
||
| 187 | [ |
||
| 188 | 'list' => false, |
||
| 189 | ]); |
||
| 190 | |||
| 191 | // $this->crud->setColumnsDetails(['column_1', 'column_2'], ['attribute' => 'value']); |
||
|
1 ignored issue
–
show
|
|||
| 192 | |||
| 193 | // ------ CRUD BUTTONS |
||
| 194 | // possible positions: 'beginning' and 'end'; defaults to 'beginning' for the 'line' stack, 'end' for the others; |
||
| 195 | $this->crud->addButton('line', 'publish', 'view', 'backpack::crud.buttons.publish', 'end'); // add a button; possible types are: view, model_function |
||
| 196 | // $this->crud->addButtonFromModelFunction($stack, $name, $model_function_name, $position); // add a button whose HTML is returned by a method in the CRUD model |
||
|
1 ignored issue
–
show
|
|||
| 197 | // $this->crud->addButtonFromView($stack, $name, $view, $position); // add a button whose HTML is in a view placed at resources\views\vendor\backpack\crud\buttons |
||
|
1 ignored issue
–
show
|
|||
| 198 | // $this->crud->removeButton($name); |
||
|
1 ignored issue
–
show
|
|||
| 199 | // $this->crud->removeButtonFromStack($name, $stack); |
||
|
1 ignored issue
–
show
|
|||
| 200 | // $this->crud->removeAllButtons(); |
||
|
1 ignored issue
–
show
|
|||
| 201 | // $this->crud->removeAllButtonsFromStack('line'); |
||
|
1 ignored issue
–
show
|
|||
| 202 | |||
| 203 | $this->crud->denyAccess(['create', 'update', 'delete', 'import', 'publish']); |
||
| 204 | if ($project->is_private) { |
||
| 205 | if (Gate::allows('index', $project)) { |
||
| 206 | $this->crud->allowAccess(['index']); |
||
| 207 | } |
||
| 208 | if (Gate::allows('view', $project)) { |
||
| 209 | $this->crud->allowAccess(['show']); |
||
| 210 | } |
||
| 211 | } else { |
||
| 212 | $this->crud->allowAccess(['index']); |
||
| 213 | $this->crud->allowAccess(['show']); |
||
| 214 | } |
||
| 215 | if (Gate::allows('create', $project)) { |
||
| 216 | $this->crud->allowAccess(['create']); |
||
| 217 | } |
||
| 218 | if (Gate::allows('update', $project)) { |
||
| 219 | $this->crud->allowAccess(['update']); |
||
| 220 | } |
||
| 221 | if (Gate::allows('delete', $project)) { |
||
| 222 | $this->crud->allowAccess(['delete']); |
||
| 223 | } |
||
| 224 | if (Gate::allows('publish', $project)) { |
||
| 225 | $this->crud->allowAccess(['publish']); |
||
| 226 | } |
||
| 227 | // ------ CRUD ACCESS |
||
| 228 | // $this->crud->allowAccess([ 'index', 'show' ]); |
||
|
1 ignored issue
–
show
|
|||
| 229 | |||
| 230 | //$this->authorizeAll(); |
||
|
1 ignored issue
–
show
|
|||
| 231 | |||
| 232 | // ------ CRUD REORDER |
||
| 233 | // $this->crud->enableReorder('label_name', MAX_TREE_LEVEL); |
||
|
1 ignored issue
–
show
|
|||
| 234 | // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('reorder'); |
||
| 235 | |||
| 236 | // ------ CRUD DETAILS ROW |
||
| 237 | // $this->crud->enableDetailsRow(); |
||
|
1 ignored issue
–
show
|
|||
| 238 | // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('details_row'); |
||
| 239 | // NOTE: you also need to do overwrite the showDetailsRow($id) method in your EntityCrudController to show whatever you'd like in the details row OR overwrite the views/backpack/crud/details_row.blade.php |
||
| 240 | |||
| 241 | // ------ REVISIONS |
||
| 242 | // You also need to use \Venturecraft\Revisionable\RevisionableTrait; |
||
| 243 | // Please check out: https://laravel-backpack.readme.io/docs/crud#revisions |
||
| 244 | // $this->crud->allowAccess('revisions'); |
||
|
1 ignored issue
–
show
|
|||
| 245 | |||
| 246 | // ------ AJAX TABLE VIEW |
||
| 247 | // Please note the drawbacks of this though: |
||
| 248 | // - 1-n and n-n columns are not searchable |
||
| 249 | // - date and datetime columns won't be sortable anymore |
||
| 250 | // $this->crud->enableAjaxTable(); |
||
|
1 ignored issue
–
show
|
|||
| 251 | |||
| 252 | // ------ DATATABLE EXPORT BUTTONS |
||
| 253 | // Show export to PDF, CSV, XLS and Print buttons on the table view. |
||
| 254 | // Does not work well with AJAX datatables. |
||
| 255 | // $this->crud->enableExportButtons(); |
||
|
1 ignored issue
–
show
|
|||
| 256 | |||
| 257 | // ------ ADVANCED QUERIES |
||
| 258 | // $this->crud->addClause('active'); |
||
|
1 ignored issue
–
show
|
|||
| 259 | // $this->crud->addClause('type', 'car'); |
||
|
1 ignored issue
–
show
|
|||
| 260 | // $this->crud->addClause('where', 'name', '==', 'car'); |
||
|
1 ignored issue
–
show
|
|||
| 261 | // $this->crud->addClause('whereName', 'car'); |
||
|
1 ignored issue
–
show
|
|||
| 262 | // $this->crud->addClause('whereHas', 'posts', function($query) { |
||
|
1 ignored issue
–
show
|
|||
| 263 | // $query->activePosts(); |
||
|
1 ignored issue
–
show
|
|||
| 264 | // }); |
||
| 265 | // $this->crud->addClause('withoutGlobalScopes'); |
||
|
1 ignored issue
–
show
|
|||
| 266 | // $this->crud->addClause('withoutGlobalScope', VisibleScope::class); |
||
|
1 ignored issue
–
show
|
|||
| 267 | // $this->crud->with(); // eager load relationships |
||
|
1 ignored issue
–
show
|
|||
| 268 | // $this->crud->orderBy(); |
||
|
1 ignored issue
–
show
|
|||
| 269 | // $this->crud->groupBy(); |
||
|
1 ignored issue
–
show
|
|||
| 270 | // $this->crud->limit(); |
||
|
1 ignored issue
–
show
|
|||
| 271 | } |
||
| 272 | |||
| 273 | public function show($id) |
||
| 274 | { |
||
| 275 | return parent::show($this->request->release); |
||
| 276 | } |
||
| 277 | |||
| 278 | public function listRevisions($id) |
||
| 279 | { |
||
| 280 | return parent::listRevisions($this->request->release); |
||
| 281 | } |
||
| 282 | |||
| 283 | public function restoreRevision($id) |
||
| 284 | { |
||
| 285 | return parent::restoreRevision($this->request->release); |
||
| 286 | } |
||
| 287 | |||
| 288 | public function showDetailsRow($id) |
||
| 289 | { |
||
| 290 | return parent::showDetailsRow($this->request->release); |
||
| 291 | } |
||
| 292 | |||
| 293 | public function edit($id) |
||
| 294 | { |
||
| 295 | return parent::edit($this->request->release); |
||
| 296 | } |
||
| 297 | |||
| 298 | public function destroy($id) |
||
| 299 | { |
||
| 300 | return parent::destroy($this->request->release); |
||
| 301 | } |
||
| 302 | |||
| 303 | public function store(StoreRequest $request) |
||
| 304 | { |
||
| 305 | // your additional operations before save here |
||
| 306 | $redirect_location = parent::storeCrud($request); |
||
| 307 | // your additional operations after save here |
||
| 308 | // use $this->data['entry'] or $this->crud->entry |
||
|
1 ignored issue
–
show
|
|||
| 309 | return $redirect_location; |
||
| 310 | } |
||
| 311 | |||
| 312 | public function update(UpdateRequest $request) |
||
| 319 | } |
||
| 320 | } |
||
| 321 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.