Пример #1
0
 public function runAddTeam(TBGRequest $request)
 {
     try {
         $mode = $request->getParameter('mode');
         if ($team_name = $request->getParameter('team_name')) {
             if ($mode == 'clone') {
                 try {
                     $old_team = TBGContext::factory()->TBGTeam($request->getParameter('team_id'));
                 } catch (Exception $e) {
                 }
                 if (!$old_team instanceof TBGTeam) {
                     throw new Exception(TBGContext::getI18n()->__("You cannot clone this team"));
                 }
             }
             if (TBGTeam::doesTeamNameExist(trim($team_name))) {
                 throw new Exception(TBGContext::getI18n()->__("Please enter a team name that doesn't already exist"));
             }
             $team = new TBGTeam();
             $team->setName($team_name);
             $team->save();
             if ($mode == 'clone') {
                 if ($request->getParameter('clone_permissions')) {
                     TBGPermissionsTable::getTable()->cloneTeamPermissions($old_team->getID(), $team->getID());
                 }
                 if ($request->getParameter('clone_memberships')) {
                     TBGTeamMembersTable::getTable()->cloneTeamMemberships($old_team->getID(), $team->getID());
                 }
                 $message = TBGContext::getI18n()->__('The team was cloned');
             } else {
                 $message = TBGContext::getI18n()->__('The team was added');
             }
             return $this->renderJSON(array('failed' => false, 'message' => $message, 'content' => $this->getTemplateHTML('configuration/teambox', array('team' => $team)), 'total_count' => TBGTeam::getTeamsCount(), 'more_available' => TBGContext::getScope()->hasTeamsAvailable()));
         } else {
             throw new Exception(TBGContext::getI18n()->__('Please enter a team name'));
         }
     } catch (Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage()));
     }
 }