Ignore:
Timestamp:
03/18/12 15:07:09 (12 years ago)
Author:
acoutinho
Message:

Ticket #2434 - Suporte copia/edicao/remocao de ocorrencias de repeticao

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/modules/calendar/interceptors/DBMapping.php

    r5741 r5746  
    150150 
    151151public function saveOccurrences( &$uri , &$result , &$criteria , $original ){ 
    152  
    153         $ranges = Controller::find( array( 'concept' => 'repeatRange' ), array( 'rangeStart', 'rangeEnd' ),  array( 'filter' => array( '=', 'user', Config::me("uidNumber") ) ) ); 
     152        $ranges = Controller::find( array( 'concept' => 'repeatRange' ), array( 'rangeStart', 'rangeEnd' ),  array( 'filter' => array( '=', 'user', Config::me("uidNumber") ) ) ); 
    154153 
    155154        if( !is_array( $ranges ) || !isset( $ranges[0]['rangeStart'] ) || !isset( $ranges[0]['rangeEnd'] ) ) 
     
    168167        $exceptions = array(); 
    169168 
    170         if( isset( $repeat['exceptions'] ) ) 
     169        if( isset( $original['properties']['exceptions'] ) ) 
    171170        { 
    172             $exceptions = explode( ',', $repeat['exceptions'] ); 
     171            $exceptions = explode( ',', $original['properties']['exceptions'] ); 
    173172            unset( $repeat['exceptions'] ); 
    174173        } 
    175  
     174         
     175        $lastExceptions = Controller::find( array( 'concept' => 'repeatOccurrence' ), array("occurrence") , array( 'filter' => array('AND', array( '=', 'repeat', $id ) , array( '=', 'exception', 1 ) ) )); 
     176 
     177        //Recurepa as execeções anteriores caso exista 
     178        if(isset($lastExceptions) && count($lastExceptions)) 
     179            foreach($lastExceptions as $key => $value) 
     180                array_push($exceptions, $lastExceptions[$key]['occurrence']); 
     181         
    176182        $params = array_diff( self::decodeRepeat( $repeat, $ranges[0]['rangeStart'], $ranges[0]['rangeEnd'] ), $exceptions ); 
    177  
     183         
    178184        Controller::delete( array( 'concept' => 'repeatOccurrence' ), false, array( 'filter' => array( '=', 'repeat', $id ) ) ); 
    179185 
    180186        if( !empty($params) ) 
    181             Controller::service('PostgreSQL')->execResultSql( "INSERT INTO calendar_repeat_occurrence(repeat_id,exception,occurrence)VALUES('".$id."','0','".implode( "'),('".$id."','0','", $params )."')".( empty($exceptions) ? "" : ",('".$id."','1','".implode( "'),('".$id."','0','", $exceptions )."')" ) ); 
    182  
     187            Controller::service('PostgreSQL')->execResultSql( "INSERT INTO calendar_repeat_occurrence(repeat_id,exception,occurrence)VALUES('".$id."','0','".implode( "'),('".$id."','0','", $params )."')".( empty($exceptions) ? "" : ",('".$id."','1','".implode( "'),('".$id."','1','", $exceptions )."')" ) ); 
    183188    } 
    184189 
     
    467472  
    468473    //TODO: Remover apos suporte a deepness na api  
    469     public function deepnessFindEvent( &$uri , &$result , &$criteria , $original ){              
    470  
     474    public function deepnessFindEvent( &$uri , &$result , &$criteria , $original ){ 
    471475       if(isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) 
    472476       { 
    473477                         
    474                         $Time = new DateTime( 'now', new DateTimeZone('UTC') ); 
    475                         $DayLigth = array(); 
     478            $Time = new DateTime( 'now', new DateTimeZone('UTC') ); 
     479            $DayLigth = array(); 
    476480           foreach ($result as $i => $v) 
    477481           { 
     
    888892    } 
    889893 
    890     public function createSchedulableMails( &$uri , &$result , &$criteria , $original ){ 
    891          
    892         require_once (ROOTPATH.'/plugins/icalcreator/iCalcreator.class.php' ); 
    893         require_once (ROOTPATH.'/api/parseTPL.php' ); 
    894         $schedulable = Controller::read( array( 'concept' => 'schedulable' , 'id' => $result['id'] ));  
    895         $participants = Controller::find( array( 'concept' => 'participant' ) , false ,array( 'filter' => array('=', 'schedulable' ,  $result['id']) )) ;  
    896          
    897          
    898         if(is_array($participants) && count($participants) > 0) //Caso exista participants 
    899         { 
    900             $att = array(); 
    901             $attList = '<UL> '; 
    902             $organizer = array(); 
    903             foreach ($participants as $i => $v) 
    904                         { 
    905                 if($part['isExternal'] == 1) 
    906                     $att[$i] =  Controller::read( array( 'concept' => 'user' , 'id' => $v['user'] , 'service' => 'PostgreSQL' ) ); 
    907                 else 
    908                     $att[$i] = Controller::read( array( 'concept' => 'user' , 'id' => $v['user'] )); 
    909              
    910                $attList .= '<LI> '.$att[$i]['name'] .'</LI> '; 
    911                 
    912                if( isset($v['isOrganizer']) && $v['isOrganizer'] == 1) 
    913                    $organizer = $att[$i]; 
    914                 
    915             } 
    916             $attList .= '</UL>'; 
    917              
    918             foreach ($participants as $i => $v) 
    919                         {                                
    920                  
    921                 if($v === $organizer) //Organizador ?  
    922                     continue; 
    923                  
    924                 //Criação do ical 
    925                 $ical = null; 
    926                 $ical = new vcalendar(); 
    927                                 $ical->setProperty( 'method' , 'REQUEST' );                      
    928                                 $vschedulable = &$ical->newComponent( 'vschedulable' ); 
    929                                 $vschedulable->setProperty( 'uid' , $schedulable['uid'] ); 
    930                                 $vschedulable->setProperty( 'dtstart', gmdate( DATE_RFC822 , (int)($schedulable['startTime'] / 1000))); 
    931                                 $vschedulable->setProperty( 'dtend', gmdate( DATE_RFC822 , (int)($schedulable['endTime'] / 1000))); 
    932                                 $vschedulable->setProperty( 'summary',( $schedulable['summary'] )); 
    933                                 $vschedulable->setProperty( 'description', $schedulable['description']); 
    934                 $vschedulable->setProperty( 'location', $schedulable['location']); 
    935                 $params = array(); 
    936                 $params['CN'] = $att[$i]['name']; 
    937                 $params['RSVP'] = 'TRUE'; 
    938                 $params['ROLE'] = 'REQ-PARTICIPANT'; 
    939                 if(isset($att[$i]['mail'])) 
    940                     $vschedulable->setProperty( 'attendee', $att[$i]['mail'] , $params); 
    941                  
    942                 $vschedulable->setProperty( 'organizer', $organizer['mail'] , array('CN' => $organizer['name']) ); 
    943                                 /////////////////////////////////////////////////////////////////////////// 
    944                  
    945                 //Criação do E-mail 
    946                 $mail = array(); 
    947                 $mail['isHtml'] = true;   
    948                  
    949                 $timzone = new DateTimeZone('UTC'); 
    950                 $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , $timzone ); 
    951                 $eTime =  new DateTime( '@'.(int)($schedulable['endTime'] / 1000) , $timzone ); 
    952                  
    953                 $mail['body'] = parseTPL::load_tpl(array( 'startDate' =>  date_format( $sTime , 'd/m/Y') , 
    954                                                           'startTime' =>  date_format( $sTime , 'H:i') , 
    955                                                           'endDate' =>  date_format( $eTime , 'd/m/Y') , 
    956                                                           'endTime' =>  date_format( $eTime , 'H:i') , 
    957                                                           'schedulableTitle' =>  $schedulable['summary'], 
    958                                                           'schedulableLocation' =>  $schedulable['location'], 
    959                                                           'participants' =>  $attList 
    960                                                         ),ROOTPATH.'/api/templates/notify_create_body.tpl'); 
    961                  
    962                 //TODO: Internacionalização do Subject 
    963                 $mail['subject'] = 'Schedulable do Calendário : '.$schedulable['summary'] .' @ '.date_format( $sTime , 'd/m/Y H:i') . ' - ' .  date_format( $eTime , 'd/m/Y H:i'); 
    964                 $mail['from'] =  $organizer['mail']; 
    965                 $mail['to'] = $att[$i]['mail']; 
    966                 $mail['attachments'][] = array('source' => $ical->createCalendar(), 'type' => 'text/calendar' ,'disposition' => 'inline' ,'name' => 'external.ics'); 
    967                 $result['participants'][$i]['sendInvite'] = Controller::create( array( 'service' => 'SMTP' ), $mail );    
    968          
    969                         }          
    970         } 
    971         } 
    972  
    973894    public function davcalCreateCollection( &$uri , &$params , &$criteria , $original ){         
    974895        if( Config::module('useCaldav') ) 
Note: See TracChangeset for help on using the changeset viewer.