- Timestamp:
- 10/25/12 13:52:45 (11 years ago)
- Location:
- sandbox/webservice/api/rest
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/webservice/api/rest/calendar/EventsResource.php
r6515 r7463 6 6 parent::post($request); 7 7 8 if( $this-> isLoggedIn())8 if( $this->isLoggedIn() ) 9 9 { 10 $user_id = $this->getUserId();11 $tz_offset = $this->getTimezoneOffset();12 10 $date_start = $this->getParam('dateStart'); 13 11 $date_end = $this->getParam('dateEnd'); 14 $split_event = $this->getParam('splitEvent'); // Boolean 1 or 0 - if you want to split the events that last for more than 1 day 15 12 16 13 // check the dates parameters formats (ex: 31/12/2012 23:59:59, but the time is optional) 17 14 $regex_date = '/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/([12][0-9]{3})( ([01][0-9]|2[0-3])(:[0-5][0-9]){2})?$/'; … … 26 23 $start_arr = explode(' ', $date_start); 27 24 $start_date_arr = explode('/', $start_arr[0]); 28 $start_time_arr = !empty($start_arr[1]) ? explode(':', $start_arr[1]) : array('00', '00', '00');29 $datetime = mktime($start_time_arr[0],$start_time_arr[1],$start_time_arr[2],$start_date_arr[1],$start_date_arr[0],$start_date_arr[2]) - ($tz_offset);30 25 31 26 // get the end timestamp UNIX from the parameter 32 27 $end_arr = explode(' ', $date_end); 33 28 $end_date_arr = explode('/', $end_arr[0]); 34 $end_time_arr = !empty($end_arr[1]) ? explode(':', $end_arr[1]) : array('23', '59', '59'); 35 $edatetime = mktime($end_time_arr[0],$end_time_arr[1],$end_time_arr[2],$end_date_arr[1],$end_date_arr[0],$end_date_arr[2]) - ($tz_offset); 36 37 $sql = 'SELECT DISTINCT ' 38 .'phpgw_cal.cal_id, ' 39 .'phpgw_cal.datetime, ' 40 .'phpgw_cal.edatetime, ' 41 .'phpgw_cal.title, ' 42 .'phpgw_cal.description, ' 43 .'phpgw_cal.location ' 44 .'FROM phpgw_cal_user, phpgw_cal ' 45 .'WHERE (phpgw_cal_user.cal_id = phpgw_cal.cal_id) '; 46 47 // user clauses 48 $sql .= ' AND (phpgw_cal_user.cal_login = ' . $user_id . ' OR (phpgw_cal.owner = ' . $user_id . ')) '; 49 50 // date range clauses 51 $sql .= ' AND ( ' 52 .' ( (phpgw_cal.datetime >= '.$datetime.') AND (phpgw_cal.edatetime <= '.$edatetime.') ) ' 53 .'OR ( (phpgw_cal.datetime <= '.$datetime.') AND (phpgw_cal.edatetime >= '.$edatetime.') ) ' 54 .'OR ( (phpgw_cal.datetime >= '.$datetime.') AND (phpgw_cal.datetime <= '.$edatetime.') AND (phpgw_cal.edatetime >= '.$edatetime.') ) ' 55 .'OR ( (phpgw_cal.datetime <= '.$datetime.') AND (phpgw_cal.edatetime >= '.$datetime.') AND (phpgw_cal.edatetime <= '.$edatetime.') ) ' 56 .') '; 57 58 $sql .= ' ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC '; 59 60 if (!$this->getDb()->query($sql)) 61 return false; 62 63 $events = array(); 64 while($this->getDb()->next_record()) { 65 $row = $this->getDb()->row(); 66 $id = $row['cal_id']; 67 $sdate = $row['datetime'] + ($tz_offset); 68 $edate = $row['edatetime'] + ($tz_offset); 69 $datetime += ($tz_offset); 70 $edatetime += ($tz_offset); 71 72 $association_arr = array( 73 'eventID' => 'cal_id', 74 'eventName' => 'title', 75 'eventDescription' => 'description', 76 'eventLocation' => 'location' 77 ); 78 79 // if the event starts and ends in the same day OR the user does not want to split the event, 80 // return the event in only one register 81 if(date('d/m/Y', $sdate) == date('d/m/Y', $edate) || !$split_event){ 82 foreach($association_arr AS $k => $v) 83 $events[$id][$k] = mb_convert_encoding($row[$v],"UTF8", "ISO_8859-1"); 84 85 $events[$id]['eventStartDate'] = date('d/m/Y H:i', $sdate); 86 $events[$id]['eventEndDate'] = date('d/m/Y H:i', $edate); 87 $events[$id]['eventAllDay'] = '0'; 29 30 $return = array(); 31 32 for( $j = (int)$start_date_arr[2]; $j <= (int)$end_date_arr[2]; $j++ ) 33 { 34 for( $i = (int)$start_date_arr[1]; $i <= (int)$end_date_arr[1]; $i++ ) 35 { 36 if( (int)$i < 10 ) 37 $result = $this->getEvents("0".$i,$j); 38 else 39 $result = $this->getEvents($i,$j); 40 41 if( count($result) > 0 ) 42 { 43 $return[] = $result; 44 } 88 45 } 89 // if the event lasts for more than one day AND the user wants it splitted day by day,90 // return the event splitted into as many parts of the array as the days remaining91 else{92 // walk through the event date range, adding one register for each day93 $step_date = $sdate;94 $step_date_ymd = date('Ymd', $step_date);95 while($step_date_ymd <= date('Ymd', $edate) && $step_date_ymd <= date('Ymd', $edatetime)){96 if($step_date_ymd >= date('Ymd', $datetime) && $step_date_ymd <= date('Ymd', $edatetime)){97 foreach($association_arr AS $k => $v)98 $events_tmp[$k] = $row[$v];99 100 // the first day of the event101 if($step_date == $sdate){102 $events_tmp['eventStartDate'] = date('d/m/Y H:i', $sdate);103 $events_tmp['eventEndDate'] = date('d/m/Y 23:59', $sdate);104 $events_tmp['eventAllDay'] = '0';105 }106 // the last day of the event107 elseif($step_date_ymd == date('Ymd', $edate)){108 $events_tmp['eventStartDate'] = date('d/m/Y 00:00', $edate);109 $events_tmp['eventEndDate'] = date('d/m/Y H:i', $edate);110 $events_tmp['eventAllDay'] = '0';111 }112 // the other days113 else{114 $events_tmp['eventStartDate'] = date('d/m/Y 00:00', $step_date);115 $events_tmp['eventEndDate'] = date('d/m/Y 23:59', $step_date);116 $events_tmp['eventAllDay'] = '1';117 }118 $events[$id.$step_date_ymd] = $events_tmp;119 }120 $step_date = strtotime("+1 day", $step_date);121 $step_date_ymd = date('Ymd', $step_date);122 }123 }124 46 } 125 47 126 $result = array ('events' => array_values($events)); 48 if( count($return) > 0 ) 49 { 50 $i = 0; 51 52 for( $j = 0 ; $j < count( $return); $j++) 53 { 54 foreach( $return[$j] as $key => $value ) 55 { 56 $events[$i]['eventID'] = "".$value[0]['id']; 57 $events[$i]['eventDate'] = "".$key; 58 $events[$i]['eventName'] = mb_convert_encoding("".$value[0]['title'],"UTF8","ISO_8859-1"); 59 $events[$i]['eventDescription'] = mb_convert_encoding("".$value[0]['description'], "UTF8","ISO_8859-1"); 60 $events[$i]['eventLocation'] = mb_convert_encoding("".$value[0]['location'], "UTF8","ISO_8859-1"); 61 $events[$i]['eventParticipants']= $value[0]['participants']; 62 63 $starttime = $this->makeTime($value[0]['start']); 64 $endtime = $this->makeTime($value[0]['end']); 65 $actualdate = mktime(0,0,0,substr($key,4,2),substr($key, 6 ),substr($key,0,4)); 66 $rawdate_offset = $actualdate - $this->getTimezoneOffset(); 67 $nextday = mktime(0,0,0,substr($key,4,2),substr($key, 6 )+1,substr($key,0,4)) - $this->getTimezoneOffset(); 68 69 if( $starttime <= $rawdate_offset && $endtime >= $nextday - 60 ) 70 { 71 $events[$i]['eventStartDate'] = substr($key, 6 )."/".substr($key,4,2)."/".substr($key,0,4)." 00:00"; 72 $events[$i]['eventEndDate'] = substr($key, 6 )."/".substr($key,4,2)."/".substr($key,0,4)." 23:59"; 73 $events[$i]['eventAllDay'] = "1"; 74 } 75 else 76 { 77 if( $value[0]['start']['mday'] === $value[0]['end']['mday'] ) 78 { 79 $hour_start = (((int)$value[0]['start']['hour'] < 10 ) ? "0".$value[0]['start']['hour'] : $value[0]['start']['hour']).":".(((int)$value[0]['start']['min'] < 10 ) ? "0".$value[0]['start']['min'] : $value[0]['start']['min'] ); 80 $hour_end = (((int)$value[0]['end']['hour'] < 10 ) ? "0".$value[0]['end']['hour'] : $value[0]['end']['hour']).":".(((int)$value[0]['end']['min'] < 10 ) ? "0".$value[0]['end']['min'] : $value[0]['end']['min'] ); 81 } 82 else 83 { 84 if( $events[$i-1] && $events[$i-1]['eventAllDay'] == "1" ) 85 { 86 $hour_start = "00:00"; 87 $hour_end = (((int)$value[0]['end']['hour'] < 10 ) ? "0".$value[0]['end']['hour'] : $value[0]['end']['hour']).":".(((int)$value[0]['end']['min'] < 10 ) ? "0".$value[0]['end']['min'] : $value[0]['end']['min'] ); 88 } 89 else 90 { 91 $hour_start = (((int)$value[0]['start']['hour'] < 10 ) ? "0".$value[0]['start']['hour'] : $value[0]['start']['hour']).":".(((int)$value[0]['start']['min'] < 10 ) ? "0".$value[0]['start']['min'] : $value[0]['start']['min'] ); 92 $hour_end = "23:59"; 93 } 94 } 95 96 $events[$i]['eventStartDate'] = substr($key, 6 )."/".substr($key,4,2)."/".substr($key,0,4)." ".$hour_start; 97 $events[$i]['eventEndDate'] = substr($key, 6 )."/".substr($key,4,2)."/".substr($key,0,4)." ".$hour_end; 98 $events[$i]['eventAllDay'] = "0"; 99 } 100 101 $events[$i++]['eventExParticipants'] = $value[0]['ex_participants']; 102 } 103 } 127 104 128 $this->setResult($result); 105 $this->setResult(array('events' => $events)); 106 } 107 else 108 { 109 $this->setResult(array('events' => array())); 110 } 129 111 } 112 130 113 //to Send Response (JSON RPC format) 131 114 return $this->getResponse(); 132 115 } 133 134 116 } -
sandbox/webservice/api/rest/catalog/ContactsResource.php
r6191 r7463 61 61 } 62 62 } 63 63 64 $result = array ('contacts' => array_values($contacts)); 64 65 $this->setResult($result); -
sandbox/webservice/api/rest/dispatch.php
r6495 r7463 12 12 13 13 // Load all resources 14 require_once(__DIR__."/availableServers/AvailableServersResource.php"); 14 15 require_once(__DIR__."/core/ExpressoVersionResource.php"); 15 16 require_once(__DIR__."/core/LoginResource.php"); … … 35 36 36 37 foreach( $config as $uri => $classFile ) 38 { 37 39 foreach( $classFile as $className => $filePath ) 38 40 { … … 45 47 'autoload' => $autoload 46 48 )); 49 } 47 50 48 51 try { 52 49 53 $resource = $request->loadResource(); 50 54 $response = $resource->exec($request);
Note: See TracChangeset
for help on using the changeset viewer.