-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorgues-nouvelles.php
190 lines (182 loc) · 4.9 KB
/
orgues-nouvelles.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
$numeros = array(
0 => "2008-01",
1 => "2008-06",
2 => "2008-10",
3 => "2008-12",
4 => "2009-03",
5 => "2009-06",
6 => "2009-10",
7 => "2009-12",
8 => "2010-03",
9 => "2010-06",
10 => "2010-10",
11 => "2011-01",
12 => "2011-04",
13 => "2011-06",
14 => "2011-10",
15 => "2012-01",
16 => "2012-04",
17 => "2012-07",
18 => "2012-10",
19 => "2012-12",
20 => "2013-03",
21 => "2013-07",
22 => "2013-10",
23 => "2013-12",
24 => "2014-03",
25 => "2014-06",
26 => "2014-10",
27 => "2014-12",
28 => "2015-04",
29 => "2015-06",
30 => "2015-10",
31 => "2016-01",
32 => "2016-04",
33 => "2016-06",
34 => "2016-10",
35 => "2016-12",
36 => "2017-04",
37 => "2017-07",
38 => "2017-10",
39 => "2018-01",
40 => "2018-04",
41 => "2018-07",
42 => "2018-10",
43 => "2018-12",
44 => "2019-03",
45 => "2019-06",
46 => "2019-10",
47 => "2019-12",
48 => "2020-03",
49 => "2020-07",
50 => "2020-10",
51 => "2020-12",
52 => "2021-03",
53 => "2021-07",
54 => "2021-10",
55 => "2021-12",
56 => "2022-03",
57 => "2022-07",
58 => "2022-10",
59 => "2022-12",
60 => "2023-03",
61 => "2023-06",
62 => "2023-10",
63 => "2023-12",
// Future
64 => "2024-03",
65 => "2024-06",
66 => "2024-10",
67 => "2024-12",
68 => "2025-03",
69 => "2025-06",
70 => "2025-10",
71 => "2025-12",
);
// Pour les tests
if (!function_exists('get_option')) {
function get_option($name)
{
if ('configuration_orgues-nouvelles_numeros_on' === $name) {
return $GLOBALS['numeros'];
}
return null;
}
}
if (!function_exists('on_date_magazine_to_numero')) {
/**
* Prend une date au format aaaa-mm-jj et la transforme en numéro de magazine
*
* @param string $date Date au format aaaa-mm-jj
*/
function on_date_magazine_to_numero($date)
{
$numeros = get_option('configuration_orgues-nouvelles_numeros_on');
$numero = 0;
$date = new DateTime($date . (strlen($date) == 7 ? '-15' : ''));
$date->setTime(0, 0, 0);
$yearmonth = $date->format('Y-m');
$numero = 0;
if ($yearmonth <= $numeros[0])
return $numero;
$numero_max = count($numeros);
while ($numero < $numero_max && $yearmonth >= $numeros[$numero]) {
$numero++;
}
if ($numero == $numero_max) {
$start = new DateTime($numeros[$numero_max - 1]);
$start->add(new DateInterval('P3M'));
while ($start->format('Y-m') <= $yearmonth) {
$start->add(new DateInterval('P3M'));
$numero++;
}
}
return $numero - 1;
}
}
if (!function_exists('on_numero_to_date_magazine')) {
/**
* Prend un numéro de magazine et le transforme en date au format aaaa-mm
*
* @param int $numero Numéro de magazine
*/
function on_numero_to_date_magazine($numero, )
{
$numeros = get_option('configuration_orgues-nouvelles_numeros_on');
if ($numero < 0)
return $numeros[0];
if ($numero > 600)
return '';
if ($numero >= count($numeros)) {
$start = new DateTime($numeros[count($numeros) - 1]);
$start->add(new DateInterval('P3M'));
while ($numero > count($numeros)) {
$start->add(new DateInterval('P3M'));
$numero--;
}
return $start->format('Y-m');
}
return $numeros[$numero];
}
}
if (!function_exists('on_magazine_title')) {
/**
* Retourne le titre d'un numéro de magazine
*
* @param int $numero Numéro de magazine
*/
function on_magazine_title()
{
$type = get_post_type();
$numero = pods_field('numero', true);
switch ($type) {
case 'partition':
return 'Cahier de Partitions n°' . $numero;
case 'cd':
return 'CD n°' . $numero;
case 'magazine':
return 'Orgues Nouvelles n°' . $numero;;
default:
return get_the_title();
}
}
}
if (!function_exists('on_next_payment_date_membership')) {
/**
* Retourne la date du prochain paiement d'un abonnement
*
* @param \WC_Memberships_Integration_Subscriptions_User_Membership $membership
*/
function on_next_payment_date_membership($membership)
{
if ($membership instanceof \WC_Memberships_Integration_Subscriptions_User_Membership) {
$subscription = $membership->get_subscription();
if ($subscription) {
$next_payment_date = $subscription->get_date('next_payment');
return $next_payment_date;
}
}
return null;
}
}