public function componentArchivedProjects() { if (!isset($this->target)) { $this->projects = entities\Project::getAllRootProjects(true); $this->project_count = count($this->projects); } elseif ($this->target == 'team') { $this->team = entities\Team::getB2DBTable()->selectById($this->id); $projects = array(); foreach (entities\Project::getAllByOwner($this->team) as $project) { $projects[$project->getID()] = $project; } foreach (entities\Project::getAllByLeader($this->team) as $project) { $projects[$project->getID()] = $project; } foreach (entities\Project::getAllByQaResponsible($this->team) as $project) { $projects[$project->getID()] = $project; } foreach ($this->team->getAssociatedProjects() as $project_id => $project) { $projects[$project_id] = $project; } $final_projects = array(); foreach ($projects as $project) { if ($project->isArchived()) { $final_projects[] = $project; } } $this->projects = $final_projects; } elseif ($this->target == 'client') { $this->client = entities\Client::getB2DBTable()->selectById($this->id); $projects = entities\Project::getAllByClientID($this->client->getID()); $final_projects = array(); foreach ($projects as $project) { if (!$project->isArchived()) { $final_projects[] = $project; } } $this->projects = $final_projects; } elseif ($this->target == 'project') { $this->parent = entities\Project::getB2DBTable()->selectById($this->id); $this->projects = $this->parent->getChildren(true); } $this->project_count = count($this->projects); }
?> class="selected"<?php } ?> > <div class="menuitem_container"> <?php echo link_tag('javascript:void(0)', image_tag('tab_clients.png') . __('Clients'), array('class' => 'not_clickable')); ?> <?php echo javascript_link_tag(image_tag('tabmenu_dropdown.png', array('class' => 'menu_dropdown')), array('onmouseover' => "")); ?> </div> <div id="client_menu" class="tab_menu_dropdown"> <?php foreach (\thebuggenie\core\entities\Client::getAll() as $client) { ?> <?php if (!$client->hasAccess()) { continue; } ?> <?php echo link_tag(make_url('client_dashboard', array('client_id' => $client->getID())), image_tag('tab_clients.png') . $client->getName()); ?> <?php } ?> </div> </li> <?php
/** * Add this user to a client * * @param \thebuggenie\core\entities\Client $client */ public function addToClient(\thebuggenie\core\entities\Client $client) { $client->addMember($this); $this->clients = null; }
/** * Configure project settings * * @param framework\Request $request The request object */ public function runConfigureProjectSettings(framework\Request $request) { if ($request->isPost()) { $this->forward403unless($this->getUser()->canEditProjectDetails($this->selected_project), framework\Context::getI18n()->__('You do not have access to update these settings')); $release_date = null; if ($request['has_release_date']) { $release_date = mktime(0, 0, 1, $request['release_month'], $request['release_day'], $request['release_year']); } $this->selected_project->setReleaseDate($release_date); $old_key = $this->selected_project->getKey(); if ($request->hasParameter('project_name')) { if (trim($request['project_name']) == '') { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Please specify a valid project name'))); } else { $this->selected_project->setName($request['project_name']); } } $message = $old_key != $this->selected_project->getKey() ? framework\Context::getI18n()->__('%IMPORTANT: The project key has changed. Remember to replace the current url with the new project key', array('%IMPORTANT' => '<b>' . framework\Context::getI18n()->__('IMPORTANT') . '</b>')) : ''; if ($request->hasParameter('project_key')) { $this->selected_project->setKey($request['project_key']); } if ($request->hasParameter('use_prefix')) { $this->selected_project->setUsePrefix((bool) $request['use_prefix']); } if ($request->hasParameter('use_prefix') && $this->selected_project->doesUsePrefix()) { if (!$this->selected_project->setPrefix($request['prefix'])) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__("Project prefixes may only contain letters and numbers"))); } } if ($request->hasParameter('client')) { if ($request['client'] == 0) { $this->selected_project->setClient(null); } else { $this->selected_project->setClient(entities\Client::getB2DBTable()->selectById($request['client'])); } } if ($request->hasParameter('subproject_id')) { if ($request['subproject_id'] == 0) { $this->selected_project->clearParent(); } else { $this->selected_project->setParent(entities\Project::getB2DBTable()->selectById($request['subproject_id'])); } } if ($request->hasParameter('workflow_scheme')) { try { $workflow_scheme = entities\WorkflowScheme::getB2DBTable()->selectById($request['workflow_scheme']); $this->selected_project->setWorkflowScheme($workflow_scheme); } catch (\Exception $e) { } } if ($request->hasParameter('issuetype_scheme')) { try { $issuetype_scheme = entities\IssuetypeScheme::getB2DBTable()->selectById($request['issuetype_scheme']); $this->selected_project->setIssuetypeScheme($issuetype_scheme); } catch (\Exception $e) { } } if ($request->hasParameter('use_scrum')) { $this->selected_project->setUsesScrum((bool) $request['use_scrum']); } if ($request->hasParameter('description')) { $this->selected_project->setDescription($request->getParameter('description', null, false)); } if ($request->hasParameter('homepage')) { $this->selected_project->setHomepage($request['homepage']); } if ($request->hasParameter('doc_url')) { $this->selected_project->setDocumentationURL($request['doc_url']); } if ($request->hasParameter('wiki_url')) { $this->selected_project->setWikiURL($request['wiki_url']); } if ($request->hasParameter('released')) { $this->selected_project->setReleased((int) $request['released']); } if ($request->hasParameter('locked')) { $this->selected_project->setLocked((bool) $request['locked']); } if ($request->hasParameter('enable_builds')) { $this->selected_project->setBuildsEnabled((bool) $request['enable_builds']); } if ($request->hasParameter('enable_editions')) { $this->selected_project->setEditionsEnabled((bool) $request['enable_editions']); } if ($request->hasParameter('enable_components')) { $this->selected_project->setComponentsEnabled((bool) $request['enable_components']); } if ($request->hasParameter('allow_changing_without_working')) { $this->selected_project->setChangeIssuesWithoutWorkingOnThem((bool) $request['allow_changing_without_working']); } if ($request->hasParameter('allow_autoassignment')) { $this->selected_project->setAutoassign((bool) $request['allow_autoassignment']); } $this->selected_project->save(); return $this->renderJSON(array('message' => $this->getI18n()->__('Settings saved'))); } }
<label for="client_<?php echo $user->getID(); ?> _<?php echo $client->getID(); ?> " style="font-weight: normal;"><?php echo $client->getName(); ?> </label> </div> <?php } ?> <?php if (count(\thebuggenie\core\entities\Client::getAll()) == 0) { ?> <?php echo __('No clients exist'); ?> <?php } ?> </td> </tr> <tr> <td colspan="4" style="text-align: right; font-size: 13px; padding-top: 10px;"> <div style="padding: 10px 0 10px 0; display: none;" id="edit_user_<?php echo $user->getID(); ?> _indicator"><span style="float: left;"><?php
protected function _processChanges() { $related_issues_to_save = array(); $changed_properties = $this->_getChangedProperties(); if (count($changed_properties)) { $is_saved_estimated = false; $is_saved_spent = false; $is_saved_assignee = false; $is_saved_owner = false; foreach ($changed_properties as $property => $value) { $compare_value = is_object($this->{$property}) ? $this->{$property}->getID() : $this->{$property}; $original_value = $value['original_value']; if ($original_value != $compare_value) { switch ($property) { case '_title': $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_TITLE, framework\Context::getI18n()->__("Title updated"), $original_value, $compare_value); break; case '_shortname': $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_SHORTNAME, framework\Context::getI18n()->__("Issue label updated"), $original_value, $compare_value); break; case '_description': $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_DESCRIPTION, framework\Context::getI18n()->__("Description updated"), $original_value, $compare_value); break; case '_reproduction_steps': $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_REPRODUCTIONSTEPS, framework\Context::getI18n()->__("Reproduction steps updated"), $original_value, $compare_value); break; case '_category': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Category::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Not determined'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getCategory() instanceof Datatype ? $this->getCategory()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_CATEGORY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_pain_bug_type': if ($original_value != 0) { $old_name = ($old_item = self::getPainTypesOrLabel('pain_bug_type', $original_value)) ? $old_item : framework\Context::getI18n()->__('Not determined'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = ($new_item = self::getPainTypesOrLabel('pain_bug_type', $value['current_value'])) ? $new_item : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_BUG_TYPE, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_pain_effect': if ($original_value != 0) { $old_name = ($old_item = self::getPainTypesOrLabel('pain_effect', $original_value)) ? $old_item : framework\Context::getI18n()->__('Not determined'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = ($new_item = self::getPainTypesOrLabel('pain_effect', $value['current_value'])) ? $new_item : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_EFFECT, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_pain_likelihood': if ($original_value != 0) { $old_name = ($old_item = self::getPainTypesOrLabel('pain_likelihood', $original_value)) ? $old_item : framework\Context::getI18n()->__('Not determined'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = ($new_item = self::getPainTypesOrLabel('pain_likelihood', $value['current_value'])) ? $new_item : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_LIKELIHOOD, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_user_pain': $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_CALCULATED, $original_value . ' ⇒ ' . $value['current_value']); break; case '_status': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Status::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getStatus() instanceof Datatype ? $this->getStatus()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_STATUS, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_reproducability': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Reproducability::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getReproducability() instanceof Datatype ? $this->getReproducability()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_REPRODUCABILITY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_priority': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Priority::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getPriority() instanceof Datatype ? $this->getPriority()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_PRIORITY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_assignee_team': case '_assignee_user': if (!$is_saved_assignee) { $new_name = $this->getAssignee() instanceof \thebuggenie\core\entities\common\Identifiable ? $this->getAssignee()->getName() : framework\Context::getI18n()->__('Not assigned'); if ($this->getAssignee() instanceof \thebuggenie\core\entities\User) { $this->startWorkingOnIssue($this->getAssignee()); } $this->addLogEntry(tables\Log::LOG_ISSUE_ASSIGNED, $new_name); $is_saved_assignee = true; } break; case '_posted_by': $old_identifiable = $original_value ? \thebuggenie\core\entities\User::getB2DBTable()->selectById($original_value) : framework\Context::getI18n()->__('Unknown'); $old_name = $old_identifiable instanceof \thebuggenie\core\entities\User ? $old_identifiable->getName() : framework\Context::getI18n()->__('Unknown'); $new_name = $this->getPostedBy()->getName(); $this->addLogEntry(tables\Log::LOG_ISSUE_POSTED, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_being_worked_on_by_user': if ($original_value != 0) { $old_identifiable = \thebuggenie\core\entities\User::getB2DBTable()->selectById($original_value); $old_name = $old_identifiable instanceof \thebuggenie\core\entities\User ? $old_identifiable->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not being worked on'); } $new_name = $this->getUserWorkingOnIssue() instanceof \thebuggenie\core\entities\User ? $this->getUserWorkingOnIssue()->getName() : framework\Context::getI18n()->__('Not being worked on'); $this->addLogEntry(tables\Log::LOG_ISSUE_USERS, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_owner_team': case '_owner_user': if (!$is_saved_owner) { $new_name = $this->getOwner() instanceof \thebuggenie\core\entities\common\Identifiable ? $this->getOwner()->getName() : framework\Context::getI18n()->__('Not owned by anyone'); $this->addLogEntry(tables\Log::LOG_ISSUE_OWNED, $new_name); $is_saved_owner = true; } break; case '_percent_complete': $this->addLogEntry(tables\Log::LOG_ISSUE_PERCENT, $original_value . '% ⇒ ' . $this->getPercentCompleted() . '', $original_value, $compare_value); break; case '_resolution': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Resolution::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getResolution() instanceof Datatype ? $this->getResolution()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_RESOLUTION, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_severity': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Severity::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getSeverity() instanceof Datatype ? $this->getSeverity()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_SEVERITY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_milestone': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Milestone::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Not determined'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getMilestone() instanceof \thebuggenie\core\entities\Milestone ? $this->getMilestone()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_MILESTONE, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); $this->_milestone_order = 0; break; case '_issuetype': if ($original_value != 0) { $old_name = ($old_item = Issuetype::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Unknown'); } $new_name = $this->getIssuetype() instanceof \thebuggenie\core\entities\Issuetype ? $this->getIssuetype()->getName() : framework\Context::getI18n()->__('Unknown'); $this->addLogEntry(tables\Log::LOG_ISSUE_ISSUETYPE, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_estimated_months': case '_estimated_weeks': case '_estimated_days': case '_estimated_hours': case '_estimated_points': if (!$is_saved_estimated) { $old_time = array('months' => $this->getChangedPropertyOriginal('_estimated_months'), 'weeks' => $this->getChangedPropertyOriginal('_estimated_weeks'), 'days' => $this->getChangedPropertyOriginal('_estimated_days'), 'hours' => $this->getChangedPropertyOriginal('_estimated_hours'), 'points' => $this->getChangedPropertyOriginal('_estimated_points')); $old_formatted_time = array_sum($old_time) > 0 ? Issue::getFormattedTime($old_time) : framework\Context::getI18n()->__('Not estimated'); $new_formatted_time = $this->hasEstimatedTime() ? Issue::getFormattedTime($this->getEstimatedTime()) : framework\Context::getI18n()->__('Not estimated'); $this->addLogEntry(tables\Log::LOG_ISSUE_TIME_ESTIMATED, $old_formatted_time . ' ⇒ ' . $new_formatted_time, serialize($old_time), serialize($this->getEstimatedTime())); $is_saved_estimated = true; } break; case '_spent_months': case '_spent_weeks': case '_spent_days': case '_spent_hours': case '_spent_points': if (!$is_saved_spent) { $old_time = array('months' => $this->getChangedPropertyOriginal('_spent_months'), 'weeks' => $this->getChangedPropertyOriginal('_spent_weeks'), 'days' => $this->getChangedPropertyOriginal('_spent_days'), 'hours' => round($this->getChangedPropertyOriginal('_spent_hours') / 100, 2), 'points' => $this->getChangedPropertyOriginal('_spent_points')); $old_formatted_time = array_sum($old_time) > 0 ? Issue::getFormattedTime($old_time) : framework\Context::getI18n()->__('No time spent'); $new_formatted_time = $this->hasSpentTime() ? Issue::getFormattedTime($this->getSpentTime()) : framework\Context::getI18n()->__('No time spent'); $this->addLogEntry(tables\Log::LOG_ISSUE_TIME_SPENT, $old_formatted_time . ' ⇒ ' . $new_formatted_time, serialize($old_time), serialize($this->getSpentTime())); $is_saved_spent = true; } break; case '_state': if ($this->isClosed()) { $this->addLogEntry(tables\Log::LOG_ISSUE_CLOSE); if ($this->getMilestone() instanceof \thebuggenie\core\entities\Milestone) { if ($this->getMilestone()->isSprint()) { if (!$this->getIssueType()->isTask()) { $this->setSpentPoints($this->getEstimatedPoints()); } else { if ($this->getSpentHours() < $this->getEstimatedHours()) { $this->setSpentHours($this->getEstimatedHours()); } foreach ($this->getParentIssues() as $parent_issue) { if ($parent_issue->checkTaskStates()) { $related_issues_to_save[$parent_issue->getID()] = true; } } } } $this->getMilestone()->updateStatus(); $this->getMilestone()->save(); } } else { $this->addLogEntry(tables\Log::LOG_ISSUE_REOPEN); } break; case '_blocking': if ($this->isBlocking()) { $this->addLogEntry(tables\Log::LOG_ISSUE_BLOCKED); } else { $this->addLogEntry(tables\Log::LOG_ISSUE_UNBLOCKED); } break; default: if (mb_substr($property, 0, 12) == '_customfield') { $key = mb_substr($property, 12); $customdatatype = CustomDatatype::getByKey($key); switch ($customdatatype->getType()) { case CustomDatatype::INPUT_TEXT: $new_value = $this->getCustomField($key) != '' ? $this->getCustomField($key) : framework\Context::getI18n()->__('Unknown'); $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $new_value, $original_value, $compare_value); break; case CustomDatatype::INPUT_TEXTAREA_SMALL: case CustomDatatype::INPUT_TEXTAREA_MAIN: $new_value = $this->getCustomField($key) != '' ? $this->getCustomField($key) : framework\Context::getI18n()->__('Unknown'); $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $new_value, $original_value, $compare_value); break; case CustomDatatype::EDITIONS_CHOICE: case CustomDatatype::COMPONENTS_CHOICE: case CustomDatatype::RELEASES_CHOICE: case CustomDatatype::MILESTONE_CHOICE: case CustomDatatype::STATUS_CHOICE: case CustomDatatype::TEAM_CHOICE: case CustomDatatype::USER_CHOICE: case CustomDatatype::CLIENT_CHOICE: $old_object = null; $new_object = null; try { switch ($customdatatype->getType()) { case CustomDatatype::EDITIONS_CHOICE: $old_object = Edition::getB2DBTable()->selectById($original_value); break; case CustomDatatype::COMPONENTS_CHOICE: $old_object = Component::getB2DBTable()->selectById($original_value); break; case CustomDatatype::RELEASES_CHOICE: $old_object = Build::getB2DBTable()->selectById($original_value); break; case CustomDatatype::MILESTONE_CHOICE: $old_object = Milestone::getB2DBTable()->selectById($original_value); break; case CustomDatatype::STATUS_CHOICE: $old_object = Status::getB2DBTable()->selectById($original_value); break; case CustomDatatype::TEAM_CHOICE: $old_object = Team::getB2DBTable()->selectById($original_value); break; case CustomDatatype::USER_CHOICE: $old_object = User::getB2DBTable()->selectById($original_value); break; case CustomDatatype::CLIENT_CHOICE: $old_object = Client::getB2DBTable()->selectById($original_value); break; } } catch (\Exception $e) { } try { switch ($customdatatype->getType()) { case CustomDatatype::EDITIONS_CHOICE: case CustomDatatype::COMPONENTS_CHOICE: case CustomDatatype::RELEASES_CHOICE: case CustomDatatype::MILESTONE_CHOICE: case CustomDatatype::STATUS_CHOICE: case CustomDatatype::TEAM_CHOICE: case CustomDatatype::USER_CHOICE: case CustomDatatype::CLIENT_CHOICE: $new_object = $this->getCustomField($key); break; } } catch (\Exception $e) { } $old_value = is_object($old_object) ? $old_object->getName() : framework\Context::getI18n()->__('Unknown'); $new_value = is_object($new_object) ? $new_object->getName() : framework\Context::getI18n()->__('Unknown'); $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $old_value . ' ⇒ ' . $new_value, $original_value, $compare_value); break; default: $old_item = null; try { $old_item = $original_value ? new CustomDatatypeOption($original_value) : null; } catch (\Exception $e) { } $old_value = $old_item instanceof \thebuggenie\core\entities\CustomDatatypeOption ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); $new_value = $this->getCustomField($key) instanceof \thebuggenie\core\entities\CustomDatatypeOption ? $this->getCustomField($key)->getName() : framework\Context::getI18n()->__('Unknown'); $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $old_value . ' ⇒ ' . $new_value, $original_value, $compare_value); break; } } break; } } } if ($is_saved_estimated) { tables\IssueEstimates::getTable()->saveEstimate($this->getID(), $this->_estimated_months, $this->_estimated_weeks, $this->_estimated_days, $this->_estimated_hours, $this->_estimated_points); } } return $related_issues_to_save; }
public function runEditClient(framework\Request $request) { try { try { $client = entities\Client::getB2DBTable()->selectById($request['client_id']); } catch (\Exception $e) { } if (!$client instanceof entities\Client) { throw new \Exception($this->getI18n()->__("You cannot edit this client")); } if (entities\Client::doesClientNameExist(trim($request['client_name'])) && strtolower($request['client_name']) != strtolower($client->getName())) { throw new \Exception($this->getI18n()->__("Please enter a client name that doesn't already exist")); } $client->setName($request['client_name']); $client->setEmail($request['client_email']); $client->setWebsite($request['client_website']); $client->setTelephone($request['client_telephone']); $client->setFax($request['client_fax']); $client->save(); return $this->renderJSON(array('success' => true, 'content' => $this->getComponentHTML('configuration/clientbox', array('client' => $client)), 'message' => $this->getI18n()->__('The client was saved'))); } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $e->getMessage())); } }
public function getPredefinedBreadcrumbLinks($type, $project = null) { $i18n = Context::getI18n(); $links = array(); switch ($type) { case 'main_links': $links[] = array('url' => Context::getRouting()->generate('home'), 'title' => $i18n->__('Frontpage')); $links[] = array('url' => Context::getRouting()->generate('dashboard'), 'title' => $i18n->__('Personal dashboard')); $links[] = array('title' => $i18n->__('Issues')); $links[] = array('title' => $i18n->__('Teams')); $links[] = array('title' => $i18n->__('Clients')); $links = Event::createNew('core', 'breadcrumb_main_links', null, array(), $links)->trigger()->getReturnList(); if (Context::getUser()->canAccessConfigurationPage()) { $links[] = array('url' => make_url('configure'), 'title' => $i18n->__('Configure %sitename', array('%sitename' => Settings::getSiteHeaderName()))); } $links[] = array('url' => Context::getRouting()->generate('about'), 'title' => $i18n->__('About %sitename', array('%sitename' => Settings::getSiteHeaderName()))); $links[] = array('url' => Context::getRouting()->generate('account'), 'title' => $i18n->__('Account details')); break; case 'project_summary': $links['project_dashboard'] = array('url' => Context::getRouting()->generate('project_dashboard', array('project_key' => $project->getKey())), 'title' => $i18n->__('Dashboard')); $links['project_releases'] = array('url' => Context::getRouting()->generate('project_release_center', array('project_key' => $project->getKey())), 'title' => $i18n->__('Releases')); $links['project_roadmap'] = array('url' => Context::getRouting()->generate('project_roadmap', array('project_key' => $project->getKey())), 'title' => $i18n->__('Roadmap')); $links['project_team'] = array('url' => Context::getRouting()->generate('project_team', array('project_key' => $project->getKey())), 'title' => $i18n->__('Team overview')); $links['project_statistics'] = array('url' => Context::getRouting()->generate('project_statistics', array('project_key' => $project->getKey())), 'title' => $i18n->__('Statistics')); $links['project_timeline'] = array('url' => Context::getRouting()->generate('project_timeline', array('project_key' => $project->getKey())), 'title' => $i18n->__('Timeline')); $links['project_issues'] = array('url' => Context::getRouting()->generate('project_issues', array('project_key' => $project->getKey())), 'title' => $i18n->__('Issues')); $links = Event::createNew('core', 'breadcrumb_project_links', null, array(), $links)->trigger()->getReturnList(); $links['project_release_center'] = array('url' => Context::getRouting()->generate('project_release_center', array('project_key' => $project->getKey())), 'title' => $i18n->__('Release center')); $links['project_settings'] = array('url' => Context::getRouting()->generate('project_settings', array('project_key' => $project->getKey())), 'title' => $i18n->__('Settings')); break; case 'client_list': foreach (\thebuggenie\core\entities\Client::getAll() as $client) { if ($client->hasAccess()) { $links[] = array('url' => Context::getRouting()->generate('client_dashboard', array('client_id' => $client->getID())), 'title' => $client->getName()); } } break; case 'team_list': foreach (\thebuggenie\core\entities\Team::getAll() as $team) { if ($team->hasAccess()) { $links[] = array('url' => Context::getRouting()->generate('team_dashboard', array('team_id' => $team->getID())), 'title' => $team->getName()); } } break; } return $links; }
/** * Partial backdrop loader * * @Route(name="get_partial_for_backdrop", url="/get/partials/:key/*") * @AnonymousRoute * * @param framework\Request $request * * @return bool */ public function runGetBackdropPartial(framework\Request $request) { if (!$request->isAjaxCall()) { return $this->return404($this->getI18n()->__('You need to enable javascript for The Bug Genie to work properly')); } try { $template_name = null; if ($request->hasParameter('issue_id')) { $issue = entities\Issue::getB2DBTable()->selectById($request['issue_id']); $options = array('issue' => $issue); } else { $options = array(); } switch ($request['key']) { case 'usercard': $template_name = 'main/usercard'; if ($user_id = $request['user_id']) { $user = entities\User::getB2DBTable()->selectById($user_id); $options['user'] = $user; } break; case 'login': $template_name = 'main/loginpopup'; $options = $request->getParameters(); $options['content'] = $this->getComponentHTML('login', array('section' => $request->getParameter('section', 'login'))); $options['mandatory'] = false; break; case 'uploader': $template_name = 'main/uploader'; $options = $request->getParameters(); $options['uploader'] = $request['uploader'] == 'dynamic' ? 'dynamic' : 'standard'; break; case 'attachlink': $template_name = 'main/attachlink'; break; case 'openid': $template_name = 'main/openid'; break; case 'notifications': $template_name = 'main/notifications'; $options['first_notification_id'] = $request['first_notification_id']; $options['last_notification_id'] = $request['last_notification_id']; break; case 'workflow_transition': $transition = entities\WorkflowTransition::getB2DBTable()->selectById($request['transition_id']); $template_name = $transition->getTemplate(); $options['transition'] = $transition; if ($request->hasParameter('issue_ids')) { $options['issues'] = array(); foreach ($request['issue_ids'] as $issue_id) { $options['issues'][$issue_id] = new entities\Issue($issue_id); } } else { $options['issue'] = new entities\Issue($request['issue_id']); } $options['show'] = true; $options['interactive'] = true; $options['project'] = $this->selected_project; break; case 'reportissue': $this->_loadSelectedProjectAndIssueTypeFromRequestForReportIssueAction($request); if ($this->selected_project instanceof entities\Project && !$this->selected_project->isLocked() && $this->getUser()->canReportIssues($this->selected_project)) { $template_name = 'main/reportissuecontainer'; $options['selected_project'] = $this->selected_project; $options['selected_issuetype'] = $this->selected_issuetype; $options['locked_issuetype'] = $this->locked_issuetype; $options['selected_milestone'] = $this->_getMilestoneFromRequest($request); $options['parent_issue'] = $this->_getParentIssueFromRequest($request); $options['board'] = $this->_getBoardFromRequest($request); $options['selected_build'] = $this->_getBuildFromRequest($request); $options['issuetypes'] = $this->issuetypes; $options['errors'] = array(); } else { throw new \Exception($this->getI18n()->__('You are not allowed to do this')); } break; case 'move_issue': $template_name = 'main/moveissue'; $options['multi'] = (bool) $request->getParameter('multi', false); break; case 'issue_permissions': $template_name = 'main/issuepermissions'; break; case 'issue_subscribers': $template_name = 'main/issuesubscribers'; break; case 'issue_spenttimes': $template_name = 'main/issuespenttimes'; $options['initial_view'] = $request->getParameter('initial_view', 'list'); break; case 'issue_spenttime': $template_name = 'main/issuespenttime'; $options['entry_id'] = $request->getParameter('entry_id'); break; case 'relate_issue': $template_name = 'main/relateissue'; break; case 'project_build': $template_name = 'project/build'; $options['project'] = entities\Project::getB2DBTable()->selectById($request['project_id']); if ($request->hasParameter('build_id')) { $options['build'] = entities\Build::getB2DBTable()->selectById($request['build_id']); } break; case 'project_icons': $template_name = 'project/projecticons'; $options['project'] = entities\Project::getB2DBTable()->selectById($request['project_id']); break; case 'project_workflow': $template_name = 'project/projectworkflow'; $options['project'] = entities\Project::getB2DBTable()->selectById($request['project_id']); break; case 'permissions': $options['key'] = $request['permission_key']; $target_module = $request['target_module'] !== 'core' ? $request['target_module'] : null; if ($details = framework\Context::getPermissionDetails($options['key'], null, $target_module)) { $template_name = 'configuration/permissionspopup'; $options['mode'] = $request['mode']; $options['module'] = $request['target_module']; $options['target_id'] = $request['target_id']; $options['item_name'] = $details['description']; $options['access_level'] = $request['access_level']; } break; case 'issuefield_permissions': $options['item_key'] = $request['item_key']; if ($details = framework\Context::getPermissionDetails($options['item_key'])) { $template_name = 'configuration/issuefieldpermissions'; $options['item_name'] = $details['description']; $options['item_id'] = $request['item_id']; $options['access_level'] = $request['access_level']; } break; case 'site_icons': $template_name = 'configuration/siteicons'; break; case 'project_config': $template_name = 'project/projectconfig_container'; $project = entities\Project::getB2DBTable()->selectById($request['project_id']); $options['project'] = $project; $options['section'] = $request->getParameter('section', 'info'); if ($request->hasParameter('edition_id')) { $edition = entities\Edition::getB2DBTable()->selectById($request['edition_id']); $options['edition'] = $edition; $options['selected_section'] = $request->getParameter('section', 'general'); } break; case 'issue_add_item': $issue = entities\Issue::getB2DBTable()->selectById($request['issue_id']); $template_name = 'main/issueadditem'; break; case 'client_users': $options['client'] = entities\Client::getB2DBTable()->selectById($request['client_id']); $template_name = 'main/clientusers'; break; case 'dashboard_config': $template_name = 'main/dashboardconfig'; $options['tid'] = $request['tid']; $options['target_type'] = $request['target_type']; $options['previous_route'] = $request['previous_route']; $options['mandatory'] = true; break; case 'archived_projects': $template_name = 'main/archivedprojects'; $options['mandatory'] = true; break; case 'team_archived_projects': $template_name = 'main/archivedprojects'; $options['target'] = 'team'; $options['id'] = $request['tid']; $options['mandatory'] = true; break; case 'client_archived_projects': $template_name = 'main/archivedprojects'; $options['target'] = 'client'; $options['id'] = $request['cid']; $options['mandatory'] = true; break; case 'project_archived_projects': $template_name = 'main/archivedprojects'; $options['target'] = 'project'; $options['id'] = $request['pid']; $options['mandatory'] = true; break; case 'bulk_workflow': $template_name = 'search/bulkworkflow'; $options['issue_ids'] = $request['issue_ids']; break; case 'confirm_username': $template_name = 'main/confirmusername'; $options['username'] = $request['username']; break; case 'add_dashboard_view': $template_name = 'main/adddashboardview'; break; case 'userscopes': if (!framework\Context::getScope()->isDefault()) { throw new \Exception($this->getI18n()->__('This is not allowed outside the default scope')); } $template_name = 'configuration/userscopes'; $options['user'] = new entities\User((int) $request['user_id']); break; case 'milestone': $template_name = 'project/milestone'; $options['project'] = \thebuggenie\core\entities\tables\Projects::getTable()->selectById($request['project_id']); if ($request->hasParameter('milestone_id')) { $options['milestone'] = \thebuggenie\core\entities\tables\Milestones::getTable()->selectById($request['milestone_id']); } break; default: $event = new \thebuggenie\core\framework\Event('core', 'get_backdrop_partial', $request['key']); $event->triggerUntilProcessed(); $options = $event->getReturnList(); $template_name = $event->getReturnValue(); } if ($template_name !== null) { return $this->renderJSON(array('content' => $this->getComponentHTML($template_name, $options))); } } catch (\Exception $e) { $this->getResponse()->cleanBuffer(); $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('An error occured: %error_message', array('%error_message' => $e->getMessage())))); } $this->getResponse()->cleanBuffer(); $this->getResponse()->setHttpStatus(400); $error = framework\Context::isDebugMode() ? framework\Context::getI18n()->__('Invalid template or parameter') : $this->getI18n()->__('Could not show the requested popup'); return $this->renderJSON(array('error' => $error)); }
public function getPredefinedBreadcrumbLinks($type, $project = null) { $i18n = Context::getI18n(); $links = array(); switch ($type) { case 'main_links': $links[] = array('url' => Context::getRouting()->generate('home'), 'title' => $i18n->__('Frontpage')); $links[] = array('url' => Context::getRouting()->generate('dashboard'), 'title' => $i18n->__('Personal dashboard')); $links[] = array('title' => $i18n->__('Issues')); if (Context::getUser()->hasPageAccess('teamlist')) { $links[] = array('url' => make_url('team_list'), 'title' => $i18n->__('Teams')); } if (Context::getUser()->hasPageAccess('clientlist')) { $links[] = array('url' => make_url('client_list'), 'title' => $i18n->__('Clients')); } $links = Event::createNew('core', 'breadcrumb_main_links', null, array(), $links)->trigger()->getReturnList(); if (Context::getUser()->canAccessConfigurationPage()) { $links[] = array('url' => make_url('configure'), 'title' => $i18n->__('Configure %sitename', array('%sitename' => Settings::getSiteHeaderName()))); } $links[] = array('url' => Context::getRouting()->generate('about'), 'title' => $i18n->__('About %sitename', array('%sitename' => Settings::getSiteHeaderName()))); $links[] = array('url' => Context::getRouting()->generate('account'), 'title' => $i18n->__('Account details')); $root_projects = array_merge(\thebuggenie\core\entities\Project::getAllRootProjects(true), \thebuggenie\core\entities\Project::getAllRootProjects(false)); $first = true; foreach ($root_projects as $project) { if (!$project->hasAccess()) { continue; } if ($first) { $first = false; $links[] = array('separator' => true); } $links[] = array('url' => Context::getRouting()->generate('project_dashboard', array('project_key' => $project->getKey())), 'title' => $project->getName()); } break; case 'project_summary': $links['project_dashboard'] = array('url' => Context::getRouting()->generate('project_dashboard', array('project_key' => $project->getKey())), 'title' => $i18n->__('Dashboard')); $links['project_releases'] = array('url' => Context::getRouting()->generate('project_releases', array('project_key' => $project->getKey())), 'title' => $i18n->__('Releases')); $links['project_roadmap'] = array('url' => Context::getRouting()->generate('project_roadmap', array('project_key' => $project->getKey())), 'title' => $i18n->__('Roadmap')); $links['project_team'] = array('url' => Context::getRouting()->generate('project_team', array('project_key' => $project->getKey())), 'title' => $i18n->__('Team overview')); $links['project_statistics'] = array('url' => Context::getRouting()->generate('project_statistics', array('project_key' => $project->getKey())), 'title' => $i18n->__('Statistics')); $links['project_timeline'] = array('url' => Context::getRouting()->generate('project_timeline', array('project_key' => $project->getKey())), 'title' => $i18n->__('Timeline')); $links['project_issues'] = array('url' => Context::getRouting()->generate('project_issues', array('project_key' => $project->getKey())), 'title' => $i18n->__('Issues')); $links = Event::createNew('core', 'breadcrumb_project_links', null, array(), $links)->trigger()->getReturnList(); $links['project_release_center'] = array('url' => Context::getRouting()->generate('project_release_center', array('project_key' => $project->getKey())), 'title' => $i18n->__('Release center')); $links['project_settings'] = array('url' => Context::getRouting()->generate('project_settings', array('project_key' => $project->getKey())), 'title' => $i18n->__('Settings')); break; case 'client_list': foreach (\thebuggenie\core\entities\Client::getAll() as $client) { if ($client->hasAccess()) { $links[] = array('url' => Context::getRouting()->generate('client_dashboard', array('client_id' => $client->getID())), 'title' => $client->getName()); } } break; case 'team_list': foreach (\thebuggenie\core\entities\Team::getAll() as $team) { if ($team->hasAccess()) { $links[] = array('url' => Context::getRouting()->generate('team_dashboard', array('team_id' => $team->getID())), 'title' => $team->getName()); } } break; case 'configure': $config_sections = Settings::getConfigSections($i18n); foreach ($config_sections as $key => $sections) { foreach ($sections as $section) { if ($key == Settings::CONFIGURATION_SECTION_MODULES) { $url = is_array($section['route']) ? make_url($section['route'][0], $section['route'][1]) : make_url($section['route']); $links[] = array('url' => $url, 'title' => $section['description']); } else { $links[] = array('url' => make_url($section['route']), 'title' => $section['description']); } } } break; } return $links; }
public function runDoImportCSV(framework\Request $request) { try { if ($request['csv_data'] == '') { throw new \Exception($this->getI18n()->__('No data supplied to import')); } $csv = str_replace("\r\n", "\n", $request['csv_data']); $csv = html_entity_decode($csv); $headerrow = null; $data = array(); $errors = array(); // Parse CSV $handle = fopen("php://memory", 'r+'); fputs($handle, $csv); rewind($handle); $i = 0; while (($row = fgetcsv($handle, 1000)) !== false) { if (!$headerrow) { $headerrow = $row; } else { if (count($headerrow) == count($row)) { $data[] = array_combine($headerrow, $row); } else { $errors[] = $this->getI18n()->__('Row %row does not have the same number of elements as the header row', array('%row' => $i)); } } $i++; } fclose($handle); if (empty($data)) { throw new \Exception($this->getI18n()->__('Insufficient data to import')); } // Verify required columns are present based on type $requiredcols = array(self::CSV_TYPE_CLIENTS => array(self::CSV_CLIENT_NAME), self::CSV_TYPE_PROJECTS => array(self::CSV_PROJECT_NAME), self::CSV_TYPE_ISSUES => array(self::CSV_ISSUE_TITLE, self::CSV_ISSUE_PROJECT, self::CSV_ISSUE_ISSUE_TYPE)); if (!isset($requiredcols[$request['type']])) { throw new \Exception('Sorry, this type is unimplemented'); } foreach ($requiredcols[$request['type']] as $col) { if (!in_array($col, $headerrow)) { $errors[] = $this->getI18n()->__('Required column \'%col\' not found in header row', array('%col' => $col)); } } // Check if rows are long enough and fields are not empty for ($i = 0; $i != count($data); $i++) { $activerow = $data[$i]; // Check if fields are empty foreach ($activerow as $col => $val) { if (strlen($val) == 0) { $errors[] = $this->getI18n()->__('Row %row column %col has no value', array('%col' => $col, '%row' => $i + 1)); } } } if (count($errors) == 0) { // Check if fields are valid switch ($request['type']) { case self::CSV_TYPE_PROJECTS: for ($i = 0; $i != count($data); $i++) { $activerow = $data[$i]; // Check if project exists $key = str_replace(' ', '', $activerow[self::CSV_PROJECT_NAME]); $key = mb_strtolower($key); $tmp = entities\Project::getByKey($key); if ($tmp !== null) { $errors[] = $this->getI18n()->__('Row %row: A project with this name already exists', array('%row' => $i + 1)); } // First off are booleans $boolitems = array(self::CSV_PROJECT_SCRUM, self::CSV_PROJECT_ALLOW_REPORTING, self::CSV_PROJECT_AUTOASSIGN, self::CSV_PROJECT_FREELANCE, self::CSV_PROJECT_EN_BUILDS, self::CSV_PROJECT_EN_COMPS, self::CSV_PROJECT_EN_EDITIONS, self::CSV_PROJECT_SHOW_SUMMARY); foreach ($boolitems as $boolitem) { if (array_key_exists($boolitem, $activerow) && isset($activerow[$boolitem]) && $activerow[$boolitem] != 1 && $activerow[$boolitem] != 0) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1/0)', array('%col' => $boolitem, '%row' => $i + 1)); } } // Now identifiables $identifiableitems = array(array(self::CSV_PROJECT_QA, self::CSV_PROJECT_QA_TYPE), array(self::CSV_PROJECT_LEAD, self::CSV_PROJECT_LEAD_TYPE), array(self::CSV_PROJECT_OWNER, self::CSV_PROJECT_OWNER_TYPE)); foreach ($identifiableitems as $identifiableitem) { if (!array_key_exists($identifiableitem[1], $activerow) && array_key_exists($identifiableitem[0], $activerow) || array_key_exists($identifiableitem[1], $activerow) && !array_key_exists($identifiableitem[0], $activerow)) { $errors[] = $this->getI18n()->__('Row %row: Both the type and item ID must be supplied for owner/lead/qa fields', array('%row' => $i + 1)); continue; } if (array_key_exists($identifiableitem[1], $activerow) && isset($activerow[$identifiableitem[1]]) !== null && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_USER && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_TEAM) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1 for a user or 2 for a team)', array('%col' => $identifiableitem[1], '%row' => $i + 1)); } if (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && !is_numeric($activerow[$identifiableitem[0]])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } elseif (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && is_numeric($activerow[$identifiableitem[0]])) { // check if they exist switch ($activerow[$identifiableitem[1]]) { case self::CSV_IDENTIFIER_TYPE_USER: try { entities\User::getB2DBTable()->selectByID($activerow[$identifiableitem[0]]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: user does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } break; case self::CSV_IDENTIFIER_TYPE_TEAM: try { entities\Team::getB2DBTable()->selectById($activerow[$identifiableitem[0]]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: team does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } break; } } } // Now check client exists if (array_key_exists(self::CSV_PROJECT_CLIENT, $activerow) && isset($activerow[self::CSV_PROJECT_CLIENT])) { if (!is_numeric($activerow[self::CSV_PROJECT_CLIENT])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_PROJECT_CLIENT, '%row' => $i + 1)); } else { try { entities\Client::getB2DBTable()->selectById($activerow[self::CSV_PROJECT_CLIENT]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: client does not exist', array('%col' => self::CSV_PROJECT_CLIENT, '%row' => $i + 1)); } } } // Now check if workflow exists if (array_key_exists(self::CSV_PROJECT_WORKFLOW_ID, $activerow) && isset($activerow[self::CSV_PROJECT_WORKFLOW_ID])) { if (!is_numeric($activerow[self::CSV_PROJECT_WORKFLOW_ID])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_PROJECT_WORKFLOW_ID, '%row' => $i + 1)); } else { try { entities\WorkflowScheme::getB2DBTable()->selectById($activerow[self::CSV_PROJECT_WORKFLOW_ID]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: workflow scheme does not exist', array('%col' => self::CSV_PROJECT_WORKFLOW_ID, '%row' => $i + 1)); } } } // Now check if issuetype scheme if (array_key_exists(self::CSV_PROJECT_ISSUETYPE_SCHEME, $activerow) && isset($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME])) { if (!is_numeric($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_PROJECT_ISSUETYPE_SCHEME, '%row' => $i + 1)); } else { try { entities\IssuetypeScheme::getB2DBTable()->selectById($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: issuetype scheme does not exist', array('%col' => self::CSV_PROJECT_ISSUETYPE_SCHEME, '%row' => $i + 1)); } } } // Finally check if the summary type is valid. At this point, your error list has probably become so big it has eaten up all your available RAM... if (array_key_exists(self::CSV_PROJECT_SUMMARY_TYPE, $activerow) && isset($activerow[self::CSV_PROJECT_SUMMARY_TYPE])) { if ($activerow[self::CSV_PROJECT_SUMMARY_TYPE] != 'issuetypes' && $activerow[self::CSV_PROJECT_SHOW_SUMMARY] != 'milestones') { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be \'issuetypes\' or \'milestones\')', array('%col' => self::CSV_PROJECT_SUMMARY_TYPE, '%row' => $i + 1)); } } } break; case self::CSV_TYPE_ISSUES: for ($i = 0; $i != count($data); $i++) { $activerow = $data[$i]; // Check if project exists try { $prjtmp = entities\Project::getB2DBTable()->selectByID($activerow[self::CSV_ISSUE_PROJECT]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: Project does not exist', array('%col' => self::CSV_ISSUE_PROJECT, '%row' => $i + 1)); break; } // First off are booleans $boolitems = array(self::CSV_ISSUE_STATE, self::CSV_ISSUE_BLOCKING); foreach ($boolitems as $boolitem) { if (array_key_exists($boolitem, $activerow) && isset($activerow[$boolitem]) && $activerow[$boolitem] != 1 && $activerow[$boolitem] != 0) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1/0)', array('%col' => $boolitem, '%row' => $i + 1)); } } // Now numerics $numericitems = array(self::CSV_ISSUE_VOTES, self::CSV_ISSUE_PERCENTAGE, self::CSV_ISSUE_ISSUENO); foreach ($numericitems as $numericitem) { if (array_key_exists($numericitem, $activerow) && isset($activerow[$numericitem]) && !is_numeric($activerow[$numericitem])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => $numericitem, '%row' => $i + 1)); } } // Percentage must be 0-100 if (array_key_exists(self::CSV_ISSUE_PERCENTAGE, $activerow) && isset($activerow[self::CSV_ISSUE_PERCENTAGE]) && ($activerow[self::CSV_ISSUE_PERCENTAGE] < 0 || $activerow[self::CSV_ISSUE_PERCENTAGE] > 100)) { $errors[] = $this->getI18n()->__('Row %row column %col: Percentage must be from 0 to 100 inclusive', array('%col' => self::CSV_ISSUE_PERCENTAGE, '%row' => $i + 1)); } // Now identifiables $identifiableitems = array(array(self::CSV_ISSUE_OWNER, self::CSV_ISSUE_OWNER_TYPE), array(self::CSV_ISSUE_ASSIGNED, self::CSV_ISSUE_ASSIGNED_TYPE)); foreach ($identifiableitems as $identifiableitem) { if (!array_key_exists($identifiableitem[1], $activerow) && array_key_exists($identifiableitem[0], $activerow) || array_key_exists($identifiableitem[1], $activerow) && !array_key_exists($identifiableitem[0], $activerow)) { $errors[] = $this->getI18n()->__('Row %row: Both the type and item ID must be supplied for owner/lead/qa fields', array('%row' => $i + 1)); continue; } if (array_key_exists($identifiableitem[1], $activerow) && isset($activerow[$identifiableitem[1]]) && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_USER && $activerow[$identifiableitem[1]] != self::CSV_IDENTIFIER_TYPE_TEAM) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be 1 for a user or 2 for a team)', array('%col' => $identifiableitem[1], '%row' => $i + 1)); } if (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && !is_numeric($activerow[$identifiableitem[0]])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } elseif (array_key_exists($identifiableitem[0], $activerow) && isset($activerow[$identifiableitem[0]]) && is_numeric($activerow[$identifiableitem[0]])) { // check if they exist switch ($activerow[$identifiableitem[1]]) { case self::CSV_IDENTIFIER_TYPE_USER: try { entities\User::getB2DBTable()->selectByID($activerow[$identifiableitem[0]]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: user does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } break; case self::CSV_IDENTIFIER_TYPE_TEAM: try { entities\Team::getB2DBTable()->selectById($activerow[$identifiableitem[0]]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: team does not exist', array('%col' => $identifiableitem[0], '%row' => $i + 1)); } break; } } } // Now timestamps if (array_key_exists(self::CSV_ISSUE_POSTED, $activerow) && isset($activerow[self::CSV_ISSUE_POSTED]) && (string) (int) $activerow[self::CSV_ISSUE_POSTED] !== $activerow[self::CSV_ISSUE_POSTED] && $activerow[self::CSV_ISSUE_POSTED] >= PHP_INT_MAX && $activerow[self::CSV_ISSUE_POSTED] <= ~PHP_INT_MAX) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a Unix timestamp)', array('%col' => self::CSV_ISSUE_POSTED, '%row' => $i + 1)); } // Now check user exists for postedby if (array_key_exists(self::CSV_ISSUE_POSTED_BY, $activerow) && isset($activerow[self::CSV_ISSUE_POSTED_BY])) { if (!is_numeric($activerow[self::CSV_ISSUE_POSTED_BY])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_POSTED_BY, '%row' => $i + 1)); } else { try { entities\User::getB2DBTable()->selectByID($activerow[self::CSV_ISSUE_POSTED_BY]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: user does not exist', array('%col' => self::CSV_ISSUE_POSTED_BY, '%row' => $i + 1)); } } } // Now check milestone exists and is valid if (array_key_exists(self::CSV_ISSUE_MILESTONE, $activerow) && isset($activerow[self::CSV_ISSUE_MILESTONE])) { if (!is_numeric($activerow[self::CSV_ISSUE_MILESTONE])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_MILESTONE, '%row' => $i + 1)); } else { try { $milestonetmp = entities\Milestone::getB2DBTable()->selectById($activerow[self::CSV_ISSUE_MILESTONE]); if ($milestonetmp->getProject()->getID() != $activerow[self::CSV_ISSUE_PROJECT]) { $errors[] = $this->getI18n()->__('Row %row column %col: milestone does not apply to the specified project', array('%col' => self::CSV_ISSUE_MILESTONE, '%row' => $i + 1)); } } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: milestone does not exist', array('%col' => self::CSV_ISSUE_MILESTONE, '%row' => $i + 1)); } } } // status if (array_key_exists(self::CSV_ISSUE_STATUS, $activerow) && isset($activerow[self::CSV_ISSUE_STATUS])) { if (!is_numeric($activerow[self::CSV_ISSUE_STATUS])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_STATUS, '%row' => $i + 1)); } else { try { entities\Status::getB2DBTable()->selectById($activerow[self::CSV_ISSUE_STATUS]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: status does not exist', array('%col' => self::CSV_ISSUE_STATUS, '%row' => $i + 1)); } } } // resolution if (array_key_exists(self::CSV_ISSUE_RESOLUTION, $activerow) && isset($activerow[self::CSV_ISSUE_RESOLUTION])) { if (!is_numeric($activerow[self::CSV_ISSUE_RESOLUTION])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_RESOLUTION, '%row' => $i + 1)); } else { try { entities\Resolution::getB2DBTable()->selectById($activerow[self::CSV_ISSUE_RESOLUTION]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: resolution does not exist', array('%col' => self::CSV_ISSUE_RESOLUTION, '%row' => $i + 1)); } } } // priority if (array_key_exists(self::CSV_ISSUE_PRIORITY, $activerow) && isset($activerow[self::CSV_ISSUE_PRIORITY])) { if (!is_numeric($activerow[self::CSV_ISSUE_PRIORITY])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_PRIORITY, '%row' => $i + 1)); } else { try { entities\Priority::getB2DBTable()->selectById($activerow[self::CSV_ISSUE_PRIORITY]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: priority does not exist', array('%col' => self::CSV_ISSUE_PRIORITY, '%row' => $i + 1)); } } } // category if (array_key_exists(self::CSV_ISSUE_CATEGORY, $activerow) && isset($activerow[self::CSV_ISSUE_CATEGORY])) { if (!is_numeric($activerow[self::CSV_ISSUE_CATEGORY])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_CATEGORY, '%row' => $i + 1)); } else { try { entities\Category::getB2DBTable()->selectById($activerow[self::CSV_ISSUE_CATEGORY]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: category does not exist', array('%col' => self::CSV_ISSUE_CATEGORY, '%row' => $i + 1)); } } } // severity if (array_key_exists(self::CSV_ISSUE_SEVERITY, $activerow) && isset($activerow[self::CSV_ISSUE_SEVERITY])) { if (!is_numeric($activerow[self::CSV_ISSUE_SEVERITY])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_SEVERITY, '%row' => $i + 1)); } else { try { entities\Severity::getB2DBTable()->selectById($activerow[self::CSV_ISSUE_SEVERITY]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: severity does not exist', array('%col' => self::CSV_ISSUE_SEVERITY, '%row' => $i + 1)); } } } // reproducability if (array_key_exists(self::CSV_ISSUE_REPRODUCIBILITY, $activerow) && isset($activerow[self::CSV_ISSUE_REPRODUCIBILITY])) { if (!is_numeric($activerow[self::CSV_ISSUE_REPRODUCIBILITY])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_REPRODUCIBILITY, '%row' => $i + 1)); } else { try { entities\Reproducability::getB2DBTable()->selectById($activerow[self::CSV_ISSUE_REPRODUCIBILITY]); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: reproducability does not exist', array('%col' => self::CSV_ISSUE_REPRODUCIBILITY, '%row' => $i + 1)); } } } // type if (array_key_exists(self::CSV_ISSUE_ISSUE_TYPE, $activerow) && isset($activerow[self::CSV_ISSUE_ISSUE_TYPE])) { if (!is_numeric($activerow[self::CSV_ISSUE_ISSUE_TYPE])) { $errors[] = $this->getI18n()->__('Row %row column %col: invalid value (must be a number)', array('%col' => self::CSV_ISSUE_ISSUE_TYPE, '%row' => $i + 1)); } else { try { $typetmp = entities\Issuetype::getB2DBTable()->selectById($activerow[self::CSV_ISSUE_ISSUE_TYPE]); if (!$prjtmp->getIssuetypeScheme()->isSchemeAssociatedWithIssuetype($typetmp)) { $errors[] = $this->getI18n()->__('Row %row column %col: this project does not support issues of this type (%type)', array('%type' => $typetmp->getName(), '%col' => self::CSV_ISSUE_ISSUE_TYPE, '%row' => $i + 1)); } } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row column %col: issue type does not exist', array('%col' => self::CSV_ISSUE_ISSUE_TYPE, '%row' => $i + 1)); } } } } break; } } // Handle errors if (count($errors) != 0) { $errordiv = '<ul>'; foreach ($errors as $error) { $errordiv .= '<li>' . $error . '</li>'; } $errordiv .= '</ul>'; $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('errordetail' => $errordiv, 'error' => $this->getI18n()->__('Errors occured while importing, see the error list in the import screen for further details'))); } } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('errordetail' => $e->getMessage(), 'error' => $e->getMessage())); } if ($request['csv_dry_run']) { return $this->renderJSON(array('message' => $this->getI18n()->__('Dry-run successful, you can now uncheck the dry-run box and import your data.'))); } else { switch ($request['type']) { case self::CSV_TYPE_CLIENTS: for ($i = 0; $i != count($data); $i++) { try { $activerow = $data[$i]; $client = new entities\Client(); $client->setName($activerow[self::CSV_CLIENT_NAME]); if (isset($activerow[self::CSV_CLIENT_EMAIL])) { $client->setEmail($activerow[self::CSV_CLIENT_EMAIL]); } if (isset($activerow[self::CSV_CLIENT_WEBSITE])) { $client->setWebsite($activerow[self::CSV_CLIENT_WEBSITE]); } if (isset($activerow[self::CSV_CLIENT_FAX])) { $client->setFax($activerow[self::CSV_CLIENT_FAX]); } if (isset($activerow[self::CSV_CLIENT_TELEPHONE])) { $client->setTelephone($activerow[self::CSV_CLIENT_TELEPHONE]); } $client->save(); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row failed: %err', array('%row' => $i + 1, '%err' => $e->getMessage())); } } break; case self::CSV_TYPE_PROJECTS: for ($i = 0; $i != count($data); $i++) { try { $activerow = $data[$i]; $project = new entities\Project(); $project->setName($activerow[self::CSV_PROJECT_NAME]); $project->save(); if (isset($activerow[self::CSV_PROJECT_PREFIX])) { $project->setPrefix($activerow[self::CSV_PROJECT_PREFIX]); $project->setUsePrefix(true); } if (isset($activerow[self::CSV_PROJECT_SCRUM])) { if ($activerow[self::CSV_PROJECT_SCRUM] == '1') { $project->setUsesScrum(true); } } if (isset($activerow[self::CSV_PROJECT_OWNER]) && isset($activerow[self::CSV_PROJECT_OWNER_TYPE])) { switch ($activerow[self::CSV_PROJECT_OWNER_TYPE]) { case self::CSV_IDENTIFIER_TYPE_USER: $user = new entities\User($activerow[self::CSV_PROJECT_OWNER]); $project->setOwner($user); break; case self::CSV_IDENTIFIER_TYPE_TEAM: $team = new entities\Team($activerow[self::CSV_PROJECT_OWNER]); $project->setOwner($team); break; } } if (isset($activerow[self::CSV_PROJECT_LEAD]) && isset($activerow[self::CSV_PROJECT_LEAD_TYPE])) { switch ($activerow[self::CSV_PROJECT_LEAD_TYPE]) { case self::CSV_IDENTIFIER_TYPE_USER: $user = new entities\User($activerow[self::CSV_PROJECT_LEAD]); $project->setLeader($user); break; case self::CSV_IDENTIFIER_TYPE_TEAM: $team = new entities\Team($activerow[self::CSV_PROJECT_LEAD]); $project->setLeader($team); break; } } if (isset($activerow[self::CSV_PROJECT_QA]) && isset($activerow[self::CSV_PROJECT_QA_TYPE])) { switch ($activerow[self::CSV_PROJECT_QA_TYPE]) { case self::CSV_IDENTIFIER_TYPE_USER: $user = new entities\User($activerow[self::CSV_PROJECT_QA]); $project->setQaResponsible($user); break; case self::CSV_IDENTIFIER_TYPE_TEAM: $team = new entities\Team($activerow[self::CSV_PROJECT_QA]); $project->setQaResponsible($team); break; } } if (isset($activerow[self::CSV_PROJECT_DESCR])) { $project->setDescription($activerow[self::CSV_PROJECT_DESCR]); } if (isset($activerow[self::CSV_PROJECT_DOC_URL])) { $project->setDocumentationUrl($activerow[self::CSV_PROJECT_DOC_URL]); } if (isset($activerow[self::CSV_PROJECT_WIKI_URL])) { $project->setWikiUrl($activerow[self::CSV_PROJECT_WIKI_URL]); } if (isset($activerow[self::CSV_PROJECT_FREELANCE])) { if ($activerow[self::CSV_PROJECT_FREELANCE] == '1') { $project->setChangeIssuesWithoutWorkingOnThem(true); } } if (isset($activerow[self::CSV_PROJECT_EN_BUILDS])) { if ($activerow[self::CSV_PROJECT_EN_BUILDS] == '1') { $project->setBuildsEnabled(true); } } if (isset($activerow[self::CSV_PROJECT_EN_COMPS])) { if ($activerow[self::CSV_PROJECT_EN_COMPS] == '1') { $project->setComponentsEnabled(true); } } if (isset($activerow[self::CSV_PROJECT_EN_EDITIONS])) { if ($activerow[self::CSV_PROJECT_EN_EDITIONS] == '1') { $project->setEditionsEnabled(true); } } if (isset($activerow[self::CSV_PROJECT_CLIENT])) { $project->setClient(entities\Client::getB2DBTable()->selectById($activerow[self::CSV_PROJECT_CLIENT])); } if (isset($activerow[self::CSV_PROJECT_SHOW_SUMMARY])) { if ($activerow[self::CSV_PROJECT_SHOW_SUMMARY] == '1') { $project->setFrontpageSummaryVisibility(true); } } if (isset($activerow[self::CSV_PROJECT_SUMMARY_TYPE])) { $project->setFrontpageSummaryType($activerow[self::CSV_PROJECT_SUMMARY_TYPE]); } if (isset($activerow[self::CSV_PROJECT_ALLOW_REPORTING])) { $project->setLocked($activerow[self::CSV_PROJECT_ALLOW_REPORTING]); } if (isset($activerow[self::CSV_PROJECT_AUTOASSIGN])) { $project->setAutoassign($activerow[self::CSV_PROJECT_AUTOASSIGN]); } if (isset($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME])) { $project->setIssuetypeScheme(entities\IssuetypeScheme::getB2DBTable()->selectById($activerow[self::CSV_PROJECT_ISSUETYPE_SCHEME])); } if (isset($activerow[self::CSV_PROJECT_WORKFLOW_ID])) { } $project->setWorkflowScheme(entities\WorkflowScheme::getB2DBTable()->selectById($activerow[self::CSV_PROJECT_WORKFLOW_ID])); $project->save(); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row failed: %err', array('%row' => $i + 1, '%err' => $e->getMessage())); } } break; case self::CSV_TYPE_ISSUES: for ($i = 0; $i != count($data); $i++) { try { $activerow = $data[$i]; $issue = new entities\Issue(); $issue->setTitle($activerow[self::CSV_ISSUE_TITLE]); $issue->setProject($activerow[self::CSV_ISSUE_PROJECT]); $issue->setIssuetype($activerow[self::CSV_ISSUE_ISSUE_TYPE]); $issue->save(); if (isset($activerow[self::CSV_ISSUE_DESCR])) { $issue->setDescription($activerow[self::CSV_ISSUE_DESCR]); } if (isset($activerow[self::CSV_ISSUE_REPRO])) { $issue->setReproductionSteps($activerow[self::CSV_ISSUE_REPRO]); } if (isset($activerow[self::CSV_ISSUE_STATE])) { $issue->setState($activerow[self::CSV_ISSUE_STATE]); } if (isset($activerow[self::CSV_ISSUE_STATUS])) { $issue->setStatus($activerow[self::CSV_ISSUE_STATUS]); } if (isset($activerow[self::CSV_ISSUE_POSTED_BY])) { $issue->setPostedBy(entities\User::getB2DBTable()->selectByID($activerow[self::CSV_ISSUE_POSTED_BY])); } if (isset($activerow[self::CSV_ISSUE_OWNER]) && isset($activerow[self::CSV_ISSUE_OWNER_TYPE])) { switch ($activerow[self::CSV_ISSUE_OWNER_TYPE]) { case self::CSV_IDENTIFIER_TYPE_USER: $user = new entities\User($activerow[self::CSV_ISSUE_OWNER]); $issue->setOwner($user); break; case self::CSV_IDENTIFIER_TYPE_TEAM: $team = new entities\Team($activerow[self::CSV_ISSUE_OWNER]); $issue->setOwner($team); break; } } if (isset($activerow[self::CSV_ISSUE_ASSIGNED]) && isset($activerow[self::CSV_ISSUE_ASSIGNED_TYPE])) { switch ($activerow[self::CSV_ISSUE_ASSIGNED_TYPE]) { case self::CSV_IDENTIFIER_TYPE_USER: $user = new entities\User($activerow[self::CSV_ISSUE_ASSIGNED]); $issue->setAssignee($user); break; case self::CSV_IDENTIFIER_TYPE_TEAM: $team = new entities\Team($activerow[self::CSV_ISSUE_ASSIGNED]); $issue->setAssignee($team); break; } } if (isset($activerow[self::CSV_ISSUE_RESOLUTION])) { $issue->setResolution($activerow[self::CSV_ISSUE_RESOLUTION]); } if (isset($activerow[self::CSV_ISSUE_PRIORITY])) { $issue->setPriority($activerow[self::CSV_ISSUE_PRIORITY]); } if (isset($activerow[self::CSV_ISSUE_CATEGORY])) { $issue->setCategory($activerow[self::CSV_ISSUE_CATEGORY]); } if (isset($activerow[self::CSV_ISSUE_BLOCKING])) { $issue->setBlocking($activerow[self::CSV_ISSUE_BLOCKING]); } if (isset($activerow[self::CSV_ISSUE_SEVERITY])) { $issue->setSeverity($activerow[self::CSV_ISSUE_SEVERITY]); } if (isset($activerow[self::CSV_ISSUE_REPRODUCIBILITY])) { $issue->setReproducability($activerow[self::CSV_ISSUE_REPRODUCIBILITY]); } if (isset($activerow[self::CSV_ISSUE_VOTES])) { $issue->setVotes($activerow[self::CSV_ISSUE_VOTES]); } if (isset($activerow[self::CSV_ISSUE_PERCENTAGE])) { $issue->setPercentCompleted($activerow[self::CSV_ISSUE_PERCENTAGE]); } if (isset($activerow[self::CSV_ISSUE_ISSUENO])) { $issue->setIssueNo((int) $activerow[self::CSV_ISSUE_ISSUENO]); } if (isset($activerow[self::CSV_ISSUE_MILESTONE])) { $issue->setMilestone($activerow[self::CSV_ISSUE_MILESTONE]); } if (isset($activerow[self::CSV_ISSUE_POSTED])) { $issue->setPosted((int) $activerow[self::CSV_ISSUE_POSTED]); } $issue->save(); } catch (\Exception $e) { $errors[] = $this->getI18n()->__('Row %row failed: %err', array('%row' => $i + 1, '%err' => $e->getMessage())); } } break; } // Handle errors if (count($errors) != 0) { $errordiv = '<ul>'; foreach ($errors as $error) { $errordiv .= '<li>' . $error . '</li>'; } $errordiv .= '</ul>'; $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('errordetail' => $errordiv, 'error' => $this->getI18n()->__('Errors occured while importing, see the error list in the import screen for further details'))); } else { return $this->renderJSON(array('message' => $this->getI18n()->__('Successfully imported %num rows!', array('%num' => count($data))))); } } }
public static function populateBreadcrumbs() { $childbreadcrumbs = array(); if (self::$_selected_project instanceof Project) { $t = self::$_selected_project; $hierarchy_breadcrumbs = array(); $projects_processed = array(); while ($t instanceof Project) { if (array_key_exists($t->getKey(), $projects_processed)) { // We have a cyclic dependency! Oh no! // If this happens, throw an exception throw new \Exception(self::geti18n()->__('A loop has been found in the project heirarchy. Go to project configuration, and alter the subproject setting for this project so that this project is not a subproject of one which is a subproject of this one.')); } else { $all_projects = array_merge(Project::getAllRootProjects(true), Project::getAllRootProjects(false)); // If this is a root project, display a list of other root projects, then t is null if (!$t->hasParent() && count($all_projects) > 1) { $itemsubmenulinks = array(); foreach ($all_projects as $child) { if (!$child->hasAccess()) { continue; } $itemsubmenulinks[] = array('url' => self::getRouting()->generate('project_dashboard', array('project_key' => $child->getKey())), 'title' => $child->getName()); } $hierarchy_breadcrumbs[] = array($t, $itemsubmenulinks); $projects_processed[$t->getKey()] = $t; $t = null; continue; } elseif (!$t->hasParent()) { $hierarchy_breadcrumbs[] = array($t, null); $projects_processed[$t->getKey()] = $t; $t = null; continue; } else { // What we want to do here is to build a list of the children of the parent unless we are the only one $parent = $t->getParent(); $children = $parent->getChildren(); $itemsubmenulinks = null; if ($parent->hasChildren() && count($children) > 1) { $itemsubmenulinks = array(); foreach ($children as $child) { if (!$child->hasAccess()) { continue; } $itemsubmenulinks[] = array('url' => self::getRouting()->generate('project_dashboard', array('project_key' => $child->getKey())), 'title' => $child->getName()); } } $hierarchy_breadcrumbs[] = array($t, $itemsubmenulinks); $projects_processed[$t->getKey()] = $t; $t = $parent; continue; } } } $clientsubmenulinks = null; if (self::$_selected_project->hasClient()) { $clientsubmenulinks = array(); foreach (Client::getAll() as $client) { if ($client->hasAccess()) { $clientsubmenulinks[] = array('url' => self::getRouting()->generate('client_dashboard', array('client_id' => $client->getID())), 'title' => $client->getName()); } } self::setCurrentClient(self::$_selected_project->getClient()); } if (mb_strtolower(Settings::getSiteHeaderName()) != mb_strtolower(self::$_selected_project->getName()) || self::isClientContext()) { self::getResponse()->addBreadcrumb(Settings::getSiteHeaderName(), self::getRouting()->generate('home')); if (self::isClientContext()) { self::getResponse()->addBreadcrumb(self::getCurrentClient()->getName(), self::getRouting()->generate('client_dashboard', array('client_id' => self::getCurrentClient()->getID())), $clientsubmenulinks); } } // Add root breadcrumb first, so reverse order $hierarchy_breadcrumbs = array_reverse($hierarchy_breadcrumbs); foreach ($hierarchy_breadcrumbs as $breadcrumb) { $class = null; if ($breadcrumb[0]->getKey() == self::getCurrentProject()->getKey()) { $class = 'selected_project'; } self::getResponse()->addBreadcrumb($breadcrumb[0]->getName(), self::getRouting()->generate('project_dashboard', array('project_key' => $breadcrumb[0]->getKey())), $breadcrumb[1], $class); } } else { self::getResponse()->addBreadcrumb(Settings::getSiteHeaderName(), self::getRouting()->generate('home')); } }