forked from extern/egroupware
Calendar CSV import
- Fix condition checking - Participant account match was too nice, restrict to exact matches - Fix participants preview was 'Array'
This commit is contained in:
parent
3a240eb67c
commit
d693871b0c
@ -111,7 +111,9 @@ class calendar_import_csv extends importexport_basic_import_csv {
|
||||
// Search for direct account name, then user in accounts first
|
||||
$search = "\"$name\"";
|
||||
$id = importexport_helper_functions::account_name2id($name);
|
||||
if(!$id) {
|
||||
|
||||
// If not found, or not an exact match to a user (account_name2id is pretty generous)
|
||||
if(!$id || $names[$key] !== $this->bo->participant_name($id)) {
|
||||
$contacts = ExecMethod2('addressbook.addressbook_bo.search', $search,array('contact_id','account_id'),'org_name,n_family,n_given,cat_id,contact_email','','%',false,'OR',array(0,1));
|
||||
if($contacts) $id = $contacts[0]['account_id'] ? $contacts[0]['account_id'] : 'c'.$contacts[0]['contact_id'];
|
||||
}
|
||||
@ -177,8 +179,8 @@ class calendar_import_csv extends importexport_basic_import_csv {
|
||||
}
|
||||
$record->tzid = calendar_timezones::id2tz($record->tz_id);
|
||||
|
||||
if ( $_definition->plugin_options['conditions'] ) {
|
||||
foreach ( $_definition->plugin_options['conditions'] as $condition ) {
|
||||
if ( $options['conditions'] ) {
|
||||
foreach ( $options['conditions'] as $condition ) {
|
||||
$records = array();
|
||||
switch ( $condition['type'] ) {
|
||||
// exists
|
||||
@ -230,7 +232,7 @@ class calendar_import_csv extends importexport_basic_import_csv {
|
||||
protected function exists(importexport_iface_egw_record &$record, Array &$condition, &$records = array())
|
||||
{
|
||||
if($record->__get($condition['string']) && $condition['string'] == 'id') {
|
||||
$event = $this->bo->read($record[$condition['string']]);
|
||||
$event = $this->bo->read($record->__get($condition['string']));
|
||||
$records = array($event);
|
||||
}
|
||||
|
||||
@ -331,64 +333,14 @@ class calendar_import_csv extends importexport_basic_import_csv {
|
||||
}
|
||||
|
||||
/**
|
||||
* return etemplate components for options.
|
||||
* @abstract We can't deal with etemplate objects here, as an uietemplate
|
||||
* objects itself are scipt orientated and not "dialog objects"
|
||||
* Alter a row for preview to show multiple participants instead of Array
|
||||
*
|
||||
* @return array (
|
||||
* name => string,
|
||||
* content => array,
|
||||
* sel_options => array,
|
||||
* preserv => array,
|
||||
* )
|
||||
* @param egw_record $row_entry
|
||||
*/
|
||||
public function get_options_etpl() {
|
||||
// lets do it!
|
||||
protected function row_preview(importexport_iface_egw_record &$row_entry)
|
||||
{
|
||||
$row_entry->participants = implode('<br />', $this->bo->participants(array('participants' => $row_entry->participants),true));
|
||||
}
|
||||
|
||||
/**
|
||||
* returns etemplate name for slectors of this plugin
|
||||
*
|
||||
* @return string etemplate name
|
||||
*/
|
||||
public function get_selectors_etpl() {
|
||||
// lets do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns warnings that were encountered during importing
|
||||
* Maximum of one warning message per record, but you can append if you need to
|
||||
*
|
||||
* @return Array (
|
||||
* record_# => warning message
|
||||
* )
|
||||
*/
|
||||
public function get_warnings() {
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns errors that were encountered during importing
|
||||
* Maximum of one error message per record, but you can append if you need to
|
||||
*
|
||||
* @return Array (
|
||||
* record_# => error message
|
||||
* )
|
||||
*/
|
||||
public function get_errors() {
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of actions taken, and the number of records for that action.
|
||||
* Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
|
||||
*
|
||||
* @return Array (
|
||||
* action => record count
|
||||
* )
|
||||
*/
|
||||
public function get_results() {
|
||||
return $this->results;
|
||||
}
|
||||
} // end of iface_export_plugin
|
||||
?>
|
||||
|
@ -136,20 +136,7 @@ class calendar_tracking extends bo_tracking
|
||||
{
|
||||
$participants = $data['participants'];
|
||||
$data['participants'] = array();
|
||||
foreach($participants as $uid => $status)
|
||||
{
|
||||
$quantity = $role = $user_type = $user_id = null;
|
||||
calendar_so::split_status($status, $quantity, $role);
|
||||
calendar_so::split_user($uid, $user_type, $user_id);
|
||||
$field = is_numeric($uid) ? 'participants' : 'participants-'.$user_type;
|
||||
$data[$field][] = array(
|
||||
'user_id' => $user_id,
|
||||
'status' => $status,
|
||||
'quantity' => $quantity,
|
||||
'role' => $role,
|
||||
'recur' => $data['recur_date'] ? $data['recur_date'] : 0,
|
||||
);
|
||||
}
|
||||
$data = array_merge($data, $this->alter_participants($participants));
|
||||
}
|
||||
// if clients eg. CalDAV do NOT set participants, they are left untouched
|
||||
// therefore we should not track them, as all updates then show up as all participants removed
|
||||
@ -161,19 +148,7 @@ class calendar_tracking extends bo_tracking
|
||||
{
|
||||
$participants = $old['participants'];
|
||||
$old['participants'] = array();
|
||||
foreach($participants as $uid => $status)
|
||||
{
|
||||
calendar_so::split_status($status, $quantity, $role);
|
||||
calendar_so::split_user($uid, $user_type, $user_id);
|
||||
$field = is_numeric($uid) ? 'participants' : 'participants-'.$user_type;
|
||||
$old[$field][] = array(
|
||||
'user_id' => $user_id,
|
||||
'status' => $status,
|
||||
'quantity' => $quantity,
|
||||
'role' => $role,
|
||||
'recur' => $data['recur_date'] ? $data['recur_date'] : 0,
|
||||
);
|
||||
}
|
||||
$old = array_merge($old, $this->alter_participants($participants));
|
||||
}
|
||||
parent::track($data,$old,$user,$deleted, $changed_fields);
|
||||
}
|
||||
@ -186,4 +161,57 @@ class calendar_tracking extends bo_tracking
|
||||
unset($data, $old, $deleted); // unused, but required by function signature
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compute changes between new and old data
|
||||
*
|
||||
* Can be used to check if saving the data is really necessary or user just pressed save
|
||||
* Overridden to handle various participants options
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $old = null
|
||||
* @return array of keys with different values in $data and $old
|
||||
*/
|
||||
public function changed_fields(array $data,array $old=null)
|
||||
{
|
||||
if(is_array($data['participants']))
|
||||
{
|
||||
$participants = $data['participants'];
|
||||
$data['participants'] = array();
|
||||
$data = array_merge($data, $this->alter_participants($participants));
|
||||
}
|
||||
if(is_array($old['participants']))
|
||||
{
|
||||
$participants = $old['participants'];
|
||||
$old['participants'] = array();
|
||||
$old = array_merge($old, $this->alter_participants($participants));
|
||||
}
|
||||
return parent::changed_fields($data,$old);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do some magic with the participants and recurrance.
|
||||
* If this is one of a recurring event, append the recur_date to the participant field so we can
|
||||
* filter by it later.
|
||||
*/
|
||||
protected function alter_participants($participants)
|
||||
{
|
||||
$data = array();
|
||||
foreach($participants as $uid => $status)
|
||||
{
|
||||
$quantity = $role = $user_type = $user_id = null;
|
||||
calendar_so::split_status($status, $quantity, $role);
|
||||
calendar_so::split_user($uid, $user_type, $user_id);
|
||||
$field = is_numeric($uid) ? 'participants' : 'participants-'.$user_type;
|
||||
$data[$field][] = array(
|
||||
'user_id' => $user_id,
|
||||
'status' => $status,
|
||||
'quantity' => $quantity,
|
||||
'role' => $role,
|
||||
'recur' => $data['recur_date'] ? $data['recur_date'] : 0,
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@ -438,6 +438,7 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
|
||||
{
|
||||
// Convert to human-friendly
|
||||
importexport_export_csv::convert($row_data,$record_class::$types,$definition->application,$this->lookups);
|
||||
$this->row_preview($row_data);
|
||||
$rows[] = $row_data->get_record_array();
|
||||
}
|
||||
$this->preview_records = array();
|
||||
@ -445,6 +446,15 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
|
||||
return html::table($rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows an extending class to alter a row for preview
|
||||
*
|
||||
* @param egw_record $row_entry
|
||||
*/
|
||||
protected function row_preview(importexport_iface_egw_record &$row_entry)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for contact, but only using family, given & org name fields.
|
||||
*
|
||||
@ -626,6 +636,18 @@ error_log("Searching for $custom_field = $value");
|
||||
// lets do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns warnings that were encountered during importing
|
||||
* Maximum of one warning message per record, but you can append if you need to
|
||||
*
|
||||
* @return Array (
|
||||
* record_# => warning message
|
||||
* )
|
||||
*/
|
||||
public function get_warnings() {
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns errors that were encountered during importing
|
||||
* Maximum of one error message per record, but you can append if you need to
|
||||
|
Loading…
Reference in New Issue
Block a user