/
membershome.php
executable file
·117 lines (117 loc) · 3.63 KB
/
membershome.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
<?php
/*
Copyright (C) 2004-2010 Kestas J. Kuliukas
This file is part of webDiplomacy.
webDiplomacy is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
webDiplomacy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with webDiplomacy. If not, see <http://www.gnu.org/licenses/>.
*/
defined('IN_CODE') or die('This script can not be run by itself.');
require_once(l_r('gamepanel/memberhome.php'));
/**
* This class displays the members subsection of a game panel in a homepage context.
*
* @package GamePanel
*/
class panelMembersHome extends panelMembers
{
/**
* Load a panelMemberHome instead of a panelMember
*/
protected function loadMember(array $row)
{
return $this->Game->Variant->panelMemberHome($row);
}
/**
* Display a table with the vital members info; who is finalized, who has sent messages etc, each member
* takes up a short, thin column.
* @return string
*/
function membersList()
{
global $User;
// $membersList[$i]=array($nameOrCountryID,$iconOne,$iconTwo,...);
$membersList = array();
if($this->Game->phase == 'Pre-game')
{
$count = count($this->ByID);
for ($i = 0; $i < $count; $i++)
$membersList[] = array(($i + 1),'<img src="images/icons/tick.png" alt=" " title="Player joined, spot filled" />');
for ($i = $count + 1; $i <= count($this->Game->Variant->countries); $i++)
$membersList[] = array(($i), '');
}
else
{
for($countryID = 1; $countryID <= count($this->Game->Variant->countries); $countryID++)
{
$Member = $this->ByCountryID[$countryID];
$membersList[] = $Member->memberColumn();
}
}
// print countries with members > $maxPerRow on multiple rows on home page
$buf = '<table class="homeMembersTable">';
$memberNum = count($membersList);
$maxPerRow = 7;
$rowsCount = count($membersList[0]);
$rowsCount2 = ceil($memberNum / $maxPerRow);
$numPerLine = round($memberNum / $rowsCount2);
$div = $maxPerRow;
if ($rowsCount2 > 1)
{
$div = $memberNum / $rowsCount2;
}
else
{
$div = count($membersList);
}
$div = ceil($div);
$alternate = libHTML::$alternate;
for ($j = 0; $j < $rowsCount2; $j++)
{
for ($i = 0; $i < $rowsCount; $i++)
{
if ($i == 0 && $div % 2 == 0) libHTML::alternate();
$rowBuf = '';
$dataPresent = false;
$count = -1;
$width = $memberNum / $maxPerRow;
foreach($membersList as $data)
{
$count++;
if($count < $j * $div || $count >= ($j + 1)*$div)
{
continue;
}
if($data[$i])
{
$dataPresent = true;
}
else {
$data[$i] = ' ';
}
$rowBuf .= '<td style="width:'.$width.'%;" class="barAlt'.libHTML::alternate().'">'.$data[$i].'</td>';
}
// account for odd numbers
if ($j == ($rowsCount2 - 1) && ($memberNum % $div) != 0)
{
$rowBuf .='<td style="display: none;" class="barAlt'.libHTML::alternate().'"> </td>';
}
if ($i + 1 < $rowsCount && $div % 2 != 0 ) libHTML::alternate();
if($dataPresent)
{
$buf .= '<tr class="homeMembersTableTr">'.$rowBuf.'</tr>';
}
}
}
$buf .= '</table>';
return $buf;
}
}
?>