private function handlePost() { $projects = array(); $trackers = array(); $statuses = array(); $priorities = array(); $categories = array(); $projectLines = preg_split("/[\r\n]/", $_POST["projects"], null, PREG_SPLIT_NO_EMPTY); foreach ($projectLines as $line) { $nameAndTitle = preg_split("/:\\s*/", $line, 2, PREG_SPLIT_NO_EMPTY); if (count($nameAndTitle) < 2) { $this->app->showBasicMessage(T_("Error: Project info line does not have name and title separated by colon (:).")); return; } $project = new \Spit\Models\Project(); $project->name = $nameAndTitle[0]; $project->title = $nameAndTitle[1]; $project->isPublic = true; array_push($projects, $project); } if (count($projects) == 0) { $this->app->showBasicMessage(T_("Error: No project names were provided.")); return; } $order = 0; $trackerParts = preg_split("/,\\s*/", $_POST["trackers"], null, PREG_SPLIT_NO_EMPTY); foreach ($trackerParts as $part) { $tracker = new \Spit\Models\Tracker(); $tracker->name = $part; // only temporary until we improve the setup form. $tracker->order = $order++; array_push($trackers, $tracker); } $order = 0; $priorityParts = preg_split("/,\\s*/", $_POST["priorities"], null, PREG_SPLIT_NO_EMPTY); foreach ($priorityParts as $part) { $priority = new \Spit\Models\Priority(); $priority->name = $part; // only temporary until we improve the setup form. $priority->order = $order++; $priority->isDefault = $part == "Normal"; array_push($priorities, $priority); } $order = 0; $statusParts = preg_split("/,\\s*/", $_POST["statuses"], null, PREG_SPLIT_NO_EMPTY); foreach ($statusParts as $part) { $status = new \Spit\Models\Status(); $status->name = $part; // only temporary until we improve the setup form. $status->order = $order++; $status->isDefault = $part == "New"; $status->closed = in_array($part, array("Fixed", "Invalid", "Duplicate")); array_push($statuses, $status); } $order = 0; $priorityParts = preg_split("/,\\s*/", $_POST["priorities"], null, PREG_SPLIT_NO_EMPTY); foreach ($priorityParts as $part) { $priority = new \Spit\Models\Priority(); $priority->name = $part; // only temporary until we improve the setup form. $priority->order = $order++; $priority->isDefault = $part == "Normal"; array_push($priorities, $priority); } $categoryParts = preg_split("/,\\s*/", $_POST["categories"], null, PREG_SPLIT_NO_EMPTY); foreach ($categoryParts as $part) { $category = new \Spit\Models\Category(); $category->name = $part; array_push($categories, $category); } // make the current user an admin since they're running the setup. $user = $this->app->security->user; $user->typeMask = \Spit\UserType::Newbie | \Spit\UserType::Member | \Spit\UserType::Manager | \Spit\UserType::Admin; $userDS = new \Spit\DataStores\UserDataStore(); $projectDS = new \Spit\DataStores\ProjectDataStore(); $trackerDS = new \Spit\DataStores\TrackerDataStore(); $priorityDS = new \Spit\DataStores\PriorityDataStore(); $statusDS = new \Spit\DataStores\StatusDataStore(); $categoryDS = new \Spit\DataStores\CategoryDataStore(); $userDS->update($user); $projectDS->insertMany($projects); $trackerDS->insertMany($trackers); $priorityDS->insertMany($priorities); $statusDS->insertMany($statuses); $categoryDS->insertMany($categories); // refresh page. since we are only sent here when there are no projects, // this should not cause an infinite loop. though there is still a risk // if we change the code outside this class, so maybe there is a better // approach to this... header("Location: ."); exit; }
private function getEditorFields($trackerId, $issue) { $fields = array(); $statusDataStore = new \Spit\DataStores\StatusDataStore(); $priorityDataStore = new \Spit\DataStores\PriorityDataStore(); $versionDataStore = new \Spit\DataStores\VersionDataStore(); $userDataStore = new \Spit\DataStores\UserDataStore(); $categoryDataStore = new \Spit\DataStores\CategoryDataStore(); $status = new SelectField("statusId", T_("Status")); $this->fillSelectField($status, $statusDataStore->get(), $issue->statusId); array_push($fields, $status); $priority = new SelectField("priorityId", T_("Priority")); $this->fillSelectField($priority, $priorityDataStore->get(), $issue->priorityId); array_push($fields, $priority); $category = new SelectField("categoryId", T_("Category")); $category->add(null, ""); $this->fillSelectField($category, $categoryDataStore->get(), $issue->categoryId); array_push($fields, $category); $found = new SelectField("foundId", T_("Found")); $found->add(null, ""); $this->fillSelectField($found, $versionDataStore->get(), $issue->foundId); array_push($fields, $found); $target = new SelectField("targetId", T_("Target")); $target->add(null, ""); $this->fillSelectField($target, $versionDataStore->get(), $issue->targetId); array_push($fields, $target); $assignee = new SelectField("assigneeId", T_("Assignee")); $assignee->add(null, ""); $this->fillSelectField($assignee, $userDataStore->getMembers(), $issue->assigneeId); array_push($fields, $assignee); $issueFields = new \Spit\IssueFields($this->app->project->name); foreach ($issueFields->getCustomFieldMap() as $name => $label) { $values = $issueFields->getCustomFieldValues($name); if (count($values) != 0) { $custom = new SelectField($name, $label); $custom->add(null, ""); foreach ($values as $value => $text) { $selected = isset($issue->{$name}) && $issue->{$name} == $value; $custom->add($value, $text, $selected); } } else { $custom = new TextField($name, $label); if (isset($issue->{$name})) { $custom->value = $issue->{$name}; } } array_push($fields, $custom); } return $issueFields->filter($fields, $trackerId, true); }