Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b323292b

Přidáno uživatelem Marek Lovčí před asi 4 roky(ů)

Merge branch 'develop'

Zobrazit rozdíly:

app/Http/Controllers/CategoriesController.php
14 14
        $this->middleware('auth');
15 15
    }
16 16

  
17
    public function calculateClusters($categoriesCount)
18
    {
19
        if(isset($categoriesCount))
20
        {
21
            $min = PHP_INT_MAX;
22
            $max = PHP_INT_MIN;
23
            foreach($categoriesCount as $category)
24
            {
25
                $c = count($category);
26
                if($c < $min)
27
                {
28
                    $min = $c;
29
                }
30

  
31
                if($c > $max)
32
                {
33
                    $max = $c;
34
                }
35
            }
36
            $center = $min + (($max - $min)/2);
37
            return array($min, $center, $max);
38
        }
39
        else
40
        {
41
            return null;
42
        }
43
    }
44

  
45 17
    /**
46 18
     * Display a listing of the resource.
47 19
     *
......
53 25
        {
54 26
            $userId = Auth::user()->id;
55 27

  
56
            $categoryNames = Category::all();
28
            $categoryNames = Category::orderBy('id')->get();
57 29
            $countCategory = count($categoryNames);
58
            $categories = array();
59
            for($i = 1; $i <= $countCategory;$i++)
60
            {
61
                array_push($categories, Category::find($i)->artefacts()->get());
62
            }
63
            $clusters = $this->calculateClusters($categories);
64

  
65
            $categorySizes = array();
66
            if(isset($clusters))
67
            {
68
                foreach($categories as $category)
69
                {
70
                    $c = count($category);
71
                    $type1 = abs($clusters['0'] - $c);
72
                    $type2 = abs($clusters['1'] - $c);
73
                    $type3 = abs($clusters['2'] - $c);
74

  
75
                    if($type1 <= $type2 && $type1 <= $type3)
76
                    {
77
                        array_push($categorySizes, 1);
78
                    }
79
                    else if($type2 <= $type1 && $type2 <= $type3)
80
                    {
81
                        array_push($categorySizes, 2);
82
                    }
83
                    else
84
                    {
85
                        array_push($categorySizes, 3);
86
                    }
87
                }
88
            }
89 30

  
90 31
            $data = array(
91 32
                'title' => 'Categories',
92 33
                'user' => User::find($userId),
93 34
                'count' => $countCategory,
94
                'categories' => $categories,
95
                'categorySizes' => $categorySizes,
96 35
                'categoryNames' => $categoryNames
97 36
            );
98 37
            return view('categories.index') -> with($data);

Také k dispozici: Unified diff