Completed
Push — master ( 307d8a...2c7bf4 )
by Phecho
05:31
created

ApiController::postUploadAvatar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4286
cc 1
eloc 4
nc 1
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 GrahamCampbell\Binput\Facades\Binput;
17
use Illuminate\Routing\Controller;
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(Binput::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 = Binput::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