Changeset 6094


Ignore:
Timestamp:
05/03/12 18:23:57 (12 years ago)
Author:
cristiano
Message:

Ticket #2688 - Implementado importação e exportação de alarmes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/services/iCal.php

    r6066 r6094  
    8282                        $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 
    8383                    } 
    84  
     84                                     
    8585                    if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 
    86                         $this->createAttendee($v['participants'], $vevent); 
     86                        $participants = $v['participants']; 
     87                    else 
     88                                $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 
     89                     
     90                        if (is_array($participants) && count($participants) > 0) 
     91                                foreach ($participants as $ii => $vv) { 
     92                                 
     93                                        if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 
     94                                        { 
     95                                                if ($vv['isExternal'] == 1) 
     96                                                        $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 
     97                                                else 
     98                                                        $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 
     99                                        } 
     100                                 
     101                                        if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 
     102                                        { 
     103                                                $alarms = (isset($participants[$ii]['alarms'])) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id'])))); 
     104                                                self::createAlarms($alarms, $vevent); 
     105                                        } 
     106                                 
     107                                } 
     108                     
     109 
     110                    if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 
     111                                $this->createAttendee($v['participants'], $vevent); 
    87112 
    88113                    if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 
    89                         $this->createAttachment($v['attachments'], $vevent); 
    90  
    91                     $vevent->setProperty('uid', $v['uid']); 
    92  
    93                     //Todo: Implementar Repetição 
    94  
     114                                $this->createAttachment($v['attachments'], $vevent); 
     115 
     116                    $vevent->setProperty('uid', $v['uid']);   
     117                     
    95118                    break; 
    96119 
     
    101124 
    102125        return $ical->createCalendar(); 
     126    } 
     127     
     128    public function createAlarms($alarms, &$vevent) 
     129    {    
     130                foreach ($alarms as $ia => $va) 
     131            { 
     132                $valarm = new valarm(); 
     133                $valarm->setProperty('ACTION' , self::codeAlarmAction($va['type'])); 
     134                 
     135                $duration = array(); 
     136                 
     137                switch ($va['unit']) 
     138                { 
     139                        case 'h': 
     140                                $duration['hour'] = $va['time']; 
     141                        break; 
     142                        case 'm': 
     143                                $duration['min'] = $va['time']; 
     144                        break; 
     145                        case 's': 
     146                                $duration['sec'] = $va['time']; 
     147                                break; 
     148                } 
     149                 
     150                $valarm->setProperty('trigger' ,$duration); 
     151                $vevent->setComponent($valarm); 
     152            }    
     153         
    103154    } 
    104155 
     
    154205 
    155206                    $vevent->setProperty('attendee', $pv['user']['mail'], $pParams); 
     207 
    156208                } 
    157209            } 
     210             
     211             
    158212        } 
    159213    } 
     
    450504                            break; 
    451505                    } 
    452  
     506         
     507                     
    453508                    $return[] = $interation; 
    454509                    break; 
     
    869924            } 
    870925        } 
    871  
     926         
     927        $alarms = array(); 
     928         
     929        /* Definindo ALARMES */ 
     930        while ($alarmComp = $component->getComponent('valarm')) 
     931        { 
     932                $alarm = array(); 
     933                $alarmID = mt_rand() . '6(Formatter)'; 
     934                $action =  $alarmComp->getProperty('action', false, true); 
     935                $trygger = $alarmComp->getProperty('trigger', false, true); 
     936                $alarm['type'] = self::decodeAlarmAction($action['value']); 
     937 
     938                 if(isset($trygger['value']['day'])) 
     939                { 
     940                        $alarm['time'] = $trygger['value']['day']; 
     941                        $alarm['unit'] = 'd'; 
     942                } 
     943                else if(isset($trygger['value']['hour'])) 
     944                { 
     945                        $alarm['time'] = $trygger['value']['hour']; 
     946                        $alarm['unit'] = 'h'; 
     947                } 
     948                else if(isset($trygger['value']['min'])) 
     949                { 
     950                        $alarm['time'] = $trygger['value']['min']; 
     951                        $alarm['unit'] = 'm'; 
     952                } 
     953                 
     954                foreach ($interation as $iint => &$vint) 
     955                { 
     956                        if(isset($vint['user']) && $vint['user'] == Config::me('uidNumber')) 
     957                        { 
     958                                $alarm['participant'] = str_replace('participant://', '', $iint);        
     959                                $vint['alarms'][] = $alarmID; 
     960                        } 
     961                } 
     962                $alarm['schedulable'] = $eventID; 
     963                                 
     964                $interation['alarm://' . $alarmID ] = $alarm; 
     965                 
     966        } 
     967         
     968         
    872969        /* Definindo DTSTAMP */ 
    873970        if ($dtstamp = self::_getTime($component, 'dtstamp')) 
     
    10031100        } 
    10041101    } 
     1102     
     1103    public function codeAlarmAction( $action ) 
     1104    { 
     1105        switch ($action) 
     1106        { 
     1107                case ALARM_MAIL :  
     1108                                return  'EMAIL'; 
     1109                                break; 
     1110                case ALARM_ALERT : 
     1111                                return  'DISPLAY'; 
     1112                                break; 
     1113                case 'mail' : 
     1114                                        return  'EMAIL'; 
     1115                                        break; 
     1116                case 'alert'  : 
     1117                                        return  'DISPLAY'; 
     1118                                        break; 
     1119        } 
     1120         
     1121    } 
     1122     
     1123    public function decodeAlarmAction( $action ) 
     1124    { 
     1125        switch ( $action ) 
     1126        { 
     1127                case 'EMAIL'  : 
     1128                        return  'mail'; 
     1129                        break; 
     1130                case 'DISPLAY' : 
     1131                        return  'alert'; 
     1132                        break; 
     1133 
     1134        } 
     1135     
     1136    } 
    10051137 
    10061138} 
Note: See TracChangeset for help on using the changeset viewer.