Ignore:
Timestamp:
08/06/12 18:17:24 (12 years ago)
Author:
acoutinho
Message:

Ticket #2966 - Suporte a importacao e exportacao de tarefas / correcoes de bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.4.2-expresso1/prototype/services/iCal.php

    r6891 r6951  
    184184                 
    185185                } 
    186              
    187186 
    188187            if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 
     
    617616        switch ($method) { 
    618617            case 'PUBLISH': 
    619                 //Caso a tarefa não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 
     618                //Caso a tarefa não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 
    620619                if (!$schedulable = self::_getSchedulable($uid)) 
    621                     $interation = self::_makeVEVENT($schedulable, $component, $params); 
     620                    $interation = self::_makeVTODO($schedulable, $component, $params); 
    622621                else{ 
    623622                    $links = Controller::read(array('concept' => 'calendarToSchedulable'), array('id'), array('filter' => 
     
    12911290    } 
    12921291 
    1293     static private function _makeVEVENT($schedulable, $component, $params) { 
     1292        static private function _makeVEVENT($schedulable, $component, $params) { 
    12941293        $interation = array(); 
    12951294        $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand() . '(Formatter)'; 
     
    13121311            $schedulable['allDay'] = 1; 
    13131312            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 
    1314         } elseif ($tzid && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     1313        } elseif ($tzid && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    13151314            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($startTime['value'])) . '000'; 
    13161315            $schedulable['allDay'] = 0; 
     
    13921391        $participantsInEvent = array(); 
    13931392 
    1394         //TODO: Participants com delegated não estao sendo levados em conta 
     1393        //TODO: Participants com delegated nao estao sendo levados em conta 
    13951394        while ($property = $component->getProperty('attendee', FALSE, TRUE)) { 
    13961395            $participant = array(); 
     
    15701569 
    15711570        $interation['schedulable://' . $eventID] = $schedulable; 
     1571 
     1572        return $interation; 
     1573    } 
     1574     
     1575    static private function _makeVTODO($schedulable, $component, $params) { 
     1576        $interation = array(); 
     1577        $todoID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand() . '(Formatter)'; 
     1578 
     1579        /* Data de Inicio */ 
     1580        $startTime = $component->getProperty('dtstart', false, true); 
     1581 
     1582        $tzid = (isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE']); 
     1583 
     1584        /* Tiem zone do evento */ 
     1585        if ($tzid){ 
     1586            $tzid = self::nomalizeTZID($tzid); 
     1587            $schedulable['timezone'] = $tzid; 
     1588        }else 
     1589            $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 
     1590 
     1591        $objTimezone = new DateTimeZone($schedulable['timezone']); 
     1592 
     1593        if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) { 
     1594            $schedulable['allDay'] = 1; 
     1595            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 
     1596        } elseif ($tzid && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     1597            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($startTime['value'])) . '000'; 
     1598            $schedulable['allDay'] = 0; 
     1599        } else { 
     1600            $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 
     1601            if (strpos($params['prodid'], 'Outlook') !== false) { 
     1602                //Se o ics veio em utc não aplicar horario de verão 
     1603                $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), new DateTimeZone('UTC')); 
     1604                $sTime->setTimezone($objTimezone); 
     1605                if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
     1606                    $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 
     1607            } 
     1608        } 
     1609 
     1610        /* Data de Termino */ 
     1611        $endTime = $component->getProperty('dtend', false, true); 
     1612 
     1613        $tzid = isset($endTime['params']['TZID']) ? $endTime['params']['TZID'] : $params['X-WR-TIMEZONE']; 
     1614         
     1615        if($tzid) 
     1616            $tzid = self::nomalizeTZID($tzid); 
     1617 
     1618        if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 
     1619            $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 
     1620        else if ($tzid && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     1621            $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($endTime['value'])) . '000'; 
     1622        else { 
     1623            $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
     1624            if (strpos($params['prodid'], 'Outlook') !== false) { 
     1625                //Se o ics veio em utc não aplicar horario de verão 
     1626                $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 
     1627                $eTime->setTimezone($objTimezone); 
     1628                if ($eTime->format('I')) 
     1629                    $schedulable['endTime'] = $schedulable['endTime'] - 3600000; 
     1630            } 
     1631        } 
     1632 
     1633        $schedulable['type'] = '2'; //type schedulable 
     1634        $schedulable['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 
     1635 
     1636        /* Definindo Description */ 
     1637        if ($desc = $component->getProperty('description', false, false)) 
     1638            $schedulable['description'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $desc), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 
     1639 
     1640        /* Definindo Class */ 
     1641        $class = $component->getProperty('class', false, false); 
     1642        if ($class && defined(constant(strtoupper('CLASS_' . $class)))) 
     1643            $schedulable['class'] = constant(strtoupper('CLASS_' . $class)); 
     1644        else if (!isset($schedulable['class'])) 
     1645            $schedulable['class'] = CLASS_PRIVATE; // padrão classe private 
     1646 
     1647        $schedulable['calendar'] = $params['calendar']; 
     1648 
     1649        $participantsInTodo = array(); 
     1650 
     1651        //TODO: Participants com delegated nao estao sendo levados em conta 
     1652        while ($property = $component->getProperty('attendee', FALSE, TRUE)) { 
     1653            $participant = array(); 
     1654 
     1655            $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 
     1656 
     1657            $participantID = ($tpID = self::_getParticipantByMail($mailUser, $schedulable['participants'])) ? $tpID : mt_rand() . '2(Formatter)'; 
     1658            $participant['schedulable'] = $eventID; 
     1659 
     1660            if (isset($params['status']) && $mailUser == Config::me('mail')) 
     1661                $participant['status'] = $params['status']; 
     1662            else 
     1663                $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED; 
     1664 
     1665 
     1666            $participant['isOrganizer'] = '0'; 
     1667 
     1668            /* Verifica se este usuario é um usuario interno do ldap */ 
     1669            $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 
     1670 
     1671            $user = null; 
     1672            if ($intUser && count($intUser) > 0) { 
     1673                $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; 
     1674                $participant['user'] = $intUser[0]['id']; 
     1675            } else { 
     1676                $participant['isExternal'] = 1; 
     1677                /* Gera um randon id para o contexto formater */ 
     1678                $userID = mt_rand() . '4(Formatter)'; 
     1679 
     1680                $user['mail'] = $mailUser; 
     1681                $user['isExternal'] = '1'; 
     1682                $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 
     1683                $user['participants'] = array($participantID); 
     1684                $participant['user'] = $userID; 
     1685                $interation['user://' . $userID] = $user; 
     1686            } 
     1687 
     1688            $interation['participant://' . $participantID] = $participant; 
     1689            $schedulable['participants'][] = $participantID; 
     1690        }; 
     1691 
     1692        if ($property = $component->getProperty('organizer', FALSE, TRUE)) { 
     1693            $participant = array(); 
     1694            $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 
     1695 
     1696            $participantID = mt_rand() . '2(Formatter)'; 
     1697 
     1698            $participant['schedulable'] = $eventID; 
     1699            $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED; 
     1700            $participant['isOrganizer'] = '1'; 
     1701            $participant['acl'] = 'rowi'; 
     1702 
     1703            /* Verifica se este usuario é um usuario interno do ldap */ 
     1704            $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 
     1705 
     1706            $user = null; 
     1707            if ($intUser && count($intUser) > 0) { 
     1708                $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; 
     1709                $participant['user'] = $intUser[0]['id']; 
     1710            } else { 
     1711                $participant['isExternal'] = 1; 
     1712                /* Gera um randon id para o contexto formater */ 
     1713                $userID = mt_rand() . '4(Formatter)'; 
     1714 
     1715                $user['mail'] = $mailUser; 
     1716                $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 
     1717                $user['participants'] = array($participantID); 
     1718                $user['isExternal'] = '1'; 
     1719                $participant['user'] = $userID; 
     1720                $interation['user://' . $userID] = $user; 
     1721            } 
     1722 
     1723            $interation['participant://' . $participantID] = $participant; 
     1724            $schedulable['participants'][] = $participantID; 
     1725            } else if (!isset($schedulable['participants']) || !is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador 
     1726            $user = Controller::read(array('concept' => 'user', 'id' => $params['owner']), array('mail')); 
     1727 
     1728            if (!self::_getParticipantByMail($user['mail'], $schedulable['participants'])) { 
     1729                $participantID = mt_rand() . '2(Formatter)'; 
     1730 
     1731                $participant['schedulable'] = $todoID; 
     1732                $participant['status'] = STATUS_CONFIRMED; 
     1733                $participant['isOrganizer'] = '1'; 
     1734                $participant['acl'] = 'rowi'; 
     1735                $participant['isExternal'] = 0; 
     1736                $participant['user'] = $params['owner']; 
     1737                $interation['participant://' . $participantID] = $participant; 
     1738                $schedulable['participants'][] = $participantID; 
     1739            } 
     1740        } 
     1741         
     1742        $alarms = array(); 
     1743         
     1744        /* Definindo ALARMES */ 
     1745        while ($alarmComp = $component->getComponent('valarm')) 
     1746        { 
     1747                $alarm = array(); 
     1748                $alarmID = mt_rand() . '6(Formatter)'; 
     1749                $action =  $alarmComp->getProperty('action', false, true); 
     1750                $trygger = $alarmComp->getProperty('trigger', false, true); 
     1751                $alarm['type'] = self::decodeAlarmAction($action['value']); 
     1752 
     1753                 if(isset($trygger['value']['day'])) 
     1754                { 
     1755                        $alarm['time'] = $trygger['value']['day']; 
     1756                        $alarm['unit'] = 'd'; 
     1757                } 
     1758                else if(isset($trygger['value']['hour'])) 
     1759                { 
     1760                        $alarm['time'] = $trygger['value']['hour']; 
     1761                        $alarm['unit'] = 'h'; 
     1762                } 
     1763                else if(isset($trygger['value']['min'])) 
     1764                { 
     1765                        $alarm['time'] = $trygger['value']['min']; 
     1766                        $alarm['unit'] = 'm'; 
     1767                } 
     1768                 
     1769                foreach ($interation as $iint => &$vint) 
     1770                { 
     1771                        if(isset($vint['user']) && $vint['user'] == Config::me('uidNumber')) 
     1772                        { 
     1773                                $alarm['participant'] = str_replace('participant://', '', $iint);        
     1774                                $vint['alarms'][] = $alarmID; 
     1775                        } 
     1776                } 
     1777                $alarm['schedulable'] = $eventID; 
     1778                                 
     1779                $interation['alarm://' . $alarmID ] = $alarm; 
     1780                 
     1781        } 
     1782         
     1783         
     1784        /* Definindo DTSTAMP */ 
     1785        if ($dtstamp = self::_getTime($component, 'dtstamp')) 
     1786            $schedulable['dtstamp'] = $dtstamp; 
     1787 
     1788        /* Definindo TRANSP */ 
     1789        if (($tranp = $component->getProperty('transp', false, true)) && $tranp && is_string($tranp) && strtoupper($tranp) == 'OPAQUE') 
     1790            $schedulable['transparent'] = 1; 
     1791 
     1792        /* Definindo last_update */ 
     1793        if ($lastUpdate = self::_getTime($component, 'LAST-MODIFIED')) 
     1794            $schedulable['lastUpdate'] = $lastUpdate; 
     1795 
     1796 
     1797        if ($sequence = $component->getProperty('SEQUENCE', false, false)) 
     1798            $schedulable['sequence'] = $sequence; 
     1799 
     1800        if ($uid = $component->getProperty('uid', false, false)) 
     1801            ; 
     1802        $schedulable['uid'] = $uid; 
     1803 
     1804        while ($attach = $component->getProperty('ATTACH', FALSE, TRUE)) { 
     1805 
     1806            $attachCurrent = array('name' => $attach['params']['X-FILENAME'], 
     1807                'size' => strlen($attach['value']), 
     1808                'type' => self::_getContentType($attach['params']['X-FILENAME']) 
     1809            ); 
     1810 
     1811            $ids = Controller::find(array('concept' => 'attachment'), array('id'), array('filter' => array('AND', array('=', 'name', $attachCurrent['name']), array('=', 'size', $attachCurrent['size']), array('=', 'type', $attachCurrent['type'])))); 
     1812 
     1813            if (!is_array($ids)) { 
     1814                $attachCurrent['source'] = $attach['value']; 
     1815                //insere o anexo no banco e pega id para colcar no relacionamento                                
     1816                $idAttachment = Controller::create(array('concept' => 'attachment'), $attachCurrent); 
     1817            }else 
     1818                $idAttachment = array('id' => $ids[0]['id']); 
     1819 
     1820            $calendarToAttachmentId = mt_rand() . '2(Formatter)'; 
     1821            $calendarToAttachment['attachment'] = $idAttachment['id']; 
     1822            $calendarToAttachment['schedulable'] = $eventID; 
     1823            $interation['schedulableToAttachment://' . $calendarToAttachmentId] = $calendarToAttachment; 
     1824 
     1825            $schedulable['attachments'][] = $calendarToAttachmentId; 
     1826        } 
     1827 
     1828        $interation['schedulable://' . $todoID] = $schedulable; 
    15721829 
    15731830        return $interation; 
Note: See TracChangeset for help on using the changeset viewer.