-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-waw-stats.php
536 lines (523 loc) · 21.9 KB
/
page-waw-stats.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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
<?php /* Template Name: Waste Picker Groups Stats*/
get_header();
$prefixpost = "_post_";
$prefix_wpo = 'wpg-';
$prefixwpg = '_wpg_';
// Grabs continent from url to filter the list of organization displayed by continent
$continent = '';
if ( !empty($_GET['continent'])) {
$continent = sanitize_text_field( $_GET['continent'] );
}
// Countries in contintents are defined in functions.php
//$continent = sanitize_text_field( $_GET['continent'] );
if ($continent == '' ) {
$active_continent = $all;
} else if ( $continent == 'asia') {
$active_continent = $asia;
$continent_name = __('Asia','globalrec');
} else if ( $continent == 'latinamerica') {
$active_continent = $latinamerica;
$continent_name = __('Latin America','globalrec');
} else if ( $continent == 'africa') {
$active_continent = $africa;
$continent_name = __('Africa','globalrec');
} else if ( $continent == 'northamerica') {
$active_continent = $northamerica;
$continent_name = __('North America','globalrec');
} else if ( $continent == 'europe') {
$active_continent = $europe;
$continent_name = __('Europe','globalrec');
} else if ( $continent == 'all') {
$active_continent = $all;
$continent_name = __('All','globalrec');
}
$meta_query = array(
array(
'key' => 'country',
'value' => $active_continent,
'compare' => 'IN',
)
);
?>
<div id="waw-stats">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php get_template_part( 'nav', 'waw' ); ?>
<div class="row">
<div class="pull-right"><?php do_action('icl_language_selector'); ?></div>
<h2 id="post-<?php the_ID(); ?>" class="col-md-10 ">
<?php the_title();?> « <?php _e('Waste pickers Around the World (WAW)','globalrec'); ?>
</h2>
</div>
<div class="row content">
<div class="col-md-9">
<?php the_content(); ?>
</div>
<?php endwhile; endif; ?>
</div>
<div class="row">
<div class="col-md-12">
<?php
$count_wpo = wp_count_posts( 'waste-picker-org' )->publish;
//global $wpdb;
//Iterate to all the available post of this ecosystem
$args = array(
'post_type' => 'waste-picker-org',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'wpg-member-occupation',
'field' => 'slug',
'terms' => 'waste-pickers',
),
array(
'taxonomy' => 'wpg-member-type',
'field' => 'slug',
'terms' => array('members-are-waste-pickers', 'members-are-waste-picker-organizations'),
'operator' => 'IN',
),
),
'meta_query' => $meta_query,
);
$posts_array = get_posts( $args );
$count_orgs = count($posts_array);
//print_r($posts_array);
//Get all the post ids
foreach ($posts_array as $key => $value) {
$post_id = $value->ID;
$posts_ids[$key] = $post_id;
$country_names[$key] = get_post_meta( $post_id, 'country', true );
$organization_scope[$key] = wp_get_post_terms($post_id, $prefix_wpo .'scope');
$organization_type[$key] = wp_get_post_terms($post_id, $prefix_wpo .'organization-type');
$member_type[$key] = wp_get_post_terms($post_id, $prefix_wpo .'member-type');
$member_occupation[$key] = wp_get_post_terms($post_id, $prefix_wpo . 'member-occupation');
$year_formed[$key] = get_post_meta( $post_id, $prefixwpg . 'year_formed', true );
$year_registered[$key] = get_post_meta( $post_id, $prefixwpg . 'registration_year', true );
$material_type[$key] = wp_get_post_terms($post_id, $prefix_wpo . 'material-type');
$activities[$key] = wp_get_post_terms($post_id, $prefix_wpo . 'activities');
$workplace[$key] = wp_get_post_terms($post_id, $prefix_wpo . 'workplace-members');
$municipality_what[$key] = wp_get_post_terms($post_id, $prefix_wpo . 'municipality-what');
$language[$key] = wp_get_post_terms($post_id, $prefix_wpo . 'language');
$number_individuals[$key] = get_post_meta( $post_id, '_wpg_number_individuals', true );
}
$country_names_count = array_count_values($country_names); //counts values of gogle page rank
arsort($country_names_count);
//Year formed and registered
$year_formed_count = array_count_values($year_formed);
$year_registered_count = array_count_values($year_registered);
ksort($year_formed_count); //sorts by key
ksort($year_registered_count); //sorts by key
//Creates arrays which term as key and number of organizations as value
$organization_scope_count = count_tax_array($organization_scope);
$organization_type_count = count_multiterm_tax_array($organization_type);
$member_type_count = count_multiterm_tax_array($member_type);
$member_occupation_count = count_multiterm_tax_array($member_occupation);
$material_type_count = count_multiterm_tax_array($material_type);
$activities_count = count_multiterm_tax_array($activities);
$workplace_count = count_multiterm_tax_array($workplace);
$municipality_what_count = count_multiterm_tax_array($municipality_what);
$language_count = count_multiterm_tax_array($language);
?>
<div class="row">
<div class="col-md-5 ">
<ul class="list-group">
<li class="list-group-item">
<strong><?php _e('WAW in numbers','globalrec'); ?></strong>
</li>
<li class="list-group-item">
<span class="badge"><?php echo $count_wpo; ?></span>
<?php _e('Number of organizations in the data base','globalrec'); ?>
</li>
<li class="list-group-item">
<span class="badge"><?php echo $count_orgs; ?></span>
<?php _e('Number of organizations that are Waste Picker Organizations','globalrec'); ?>
<?php
//Displays the name of the continent being used as filter
echo $continent == 'all' || $continent == '' ? '' : '(<strong>'. $continent_name .'</strong>)'; ?>
</li>
<li class="list-group-item">
<span class="badge"><?php echo number_format(array_sum($number_individuals)); ?></span>
<?php _e('Waste pickers in waste picker organizations','globalrec'); ?>
</li>
</ul>
</div>
<div class="col-md-7">
<ul class="nav nav-pills">
<li role="presentation" class="disabled"><a href="?continent=all" title=""><?php _e('Filter by continent','globalrec'); ?>: </a></li>
<li role="presentation"><a href="?continent=all" title="<?php _e('All','globalrec'); ?>"><?php _e('All','globalrec'); ?></a></li>
<li role="presentation"><a href="?continent=asia" title="<?php _e('Asia','globalrec'); ?>"><?php _e('Asia','globalrec'); ?></a></li>
<li role="presentation"><a href="?continent=latinamerica" title="<?php _e('Latin America','globalrec'); ?><"><?php _e('Latin America','globalrec'); ?></a></li>
<li role="presentation"><a href="?continent=africa" title="<?php _e('Africa','globalrec'); ?> "><?php _e('Africa','globalrec'); ?></a></li>
<li role="presentation"><a href="?continent=northamerica" title="<?php _e('North America','globalrec'); ?> "><?php _e('North America','globalrec'); ?></a></li>
<li role="presentation"><a href="?continent=europe" title="<?php _e('Europe','globalrec'); ?> "><?php _e('Europe','globalrec'); ?></a></li>
</ul>
<h3><?php echo $continent == 'all' || $continent == '' ? '' : '<strong>'. $continent_name .'</strong>'; ?></h3>
</div>
</div>
<div class="row">
<div class="col-md-5">
<h3><?php _e('Table of contents','globalrec'); ?></h3>
<nav>
<ul>
<li><a href="#scope"><?php _e('Organizational Reach','globalrec'); ?></a></li>
<li><a href="#type-organization"><?php _e('Type of organization','globalrec'); ?></a></li>
<li><a href="#country"><?php _e('Country','globalrec'); ?></a></li>
<li><a href="#type-organization"><?php _e('Type of members','globalrec'); ?></a></li>
<li><a href="#member-occupation"><?php _e('Occupation of members','globalrec'); ?></a></li>
<li><a href="#year-formed"><?php _e('Year Formed','globalrec'); ?></a></li>
<li><a href="#year-registered"><?php _e('Year Registered','globalrec'); ?></a></li>
<li><a href="#materials"><?php _e('Materials collected','globalrec'); ?></a></li>
<li><a href="#activitites"><?php _e('Activities','globalrec'); ?></a></li>
<li><a href="#workplace"><?php _e('Workplace of Members','globalrec'); ?></a></li>
<li><a href="#what-municipal"><?php _e('What kind of relationship exists with the municipality?','globalrec'); ?></a></li>
<li><a href="#languages"><?php _e('Languages','globalrec'); ?></a></li>
</ul>
</nav>
</div>
</div>
<div class="row">
<div class="col-md-5">
<h3 id="scope"><?php _e('Organizational Reach','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?> (%)</small></h3>
<?php
//reoders array manually TODO: make this work in all the languages. U ntil them, deactivate
// $organization_scope_count = array_merge(array_flip(array('local','regional','national','not known')), $organization_scope_count);
//sets colors for scope
$color_scope = array('local' => '#ff3399','regional' => '#ff3333','national' => '#ff9933','not known' => '#ccc','nacional' => '#ff9933');
//calculates max scope value
$max_count_org_scope = 0;
foreach ($organization_scope_count as $value) {
$max_count_org_scope = $value > $max_count_org_scope ? $value : $max_count_org_scope;
}
?>
<?php foreach ($organization_scope_count as $key => $value) { ?>
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-4 text-right">
<?php echo '<p>'.ucfirst($key). ' <small>(' . round($value/$count_orgs*100,1) .'%)</small> </p>'; ?>
</div>
<div class="col-md-8 col-sm-8 col-xs-8">
<div class="progress">
<div class="progress-bar" style="width:<?php echo 100*$value/$max_count_org_scope; ?>%;background-color:<?php echo isset($color_scope[$key]) ? $color_scope[$key]: '#eee'; ?>;color:black">
<span title="<?php echo round($value/$count_orgs*100,1). '% '. ucfirst($key); ?>">
<small>
<?php echo $value;
if (($value/$count_orgs*100) > 6) {
echo " (".round($value/$count_orgs*100,1) ."%)";
} ?>
</small>
</span>
</div>
</div>
</div>
</div>
<?php
}
echo '<p><small>('. __('Total organizations formed by waste pickers','globalrec'). ': ' .$count_orgs. ')</small></p>';?>
<div class="progress">
<?php foreach ($organization_scope_count as $key => $value) { ?>
<div class="progress-bar" style="width:<?php echo 100*$value/$count_orgs; ?>%;background-color:<?php echo $color_scope[$key]; ?>;">
<span title="<?php echo round($value/$count_orgs*100,1). '% '. $key; ?>">
<?php echo round($value/$count_orgs*100,1); ?>%
</span>
</div>
<?php } ?>
</div>
</div><!-- ends Scope -->
<div class="col-md-6 col-md-offset-1">
<h3 id="type-organization"><?php _e('Type of organization','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?> (%)</small></h3>
<?php
//calculates max organization type value
$max_count_org_type = 0;
foreach ($organization_type_count as $value) {
$max_count_org_type = $value > $max_count_org_type ? $value : $max_count_org_type;
}
//sets up colors for each taxonomy term
$color_type = array('cooperative' => '#99eeee', 'cooperative federation' => '#339999', 'association' => '#99cc33', 'trade union' => '#003366','not known' => '#ccc');
foreach ($organization_type_count as $key => $value) {
$percent_org_type = round($value/$count_orgs*100,1); ?>
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6 text-right">
<?php echo '<p>'.ucfirst($key). ' <small>';
if ($percent_org_type > 4) {
echo " (". $percent_org_type ."%)";
}
echo '</small></p>'; ?>
</div>
<div class="col-md-6 col-sm-6 col-xs-6 ">
<div class="progress">
<div class="progress-bar" style="width:<?php echo 100*$value/$max_count_org_type; ?>%;background-color:<?php echo isset($color_type[$key]) ? $color_type[$key]: '#ccc'; ?>;color:#000;">
<span title="<?php echo $value; ?>">
<small><?php
echo $value;
if ($percent_org_type > 6) {
echo " (". $percent_org_type ."%)";
} ?>
</small>
</span>
</div>
</div>
</div>
</div>
<?php }
echo '<p><small>('. __('Total organizations formed by waste pickers','globalrec'). ': ' .$count_orgs. ')</small></p>';?>
<div class="progress">
<?php foreach ($organization_type_count as $key => $value) { ?>
<div class="progress-bar" style="width:<?php echo 100*$value/$count_orgs; ?>%;background-color:<?php echo isset($color_type[$key]) ? $color_type[$key]: '#eee'; ?>;color:#000;">
<span title="<?php echo round($value/$count_orgs*100,1). '% '. $key; ?>">
<?php
if (($value/$count_orgs*100) > 4) {
echo $value. " (".round($value/$count_orgs*100,1) ."%)";
} ?>
</span>
</div>
<?php } ?>
</div>
</div> <!-- ends Type of organization -->
</div> <!-- ends row -->
<div class="row">
<div id="country" class="col-md-3"><h3><?php _e('Country','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?> (%)</small></h3>
<div class="row">
<div class="col-md-12">
<?php
foreach ($country_names_count as $key => $value) {
echo '<p>'. ucfirst($key) .': '. $value;
echo $value < 5 ? '' : ' <small>('. round(100*$value/$count_orgs,1) . '%)</small>';
echo '</p>';
}
?>
</div>
</div>
</div>
<div class="col-md-5">
<h3 id="member-type"><?php _e('Type of members','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?> (%)</small></h3>
<?php
foreach ($member_type_count as $key => $value) {
echo '<p>'. ucfirst($key) .' '. $value . ' ('. round(100*$value/$count_orgs,1) . '%)</p>';
}
?>
</div>
<div class="col-md-4">
<h3 id="member-occupation"><?php _e('Occupation of members','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?> (%)</small></h3>
<?php
foreach ($member_occupation_count as $key => $value) {
echo '<p>'. ucfirst($key) .' '. $value . ' ('. round(100*$value/$count_orgs,1) . '%)</p>';
}
?>
</div>
</div>
<div class="row">
<div class="col-md-3">
<h3 id="year-formed"><?php _e('Year Formed','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?></small></h3>
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-4 text-right">
<?php
foreach ($year_formed_count as $key => $value) {
echo $key=='' ? '<p>'.__('Not known','globalrec').'</p>' : '<p>'.ucfirst($key).'</p>';
}
?>
</div>
<div class="col-md-8">
<?php
$max_year_formed=0;
foreach ($year_formed_count as $key => $value) {
$max_year_formed = max( array( $max_year_formed, $value) ); //calculates max value
}
foreach ($year_formed_count as $year => $value) {
?>
<div class="progress">
<div class="progress-bar" style="width:<?php echo 100*$value/$max_year_formed; ?>%;background-color:#999;color:black">
<span title="<?php echo $value; ?> organizations formed">
<?php echo $value; ?>
</span>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<div class="col-md-3">
<h3 id="year-registered"><?php _e('Year Registered','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?></small></h3>
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-4 text-right">
<?php
foreach ($year_registered_count as $key => $value) {
echo $key=='' ? '<p>'.__('Not known','globalrec').'</p>' : '<p>'.ucfirst($key).'</p>';
}
?>
</div>
<div class="col-md-8 col-sm-8 col-xs-8 ">
<?php
$max_year_registered = 0;
foreach ($year_registered_count as $key => $value) {
$max_year_registered = max( array( $max_year_registered, $value) ); //calculates max value
}
foreach ($year_registered_count as $key => $value) {
?>
<div class="progress">
<div class="progress-bar" style="width:<?php echo 100*$value/$max_year_registered; ?>%;background-color:#999;color:black">
<span title="<?php echo $value; ?> organizations formed">
<?php echo $value; ?>
</span>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<div class="col-md-5">
<h3 id="materials"><?php _e('Materials collected','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?></small></h3>
<div class="row">
<div class="col-md-5 col-sm-5 col-xs-5 text-right">
<?php
foreach ($material_type_count as $key => $value) {
echo '<p><a href="/wpg-material-type/'.strtolower( str_replace(" ","-",$key) ).'">'.ucfirst($key).'</a></p>';
}
?>
</div>
<div class="col-md-7 col-sm-7 col-xs-7">
<?php
$max_material_type = 0;
foreach ($material_type_count as $key => $value) {
$max_material_type = max( array( $max_material_type, $value) ); //calculates max value
}
foreach ($material_type_count as $key => $value) {
?>
<div class="progress">
<div class="progress-bar" style="width:<?php echo 100*$value/$max_material_type; ?>%;background-color:#999;color:black">
<span title="<?php echo $value; ?>">
<?php echo $value; ?>
</span>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-9">
<h3 id="activities"><?php _e('Activities','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?></small></h3>
<div class="row">
<div class="col-md-8 col-sm-8 col-xs-8 text-right">
<?php
foreach ($activities_count as $key => $value) {
echo $key=='' ? '<p>'.__('Not known','globalrec').'</p>' : '<p>'.ucfirst($key).'</p>';
}
?>
</div>
<div class="col-md-4 col-sm-4 col-xs-4">
<?php
$max_activities = 0;
foreach ($activities_count as $key => $value) {
$max_activities = max( array( $max_activities, $value) ); //calculates max value
}
foreach ($activities_count as $key => $value) {
?>
<div class="progress">
<div class="progress-bar" style="width:<?php echo 100*$value/$max_activities; ?>%;background-color:#999;color:black">
<span title="<?php echo $value; ?>">
<?php echo $value; ?>
</span>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h3 id="workplace"><?php _e('Workplace of Members','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?></small></h3>
<div class="row">
<div class="col-md-7 col-sm-7 col-xs-7 text-right">
<?php
foreach ($workplace_count as $key => $value) {
echo $key=='' ? '<p>'.__('Not known','globalrec').'</p>' : '<p>'.ucfirst($key).'</p>';
}
?>
</div>
<div class="col-md-5 col-sm-5 col-xs-5">
<?php
$max_workplace = 0;
foreach ($workplace_count as $key => $value) {
$max_workplace = max( array( $max_workplace, $value) ); //calculates max value
}
foreach ($workplace_count as $key => $value) {
?>
<div class="progress">
<div class="progress-bar" style="width:<?php echo 100*$value/$max_workplace; ?>%;background-color:#999;color:black">
<span title="<?php echo $value; ?>">
<?php echo $value; ?>
</span>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<div class="col-md-6">
<h3 id="what-municipal"><?php _e('What kind of relationship exists with the municipality?','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?></small></h3>
<div class="row">
<div class="col-md-9 col-sm-9 col-xs-9 text-right">
<?php
foreach ($municipality_what_count as $key => $value) {
echo $key=='' ? '<p>'.__('Not known','globalrec').'</p>' : '<p>'.ucfirst($key).'</p>';
}
?>
</div>
<div class="col-md-3 col-sm-3 col-xs-3">
<?php
$max_municipality_what = 0;
foreach ($municipality_what_count as $key => $value) {
$max_municipality_what = max( array( $max_municipality_what, $value) ); //calculates max value
}
foreach ($municipality_what_count as $key => $value) {
?>
<div class="progress">
<div class="progress-bar" style="width:<?php echo 100*$value/$max_municipality_what; ?>%;background-color:#999;color:black">
<span title="<?php echo $value; ?>">
<?php echo $value; ?>
</span>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<h3 id="languages"><?php _e('Languages','globalrec'); ?> <small><?php _e('number of organizations','globalrec'); ?></small></h3>
<div class="row">
<div class="col-md-5 col-sm-5 col-xs-5 text-right">
<?php
foreach ($language_count as $key => $value) {
echo $key=='' ? '<p>'.__('Not known','globalrec').'</p>' : '<p>'.ucfirst($key).'</p>';
}
?>
</div>
<div class="col-md-7 col-sm-7 col-xs-7">
<?php
$max_language = 0;
foreach ($language_count as $key => $value) {
$max_language = max( array( $max_language, $value) ); //calculates max value
}
foreach ($language_count as $key => $value) {
?>
<div class="progress">
<div class="progress-bar" style="width:<?php echo 100*$value/$max_language; ?>%;background-color:#999;color:black">
<span title="<?php echo $value; ?>">
<?php echo $value; ?>
</span>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>