function assignTo($userId) { global $dbInst, $loginInst; if (!$loginInst->hasAccess("request.assignTo")) { return false; } $taskInst = new task(); $taskInst->subject = $this->subject; $taskInst->body = $this->body; $taskInst->projectId = $this->projectId; $taskInst->typeId = $this->typeId; $taskInst->priorityId = $this->priorityId; $taskInst->userId = $userId; $taskInst->statusId = TASK_STATUS_REQUEST; $taskInst->posterId = $loginInst->id; $taskInst->attachments = $this->attachments; $taskId = $taskInst->insert(); if (!$taskId) { return false; } // task saved successfully. Now whe can assign the attachments to the task id $taskInst->id = $taskId; while ($element = current($taskInst->attachments)) { $attachment = new attachment($element); $attachment->taskId = $taskId; $attachment->update(); next($taskInst->attachments); } // the attachments are now assigned to the task -> so we should // clean the attachment array in the request instance, to prevent // deleting of the attachments $this->attachments = array(); if ($this->delete()) { return $taskId; } return false; }