1 | <?php |
---|
2 | |
---|
3 | class Helpers { |
---|
4 | |
---|
5 | protected static function parseFilter($filter, $map) { |
---|
6 | if (!is_array($filter) || count($filter) <= 0) |
---|
7 | return null; |
---|
8 | |
---|
9 | $op = array_shift($filter); |
---|
10 | |
---|
11 | if (is_array($filter[0])) { |
---|
12 | foreach ($filter as $i => $f) |
---|
13 | $filter[$i] = self::parseFilter($f, $map); |
---|
14 | } |
---|
15 | else |
---|
16 | $filter[0] = isset($map[$filter[0]]) ? $map[$filter[0]] : $filter[0]; |
---|
17 | |
---|
18 | array_unshift($filter, $op); |
---|
19 | |
---|
20 | return( $filter ); |
---|
21 | } |
---|
22 | |
---|
23 | protected static function parseConcept($data, $map, $flip = false) { |
---|
24 | if (!is_array($data) || count($data) <= 0) |
---|
25 | return false; |
---|
26 | |
---|
27 | if ($flip === true) |
---|
28 | $map = array_flip($map); |
---|
29 | |
---|
30 | $new = array(); |
---|
31 | foreach ($data as $i => $v) |
---|
32 | if (array_key_exists($i, $map)) |
---|
33 | $new[$map[$i]] = $v; |
---|
34 | return $new; |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | protected static function parseOrder($data, $map) { |
---|
39 | $new = array(); |
---|
40 | |
---|
41 | if (!is_array($data)) |
---|
42 | $data = array($data); |
---|
43 | |
---|
44 | foreach ($data as $v) |
---|
45 | if (array_key_exists($v, $map)) |
---|
46 | $new[] = $map[$v]; |
---|
47 | |
---|
48 | return $new; |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | protected static function parsejustthese($data, $map, $flip = false) { |
---|
53 | |
---|
54 | if (!is_array($data) || count($data) <= 0) |
---|
55 | return false; |
---|
56 | |
---|
57 | if ($flip === true) |
---|
58 | $map = array_flip($map); |
---|
59 | |
---|
60 | $new = array(); |
---|
61 | foreach ($data as $v) |
---|
62 | if (array_key_exists($v, $map)) |
---|
63 | $new[] = $map[$v]; |
---|
64 | return $new; |
---|
65 | } |
---|
66 | |
---|
67 | protected static function parserCristeria($criteria, $map) { |
---|
68 | if (isset($criteria['filter'])) |
---|
69 | $criteria['filter'] = self::parseFilter($criteria['filter'], $map); |
---|
70 | |
---|
71 | if (isset($criteria['order'])) { |
---|
72 | $ord = self::parseOrder($criteria['order'], $map); |
---|
73 | if (count($ord) > 0) |
---|
74 | $criteria['order'] = $ord; |
---|
75 | else |
---|
76 | unset($criteria['order']); |
---|
77 | } |
---|
78 | |
---|
79 | return $criteria; |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | public static function futureEvent( $startTime , $rangeEnd ) |
---|
84 | { |
---|
85 | //Verifica data |
---|
86 | list( $y1 , $m1 , $d1) = explode( '-' , $rangeEnd ); |
---|
87 | |
---|
88 | $rangeEndMicrotime = gmmktime(0, 0, 0, $m1 , $d1, $y1); |
---|
89 | $nowMicrotime = gmmktime(0, 0, 0); |
---|
90 | |
---|
91 | if($rangeEndMicrotime < $nowMicrotime ) |
---|
92 | return false; |
---|
93 | |
---|
94 | if($rangeEndMicrotime === $nowMicrotime ) //caso seja o mesmo dia verifica a hora do evento. |
---|
95 | { |
---|
96 | $sTime = new DateTime( '@'.(int)($startTime / 1000) , new DateTimeZone('UTC') ); |
---|
97 | $eventHour = (date_format( $sTime , 'H') * 3600) + (date_format( $sTime , 'i') * 60) + date_format( $sTime , 's'); |
---|
98 | $nowHour = (gmdate('H') * 3600) + (gmdate('i') * 60) + gmdate('s'); |
---|
99 | |
---|
100 | if( $eventHour < $nowHour ) |
---|
101 | return false; |
---|
102 | } |
---|
103 | return true; |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * Resgata o organizador do evento |
---|
108 | * |
---|
109 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
110 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
111 | * @sponsor Caixa Econômica Federal |
---|
112 | * @author Cristiano Corrêa Schmidt |
---|
113 | * @access public |
---|
114 | */ |
---|
115 | protected static function getOrganizer( &$schedulable ) { |
---|
116 | $f = Controller::find(array('concept' => 'participant') , false , array('deepness' => '1' , 'filter' => array('AND' , array('=', 'schedulable' , $schedulable ) , array('=', 'isOrganizer' , '1')))); |
---|
117 | return ( isset( $f[0] ) ) ? $f[0] : false; |
---|
118 | } |
---|
119 | |
---|
120 | public static function lg($print, $name = ''){ |
---|
121 | ob_start(); |
---|
122 | print "\n"; |
---|
123 | print $name . ": "; |
---|
124 | print_r( $print ); |
---|
125 | $output = ob_get_clean(); |
---|
126 | file_put_contents( "/tmp/prototype.log", $output , FILE_APPEND ); |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | } |
---|
131 | |
---|
132 | ?> |
---|