コード例 #1
0
ファイル: User.php プロジェクト: underblaze/thebuggenie-4.1.0
 /**
  * Pre-save function to check for conflicting usernames and to make
  * sure some properties are set
  *
  * @param boolean $is_new Whether this is a new user object
  */
 protected function _preSave($is_new)
 {
     parent::_preSave($is_new);
     if (!framework\Context::isInstallmode() && !framework\Context::isUpgrademode()) {
         $compare_user = self::getByUsername($this->getUsername());
         if ($compare_user instanceof User && $compare_user->getID() && $compare_user->getID() != $this->getID()) {
             throw new \Exception(framework\Context::getI18n()->__('This username already exists'));
         }
     }
     if ($is_new) {
         // In case the postsave event isn't processed we automatically enable the user
         // since we can't be sure that an activation email has been sent out
         $this->setEnabled();
         $this->setActivated();
     }
     if (!$this->_realname) {
         $this->_realname = $this->_username;
     }
     if (!$this->_buddyname) {
         $this->_buddyname = $this->_username;
     }
     if (is_object($this->_timezone)) {
         $this->_timezone = $this->_timezone->getName();
     }
     if ($is_new && $this->_joined === 0) {
         $this->_joined = NOW;
     }
     if ($is_new && $this->_group_id === null) {
         $this->setGroup(framework\Settings::getDefaultGroup());
     }
     if ($this->_deleted) {
         try {
             if ($this->getGroup() instanceof \thebuggenie\core\entities\Group) {
                 $this->getGroup()->removeMember($this);
             }
         } catch (\Exception $e) {
         }
         $this->_group_id = null;
         $this->_buddyname = $this->_username;
         $this->_username = '';
         if (!$is_new) {
             tables\TeamMembers::getTable()->clearTeamsByUserID($this->getID());
             tables\ClientMembers::getTable()->clearClientsByUserID($this->getID());
             tables\UserScopes::getTable()->clearUserScopes($this->getID());
         }
     }
 }
コード例 #2
0
ファイル: Team.php プロジェクト: JonathanRH/thebuggenie
 public function getNumberOfMembers()
 {
     if ($this->_members !== null) {
         return count($this->_members);
     } elseif ($this->_num_members === null) {
         $this->_num_members = tables\TeamMembers::getTable()->getNumberOfMembersByTeamID($this->getID());
     }
     return $this->_num_members;
 }
コード例 #3
0
ファイル: User.php プロジェクト: underblaze/thebuggenie-4.1.0
 /**
  * Clear this users teams
  */
 public function clearTeams()
 {
     \thebuggenie\core\entities\tables\TeamMembers::getTable()->clearTeamsByUserID($this->getID());
 }
コード例 #4
0
ファイル: Main.php プロジェクト: nrensen/thebuggenie
 public function runAddTeam(framework\Request $request)
 {
     try {
         $mode = $request['mode'];
         if ($team_name = $request['team_name']) {
             if ($mode == 'clone') {
                 try {
                     $old_team = entities\Team::getB2DBTable()->selectById($request['team_id']);
                 } catch (\Exception $e) {
                 }
                 if (!$old_team instanceof entities\Team) {
                     throw new \Exception(framework\Context::getI18n()->__("You cannot clone this team"));
                 }
             }
             if (entities\Team::doesTeamNameExist(trim($team_name))) {
                 throw new \Exception(framework\Context::getI18n()->__("Please enter a team name that doesn't already exist"));
             }
             $team = new entities\Team();
             $team->setName($team_name);
             $team->save();
             if ($mode == 'clone') {
                 if ($request['clone_permissions']) {
                     tables\Permissions::getTable()->cloneTeamPermissions($old_team->getID(), $team->getID());
                 }
                 if ($request['clone_memberships']) {
                     tables\TeamMembers::getTable()->cloneTeamMemberships($old_team->getID(), $team->getID());
                 }
                 $message = framework\Context::getI18n()->__('The team was cloned');
             } else {
                 $message = framework\Context::getI18n()->__('The team was added');
             }
             return $this->renderJSON(array('message' => $message, 'content' => $this->getComponentHTML('configuration/teambox', array('team' => $team)), 'total_count' => entities\Team::countAll(), 'more_available' => framework\Context::getScope()->hasTeamsAvailable()));
         } else {
             throw new \Exception(framework\Context::getI18n()->__('Please enter a team name'));
         }
     } catch (\Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $e->getMessage()));
     }
 }