ApiController::postUpdateProjectOrder()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
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 Illuminate\Routing\Controller;
17
use Illuminate\Support\Facades\Request;
18
19
class ApiController extends Controller
20
{
21
    /**
22
     * Updates a project with the entered info.
23
     *
24
     * @param \Gitamin\Models\Project $project
25
     *
26
     * @throws \Exception
27
     *
28
     * @return \Gitamin\Models\Project
29
     */
30
    public function postUpdateProject(Project $project)
31
    {
32
        if (! $project->update(Request::except(['_token']))) {
33
            throw new Exception(trans('dashboard.projects.edit.failure'));
34
        }
35
36
        return $project;
37
    }
38
39
    /**
40
     * Updates a projects ordering.
41
     *
42
     * @return array
43
     */
44
    public function postUpdateProjectOrder()
45
    {
46
        $projectData = Request::get('ids');
47
48
        foreach ($projectData as $order => $projectId) {
49
            // Ordering should be 1-based, data comes in 0-based
50
            Project::find($projectId)->update(['order' => $order + 1]);
51
        }
52
53
        return $projectData;
54
    }
55
56
    public function postUploadAvatar()
57
    {
58
        $data = [
59
            'path' => '/img/no_group_avatar.png',
60
        ];
61
62
        return $data;
63
    }
64
}
65