Ignore:
Timestamp:
04/13/12 17:25:00 (12 years ago)
Author:
acoutinho
Message:

Ticket #2626 - Inconsistencia no organizador de um evento quando criado a partir de uma agenda compartilhada

File:
1 edited

Legend:

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

    r5804 r5947  
    99     
    1010        public function formatNotification(&$uri , &$params , &$data , $original){       
    11                 switch ($params['type']) { 
    12                         case 'suggestion': 
    13                                 self::formatSuggestion($params);     
    14                                 break; 
    15                         case 'suggestionResponse': 
    16                                 self::formatSuggestionResponse($params);     
    17                                 break; 
    18                         }  
     11            switch ($params['type']) { 
     12                case 'suggestion': 
     13                        self::formatSuggestion($params);     
     14                        break; 
     15                case 'suggestionResponse': 
     16                        self::formatSuggestionResponse($params);     
     17                        break; 
     18                }  
    1919        } 
    2020         
     
    7878               $organizer = isset( $organizers[$pCreated['schedulable']] ) ? $organizers[ $pCreated['schedulable'] ] : self::getOrganizer( $pCreated['schedulable'] ); 
    7979                            
    80                                 if($pCreated['delegatedFrom'] != 0){ 
    81                                         self::participantDelegated( $pCreated , $schedulable , $organizer);     
    82                                         continue; 
    83                                 } 
     80                if($pCreated['delegatedFrom'] != 0){ 
     81                        self::participantDelegated( $pCreated , $schedulable , $organizer);     
     82                        continue; 
     83                } 
    8484                            
    8585               switch ($pCreated['status'])  
     
    8989                       break; 
    9090                   case STATUS_UNANSWERED: 
    91                         self::participantCreated( $pCreated['id'] , $schedulable ); 
     91                        self::participantCreated( $pCreated['id'] , $schedulable, false, false, $organizer ); 
    9292                       break; 
    9393               }  
     
    108108                     
    109109                if($pUpdated['delegatedFrom'] != 0){ 
    110                                         self::participantDelegatedStatusChange( $pUpdated , $schedulable , $organizer , $pUpdated['status'] );     
     110                    self::participantDelegatedStatusChange( $pUpdated , $schedulable , $organizer , $pUpdated['status'] );     
    111111                }else if( $pUpdated['status'] != STATUS_UNANSWERED && $pUpdated['status'] != STATUS_DELEGATED) 
    112                                         self::participantStatusChange( $pUpdated['id'] , $schedulable , $organizer , $pUpdated['status'] );     
     112                    self::participantStatusChange( $pUpdated['id'] , $schedulable , $organizer , $pUpdated['status'] );     
    113113            } 
    114114        } 
     
    117117        public function formatSuggestion(&$params){ 
    118118             
    119                 $schedulable =  Controller::read(  array( 'concept' => 'schedulable' , 'id' => $params['schedulable'] ) , null , array('deepness' => '2') ) ; 
    120                  
    121                 foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador       
     119            $schedulable =  Controller::read(  array( 'concept' => 'schedulable' , 'id' => $params['schedulable'] ) , null , array('deepness' => '2') ) ; 
     120 
     121            foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador       
    122122            if(($v['isOrganizer'] === '1') && ($organizer = $v) ) break; 
    123123                 
     
    227227        } 
    228228         
    229         /** 
     229    /** 
    230230    * Monta o email de resposta que sera enviado ao delegatedFrom 
    231231    * 
     
    239239    public static function participantDelegatedStatusChange( &$partID , &$schedulable, $organizer, &$type = false){ 
    240240         
    241                 $delegatedParams = array(); 
    242                                          
    243                 $delegated = self::_getAttendeeById($partID['id'], $schedulable); 
    244                 $delegatedParams['delegated'] = $delegated['user']['uid'];               
    245                  
    246                 switch($partID['status']){ 
     241            $delegatedParams = array(); 
     242 
     243            $delegated = self::_getAttendeeById($partID['id'], $schedulable); 
     244            $delegatedParams['delegated'] = $delegated['user']['uid'];           
     245 
     246            switch($partID['status']){ 
    247247            case STATUS_ACCEPTED: 
    248248                $delegatedParams['status'] = 'aceitou'; 
     
    254254                $delegatedParams['status'] = 'rejeitou'; 
    255255            break; 
    256                         case STATUS_DELEGATED: 
    257                                 $delegatedParams['status'] = 'delegou para um novo participante'; 
     256            case STATUS_DELEGATED: 
     257                    $delegatedParams['status'] = 'delegou para um novo participante'; 
    258258            break; 
    259259                } 
    260                         //notifica o organizador a resposta do delegado 
    261                         self::participantStatusChange( $partID['delegatedFrom'] , $schedulable , $organizer , $type, $delegatedParams ); 
    262          
    263                         $method = 'REQUEST'; 
    264                         $notificationType = 'Resposta Delegação';  
    265                         $part = 'attendees'; 
    266                         self::mountStruture($partID['delegatedFrom'], $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType ); 
    267                          
    268                         $data = array_merge($data, $delegatedParams); 
     260            //notifica o organizador a resposta do delegado 
     261            self::participantStatusChange( $partID['delegatedFrom'] , $schedulable , $organizer , $type, $delegatedParams ); 
     262 
     263            $method = 'REQUEST'; 
     264            $notificationType = 'Resposta Delegação';  
     265            $part = 'attendees'; 
     266            self::mountStruture($partID['delegatedFrom'], $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType ); 
     267 
     268            $data = array_merge($data, $delegatedParams); 
    269269                         
    270270            self::sendMail($data, $ical , $part['user']['mail'] , $subject , 'notify_response_delegated_status_body'); 
     
    305305                        $temp = $part; 
    306306                        $part = false; 
     307 
    307308                        switch($temp){ 
    308309                                case 'attendees': 
     
    352353    * @access     public 
    353354    */ 
    354     public static function participantCreated( &$partID , &$schedulable, $type = false, $delegatedParams = false) 
     355    public static function participantCreated( &$partID , &$schedulable, $type = false, $delegatedParams = false, $organizer = false) 
    355356    {    
    356                 $method = 'REQUEST'; 
    357                 $notificationType = 'Convite de Calendario';  
    358                 $part = 'attendees'; 
    359                 self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true); 
    360          
    361                 if($delegatedParams) 
    362                         $data = array_merge($data, $delegatedParams); 
    363                                           
    364                  self::sendMail($data, $ical , $part['user']['mail'] , $subject , !$delegatedParams  ? 'notify_create_body' : 'notify_create_delegated_body' ); 
     357        $method = 'REQUEST'; 
     358        $notificationType = 'Convite de Calendario';  
     359        $part = 'attendees'; 
     360        self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true); 
     361 
     362        if($delegatedParams) 
     363                $data = array_merge($data, $delegatedParams); 
     364 
     365            self::sendMail($data, $ical , $part['user']['mail'] , $subject , !$delegatedParams  ? 'notify_create_body' : 'notify_create_delegated_body', $organizer ); 
    365366        
    366367    } 
     
    379380    {    
    380381        $method = 'REPLY'; 
    381                 $notificationType = 'Convite Aceito'; 
    382                 $part = 'me'; 
    383                  
    384                 self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true ); 
    385                         
    386                 if($delegatedParams){ 
    387                         $data = array_merge($data, $delegatedParams); 
    388                         $tplDelegated = 'notify_delegated_status_body'; 
    389                 } 
     382        $notificationType = 'Convite Aceito'; 
     383        $part = 'me'; 
     384 
     385        self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true ); 
     386 
     387        if($delegatedParams){ 
     388                $data = array_merge($data, $delegatedParams); 
     389                $tplDelegated = 'notify_delegated_status_body'; 
     390        } 
    390391 
    391392       switch($type) 
     
    403404                $subject['notificationType'] = 'Convite rejeitado'; 
    404405            break; 
    405                         case STATUS_DELEGATED: 
    406                                 if($delegatedParams) 
    407                                         $data = array_merge($data, $delegatedParams); 
     406                case STATUS_DELEGATED: 
     407                    if($delegatedParams) 
     408                        $data = array_merge($data, $delegatedParams); 
    408409                $tpl =   'notify_delegated_body'; 
    409410                $subject['notificationType'] = 'Convite delegado'; 
     
    412413       } 
    413414         
    414         self::sendMail($data, $ical , $organizer['user']['mail'] , $subject , $tpl); 
     415        self::sendMail($data, $ical , $organizer['user']['mail'] , $subject , $tpl, false); 
    415416    } 
    416417     
     
    425426    * @access     public 
    426427    */ 
    427     private static function sendMail(&$data , &$ical , $to ,  &$subject , $template ) 
     428    private static function sendMail(&$data , &$ical , $to ,  &$subject , $template, $from = false ) 
    428429    {  
    429430       $ical2 = $ical; 
     
    435436       $mail['body'] = parseTPL::load_tpl( $data ,ROOTPATH.'/modules/calendar/templates/'.$template.'.tpl'); 
    436437       $mail['subject'] = parseTPL::load_tpl( $subject ,ROOTPATH.'/modules/calendar/templates/notify_subject.tpl');; 
    437        $mail['from'] = '"'.Config::me('cn').'" <'.Config::me('mail').'>'; 
     438       $mail['from'] = $from ? ('"'.$from['user']['name'].'" <'.$from['user']['mail'].'>') : ('"'.Config::me('cn').'" <'.Config::me('mail').'>'); 
    438439       $mail['to'] = $to; 
    439440       Controller::create( array( 'service' => 'SMTP' ), $mail );  
     
    456457       if((Config::regGet('noAlarm') === false) && (self::futureEvent( $schedulable['startTime'] , $schedulable['rangeEnd']))) 
    457458       { 
    458                         $method = 'CANCEL'; 
    459                         $notificationType = 'Cancelamento de Calendario'; 
    460                         $part = 'othersAttendees'; 
    461                         self::mountStruture($uri['id'], $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType ); 
     459            $method = 'CANCEL'; 
     460            $notificationType = 'Cancelamento de Calendario'; 
     461            $part = 'othersAttendees'; 
     462            self::mountStruture($uri['id'], $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType ); 
    462463                 
    463            if(count($part) > 0) 
    464             self::sendMail($data, $ical , implode(',' , $part) ,$subject, 'notify_cancel_body'); 
     464            if(count($part) > 0) 
     465                self::sendMail($data, $ical , implode(',' , $part) ,$subject, 'notify_cancel_body'); 
    465466       } 
    466467    } 
     
    484485       if((Config::regGet('noAlarm') === false) && (self::futureEvent( $schedulable['startTime'] , $schedulable['rangeEnd']))) 
    485486       {   
    486                         $method = 'CANCEL'; 
    487                         $notificationType = 'Cancelamento de Calendario'; 
    488                         $part = 'others'; 
    489                         self::mountStruture(false, $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType ); 
    490                                              
    491                         self::sendMail($data, $ical , $participant['user']['mail'] , $subject , 'notify_cancel_body');   
     487            $method = 'CANCEL'; 
     488            $notificationType = 'Cancelamento de Calendario'; 
     489            $part = 'others'; 
     490            self::mountStruture(false, $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType ); 
     491 
     492            self::sendMail($data, $ical , $participant['user']['mail'] , $subject , 'notify_cancel_body');   
    492493        } 
    493494    } 
     
    518519       if ( ($alt === true) && (Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'])) )  
    519520       {                         
    520                         $method = 'REQUEST'; 
    521                         $notificationType = 'Modificação de Calendario';  
    522                         $part = 'othersAttendees'; 
    523                         self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType); 
     521            $method = 'REQUEST'; 
     522            $notificationType = 'Modificação de Calendario';  
     523            $part = 'othersAttendees'; 
     524            self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType); 
    524525 
    525526            if ( isset($part) && count($part) > 0) 
Note: See TracChangeset for help on using the changeset viewer.