// The following arrays are maps between entity ids in the file versus the database.
// We write to the file sequentially (1,2,3...) while in the database the entities have different ids.
- var $userMap = array(); // User ids.
- var $roleMap = array(); // Role ids.
- var $taskMap = array(); // Task ids.
- var $projectMap = array(); // Project ids.
- var $clientMap = array(); // Client ids.
- var $invoiceMap = array(); // Invoice ids.
- var $logMap = array(); // Time log ids.
+ var $userMap = array();
+ var $roleMap = array();
+ var $taskMap = array();
+ var $projectMap = array();
+ var $clientMap = array();
+ var $invoiceMap = array();
+ var $logMap = array();
+ var $customFieldMap = array();
+ var $customFieldOptionMap = array();
// Constructor.
function __construct($group_id, $file, $indentation) {
foreach ($invoices as $key=>$invoice_item)
$this->invoiceMap[$invoice_item['id']] = $key + 1;
+ // Prepare custom fields map.
+ $custom_fields = ttTeamHelper::getAllCustomFields($this->group_id);
+ foreach ($custom_fields as $key=>$custom_field)
+ $this->customFieldMap[$custom_field['id']] = $key + 1;
+
+ // Prepare custom field options map.
+ $custom_field_options = ttTeamHelper::getAllCustomFieldOptions($this->group_id);
+ foreach ($custom_field_options as $key=>$option)
+ $this->customFieldOptionMap[$option['id']] = $key + 1;
+
// Write roles.
fwrite($this->file, $this->indentation." <roles>\n");
foreach ($roles as $role) {
fwrite($this->file, $this->indentation." </log>\n");
unset($records);
+ // Write custom fields.
+ fwrite($this->file, $this->indentation." <custom_fields>\n");
+ foreach ($custom_fields as $custom_field) {
+ $custom_field_part = $this->indentation.' '."<custom_field id=\"".$this->customFieldMap[$custom_field['id']]."\"";
+ $custom_field_part .= " type=\"".$custom_field['type']."\"";
+ $custom_field_part .= " label=\"".htmlentities($custom_field['label'])."\"";
+ $custom_field_part .= " required=\"".$custom_field['required']."\"";
+ $custom_field_part .= " status=\"".$custom_field['status']."\"";
+ $custom_field_part .= "></custom_field>\n";
+ fwrite($this->file, $custom_field_part);
+ }
+ fwrite($this->file, $this->indentation." </custom_fields>\n");
+ unset($custom_fields);
+
// Call self recursively for all subgroups.
foreach ($this->subgroups as $subgroup) {
$subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.' ');
import('ttProjectHelper');
import('ttClientHelper');
import('ttInvoiceHelper');
+import('ttCustomFieldHelper');
// ttOrgImportHelper - this class is a future replacement for ttImportHelper.
// Currently, it is work in progress.
var $currentGroupUserMap = array();
var $currentGroupInvoiceMap = array();
var $currentGroupLogMap = array();
+ var $currentGroupCustomFieldMap = array();
+ var $currentGroupCustomFieldOptionMap = array();
// Constructor.
function __construct(&$errors) {
$this->currentGroupLogMap[$attrs['ID']] = $log_item_id;
} else $this->errors->add($i18n->get('error.db'));
}
+
+ if ($name == 'CUSTOM_FIELDS') {
+ // If we get here, we have to recycle $currentGroupCustomFieldMap.
+ unset($this->currentGroupCustomFieldMap);
+ $this->currentGroupCustomFieldMap = array();
+ // Custom field map is reconstructed after processing <custom_field> elements in XML. See below.
+ }
+
+ if ($name == 'CUSTOM_FIELD') {
+ // We get here when processing <custom_field> tags for the current group.
+ $custom_field_id = ttCustomFieldHelper::insertField(array(
+ 'group_id' => $this->current_group_id,
+ // 'org_id' => $this->org_id, TODO: add this when org_id field is added to the table.
+ 'type' => $attrs['TYPE'],
+ 'label' => $attrs['LABEL'],
+ 'required' => $attrs['REQUIRED'],
+ 'status' => $attrs['STATUS']));
+ if ($custom_field_id) {
+ // Add a mapping.
+ $this->currentGroupCustomFieldMap[$attrs['ID']] = $custom_field_id;
+ } else $this->errors->add($i18n->get('error.db'));
+ }
}
}