Passed
Pull Request — master (#1859)
by
unknown
06:03
created

currency()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 2
rs 10
c 1
b 0
f 0
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->emoji() ?><?= $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
                    </div>
93
94
95
96
                        <?php if ($register->categories->isEmpty()) { ?>
97
                            <div class="panel register">
98
                                <p><?= ucfirst($full_name) ?> did not declare any relevant donations or gifts in the September 2024 register. </p>
99
                                <p>This means he did not declare any donations above £1,500 in value, or any gifts above £300 in value.</p>
100
                            </div>
101
                        <?php }; ?>
102
103
                        <?php foreach ($register->categories as $category) { ?>
104
                            <div class="panel register">    
105
                            <h2 id="category-<?= $register->chamber . $category->category_id ?>"><?= $category->emoji() ?><?= $category->category_name ?></h2>
106
107
108
                            <?php $summary = $category->summary_details("enriched_info"); ?>
109
                            <h3>Summary</h3>
110
111
                                <?php if ($summary["category_id"] == "2") { ?>
112
                                <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>
113
                                <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>
114
                                <hr/>
115
                                <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>
116
117
                                <?php } elseif ($summary["category_id"] == "3") { ?>
118
                                    <p>Donations need to be declared if they are more than £300 in value (or are multiple benefits that add up to £300).</p>
119
                                    <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>
120
                                    <hr/>
121
                                    <p>As of the September 2024 register <?= ucfirst($full_name) ?> had declared <?= humInt($summary["items_count"]) ?> <?= make_plural("gift", $summary["items_count"]) ?>.</p>
122
                                <?php }; ?>
123
                                
124
                                <p> Of these, <?= currency_k($summary["in_kind_sum"]) ?> was in kind, and <?= currency_k($summary["cash_sum"]) ?> was cash. </p>
125
126
                                <?php if (!($summary["single_mp_sum"] ?? null)) { ?>
127
                                    <p>In-kind <?= strtolower($summary["item_name"]) ?> are <?= strtolower($summary["item_name"]) ?> of goods or services, rather than cash.</p>
128
                                <?php }; ?>
129
130
                                <p> <?= currency_k($summary["individual_income"]) ?> came from private individuals, and <?= currency_k($summary["non_individual_income"]) ?> came from other sources.</p>
131
132
                                <?php if (isset($summary["single_mp_sum"])) { ?>
133
                                    <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>
134
                                <?php }; ?>
135
                                <h3>Source of <?= strtolower($summary["item_name"]) ?></h3>
136
137
                                <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>
138
139
140
                                <?= $summary["source_pivot"] ?>
141
142
                                <h3><?= $summary["item_name"] ?> from organisations</h3>
143
144
                                <?php if ($summary["org_table"] ?? null) { ?>
145
146
                                <p>We have grouped organisations into a set of common categories.</p>
147
                                    
148
                                <p>Here is a summary of the kinds of organisations that donated to <?= ucfirst($full_name) ?>.</p>
149
150
                                <?= $summary["org_group_pivot"] ?>
151
152
                                <h4>Details</h4>
153
                                <?= $summary["org_table"] ?>
154
                                <?php } else { ?>
155
156
                                <p>No <?= strtolower($summary["item_name"]) ?> were from organisations.</p>
157
158
                                <?php }; ?>
159
160
                                <h3><?= $summary["item_name"] ?> from individuals</h3>
161
162
                                <?php if ($summary["multi_pivot"] ?? null) { ?>
163
                                <p>Most donors only donate to a single MP, but a small number of donors donate to multiple MPs.</p>
164
                                <p>Here is a summary of the <?= $summary["item_name"] ?> from individuals to <?= ucfirst($full_name) ?>.</p>
165
166
                                <?= $summary["multi_pivot"] ?>
167
168
                                <h4>Details</h4>
169
170
                                <?= $summary["individual_table"] ?>
171
172
                                <?php } else { ?>
173
174
                                <p>No registered <?= strtolower($summary["item_name"]) ?> were from individuals.</p>
175
176
                                <?php }; ?>
177
178
179
180
                                </div>
181
                        
182
                        <?php }; ?>
183
                    
184
                    <?php }; ?>
185
186
187
                <?php }; ?>
188
189
                <?php include('_profile_footer.php'); ?>
190
191
            </div>
192
        </div>
193
    </div>
194
</div>
195