-
Notifications
You must be signed in to change notification settings - Fork 0
/
Listener.php
130 lines (103 loc) · 3.41 KB
/
Listener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php namespace Hampel\ItemsThisPage;
use XF\Entity\FindNew;
use XF\Mvc\Entity\ArrayCollection;
class Listener
{
public static function templaterGlobalData(\XF\App $app, array &$data, $reply)
{
if ($app instanceof \XF\Pub\App && $reply && $reply instanceof \XF\Mvc\Reply\View)
{
$params = $reply->getParams();
$template = $reply->getTemplateName();
switch ($template)
{
case 'thread_view': // fall through
case 'thread_view_type_article':
case 'thread_view_type_poll':
case 'thread_view_type_question':
case 'thread_view_type_suggestion':
case 'xfrm_thread_view_type_resource':
$data['itemsThisPage'] = self::itemsThisPage($params['page'], $params['totalPosts'], $params['perPage']);
break;
case 'forum_view': // fall through
case 'forum_view_type_article':
case 'forum_view_type_question':
case 'forum_view_type_suggestion':
case 'find_threads_list':
case 'watched_threads_list':
case 'xfmg_watched_media':
case 'member_list':
case 'online_list':
case 'xfrm_overview':
case 'xfrm_category_view':
case 'xfrm_latest_reviews':
case 'xfrm_author_view':
case 'xfrm_watched_resources':
$data['itemsThisPage'] = self::itemsThisPage($params['page'], $params['total'], $params['perPage']);
break;
case 'watched_forums_list':
$data['itemsThisPage'] = $params['watchedForums'] instanceof ArrayCollection ? $params['watchedForums']->count() : 0;
break;
case 'xfmg_media_index': // fall through
case 'xfmg_media_view':
case 'xfmg_category_view':
case 'xfmg_album_index':
case 'xfmg_media_user_index':
case 'xfmg_album_user_index':
$data['itemsThisPage'] = self::itemsThisPage($params['page'], $params['totalItems'], $params['perPage']);
break;
case 'xfmg_watched_albums':
$data['itemsThisPage'] = $params['albums'] instanceof ArrayCollection ? $params['albums']->count() : 0;
break;
case 'xfmg_watched_categories': // fall through
case 'xfrm_watched_categories':
$data['itemsThisPage'] = $params['watchedCategories'] instanceof ArrayCollection ? $params['watchedCategories']->count() : 0;
break;
case 'whats_new_posts': // fall through
case 'xfmg_whats_new_media':
case 'xfmg_whats_new_media_comments':
case 'xfrm_whats_new_resources':
case 'whats_new_profile_posts':
/** @var FindNew $findNew */
$findNew = $params['findNew'];
$data['itemsThisPage'] = self::itemsThisPage($params['page'], $findNew->getResultCount(), $params['perPage']);
break;
case 'news_feed': // fall through
case 'latest_activity':
$data['itemsThisPage'] = $params['newsFeedItems'] instanceof ArrayCollection ? $params['newsFeedItems']->count() : 0;
break;
case 'tag_view':
$data['itemsThisPage'] = self::itemsThisPage($params['page'], $params['totalResults'], $params['perPage']);
break;
case 'search_results':
$data['itemsThisPage'] = self::itemsThisPage($params['page'], count($params['results']), $params['perPage']);
break;
default:
break;
}
}
}
public static function itemsThisPage($page, $total, $perPage)
{
if ($total == 0)
{
return 0;
}
$totalPages = intval(ceil($total / $perPage));
if ($page < $totalPages)
{
return intval($perPage);
}
else
{
if ($total % $perPage == 0)
{
return intval($perPage);
}
else
{
return $total % $perPage;
}
}
}
}