-
Notifications
You must be signed in to change notification settings - Fork 0
/
page-resources.php
446 lines (284 loc) · 13 KB
/
page-resources.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<?php
/*
Template Name: Resources Print Page
*/
//If we create a link on parent resources pages pointing to the full print page template then url_to_postid(wp_get_referer()) should extract the id from the referring page and let us build the full guide for printing
// should probably then check that referring ID does belong to a parent resource before running the code below maybe with a progress animation for fanciness
$parent_page = url_to_postid(wp_get_referer()); // and then use $parent_page to build the page
get_header();
?>
<main id="maincontent" class="container">
<div class="row">
<?php
if($parent_page) {
$print_page = get_post($parent_page);
$args = array(
'post_parent' => $parent_page,
'post_type' => 'resources'
);
$children_array = array();
$children = get_children($args);
foreach ($children as $child) {
$children_array[] = $child->ID;
}?>
<div class="grey lighten-3 no-print" style="margin-top: 3rem; padding: 1rem;">
<p>
This is an automatically generated printable version of the full <strong><?php echo get_the_title($parent_page);?></strong> guide. This page is only generated when you click on the "Print Full Guide" button that is found on the introduction page of a resources with multiple pages.</p>
<p>
Single-page guides and the individual pages of larger guides can be printed directly from their respective pages using the "Print Page" button.
</p>
<p>
Print this page by clicking on the button at the bottom right of the screen. You can either print the page normally or create a PDF and save it to your computer. To create a PDF, you should have the option to 'Save as PDF' or 'Print to PDF' when the printing options box opens.
</p>
</div>
<div class="fixed-action-btn no-print">
<button class="btn-floating hide-on-large-only" onclick="printFunction()"><i class="material-icons">print</i></button>
<button class="btn hide-on-med-and-down" onclick="printFunction()">Print page</button>
</div>
<script>
function printFunction() {
window.print();
}
</script>
<div id="print_logo" class="center row responsive-img">
<?php echo get_the_post_thumbnail($parent_page, 'full');?>
</div>
<?php echo '<h1 class="print">' . get_the_title($parent_page) . '</h1>';
// check if the repeater field has rows of data
if( have_rows('section', $parent_page) ):
// foreach($rows as $row)
// {
// echo '<h2 class="green">' . $row['heading'] . '</h2>';
// }
// loop through the rows of data
while ( have_rows('section', $parent_page) ) : the_row();
// display a sub field value
if( have_rows('blocks', $parent_page) ):
$rows = get_field('heading_block', $parent_page);
// loop through the rows of data
while ( have_rows('blocks', $parent_page) ) : the_row();
if( get_row_layout() == 'heading_block' ):
echo '<' . get_sub_field('heading_size', $parent_page) . ' id="heading-' . get_row_index() . '" class="print">' . get_sub_field('heading', $parent_page) . '</' . get_sub_field('heading_size', $parent_page) . '>';
endif;
if( get_row_layout() == 'text_block' ):
the_sub_field('content', $parent_page);
endif;
if( get_row_layout() == 'note_block' ):
$note_url = get_sub_field('note_url', $parent_page);
echo '<div class="row"><div class="col s12 note-heading grey lighten-3 black-text">' . get_sub_field('note_heading', $parent_page) . '</strong></div> <div class="col s12 note-content grey lighten-4 black-text ">' . get_sub_field('note', $parent_page);
if($note_url) {
echo '<a class="block" href="' . $note_url . '"><i class="material-icons left">arrow_forward</i>Click on this link for more information</a>';
}
if( have_rows('note_upload') ):
// loop through the rows of data
while ( have_rows('note_upload') ) : the_row();
$file_link = get_sub_field('file_source', $parent_page);
$file_type = $file_link['mime_type'];
echo '<a class="block" href="' . $file_link['url'] . '"><i class="material-icons left">folder</i>Download ' . $file_link['title'] . '</a>';
endwhile;
else :
// no rows found
endif;
if( have_rows('note_link') ):
// loop through the rows of data
while ( have_rows('note_link') ) : the_row();
echo '<a class="block" href="' . get_sub_field('link_url', $parent_page) . '"><i class="material-icons left">arrow_forward</i>' . get_sub_field('link_text', $parent_page) . '</a>';
endwhile;
else :
// no rows found
endif;
echo '</div></div>';
endif;
if( get_row_layout() == 'recommendation_block' ):
$block_title = get_sub_field('block_title', $parent_page);
// check if the repeater field has rows of data
if( have_rows('recommendation_add') ):
echo '<div class="row recommendation"><div class="col s12 note-heading grey lighten-3"><i class="material-icons left">done_all</i><strong>' . $block_title . '</strong></div> <div class="col center s12 note-content grey lighten-4">';
// loop through the rows of data
while ( have_rows('recommendation_add') ) : the_row();
$rec_link = get_sub_field('recommended_product_guide');
$rec_desc = get_sub_field('recommended_product_description');
$rec_product_logo = get_sub_field('recommended_product_logo');
$rec_name = get_sub_field('recommended_product_name');
echo '<div class="col s12 l3">';
if($rec_link) {
echo '<div><a class="block product_link" href="' . $rec_link . '" data-note="View the guide to using ' . $rec_name . '">' . $rec_name . '</a></div>';
} else {
echo '<div><span class="block product_link">' . $rec_name . '</span></div>';
}
if($rec_product_logo) {
echo '<img src="' . $rec_product_logo . '" />';
}
if($rec_desc) {
echo '<p>' . $rec_desc . '</p>';
}
echo '</div>';
endwhile;
else :
// no rows found
endif;
echo '</div></div>';
endif;
if( get_row_layout() == 'product_overview_block' ):
$overview_title = get_sub_field('overview_title');
// check if the repeater field has rows of data
if( have_rows('product_add') ):
echo '<div class="row recommendation"><div class="col s12 note-heading grey lighten-3"><i class="material-icons left">done_all</i><strong>' . $overview_title . '</strong></div> <div class="col center s12 note-content grey lighten-4">';
// loop through the rows of data
while ( have_rows('product_add') ) : the_row();
$link = get_sub_field('product_link');
$desc = get_sub_field('product_description');
$good = get_sub_field('product_good');
$bad = get_sub_field('product_bad');
$platforms = get_sub_field('product_platforms');
if($link) {
echo '<div><a class="block product_link" href="' . $link . '" data-note="This link takes you to an external website">' . get_sub_field('recommended_product') . '</a></div>';
} else {
echo '<div><span class="block product_link">' . get_sub_field('recommended_product') . '</span></div>';
}
if($desc) {
echo '<p>' . $desc . '</p>';
}
if($good) {
echo '<p><i class="material-icons left green-text lighten-1">thumb_up</i> Good - ' . $good . '</p>';
}
if($bad) {
echo '<p><i class="material-icons left materialize-red-text lighten-2">thumb_down</i> Bad - ' . $bad . '</p>';
}
if($platforms) {
echo '<ul class="center platforms white"><li>
Available on:
</li>';
foreach ($platforms as $platform) {
if($platform['value'] === 'web') {
echo '<li>
<span class="mdi mdi-web"></span> Web
</li>';
}
if($platform['value'] === 'android') {
echo '<li>
<span class="mdi mdi-android"></span> Android
</li>';
}
if($platform['value'] === 'ios') {
echo '<li>
<span class="mdi mdi-apple-ios"></span> iOS
</li>';
}
if($platform['value'] === 'desktop') {
echo '<li>
<span class="mdi mdi-desktop-mac"></span> Desktop
</li>';
}
}
echo '</ul>';
}
endwhile;
else :
// no rows found
endif;
echo '</div></div>';
endif;
if( get_row_layout() == 'steps_block' ):
$step_title = get_sub_field('step_title');
// check if the repeater field has rows of data
if( have_rows('step') ):
echo '<div class="row steps_block"><ol class="steps">';
// loop through the rows of data
while ( have_rows('step') ) : the_row();
echo '<li>' . get_sub_field('step_description') . '</li>';
endwhile;
echo '</ol>';
else :
// no rows found
endif; // end steps block
echo '</div>';
endif;
if( get_row_layout() == 'image_block' ):
echo '<figure class="card"><img src="' . get_sub_field('image', $parent_page) . '" />
<figcaption class="grey lighten-4"><i class="material-icons left">camera_alt</i>' . get_sub_field('caption', $parent_page) . '</figcaption></figure>';
endif;
endwhile;
else :
// no layouts found
endif;
echo '<div style=""></div>'; // adds a div after the intro page of the guide to create a page break when printing
endwhile;
else :
// no rows found
endif;
?>
<?php
foreach($children_array as $child)
{
echo '<h1 class="print">' . get_the_title($child) . '</h1>';
if( have_rows('section', $child) ):
// loop through the rows of data
while ( have_rows('section', $child) ) : the_row();
// display a sub field value
if( have_rows('blocks', $child) ):
$rows = get_field('heading_block', $child);
//print_R($rows);
// loop through the rows of data
while ( have_rows('blocks', $child) ) : the_row();
if( get_row_layout() == 'heading_block' ):
echo '<' . get_sub_field('heading_size', $child) . ' id="heading-' . get_row_index() . '" class="print">' . get_sub_field('heading', $child) . '</' . get_sub_field('heading_size', $child) . '>';
endif;
if( get_row_layout() == 'text_block' ):
the_sub_field('content', $child);
endif;
if( get_row_layout() == 'note_block' ):
$note_url = get_sub_field('note_url', $child);
echo '<div class="row "><div class="col s12 note-heading grey lighten-3 black-text">' . get_sub_field('note_heading', $child) . '</strong></div> <div class="col s12 note-content grey lighten-4 black-text ">' . get_sub_field('note', $child);
if($note_url) {
echo '<a class="block" href="' . $note_url . '"><i class="material-icons left">arrow_forward</i>Click on this link for more information</a>';
}
if( have_rows('note_upload') ):
// loop through the rows of data
while ( have_rows('note_upload') ) : the_row();
$file_link = get_sub_field('file_source', $child);
$file_type = $file_link['mime_type'];
echo '<a class="block" href="' . $file_link['url'] . '"><i class="material-icons left">folder</i>Download ' . $file_link['title'] . '</a>';
endwhile;
else :
// no rows found
endif;
if( have_rows('note_link') ):
// loop through the rows of data
while ( have_rows('note_link') ) : the_row();
echo '<a class="block" href="' . get_sub_field('link_url', $child) . '"><i class="material-icons left">arrow_forward</i>' . get_sub_field('link_text', $child) . '</a>';
endwhile;
else :
// no rows found
endif;
echo '</div></div>';
endif;
if( get_row_layout() == 'image_block' ):
echo '<figure class="card"><img src="' . get_sub_field('image', $child) . '" />
<figcaption class="grey lighten-4"><i class="material-icons left">camera_alt</i>' . get_sub_field('caption', $child) . '</figcaption></figure>';
endif;
endwhile;
else :
// no layouts found
endif;
echo '<div style=""></div>'; // adds a div after each page of the guide to create a page break when printing
endwhile;
else :
// no rows found
endif;
}
} else {
echo '<div class="grey lighten-3 col s12 no-print">
<p>
This is the page used to automatically generate printable versions of full resource guides. These are generated on demand when you click on the "Print Full Guide" button that is found on the introduction page of a resources with multiple pages. You can explore are resources at <a href="' . get_post_type_archive_link( 'resources' ) . '">this link</a></p>
</div>';
}
?>
<footer class="grey lighten-4" style="text-align: center; padding: 1rem;">
This resource is produced by <strong>Our Connected Neighbourhoods</strong><br />
For more information please visit <a href="<?php echo get_home_url(); ?>"><?php echo get_home_url(); ?></a><br />
Date printed: <?php echo date("d F, Y");?>
</footer>
</div>
</main> <!-- end main -->
<?php get_footer(); ?>