Fixes to special export category columns:

- Sub-categories are properly detected, and the main category added if needed
- Sub-categories are listed as the path (Sub/Sub-Sub/Level 3) not just their name
This commit is contained in:
Nathan Gray 2010-11-19 18:35:37 +00:00
parent d8f79014f8
commit 73c445a694
3 changed files with 42 additions and 11 deletions

View File

@ -33,8 +33,10 @@ class addressbook_egw_record implements importexport_iface_egw_record
public function __construct( $_identifier='' ){ public function __construct( $_identifier='' ){
$this->identifier = $_identifier; $this->identifier = $_identifier;
$this->bocontacts = new addressbook_bo(); $this->bocontacts = new addressbook_bo();
if($_identifier) {
$this->contact = $this->bocontacts->read($this->identifier); $this->contact = $this->bocontacts->read($this->identifier);
} }
}
/** /**
* magic method to set attributes of record * magic method to set attributes of record

View File

@ -41,11 +41,16 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi
$uicontacts = new addressbook_ui(); $uicontacts = new addressbook_ui();
$selection = array(); $selection = array();
// Need to switch the app to get the same results
$old_app = $GLOBALS['egw_info']['flags']['currentapp'];
$GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook';
if ($options['selection'] == 'use_all') { if ($options['selection'] == 'use_all') {
// uicontacts selection with checkbox 'use_all' // uicontacts selection with checkbox 'use_all'
$query = $GLOBALS['egw']->session->appsession('index','addressbook'); $query = $GLOBALS['egw']->session->appsession('index','addressbook');
$query['num_rows'] = -1; // all $query['num_rows'] = -1; // all
$uicontacts->get_rows($query,$selection,$readonlys,true); // true = only return the id's $uicontacts->get_rows($query,$selection,$readonlys, true); // only return the ids
} }
elseif ( $options['selection'] == 'all_contacts' ) { elseif ( $options['selection'] == 'all_contacts' ) {
$selection = ExecMethod('addressbook.addressbook_bo.search',array()); $selection = ExecMethod('addressbook.addressbook_bo.search',array());
@ -53,6 +58,7 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi
} else { } else {
$selection = explode(',',$options['selection']); $selection = explode(',',$options['selection']);
} }
$GLOBALS['egw_info']['flags']['currentapp'] = $old_app;
if($options['explode_multiselects']) { if($options['explode_multiselects']) {
$customfields = config::get_customfields('addressbook'); $customfields = config::get_customfields('addressbook');
@ -68,18 +74,30 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi
'label' => $settings['name'], 'label' => $settings['name'],
'subs' => array(), 'subs' => array(),
); );
$subs = $cat_obj->return_array('subs', 0, false, '', 'ASC','', True, $settings['id']); $subs = $cat_obj->return_sorted_array(0, False, '', 'ASC', 'cat_name', True, $settings['id']);
foreach($subs as $sub) { foreach($subs as $sub) {
$additional_fields[$field][$settings['id']]['subs'][$sub['id']] = $sub['name']; $name = $sub['name'];
$path = $sub;
while($path['parent'] != $settings['id']) {
$path = $cat_obj->read($path['parent']);
$name = $path['name'] . '/' . $name;
}
$additional_fields[$field][$settings['id']]['subs'][$sub['id']] = $name;
} }
} }
break; break;
case self::EACH_CAT: case self::EACH_CAT:
$cats = $cat_obj->return_array('all', 0, false); $cats = $cat_obj->return_array('all', 0, false);
foreach($cats as $settings) { foreach($cats as $settings) {
$name = $settings['name'];
$path = $settings;
while($path['level'] != 0) {
$path = $cat_obj->read($path['parent']);
$name = $path['name'] . '/' . $name;
}
$additional_fields[$field][$settings['id']] = array( $additional_fields[$field][$settings['id']] = array(
'count' => 0, 'count' => 0,
'label' => $settings['name'] 'label' => $name
); );
} }
break; break;
@ -96,9 +114,14 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi
} }
} }
// Check records to see if additional fields are acutally used // Check records to see if additional fields are actually used
foreach ($selection as $identifier) { foreach ($selection as $_contact) {
$contact = new addressbook_egw_record($identifier); if(is_array($_contact) && $_contact['id']) {
$contact = new addressbook_egw_record();
$contact->set_record($_contact);
} else {
$contact = new addressbook_egw_record($_contact);
}
foreach($additional_fields as $field => &$values) { foreach($additional_fields as $field => &$values) {
if(!$contact->$field) continue; if(!$contact->$field) continue;
foreach($values as $value => &$settings) { foreach($values as $value => &$settings) {
@ -109,6 +132,8 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi
$settings['count']++; $settings['count']++;
} elseif($contact->$field == $value) { } elseif($contact->$field == $value) {
$settings['count']++; $settings['count']++;
} elseif($options['explode_multiselects'][$field]['explode'] == self::MAIN_CATS && array_intersect($contact->$field, array_keys($settings['subs']))) {
$settings['count']++;
} }
} }
} }
@ -145,8 +170,13 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi
// $options['selection'] is array of identifiers as this plugin doesn't // $options['selection'] is array of identifiers as this plugin doesn't
// support other selectors atm. // support other selectors atm.
foreach ($selection as $identifier) { foreach ($selection as $_contact) {
$contact = new addressbook_egw_record($identifier); if(is_array($_contact) && $_contact['id']) {
$contact = new addressbook_egw_record();
$contact->set_record($_contact);
} else {
$contact = new addressbook_egw_record($_contact);
}
// Some conversion // Some conversion
$this->convert($contact, $options); $this->convert($contact, $options);
importexport_export_csv::convert($contact, self::$types, 'addressbook'); importexport_export_csv::convert($contact, self::$types, 'addressbook');

View File

@ -990,7 +990,6 @@ class addressbook_ui extends addressbook_bo
unset($query['advanced_search']['meth_select']); unset($query['advanced_search']['meth_select']);
} }
//if ($do_email ) $email_only = array('id','owner','tid','n_fn','n_family','n_given','org_name','email','email_home'); //if ($do_email ) $email_only = array('id','owner','tid','n_fn','n_family','n_given','org_name','email','email_home');
$rows = parent::search($query['advanced_search'] ? $query['advanced_search'] : $query['search'],$id_only, $rows = parent::search($query['advanced_search'] ? $query['advanced_search'] : $query['search'],$id_only,
$order,'',$wildcard,false,$op,array((int)$query['start'],(int) $query['num_rows']),$query['col_filter']); $order,'',$wildcard,false,$op,array((int)$query['start'],(int) $query['num_rows']),$query['col_filter']);