Passed
Push — master ( 1e77ab...d0f64e )
by Matthew
06:39
created

roundAndFormat()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
include_once INCLUDESPATH . "easyparliament/templates/html/mp/header.php";
3
?>
4
5
6
<?php
7
8
function roundAndFormat($number) {
9
    // Round to the nearest hundred
10
    $rounded = round($number / 100) * 100;
11
12
    // If above 1000, format as "1k", "1.5k", etc.
13
    if ($rounded >= 1000) {
14
        return round($rounded / 1000, 1) . "k";
15
    }
16
17
    return $rounded;
18
}
19
20
function currency($amount) {
21
    return '£' . (intval($amount) == $amount ? number_format($amount, 0) : number_format($amount, 2));
22
}
23
24
function currency_k($amount) {
25
    return '<span class="rounded_currency">' . '£' . roundAndFormat($amount) . '</span>';
26
}
27
28
29
function humInt(int $num): string {
30
    $words = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
31
32
    return ($num >= 0 && $num < 10) ? $words[$num] : strval($num);
33
}
34
35
?>
36
37
<div class="full-page">
38
    <div class="full-page__row">
39
        <div class="full-page__unit">
40
            <?php include '_person_navigation.php'; ?>
41
        </div>
42
        <div class="person-panels">
43
            <div class="sidebar__unit in-page-nav">
44
                <div>
45
46
                <h3 class="browse-content"><?= gettext('Browse content') ?></h3>
47
                <ul>
48
                        <li><a href="https://www.whofundsthem.com">About WhoFundsThem</a></li>              
49
                    <?php $election_registers = [$register_2024_enriched]; ?>
50
                    <?php foreach ($election_registers as $register) { ?>
51
                        <?php foreach ($register->categories as $category) { ?>
52
                            <?php if ($category->only_null_entries()) { ?>
53
                                <?php continue; ?>
54
                            <?php }; ?>
55
                            <li><a href="#category-<?= $register->chamber . $category->category_id ?>"><?= $category->category_name ?></a></li>
56
                        <?php }; ?>
57
                    <?php }; ?>
58
                    </ul>
59
                    <?php include '_featured_content.php'; ?>
60
                    <?php include '_donation.php'; ?>
61
                </div>
62
            </div>
63
64
            <div class="primary-content__unit">
65
66
                <?php if ($register_interests) { ?>
67
68
                    <?php /** @var MySociety\TheyWorkForYou\DataClass\Regmem\Person $register */ ?>
69
                    <?php foreach ($election_registers as $register) { ?>                        
70
                    <div class="panel register">
71
                    <a name="register"></a>
72
                    <h2>🏛️ Enriched Election Register</h2>
73
                    
74
                        <p>This is an enriched version of the post-election September 2024 register of members' interests for any donations/support or gifts declared.</p>
75
                        We have worked with a group of volunteers to add additional context to the register, including:
76
                        <ul style="list-style-type: disc; padding-left: 20px;padding-top:20px;">
77
                            <li>Adding short descriptions/urls of organisations</li>
78
                            <li>Grouping organisations into categories</li>
79
                            <li>Identifying donors who have given to multiple MPs</li>
80
                            </ul>
81
                        <p>This is an experiment in new ways of summarising, enhancing and displaying the register. <a href="<?= $member_url ?>/register">View the standard version of the register</a>.</p>
82
                        <p>Read our <a href="http://research.mysociety.org/html/beyond-transparency/">Beyond Transparency report</a> for more information about the register and our recommendations for improving it.</p>
83
                            <hr>
84
                            <p>As part of this project we have also <a href="/interests/highlighted_2024">highlighted a set of interests</a> related to industries with low public support (gambling and oil/gas), or the governments of not free countries.
85
                            <?php if ($mp_has_highlighted_interests) { ?>
86
87
                            <p>This MP has <a href="/interests/highlighted_2024"> highlighted interests on that page</a>.</p>
88
                            <?php } else { ?>
89
                            <p>This MP does not have any highlighted interests on that page.</p>
90
                            </p>
91
                            <?php }; ?>
92
                        <hr>
93
                        <p>If this was useful to you, you've noticed a problem, or have other suggestions, please fill out <a href="https://survey.alchemer.com/s3/8216436/WhoFundsThem-feedback">our feedback survey</a>.<p>
94
                    
95
                    </div>
96
97
98
99
                        <?php if ($register->categories->isEmpty()) { ?>
100
                            <div class="panel register">
101
                                <p><?= ucfirst($full_name) ?> did not declare any relevant donations or gifts in the September 2024 register. </p>
102
                                <p>This means he did not declare any donations above £1,500 in value, or any gifts above £300 in value.</p>
103
                            </div>
104
                        <?php }; ?>
105
106
                        <?php foreach ($register->categories as $category) { ?>
107
                            <div class="panel register">    
108
                            <h2 id="category-<?= $register->chamber . $category->category_id ?>"><?= $category->emoji() ?> <?= $category->category_name ?></h2>
109
110
111
                            <?php $summary = $category->summary_details("enriched_info"); ?>
112
                            <h3>Summary</h3>
113
114
                                <?php if ($summary["category_id"] == "2") { ?>
115
                                <p>Donations need to be declared if they are more than £1,500 in value (or if multiple donations of over £500 from the same source add up to more than £1,500) </p>
116
                                <p>As such, we can only show the breakdown of donations we know about. One of our recommendations is that MPs should declare an aggregate summary of donations below the threshold to fill in the context of large donations. </p>
117
                                <hr/>
118
                                <p>As of the September 2024 register, <?= ucfirst($full_name) ?> had declared <?= humInt($summary["items_count"]) ?> <?= make_plural("donation", $summary["items_count"]) ?> of money or support.</p>
119
120
                                <?php } elseif ($summary["category_id"] == "3") { ?>
121
                                    <p>Donations need to be declared if they are more than £300 in value (or are multiple benefits that add up to £300).</p>
122
                                    <p>One of our recommendations is to adopt a disclosure threshold in line with wider public sector / civil service thresholds (e.g. £20), and to consult and adopt new rules and guidance on when MPs should not accept gifts. </p>
123
                                    <hr/>
124
                                    <p>As of the September 2024 register <?= ucfirst($full_name) ?> had declared <?= humInt($summary["items_count"]) ?> <?= make_plural("gift", $summary["items_count"]) ?>.</p>
125
                                <?php }; ?>
126
                                
127
                                <p> Of these, <?= currency_k($summary["in_kind_sum"]) ?> was in kind, and <?= currency_k($summary["cash_sum"]) ?> was cash. </p>
128
129
                                <?php if (!($summary["single_mp_sum"] ?? null)) { ?>
130
                                    <p>In-kind <?= strtolower($summary["item_name"]) ?> are <?= strtolower($summary["item_name"]) ?> of goods or services, rather than cash.</p>
131
                                <?php }; ?>
132
133
                                <p> <?= currency_k($summary["individual_income"]) ?> came from private individuals, and <?= currency_k($summary["non_individual_income"]) ?> came from other sources.</p>
134
135
                                <?php if (isset($summary["single_mp_sum"])) { ?>
136
                                    <p><?= currency_k($summary["single_mp_sum"]) ?> came from private individuals unique to this MP and <?= currency_k($summary["multi_mp_sum"]) ?> came from private individuals who had also given to other MPs. </p>
137
                                <?php }; ?>
138
                                <h3>Source of <?= strtolower($summary["item_name"]) ?></h3>
139
140
                                <p>The following table shows the split between the sources of <?= strtolower($summary["item_name"]) ?>, and whether they are cash or in-kind <?= strtolower($summary["item_name"]) ?>.</p>
141
142
143
                                <?= $summary["source_pivot"] ?>
144
145
                                <h3><?= $summary["item_name"] ?> from organisations</h3>
146
147
                                <?php if ($summary["org_table"] ?? null) { ?>
148
149
                                <p>We have grouped organisations into a set of common categories.</p>
150
                                    
151
                                <p>Here is a summary of the kinds of organisations that donated to <?= ucfirst($full_name) ?>.</p>
152
153
                                <?= $summary["org_group_pivot"] ?>
154
155
                                <h4>Details</h4>
156
                                <?= $summary["org_table"] ?>
157
                                <?php } else { ?>
158
159
                                <p>No <?= strtolower($summary["item_name"]) ?> were from organisations.</p>
160
161
                                <?php }; ?>
162
163
                                <h3><?= $summary["item_name"] ?> from individuals</h3>
164
165
                                <?php if ($summary["multi_pivot"] ?? null) { ?>
166
                                <p>Most donors only donate to a single MP, but a small number of donors donate to multiple MPs.</p>
167
                                <p>Here is a summary of the <?= $summary["item_name"] ?> from individuals to <?= ucfirst($full_name) ?>.</p>
168
169
                                <?= $summary["multi_pivot"] ?>
170
171
                                <h4>Details</h4>
172
173
                                <?= $summary["individual_table"] ?>
174
175
                                <?php } else { ?>
176
177
                                <p>No registered <?= strtolower($summary["item_name"]) ?> were from individuals.</p>
178
179
                                <?php }; ?>
180
181
182
183
                                </div>
184
                        
185
                        <?php }; ?>
186
                    
187
                    <?php }; ?>
188
189
190
                <?php }; ?>
191
192
                <?php include('_profile_footer.php'); ?>
193
194
            </div>
195
        </div>
196
    </div>
197
</div>
198