[5341] | 1 | <?php |
---|
| 2 | |
---|
[5437] | 3 | class Helpers { |
---|
[5341] | 4 | |
---|
[6177] | 5 | public static function futureEvent( $startTime , $rangeEnd, $idSchedulable ) |
---|
[5636] | 6 | { |
---|
[5615] | 7 | //Verifica data |
---|
[6177] | 8 | $range = new DateTime( '@'.(int)($rangeEnd / 1000) , new DateTimeZone('UTC') ); |
---|
[5615] | 9 | list( $y1 , $m1 , $d1) = explode( '-' , $range->format('y-m-d')); |
---|
[5341] | 10 | |
---|
| 11 | $rangeEndMicrotime = gmmktime(0, 0, 0, $m1 , $d1, $y1); |
---|
| 12 | $nowMicrotime = gmmktime(0, 0, 0); |
---|
| 13 | |
---|
| 14 | if($rangeEndMicrotime < $nowMicrotime ) |
---|
[6177] | 15 | return self::futureEventDecodedRepeat($startTime , $idSchedulable, $nowMicrotime); |
---|
[5341] | 16 | |
---|
[6177] | 17 | if($rangeEndMicrotime === $nowMicrotime ) //caso seja o mesmo dia verifica a hora do evento. |
---|
[5341] | 18 | { |
---|
| 19 | $sTime = new DateTime( '@'.(int)($startTime / 1000) , new DateTimeZone('UTC') ); |
---|
| 20 | $eventHour = (date_format( $sTime , 'H') * 3600) + (date_format( $sTime , 'i') * 60) + date_format( $sTime , 's'); |
---|
| 21 | $nowHour = (gmdate('H') * 3600) + (gmdate('i') * 60) + gmdate('s'); |
---|
| 22 | |
---|
| 23 | if( $eventHour < $nowHour ) |
---|
[6177] | 24 | return self::futureEventDecodedRepeat($startTime , $idSchedulable, $nowMicrotime); |
---|
[5341] | 25 | } |
---|
| 26 | return true; |
---|
| 27 | } |
---|
| 28 | |
---|
[6177] | 29 | public static function futureEventDecodedRepeat( $startTime , $idSchedulable, $nowMicrotime ) |
---|
| 30 | { |
---|
| 31 | |
---|
| 32 | $sql = 'SELECT calendar_repeat_occurrence.occurrence as "occurrence" ' |
---|
| 33 | .'FROM calendar_repeat, calendar_repeat_occurrence WHERE calendar_repeat_occurrence.occurrence >= \'' . $startTime . '\' ' |
---|
| 34 | .'AND calendar_repeat.object_id = \'' . $idSchedulable . '\' ' |
---|
| 35 | .'AND calendar_repeat.id = calendar_repeat_occurrence.repeat_id AND ' |
---|
| 36 | .'calendar_repeat_occurrence.exception != 1'; |
---|
| 37 | |
---|
| 38 | $ocurrences = Controller::service('PostgreSQL')->execResultSql($sql); |
---|
| 39 | |
---|
| 40 | if($ocurrences){ |
---|
| 41 | $valid = FALSE; |
---|
| 42 | foreach($ocurrences as $value) |
---|
| 43 | if(($value['occurrence'] / 1000) > $nowMicrotime){ |
---|
| 44 | $valid = true; |
---|
| 45 | break; |
---|
| 46 | } |
---|
| 47 | return $valid; |
---|
| 48 | } else |
---|
| 49 | return false; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | |
---|
[5341] | 55 | /** |
---|
| 56 | * Resgata o organizador do evento |
---|
| 57 | * |
---|
| 58 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 59 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 60 | * @sponsor Caixa Econômica Federal |
---|
| 61 | * @author Cristiano Corrêa Schmidt |
---|
| 62 | * @access public |
---|
| 63 | */ |
---|
| 64 | protected static function getOrganizer( &$schedulable ) { |
---|
| 65 | $f = Controller::find(array('concept' => 'participant') , false , array('deepness' => '1' , 'filter' => array('AND' , array('=', 'schedulable' , $schedulable ) , array('=', 'isOrganizer' , '1')))); |
---|
| 66 | return ( isset( $f[0] ) ) ? $f[0] : false; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | public static function lg($print, $name = ''){ |
---|
| 70 | ob_start(); |
---|
| 71 | print "\n"; |
---|
| 72 | print $name . ": "; |
---|
| 73 | print_r( $print ); |
---|
| 74 | $output = ob_get_clean(); |
---|
| 75 | file_put_contents( "/tmp/prototype.log", $output , FILE_APPEND ); |
---|
| 76 | |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | ?> |
---|