Ignore:
Timestamp:
05/04/12 18:38:56 (12 years ago)
Author:
natan
Message:

Ticket #2141 - Eventos com repeticao nao dispara notificacao nos alarmes - implementação final

File:
1 edited

Legend:

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

    r6096 r6111  
    117117                } 
    118118 
    119             $sql = ' SELECT calendar_object.id as id ,calendar_object.cal_uid as "uid", calendar_object.type_id as "type", calendar_object.dtstart as "startTime", calendar_object.summary as "summary", calendar_object.description as "description", calendar_object.dtend as "endTime" , calendar_object.location as "location", calendar_object.allday as "allDay", calendar_object.transp as "transparent", calendar_object.class_id as "class", calendar_object.repeat as "repeat", calendar_object.range_start as "rangeStart",calendar_object.range_end as "rangeEnd", calendar_object.last_update as "lastUpdate", calendar_object.dtstamp as "dtstamp", calendar_object.sequence as "sequence",  calendar_object.tzid as "timezone" ,calendar_to_calendar_object.calendar_id as calendar FROM calendar_to_calendar_object , calendar_object WHERE (range_start >= \'' . $start . '\' AND range_end <= \'' . $end . '\' AND calendar_to_calendar_object.calendar_id IN (\'' . implode('\',\'', $criteria['filter'][3][2]) . '\')) AND calendar_to_calendar_object.calendar_object_id = calendar_object.id' . (!empty($ids) ? ' AND calendar_object.id NOT IN (\'' . implode('\',\'', $ids) . '\')' : ''); 
     119            $sql = ' SELECT calendar_object.id as id ,calendar_object.cal_uid as "uid", calendar_object.type_id as "type", calendar_object.dtstart as "startTime", calendar_object.summary as "summary", calendar_object.description as "description", calendar_object.dtend as "endTime" , calendar_object.location as "location", calendar_object.allday as "allDay", calendar_object.transp as "transparent", calendar_object.class_id as "class", calendar_object.repeat as "repeat", calendar_object.range_start as "rangeStart",calendar_object.range_end as "rangeEnd", calendar_object.last_update as "lastUpdate", calendar_object.dtstamp as "dtstamp", calendar_object.sequence as "sequence",  calendar_object.tzid as "timezone" ,calendar_to_calendar_object.calendar_id as calendar FROM calendar_to_calendar_object , calendar_object WHERE (range_start >= \'' . $start . '\' AND range_end <= \'' . $end . '\' AND calendar_to_calendar_object.calendar_id IN (\'' . implode('\',\'', $criteria['filter'][3][2]) . '\')) AND calendar_to_calendar_ 
     120object.calendar_object_id = calendar_object.id' . (!empty($ids) ? ' AND calendar_object.id NOT IN (\'' . implode('\',\'', $ids) . '\')' : ''); 
    120121 
    121122            $params = Controller::service('PostgreSQL')->execResultSql($sql); 
     
    504505 
    505506                if (isset($v['id'])) { 
    506                     $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 
    507  
    508                     if (is_array($participants) && count($participants) > 0) 
    509                         foreach ($participants as $ii => $vv) { 
    510                             if ($vv['isExternal'] == 1) 
    511                                 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 
    512                             else 
    513                                 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 
    514  
    515                             if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 
    516                                 $participants[$ii]['alarms'] = Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id'])))); 
    517                         } 
    518                     $result[$i]['participants'] = $participants; 
    519  
    520  
     507                    $result[$i]['participants'] = Controller::find( array( 'concept' => 'participant' ) , false ,array( 'filter' => array('=', 'schedulable'  ,  $v['id']), 'criteria' => array( 'deepness' => $original['criteria']['deepness'] - 1 )));  
    521508 
    522509                    $attachmentRelation = Controller::find(array('concept' => 'schedulableToAttachment'), false, array('filter' => array('=', 'schedulable', $v['id']))); 
     
    568555    } 
    569556 
    570     //TODO: Remover apos suporte a deepness na api 
    571     public function deepnessReadParticipant(&$uri, &$result, &$criteria, $original) { 
    572  
    573         if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) { 
    574             if (isset($result['id'])) { 
    575                 if ($result['isExternal'] == 1) 
    576                     $result['user'] = Controller::read(array('concept' => 'user', 'id' => $result['user'], 'service' => 'PostgreSQL')); 
    577                 else 
    578                     $result['user'] = Controller::read(array('concept' => 'user', 'id' => $result['user'])); 
    579             } 
    580         } 
    581     } 
    582  
    583557    //TODO: Remover apos suporte a deepness na api  
    584     public function deepnessFindParticipant(&$uri, &$result, &$criteria, $original) { 
    585  
    586         if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) { 
    587             foreach ($result as $i => $v) { 
    588                 if (isset($v['id'])) { 
    589                     if ($result[$i]['isExternal'] == 1) 
    590                         $result[$i]['user'] = Controller::read(array('concept' => 'user', 'id' => $result[$i]['user'], 'service' => 'PostgreSQL')); 
    591                     else 
    592                         $result[$i]['user'] = Controller::read(array('concept' => 'user', 'id' => $result[$i]['user'])); 
    593                 } 
    594             } 
    595         } 
    596     } 
     558    public function deepnessReadEvent( &$uri , &$result , &$criteria , $original ){              
     559        
     560       if(isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) 
     561       { 
     562            if(isset($result['id'])) 
     563            { 
     564                $result['participants'] = Controller::find( array( 'concept' => 'participant' ) , false ,array( 'filter' => array('=' ,  'schedulable' ,  $result['id']), 'criteria' => array('deepness' => $original['criteria']['deepness'] - 1) ));  
     565 
     566                $repeat =  Controller::find( array( 'concept' => 'repeat' ), false, array( 'filter' => array( '=', 'schedulable', $result['id'] ) ) ); 
     567 
     568                if(is_array($repeat)) 
     569                    $result['repeat'] = $repeat[0]; 
     570            } 
     571       } 
     572   }  
     573    
     574    //TODO: Remover apos suporte a deepness na api  
     575    public function deepnessFindParticipant( &$uri , &$result , &$criteria , $original ){                
     576        
     577       if(isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) 
     578       { 
     579           foreach ($result as $i => &$v) 
     580           { 
     581                self::deepnessReadParticipant( $uri, $v, $criteria, $original ); 
     582           } 
     583       } 
     584        
     585   }  
    597586 
    598587    //TODO: Remover apos suporte a deepness na api  
     
    673662///////////////////////////////////////////////////////////////////////// 
    674663 
    675     static function dayAlarm(&$uri, &$params, &$criteria, $original) { 
    676         if (isset($criteria['filter'][1]) && $criteria['filter'][1] == 'date') { 
    677             $filter = array('AND', 
    678                 array('=', 'sent', '0'), 
    679                 array('=', 'type', ALARM_ALERT), 
    680                 array('>=', 'rangeStart', $criteria['filter'][2]), 
    681                 array('<=', 'rangeEnd', $criteria['filter'][2] + 86400000)); 
    682  
    683             //Busca os Alarmes no Range 
    684             $al = Controller::find(array('concept' => 'alarm'), false, array('filter' => $filter)); 
    685  
    686             if (is_array($al)) 
    687                 foreach ($al as $i => $v) { 
    688                     $ev = Controller::read(array('concept' => 'schedulable', 'id' => $v['schedulable'])); 
    689  
    690                     $unit = 0; 
    691                     switch (strtolower($v['unit'])) { 
    692                         case 'm': $unit = 60; 
    693                             break; 
    694                         case 'H': $unit = 3600; 
    695                             break; 
    696                         case 'd': $unit = 216000; 
    697                             break; 
    698                     } 
    699  
    700                     $al[$i]['sendTime'] = (((int) ( $ev['startTime'] / 1000 )) - ( $v['time'] * $unit )); 
    701                     $al[$i]['schedulable'] = $ev; 
    702                 } 
    703  
    704             $params = $al; 
    705             return false; 
    706         } 
    707     } 
     664    static function dayAlarm( &$uri , &$params , &$criteria , $original ) {      
     665        if(isset($criteria['filter'][1]) && $criteria['filter'][1] == 'date') 
     666        { 
     667            $target = $criteria['filter'][2]; 
     668 
     669            $params = array(); 
     670             
     671            $al = Controller::service('PostgreSQL')->execSql("SELECT co.id as id, co.cal_uid as uid, co.type_id as type, co.dtstart as startTime, co.summary as summary, co.description as description, co.dtend as endTime, co.location as location, co.allday as allDay, co.transp as transparent, co.class_id as class, ". 
     672                                                              "co.range_start as rangeStart, co.range_end as rangeEnd, co.last_update as lastUpdate, co.dtstamp as dtstamp, co.sequence as sequence, co.tzid as timezone, CASE WHEN rep.object_id = co.id THEN occ.occurrence - al.alarm_offset ELSE co.dtstart - al.alarm_offset END as sendTime ". 
     673                                                              "FROM calendar_alarm as al, calendar_object as co, calendar_repeat as rep, calendar_repeat_occurrence as occ, calendar_participant as part WHERE ". 
     674                                                              "al.action_id = '".ALARM_ALERT."' AND al.sent = '0' AND al.participant_id = part.id AND part.object_id = co.id AND ". 
     675                                                              "CASE WHEN rep.object_id = co.id ". 
     676                                                              "THEN rep.id = occ.repeat_id AND occ.occurrence - al.alarm_offset >= '$target' AND occ.occurrence - al.alarm_offset <= '".( $target + 86400000)."' ". 
     677                                                              "ELSE co.range_start - al.alarm_offset >= '$target' AND co.range_start - al.alarm_offset <= '".( $target + 86400000)."' END"); 
     678 
     679            if(is_array($al)) 
     680              foreach( $al as $v ) 
     681              { 
     682                    $params['sendTime'] = $al['sendTime']; 
     683 
     684                    unset( $al['sendTime'] ); 
     685 
     686                    $params['schedulable'] = $al; 
     687              } 
     688            else 
     689              $params = false; 
     690 
     691            return false; 
     692        } 
     693    }  
    708694 
    709695    public function deleteSchedulable(&$uri, &$params, &$criteria, $original) { 
Note: See TracChangeset for help on using the changeset viewer.