Skip to content

Commit 25d217e

Browse files
committed
finishing make statistics
1 parent 7fc9e64 commit 25d217e

File tree

2 files changed

+80
-25
lines changed

2 files changed

+80
-25
lines changed

app/Http/Controllers/StaticPagesController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function statisticsIndex() {
2323
$newsCount = News::all()->count();
2424

2525
//ФИО автора, у которого больше всего статей на сайте
26-
$userWithMostPosts = getUserWithMaxPosts();
26+
$usersWithMostPosts = getUserWithMaxPosts();
2727

2828
//Самая длинная статья - название, ссылка на статью и длина статьи в символах
2929
$theLongestPost = getTheLongestPosts();
@@ -35,19 +35,19 @@ public function statisticsIndex() {
3535
$avgPostsHaveActiveUsers = getAveragePosts();
3636

3737
//Самая непостоянная - название, ссылка на статью, которую меняли больше всего раз
38-
$mostChangingPost = getMostChangingPosts();
38+
$mostChangingPosts = getMostChangingPosts();
3939

4040
//Самая обсуждаемая статья - название, ссылка на статью, у которой больше всего комментариев.
4141
$mostCommentPosts = getMostCommentPosts();
4242

4343
$statistics = [
4444
'posts_count' => $postsCount,
4545
'news_count' => $newsCount,
46-
'user_with_most_posts' => $userWithMostPosts,
46+
'users_with_most_posts' => $usersWithMostPosts,
4747
'the_longest_posts' => $theLongestPost,
4848
'the_shortest_posts' => $theShortestPost,
4949
'avg_posts_have_active_users' => $avgPostsHaveActiveUsers,
50-
'most_changing_posts' => $mostChangingPost,
50+
'most_changing_posts' => $mostChangingPosts,
5151
'most_comment_posts' => $mostCommentPosts
5252
];
5353

resources/views/static/statistics.blade.php

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,92 @@
2121

2222
@if(!is_null($statistics['news_count']))
2323
<li class="statistic__item list-group-item">
24-
Общее количество новостей :
24+
Общее количество новостей на сайте :
2525
<strong>{{ $statistics['news_count'] }}</strong>
2626
</li>
2727
@endif
2828

29-
<li class="statistic__item list-group-item">
30-
ФИО автора, у которого больше всего статей на сайте :
31-
{{-- @foreach()--}}
29+
@if(!is_null($statistics['users_with_most_posts']))
30+
<li class="statistic__item list-group-item">
31+
Авторы с наибольшим количеством статей на сайте :
32+
@foreach($statistics['users_with_most_posts'] as $key => $user)
33+
<div class="values">
34+
{{ $key + 1 }}. <span>{{ $user->name }}</span>
3235

33-
{{-- @endforeach--}}
34-
</li>
36+
<a href="" class="text-primary">{{ $user->email }}</a> -
3537

36-
<li class="statistic__item list-group-item">
37-
Самая длинная статья - название, ссылка на статью и длина статьи в символах
38-
</li>
38+
<strong>{{ $user->posts_count }}</strong>
39+
</div>
40+
@endforeach
41+
</li>
42+
@endif
3943

40-
<li class="statistic__item list-group-item">
41-
Самая короткая статья - название, ссылка на статью и длина статьи в символах
42-
</li>
44+
@if(!is_null($statistics['the_longest_posts']))
45+
<li class="statistic__item list-group-item">
46+
Самая длинная статья на сайте.
47+
@foreach($statistics['the_longest_posts'] as $key => $post)
48+
<div class="values">
49+
{{ $key + 1 }}.
50+
<span>Название статьи:
51+
<a href="{{ route('posts.show', $post) }}">{{ $post->name }}</a> -
52+
<strong>{{ mb_strlen($post->text) }}</strong>
53+
</span>
54+
</div>
55+
@endforeach
56+
</li>
57+
@endif
4358

44-
<li class="statistic__item list-group-item">
45-
Средние количество статей у “активных” пользователей, при этом активным пользователь считается, если у него есть более 1-й статьи
46-
</li>
59+
@if(!is_null($statistics['the_shortest_posts']))
60+
<li class="statistic__item list-group-item">
61+
Самая короткая статья на сайте.
62+
@foreach($statistics['the_shortest_posts'] as $key => $post)
63+
<div class="values">
64+
{{ $key + 1 }}.
65+
<span>Название статьи:
66+
<a href="{{ route('posts.show', $post) }}">{{ $post->name }}</a> -
67+
<strong>{{ mb_strlen($post->text) }}</strong>
68+
</span>
69+
</div>
70+
@endforeach
71+
</li>
72+
@endif
4773

48-
<li class="statistic__item list-group-item">
49-
Самая непостоянная - название, ссылка на статью, которую меняли больше всего раз
50-
</li>
74+
@if(!is_null($statistics['avg_posts_have_active_users']))
75+
<li class="statistic__item list-group-item">
76+
Среднее количество статей у "активных" пользователей -
77+
<strong>{{ $statistics['avg_posts_have_active_users'] }}</strong>
78+
</li>
79+
@endif
5180

52-
<li class="statistic__item list-group-item">
53-
Самая обсуждаемая статья - название, ссылка на статью, у которой больше всего комментариев.
54-
</li>
81+
@if(!is_null($statistics['most_changing_posts']))
82+
<li class="statistic__item list-group-item">
83+
Самая часто изменяемая статья на сайте.
84+
@foreach($statistics['most_changing_posts'] as $key => $post)
85+
<div class="values">
86+
{{ $key + 1 }}.
87+
<span>Название статьи:
88+
<a href="{{ route('posts.show', $post) }}">{{ $post->name }}</a> -
89+
<strong>{{ $post->history_count }}</strong>
90+
</span>
91+
</div>
92+
@endforeach
93+
</li>
94+
@endif
95+
96+
@if(!is_null($statistics['most_comment_posts']))
97+
<li class="statistic__item list-group-item">
98+
Самая обсуждаемая статья на сайте.
99+
@foreach($statistics['most_comment_posts'] as $key => $post)
100+
<div class="values">
101+
{{ $key + 1 }}.
102+
<span>Название статьи:
103+
<a href="{{ route('posts.show', $post) }}">{{ $post->name }}</a> -
104+
<strong>{{ $post->comments_count }}</strong>
105+
</span>
106+
</div>
107+
@endforeach
108+
</li>
109+
@endif
55110
</ul>
56111
</div>
57112
</section>

0 commit comments

Comments
 (0)