public static function loadFixtures(TBGScope $scope)
 {
     $scheme = new TBGWorkflowScheme();
     $scheme->setScope($scope);
     $scheme->setName("Default workflow scheme");
     $scheme->setDescription("This is the default workflow scheme. It is used by all projects with no specific workflow scheme selected. This scheme cannot be edited or removed.");
     $scheme->save();
     TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_WORKFLOWSCHEME, $scheme->getID(), 'core', $scope->getID());
 }
 public function runConfigureWorkflowScheme(TBGRequest $request)
 {
     $this->workflow_scheme = null;
     $this->mode = $request->getParameter('mode', 'list');
     try {
         $this->workflow_scheme = TBGContext::factory()->TBGWorkflowScheme($request->getParameter('scheme_id'));
         $this->issuetypes = TBGIssuetype::getAll();
         if (TBGContext::getScope()->isCustomWorkflowsEnabled() && $this->mode == 'copy_scheme') {
             if ($new_name = $request->getParameter('new_name')) {
                 $new_scheme = new TBGWorkflowScheme();
                 $new_scheme->setName($new_name);
                 $new_scheme->save();
                 foreach ($this->issuetypes as $issuetype) {
                     if ($this->workflow_scheme->hasWorkflowAssociatedWithIssuetype($issuetype)) {
                         $new_scheme->associateIssuetypeWithWorkflow($issuetype, $this->workflow_scheme->getWorkflowForIssuetype($issuetype));
                     }
                 }
                 return $this->renderJSON(array('content' => $this->getTemplateHTML('configuration/workflowscheme', array('scheme' => $new_scheme))));
             } else {
                 $this->error = TBGContext::getI18n()->__('Please enter a valid name');
             }
         } elseif (TBGContext::getScope()->isCustomWorkflowsEnabled() && $this->mode == 'delete_scheme') {
             $this->workflow_scheme->delete();
             return $this->renderJSON(array('success' => true, 'message' => TBGContext::getI18n()->__('The workflow scheme was deleted')));
         } elseif (TBGContext::getScope()->isCustomWorkflowsEnabled() && $request->isMethod(TBGRequest::POST)) {
             foreach ($request->getParameter('workflow_id', array()) as $issuetype_id => $workflow_id) {
                 $issuetype = TBGContext::factory()->TBGIssuetype($issuetype_id);
                 if ($workflow_id) {
                     $workflow = TBGContext::factory()->TBGWorkflow($workflow_id);
                     $this->workflow_scheme->associateIssuetypeWithWorkflow($issuetype, $workflow);
                 } else {
                     $this->workflow_scheme->unassociateIssuetype($issuetype);
                 }
             }
             return $this->renderJSON(array('success' => true, 'message' => TBGContext::getI18n()->__('Workflow associations were updated')));
         }
     } catch (Exception $e) {
         if ($request->getRequestedFormat() == 'json') {
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('success' => false, 'message' => TBGContext::getI18n()->__('An error occured'), 'error' => $e->getMessage()));
         } else {
             $this->error = TBGContext::getI18n()->__('This workflow scheme does not exist');
         }
     }
 }