-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpgp.util.php
112 lines (99 loc) · 3.43 KB
/
wpgp.util.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
<?php /* -*- Mode: php; c-basic-offset:4; -*- */
/* Copyright (C) 2011 Governo do Estado do Rio Grande do Sul
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Small hammer to convert a date string into an us formatted
* date. Currently, the input format is the brazillian one d/m/YY, but
* if you want help to improve it, please make a configurable system and
* help us to change all hardcoded dates in the code :)
*/
function wpgp__date_to_us($input) {
return preg_replace('/(\d+)\/(\d+)\/(\d+)/','${3}-${2}-${1}', $input);
}
/**
* Does exactly the contrary of the above function. Transforms a date
* string from the us format to the "current one".
*/
function wpgp__date_from_us($input) {
return preg_replace('/(\d+)\-(\d+)\-(\d+).*/','${3}/${2}/${1}', $input);
}
/**
* Govr Helper function to get the proper css class of a contribution row
*/
function wpgp__govr_get_class($contrib) {
$klass = array();
if ($contrib['parent'] > 0) {
array_push($klass, "is-duplicated");
array_push($klass, "duplication-of-${contrib[parent]}");
} else if (wpgp_govr_contrib_get_parents($contrib)){
array_push($klass, "wpgp-part");
} else {
if ($contrib['status'] == 'approved') {
array_push($klass, "wpgp-approved");
} else {
array_push($klass, "wpgp-disapproved");
}
}
return join(" ", $klass);
}
function wpgp__govr_get_parents_string($contrib) {
$parents = array();
foreach (wpgp_govr_contrib_get_parents($contrib) as $c) {
array_push($parents, $c['id']);
}
return join(" ", $parents);
}
function wpgp__govr_get_part_string($contrib) {
$parts = array();
foreach (wpgp_govr_contrib_get_children($contrib) as $c) {
array_push($parts, $c['id']);
}
return join(" ", $parts);
}
/**
* Govp Helper function to get the proper css class of a contribution row
*/
function wpgp__govp_get_class($contrib) {
$klass = array();
if ($contrib['parent'] > 0) {
array_push($klass, "is-duplicated");
array_push($klass, "duplication-of-${contrib[parent]}");
} else if (wpgp_govp_contrib_get_parents($contrib)){
array_push($klass, "wpgp-part");
} else {
if ($contrib['status'] == 'approved') {
array_push($klass, "wpgp-approved");
} else {
array_push($klass, "wpgp-disapproved");
}
}
return join(" ", $klass);
}
function wpgp__govp_get_parents_string($contrib) {
$parents = array();
foreach (wpgp_govp_contrib_get_parents($contrib) as $c) {
array_push($parents, $c['id']);
}
return join(" ", $parents);
}
function wpgp__govp_get_part_string($contrib) {
$parts = array();
foreach (wpgp_govr_contrib_get_children($contrib) as $c) {
array_push($parts, $c['id']);
}
return join(" ", $parts);
}
?>