+
+ if ($name == 'USERS') {
+ // If we get here, we have to recycle $currentGroupUserMap.
+ unset($this->currentGroupUserMap);
+ $this->currentGroupUserMap = array();
+ // User map is reconstructed after processing <user> elements in XML. See below.
+ }
+
+ if ($name == 'USER') {
+ // We get here when processing <user> tags for the current group.
+
+ $role_id = $attrs['ROLE_ID'] === '0' ? $this->top_role_id : $this->currentGroupRoleMap[$attrs['ROLE_ID']]; // 0 (not null) means top manager role.
+
+ $user_id = ttUserHelper::insert(array(
+ 'group_id' => $this->current_group_id,
+ 'org_id' => $this->org_id,
+ 'role_id' => $role_id,
+ 'client_id' => $this->currentGroupClientMap[$attrs['CLIENT_ID']],
+ 'name' => $attrs['NAME'],
+ 'login' => $attrs['LOGIN'],
+ 'password' => $attrs['PASSWORD'],
+ 'rate' => $attrs['RATE'],
+ 'email' => $attrs['EMAIL'],
+ 'status' => $attrs['STATUS']), false);
+ if ($user_id) {
+ // Add a mapping.
+ $this->currentGroupUserMap[$attrs['ID']] = $user_id;
+ } else $this->errors->add($i18n->get('error.db'));
+ }
+
+ if ($name == 'USER_PROJECT_BIND') {
+ if (!ttUserHelper::insertBind(array(
+ 'user_id' => $this->currentGroupUserMap[$attrs['USER_ID']],
+ 'project_id' => $this->currentGroupProjectMap[$attrs['PROJECT_ID']],
+ 'group_id' => $this->current_group_id,
+ 'org_id' => $this->org_id,
+ 'rate' => $attrs['RATE'],
+ 'status' => $attrs['STATUS']))) {
+ $this->errors->add($i18n->get('error.db'));
+ }
+ }
+
+ if ($name == 'INVOICES') {
+ // If we get here, we have to recycle $currentGroupInvoiceMap.
+ unset($this->currentGroupInvoiceMap);
+ $this->currentGroupInvoiceMap = array();
+ // Invoice map is reconstructed after processing <invoice> elements in XML. See below.
+ }
+
+ if ($name == 'INVOICE') {
+ // We get here when processing <invoice> tags for the current group.
+ $invoice_id = ttInvoiceHelper::insert(array(
+ 'group_id' => $this->current_group_id,
+ 'org_id' => $this->org_id,
+ 'name' => $attrs['NAME'],
+ 'date' => $attrs['DATE'],
+ 'client_id' => $this->currentGroupClientMap[$attrs['CLIENT_ID']],
+ 'status' => $attrs['STATUS']));
+ if ($invoice_id) {
+ // Add a mapping.
+ $this->currentGroupInvoiceMap[$attrs['ID']] = $invoice_id;
+ } else $this->errors->add($i18n->get('error.db'));
+ }
+
+ if ($name == 'LOG') {
+ // If we get here, we have to recycle $currentGroupLogMap.
+ unset($this->currentGroupLogMap);
+ $this->currentGroupLogMap = array();
+ // Log map is reconstructed after processing <log_item> elements in XML. See below.
+ }
+
+ if ($name == 'LOG_ITEM') {
+ // We get here when processing <log_item> tags for the current group.
+ $log_item_id = ttTimeHelper::insert(array(
+ 'user_id' => $this->currentGroupUserMap[$attrs['USER_ID']],
+ 'group_id' => $this->current_group_id,
+ 'org_id' => $this->org_id,
+ 'date' => $attrs['DATE'],
+ 'start' => $attrs['START'],
+ 'finish' => $attrs['FINISH'],
+ 'duration' => $attrs['DURATION'],
+ 'client' => $this->currentGroupClientMap[$attrs['CLIENT_ID']],
+ 'project' => $this->currentGroupProjectMap[$attrs['PROJECT_ID']],
+ 'task' => $this->currentGroupTaskMap[$attrs['TASK_ID']],
+ 'invoice' => $this->currentGroupInvoiceMap[$attrs['INVOICE_ID']],
+ 'note' => (isset($attrs['COMMENT']) ? $attrs['COMMENT'] : ''),
+ 'billable' => $attrs['BILLABLE'],
+ 'paid' => $attrs['PAID'],
+ 'status' => $attrs['STATUS']));
+ if ($log_item_id) {
+ // Add a mapping.
+ $this->currentGroupLogMap[$attrs['ID']] = $log_item_id;
+ } else $this->errors->add($i18n->get('error.db'));
+ }