Changeset 4497
- Timestamp:
- 10/27/06 14:57:20 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/org.openpsa.calendar/calendar_midcomdba.php
r4085 r4497 508 508 $this->_get_em('old_'); 509 509 510 /* 510 511 debug_add("this->participants\n===\n" . sprint_r($this->participants) . "===\n"); 511 512 debug_add("this->old_participants\n===\n" . sprint_r($this->old_participants) . "===\n"); 512 513 debug_add("this->_carried_participants_obj\n===\n" . sprint_r($this->_carried_participants_obj) . "===\n"); 514 */ 513 515 514 516 $this->_update_em($repeat_handler); … … 520 522 function _on_updated() 521 523 { 524 debug_push_class(__CLASS__, __FUNCTION__); 525 526 debug_add("this->participants\n===\n" . sprint_r($this->participants) . "===\n"); 527 debug_add("this->old_participants\n===\n" . sprint_r($this->old_participants) . "===\n"); 528 debug_add("this->_carried_participants_obj\n===\n" . sprint_r($this->_carried_participants_obj) . "===\n"); 529 522 530 foreach ($this->_carried_participants_obj as $resObj) 523 531 { 532 debug_add("Notifying participant #{$resObj->id}"); 524 533 if ($this->notify_force_add) 525 534 { … … 533 542 foreach ($this->_carried_resources_obj as $resObj) 534 543 { 544 debug_add("Notifying resource #{$resObj->id}"); 535 545 if ($this->notify_force_add) 536 546 { … … 568 578 $this->get_suspected_task_links(); 569 579 $this->get_suspected_sales_links(); 580 debug_pop(); 570 581 return true; 571 582 } … … 573 584 function _get_member_by_personid($id, $type='participant') 574 585 { 586 debug_push_class(__CLASS__, __FUNCTION__); 575 587 switch ($type) 576 588 { … … 582 594 default: 583 595 //Other values are disallowed 596 debug_add("Type '{$type}' is invalid, aborting", MIDCOM_LOG_ERROR); 597 debug_pop(); 584 598 return false; 585 599 break; 586 600 } 587 $className = 'org_openpsa_calendar_event' . $type; 588 589 //Find the correct eventmember by person ID 590 $finder = new org_openpsa_eventmember(); 591 $finder->eid = $this->id; 592 $finder->uid = $id; 593 $finder->find(); 594 if ($finder->N > 0) 595 { 596 //There should be only one match in any case 597 $finder->fetch(); 598 $resObj = new $className($finder->id); 599 return $resObj; 600 } 601 $class = 'org_openpsa_calendar_event' . $type; 602 if (!class_exists($class)) 603 { 604 // For the weirdest reason we don't have the class 605 debug_add("Class '{$class}' does not exist, aborting", MIDCOM_LOG_ERROR); 606 debug_pop(); 607 return false; 608 } 609 610 $qb = call_user_func(array($class, 'new_query_builder')); 611 $qb->add_constraint('eid', '=', $this->id); 612 $qb->add_constraint('uid', '=', $id); 613 $results = $qb->execute_unchecked(); 614 debug_add("qb returned:\n===\n" . sprint_r($results) . "===\n"); 615 if (empty($results)) 616 { 617 debug_pop(); 618 return false; 619 } 620 debug_pop(); 621 return $results[0]; 601 622 } 602 623 … … 872 893 { 873 894 debug_push_class(__CLASS__, __FUNCTION__); 874 //We need sudo to see busys in events we normally don't see and to rob resources from tentative events875 $_MIDCOM->auth->request_sudo();876 //If this event is tentative always disallow robbing resources from other tentative events877 if ($this->tentative)878 {879 $rob_tentative=false;880 }881 895 //If we're not busy it's not worth checking 882 896 if (!$this->busy) { … … 885 899 return false; 886 900 } 901 //If this event is tentative always disallow robbing resources from other tentative events 902 if ($this->tentative) 903 { 904 $rob_tentative = false; 905 } 906 //We need sudo to see busys in events we normally don't see and to rob resources from tentative events 907 $_MIDCOM->auth->request_sudo(); 887 908 888 909 //Storage for events that have been modified due the course of this method … … 1133 1154 * Creates/removes eventmembers based on $this->resources and $this->participants 1134 1155 */ 1135 function _update_em($repeat_handler ='this')1156 function _update_em($repeat_handler = 'this') 1136 1157 { 1137 1158 debug_push_class(__CLASS__, __FUNCTION__); 1138 1159 //There is probably a better way... 1139 if ($repeat_handler !='this')1140 { 1141 $this->send_notify =false;1142 } 1143 1160 if ($repeat_handler != 'this') 1161 { 1162 $this->send_notify = false; 1163 } 1164 1144 1165 $ret = array(); 1145 1166 $ret['resources'] = array(); … … 1165 1186 $this->old_participants = array(); 1166 1187 } 1167 1188 1168 1189 // ** Start with resources 1169 1190 $added_resources = $this->resource_diff($this->resources, $this->old_resources); … … 1176 1197 $resObj->uid = $resourceId; 1177 1198 $resObj->eid = $this->id; 1199 $resObj->orgOpenpsaObtype = ORG_OPENPSA_OBTYPE_EVENTRESOURCE; 1178 1200 $ret['resources']['added'][$resObj->uid] = $resObj->create($this->send_notify, &$this); 1179 1201 } 1180 1202 1181 1203 foreach ($removed_resources as $resourceId => $bool) 1182 1204 { … … 1185 1207 { 1186 1208 $ret['resources']['removed'][$resObj->uid] = $resObj->delete($this->send_notify, &$this); 1187 // TODO: Remove ACL permissions from removed members 1188 } 1189 } 1190 1209 // TODO: Remove ACL permissions from removed members 1210 } 1211 } 1212 1213 // Make sure we can read the carried objects 1214 $_MIDCOM->auth->request_sudo(); 1191 1215 foreach ($carried_resources as $resourceId => $bool) 1192 1216 { 1193 1217 //Find the correct eventmember by person ID 1194 1218 $resObj = $this->_get_member_by_personid($resourceId, 'resource'); 1195 if (is_object($resObj)) 1196 { 1197 $this->_carried_resources_obj[] = $resObj; 1198 } 1199 } 1219 if (!is_object($resObj)) 1220 { 1221 debug_add("Failed to get resource object for #{$resourceId}, errstr: " . mgd_errstr(), MIDCOM_LOG_ERROR); 1222 continue; 1223 } 1224 $this->_carried_resources_obj[] = $resObj; 1225 } 1226 $_MIDCOM->auth->drop_sudo(); 1200 1227 // ** Done with resources 1201 1228 1202 1229 // ** Start with participants 1203 1230 $added_participants = $this->resource_diff($this->participants, $this->old_participants); … … 1210 1237 $resObj->uid = $participantId; 1211 1238 $resObj->eid = $this->id; 1239 $resObj->orgOpenpsaObtype = ORG_OPENPSA_OBTYPE_EVENTPARTICIPANT; 1212 1240 $ret['participants']['added'][$resObj->uid] = $resObj->create($this->send_notify, &$this); 1213 1241 } 1214 1242 1215 1243 foreach ($removed_participants as $participantId => $bool) 1216 1244 { 1217 1245 $resObj = $this->_get_member_by_personid($participantId, 'participant'); 1218 if (is_object($resObj)) 1219 { 1220 $ret['participants']['removed'][$resObj->uid] = $resObj->delete($this->send_notify, &$this); 1221 } 1222 } 1223 1246 if (!is_object($resObj)) 1247 { 1248 debug_add("Failed to get participant object for person #{$participantId}, errstr: " . mgd_errstr(), MIDCOM_LOG_ERROR); 1249 continue; 1250 } 1251 $ret['participants']['removed'][$resObj->uid] = $resObj->delete($this->send_notify, &$this); 1252 } 1253 1254 // Make sure we can read the carried objects 1255 $_MIDCOM->auth->request_sudo(); 1224 1256 foreach ($carried_participants as $participantId => $bool) 1225 1257 { 1226 1258 $partObj = $this->_get_member_by_personid($participantId, 'participant'); 1227 if (is_object($partObj)) 1228 { 1229 $this->_carried_participants_obj[] = $partObj; 1230 } 1231 } 1259 if (!is_object($partObj)) 1260 { 1261 debug_add("Failed to get participant object for person #{$participantId}, errstr: " . mgd_errstr(), MIDCOM_LOG_ERROR); 1262 continue; 1263 } 1264 $this->_carried_participants_obj[] = $partObj; 1265 } 1266 $_MIDCOM->auth->drop_sudo(); 1232 1267 // ** Done with participants 1233 1268 /* 1234 1269 debug_add("added_participants\n===\n" . sprint_r($added_participants) . "===\n"); 1235 1270 debug_add("removed_participants\n===\n" . sprint_r($removed_participants) . "===\n"); 1236 debug_add("carried_participants\n===\n" . sprint_r($carried_participants) . "===\n");1237 1271 debug_add("this->participants\n===\n" . sprint_r($this->participants) . "===\n"); 1238 1272 debug_add("this->old_participants\n===\n" . sprint_r($this->old_participants) . "===\n"); 1273 debug_add("carried_participants\n===\n" . sprint_r($carried_participants) . "===\n"); 1239 1274 debug_add("this->_carried_participants_obj\n===\n" . sprint_r($this->_carried_participants_obj) . "===\n"); 1240 1275 */ 1241 1242 debug_add("returning:\n===\n" .sprint_r($ret)."===\n");1243 debug_pop(); 1244 return $ret; 1276 1277 debug_add("returning:\n===\n" . sprint_r($ret) . "===\n"); 1278 debug_pop(); 1279 return $ret; 1245 1280 } 1246 1281 … … 1332 1367 return $str; 1333 1368 } 1334 1335 1336 1369 1337 1370 /** trunk/src/org.openpsa.calendar/config/manifest.inc
r4301 r4497 6 6 ), 7 7 'class_definitions' => Array('midcom_dba_classes.inc'), 8 'version' => '2.0. 9',8 'version' => '2.0.10', 9 9 'state' => 'stable', 10 10 'package.xml' => Array( trunk/src/org.openpsa.calendar/documentation/CHANGES
r4301 r4497 6 6 which might even break existing functionality. 7 7 - All items marked with "+" represent completly new features. 8 9 2006-10-27 rambo 10 - bulletproofing in notifications handling 11 + iCal files attached to notifications 12 - version bump 8 13 9 14 2006-10-05 rambo trunk/src/org.openpsa.calendar/participant_midcomdba.php
r4259 r4497 67 67 function notify($repeat_handler='this', $event=false) 68 68 { 69 debug_push_class(__CLASS__, __FUNCTION__); 70 debug_add('This method must be overridden in a subclass', MIDCOM_LOG_ERROR); 71 debug_pop(); 69 72 return false; 70 73 } … … 128 131 } 129 132 133 function _on_loaded() 134 { 135 // Make sure we have correct class 136 switch($this->orgOpenpsaObtype) 137 { 138 case ORG_OPENPSA_OBTYPE_EVENTRESOURCE: 139 $this = new org_openpsa_calendar_eventresource($this->id); 140 break; 141 default: 142 case ORG_OPENPSA_OBTYPE_EVENTPARTICIPANT: 143 $this = new org_openpsa_calendar_eventparticipant($this->id); 144 break; 145 } 146 return true; 147 } 130 148 } 131 149 … … 157 175 var $participant; 158 176 159 function org_openpsa_calendar_eventparticipant($identifier=NULL) { 177 function org_openpsa_calendar_eventparticipant($identifier=NULL) 178 { 160 179 if (parent::_constructor($identifier)) 161 180 { … … 171 190 return false; 172 191 } 173 174 192 193 function _on_loaded() 194 { 195 return true; 196 } 197 175 198 //TODO: Rewrite 176 function notify($type = 'update', $event = false, $nl = "\n") { 199 function notify($type = 'update', $event = false, $nl = "\n") 200 { 177 201 debug_push_class(__CLASS__, __FUNCTION__); 202 debug_add("called with options: '{$type}', '{$event}', '{$nl}'"); 178 203 $l10n =& $_MIDCOM->i18n->get_l10n('org.openpsa.calendar'); 179 204 $recipient =& $this->get_person_obj(); … … 195 220 { 196 221 //Do not send notification to current user 197 debug_add('event->send_notify_me is false and recipient is current user, aborting ');222 debug_add('event->send_notify_me is false and recipient is current user, aborting notify'); 198 223 debug_pop(); 199 224 return false; … … 232 257 $message['content'] = sprintf($l10n->get('event "%s" (%s) was cancelled.'), $event->title, $event->format_timeframe()); 233 258 break; 234 } 235 236 //TODO: attach vcal when we have working dumps 237 259 default: 260 debug_add("action '{$type}' is invalid, aborting notification", MIDCOM_LOG_ERROR); 261 debug_pop(); 262 return false; 263 } 264 265 if ( $type == 'cancel' 266 || $type == 'remove') 267 { 268 // TODO: Create iCal export with correct delete commands 269 } 270 else 271 { 272 $vcal_data = $event->vcal_headers(); 273 $vcal_data .= $event->vcal_export(); 274 $vcal_data .= $event->vcal_footers(); 275 $message['attachments'] = array 276 ( 277 array 278 ( 279 'name' => midcom_generate_urlname_from_string(sprintf('%s on %s', $event->title, date('Ymd_Hi', $event->start))) . '.ics', 280 'mimetype' => 'text/calendar', 281 'content' => $vcal_data, 282 ), 283 ); 284 } 285 286 debug_pop(); 238 287 return org_openpsa_notifications::notify($action, $recipient->guid, $message); 239 288 } … … 245 294 * Wrapper class for eventmembers as resources to an event. 246 295 */ 247 class org_openpsa_calendar_eventresource extends org_openpsa_calendar_eventmember { 296 class org_openpsa_calendar_eventresource extends org_openpsa_calendar_eventmember 297 { 248 298 //More meaningfull aliases for some fields 249 299 var $resource; … … 251 301 var $notes; 252 302 253 function org_openpsa_calendar_eventresource($identifier=NULL) { 303 function org_openpsa_calendar_eventresource($identifier=NULL) 304 { 254 305 if (parent::_constructor($identifier)) 255 306 { … … 266 317 } 267 318 319 function _on_loaded() 320 { 321 return true; 322 } 323 268 324 function update($notify=true, $event=false) 269 325 {
