Changeset 4266 in subversion
- Timestamp:
- Nov 24, 2010 1:50:29 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php
r4251 r4266 33 33 'im' => array('limit' => 1), 34 34 'website' => array('limit' => 1, 'subtypes' => null), 35 'address' => array('limit' => 2, 'subtypes' => array('home',' work')),35 'address' => array('limit' => 2, 'subtypes' => array('home','business')), 36 36 'notes' => array(), 37 37 // define additional coltypes … … 54 54 private $imap_folder = 'INBOX/Contacts'; 55 55 private $gender_map = array(0 => 'male', 1 => 'female'); 56 private $phonetypemap = array('home' => 'home1', 'work' => 'business1', 'work2' => 'business2', 'workfax' => 'businessfax'); 57 private $addresstypemap = array('work' => 'business'); 56 58 private $fieldmap = array( 57 59 // kolab => roundcube … … 83 85 $format = rcube_kolab::get_format('contact'); 84 86 $this->coltypes['phone']['subtypes'] = $format->_phone_types; 87 $this->coltypes['address']['subtypes'] = $format->_address_types; 85 88 $this->coltypes['anniversary']['label'] = rcube_label('anniversary'); 86 89 … … 201 204 public function search($fields, $value, $strict=false, $select=true) 202 205 { 203 // TODO: currently not implemented , just list all records204 return $this->list_records();206 // TODO: currently not implemented 207 return new rcube_result_set(0, ($this->list_page-1) * $this->page_size); 205 208 } 206 209 … … 282 285 public function insert($save_data, $check=false) 283 286 { 284 if ( is_object($save_data) && is_a($save_data, rcube_result_set))285 return $this->insert_recset($save_data, $check);287 if (!is_array($save_data)) 288 return false; 286 289 287 290 $insert_id = $existing = false; … … 289 292 // check for existing records by e-mail comparison 290 293 if ($check) { 291 foreach ($this->_get_col_values('email', $save_data, true) as $email) { 292 if ($existing = $this->search('email', $email, true, false)) 294 foreach ($this->get_col_values('email', $save_data, true) as $email) { 295 if (($res = $this->search('email', $email, true, false)) && $res->count) { 296 $existing = true; 293 297 break; 294 } 295 } 296 297 $object = $this->_from_rcube_contact($save_data); 298 var_dump($object); 299 300 // TODO: how to create new Kolab objects? 301 298 } 299 } 300 } 301 302 if (!$existing) { 303 // generate new Kolab contact item 304 $object = $this->_from_rcube_contact($save_data); 305 $object['uid'] = $this->contactstorage->generateUID(); 306 $object['creation-date'] = time(); 307 $object['last-modification-date'] = time(); 308 309 $saved = $this->contactstorage->save($object); 310 311 if (PEAR::isError($saved)) { 312 raise_error(array( 313 'code' => 600, 'type' => 'php', 314 'file' => __FILE__, 'line' => __LINE__, 315 'message' => "Error saving contact object to Kolab server:" . $saved->getMessage()), 316 true, false); 317 } 318 else { 319 $contact = $this->_to_rcube_contact($object); 320 $id = $contact['ID']; 321 $this->contacts[$id] = $contact; 322 $this->id2uid[$id] = $object['uid']; 323 $insert_id = $id; 324 } 325 } 302 326 303 327 return $insert_id; 304 }305 306 /**307 * Insert new contacts for each row in set308 *309 * @see rcube_kolab_contacts::insert()310 */311 private function insert_recset($result, $check=false)312 {313 $ids = array();314 while ($row = $result->next()) {315 if ($insert = $this->insert($row, $check))316 $ids[] = $insert;317 }318 return $ids;319 328 } 320 329 … … 337 346 $object = array_merge($old, $this->_from_rcube_contact($save_data)); 338 347 $object['last-modification-date'] = time(); 339 348 console($save_data, $object); 340 349 $saved = $this->contactstorage->save($object, $uid); 341 350 if (PEAR::isError($saved)) { … … 362 371 public function delete($ids) 363 372 { 364 373 $this->_fetch_contacts(); 374 375 if (!is_array($ids)) 376 $ids = explode(',', $ids); 377 378 $count = 0; 379 foreach ($ids as $id) { 380 if ($uid = $this->id2uid[$id]) { 381 $deleted = $this->contactstorage->delete($uid); 382 383 if (PEAR::isError($deleted)) { 384 raise_error(array( 385 'code' => 600, 'type' => 'php', 386 'file' => __FILE__, 'line' => __LINE__, 387 'message' => "Error deleting a contact object from the Kolab server:" . $deleted->getMessage()), 388 true, false); 389 } 390 else { 391 unset($this->contacts[$id], $this->id2uid[$id]); 392 $count++; 393 } 394 } 395 } 396 397 return $count; 365 398 } 366 399 … … 370 403 public function delete_all() 371 404 { 372 /* empty for read-only address books */405 return !PEAR::isError($this->contactstorage->deleteAll()); 373 406 } 374 407 … … 499 532 if (isset($contact[$rcube])) 500 533 $object[$kolab] = is_array($contact[$rcube]) ? $contact[$rcube][0] : $contact[$rcube]; 534 else if ($rcube .= ':home' && isset($contact[$rcube])) 535 $object[$kolab] = is_array($contact[$rcube]) ? $contact[$rcube][0] : $contact[$rcube]; 501 536 } 502 537 … … 511 546 $object['gender'] = $gendermap[$contact['gender']]; 512 547 513 foreach (($emails = $this->_get_col_values('email', $contact, true)) as $email) 514 $object['email'][] = array('smtp-address' => $email, 'display-name' => $object['full-name']); 548 $emails = $this->get_col_values('email', $contact, true); 515 549 $object['emails'] = join(', ', $emails); 516 550 517 foreach ($this->_get_col_values('phone', $contact) as $type => $values) { 551 foreach ($this->get_col_values('phone', $contact) as $type => $values) { 552 if ($this->phonetypemap[$type]) 553 $type = $this->phonetypemap[$type]; 518 554 foreach ((array)$values as $phone) 519 555 $object['phone'][] = array('number' => $phone, 'type' => $type); 520 556 } 521 557 522 foreach ($this->_get_col_values('address', $contact) as $type => $values) { 558 foreach ($this->get_col_values('address', $contact) as $type => $values) { 559 if ($this->addresstypemap[$type]) 560 $type = $this->addresstypemap[$type]; 561 562 $basekey = 'addr-' . $type . '-'; 523 563 foreach ((array)$values as $adr) { 524 $object['address'][] = array( 525 'type' => $type, 526 'street' => $adr['street'], 527 'locality' => $adr['locality'], 528 'postal-code' => $adr['zipcode'], 529 'region' => $adr['region'], 530 'country' => $adr['country'], 531 ); 532 } 533 } 534 535 return $object; 536 } 537 538 539 private function _get_col_values($col, $data, $flat = false) 540 { 541 $out = array(); 542 foreach ($data as $c => $values) { 543 if (strpos($c, $col) === 0) { 544 if ($flat) { 545 $out = array_merge($out, (array)$values); 564 // switch type if slot is already taken 565 if (isset($object[$basekey . 'type'])) { 566 $type = $type == 'home' ? 'business' : 'home'; 567 $basekey = 'addr-' . $type . '-'; 568 } 569 570 if (!isset($object[$basekey . 'type'])) { 571 $object[$basekey . 'type'] = $type; 572 $object[$basekey . 'street'] = $adr['street']; 573 $object[$basekey . 'locality'] = $adr['locality']; 574 $object[$basekey . 'postal-code'] = $adr['zipcode']; 575 $object[$basekey . 'region'] = $adr['region']; 576 $object[$basekey . 'country'] = $adr['country']; 546 577 } 547 578 else { 548 list($f, $type) = explode(':', $c); 549 $out[$type] = array_merge((array)$out[$type], (array)$values); 579 $object['address'][] = array( 580 'type' => $type, 581 'street' => $adr['street'], 582 'locality' => $adr['locality'], 583 'postal-code' => $adr['zipcode'], 584 'region' => $adr['region'], 585 'country' => $adr['country'], 586 ); 550 587 } 551 588 } 552 589 } 553 554 return $o ut;590 591 return $object; 555 592 } 556 593
Note: See TracChangeset
for help on using the changeset viewer.
