public static function getUserBelongGroups($userId) { $userGroups = MapUserGroup::model()->findAllByAttributes(array('test_user_id' => $userId)); return $userGroups; }
public static function getGroupUser($groupId) { $userMapInfos = MapUserGroup::model()->findAllByAttributes(array('user_group_id' => $groupId)); $userIdArr = array(); foreach ($userMapInfos as $userMapInfo) { $userIdArr[$userMapInfo->test_user_id] = $userMapInfo->is_admin; } $userInfos = Yii::app()->db->createCommand()->select('*')->from('{{test_user}}')->where(array('in', 'id', array_keys($userIdArr)))->order('username')->queryAll(); $userDataArr = array(); foreach ($userInfos as $userInfo) { $userInfo['is_admin'] = $userIdArr[$userInfo['id']]; $userDataArr[] = $userInfo; } return $userDataArr; }