Completed
Pull Request — master (#33)
by Phecho
03:26
created

ApiController::postUpdateProjectTeamOrder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 * 
6
 * Copyright (C) 2015-2016 The Gitamin Team
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 Gitamin\Http\Controllers\Dashboard;
13
14
use Exception;
15
use Gitamin\Models\Project;
16
use Gitamin\Models\ProjectNamespace;
17
use GrahamCampbell\Binput\Facades\Binput;
18
use Illuminate\Routing\Controller;
19
20
class ApiController extends Controller
21
{
22
    /**
23
     * Updates a project with the entered info.
24
     *
25
     * @param \Gitamin\Models\Project $project
26
     *
27
     * @throws \Exception
28
     *
29
     * @return \Gitamin\Models\Project
30
     */
31
    public function postUpdateProject(Project $project)
32
    {
33
        if (!$project->update(Binput::except(['_token']))) {
34
            throw new Exception(trans('dashboard.projects.edit.failure'));
35
        }
36
37
        return $project;
38
    }
39
40
    /**
41
     * Updates a projects ordering.
42
     *
43
     * @return array
44
     */
45
    public function postUpdateProjectOrder()
46
    {
47
        $projectData = Binput::get('ids');
48
49
        foreach ($projectData as $order => $projectId) {
50
            // Ordering should be 1-based, data comes in 0-based
51
            Project::find($projectId)->update(['order' => $order + 1]);
52
        }
53
54
        return $projectData;
55
    }
56
}
57