Exemplo n.º 1
0
 /**
  * Add a project (AJAX call)
  * 
  * @param TBGRequest $request The request object
  */
 public function runAddProject(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     if (!TBGContext::getScope()->hasProjectsAvailable()) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array("error" => $i18n->__("There are no more projects available in this instance")));
     }
     if ($this->access_level == TBGSettings::ACCESS_FULL) {
         if (($p_name = $request['p_name']) && trim($p_name) != '') {
             try {
                 $project = new TBGProject();
                 $project->setName($p_name);
                 $project->setWorkflowSchemeID($request['workflow_scheme_id']);
                 $project->setIssuetypeSchemeID($request['issuetype_scheme_id']);
                 $project->save();
                 return $this->renderJSON(array('message' => $i18n->__('The project has been added'), 'content' => $this->getTemplateHTML('projectbox', array('project' => $project, 'access_level' => $this->access_level)), 'total_count' => TBGProject::getProjectsCount(), 'more_available' => TBGContext::getScope()->hasProjectsAvailable()));
             } catch (InvalidArgumentException $e) {
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array("error" => $i18n->__('A project with the same key already exists')));
             } catch (Exception $e) {
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array("error" => $i18n->__('An error occurred: ' . $e->getMessage())));
             }
         }
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array("error" => $i18n->__('Please specify a valid project name')));
     }
     $this->getResponse()->setHttpStatus(400);
     return $this->renderJSON(array("error" => $i18n->__("You don't have access to add projects")));
 }