Index: trunk/prototype/services/iCal.php
===================================================================
--- trunk/prototype/services/iCal.php	(revision 6066)
+++ trunk/prototype/services/iCal.php	(revision 6094)
@@ -82,15 +82,38 @@
 			$vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE');
 		    }
-
+		   		    
 		    if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0)
-			$this->createAttendee($v['participants'], $vevent);
+		    	$participants = $v['participants'];
+		    else
+				$participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id'])));
+		    
+			if (is_array($participants) && count($participants) > 0)
+				foreach ($participants as $ii => $vv) {
+				
+					if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user']))
+					{
+						if ($vv['isExternal'] == 1)
+							$participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL'));
+						else
+							$participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user']));
+					}
+				
+					if ($participants[$ii]['user']['id'] == Config::me('uidNumber'))
+					{
+						$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']))));
+						self::createAlarms($alarms, $vevent);
+					}
+				
+				}
+		    
+
+		    if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0)
+				$this->createAttendee($v['participants'], $vevent);
 
 		    if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0)
-			$this->createAttachment($v['attachments'], $vevent);
-
-		    $vevent->setProperty('uid', $v['uid']);
-
-		    //Todo: Implementar Repetição
-
+				$this->createAttachment($v['attachments'], $vevent);
+
+		    $vevent->setProperty('uid', $v['uid']);  
+		    
 		    break;
 
@@ -101,4 +124,32 @@
 
 	return $ical->createCalendar();
+    }
+    
+    public function createAlarms($alarms, &$vevent)
+    {	
+		foreach ($alarms as $ia => $va)
+	    {
+	    	$valarm = new valarm();
+	    	$valarm->setProperty('ACTION' , self::codeAlarmAction($va['type']));
+	    	
+	    	$duration = array();
+	    	
+	    	switch ($va['unit'])
+	    	{
+	    		case 'h':
+	    			$duration['hour'] = $va['time'];
+	    		break;
+	    		case 'm':
+	    			$duration['min'] = $va['time'];
+	    		break;
+	    		case 's':
+	    			$duration['sec'] = $va['time'];
+	    			break;
+	    	}
+	    	
+	    	$valarm->setProperty('trigger' ,$duration);
+	    	$vevent->setComponent($valarm);
+	    }	
+    	
     }
 
@@ -154,6 +205,9 @@
 
 		    $vevent->setProperty('attendee', $pv['user']['mail'], $pParams);
+
 		}
 	    }
+	    
+	    
 	}
     }
@@ -450,5 +504,6 @@
 			    break;
 		    }
-
+	
+		    
 		    $return[] = $interation;
 		    break;
@@ -869,5 +924,47 @@
 	    }
 	}
-
+	
+	$alarms = array();
+	
+	/* Definindo ALARMES */
+	while ($alarmComp = $component->getComponent('valarm'))
+	{
+		$alarm = array();
+		$alarmID = mt_rand() . '6(Formatter)';
+		$action =  $alarmComp->getProperty('action', false, true);
+		$trygger = $alarmComp->getProperty('trigger', false, true);
+		$alarm['type'] = self::decodeAlarmAction($action['value']);
+
+		 if(isset($trygger['value']['day']))
+		{
+			$alarm['time'] = $trygger['value']['day'];
+			$alarm['unit'] = 'd';
+		}
+		else if(isset($trygger['value']['hour']))
+		{
+			$alarm['time'] = $trygger['value']['hour'];
+			$alarm['unit'] = 'h';
+ 		}
+		else if(isset($trygger['value']['min']))
+		{
+			$alarm['time'] = $trygger['value']['min'];
+			$alarm['unit'] = 'm';
+		}
+		
+		foreach ($interation as $iint => &$vint)
+		{
+			if(isset($vint['user']) && $vint['user'] == Config::me('uidNumber'))
+			{
+				$alarm['participant'] = str_replace('participant://', '', $iint);	
+				$vint['alarms'][] = $alarmID;
+			}
+		}
+		$alarm['schedulable'] = $eventID;
+				
+		$interation['alarm://' . $alarmID ] = $alarm;
+		
+	}
+	
+	
 	/* Definindo DTSTAMP */
 	if ($dtstamp = self::_getTime($component, 'dtstamp'))
@@ -1003,4 +1100,39 @@
 	}
     }
+    
+    public function codeAlarmAction( $action )
+    {
+    	switch ($action)
+    	{
+    		case ALARM_MAIL : 
+    				return  'EMAIL';
+    				break;
+    		case ALARM_ALERT :
+    				return  'DISPLAY';
+    				break;
+    		case 'mail' :
+    					return  'EMAIL';
+    					break;
+    		case 'alert'  :
+    					return  'DISPLAY';
+    					break;
+    	}
+    	
+    }
+    
+    public function decodeAlarmAction( $action )
+    {
+    	switch ( $action )
+    	{
+    		case 'EMAIL'  :
+    			return  'mail';
+    			break;
+    		case 'DISPLAY' :
+    			return  'alert';
+    			break;
+
+    	}
+    
+    }
 
 }
