/** * @param $id * @return null|UserProfileModel */ protected function getUserProfile($id) { $user_profile = UserProfileModel::getProfile($id); if (!$user_profile) { $user_profile = new UserProfileModel(); $user_profile->id = $id; // 保存 $user_profile = UserProfileModel::createProfile($user_profile); } return $user_profile; }
public function __invoke() { /** @var \Tachigo\User\Aware\Hook\UserHook $hook */ $hook = $this->getHook(); $user_id = $hook->getUserId(); $hook_results = $hook->getResults(); $hook_results['auth'] = UserAuthModel::getAuth($user_id); $hook_results['profile'] = UserProfileModel::getProfile($user_id); $hook->setResults($hook_results); /*$hook = $this->getHook(); $user_id = $hook->getUserId(); $hook_results = $hook->getResults(); $db = UserDatabase::getDb(); $hook_results['auth'] = $db->getUserInfo($user_id); $hook_results['profile'] = $hook_results['auth']; $hook->setResults($hook_results);*/ }
private function handleAvatar($auth_id) { $user_auth = UserAuthModel::getAuth($auth_id); if (!$user_auth) { throw new \Exception('用户不存在'); } $user_profile = UserProfileModel::getProfile($user_auth->id); if (!$user_profile) { $user_profile = new UserProfileModel(); $user_profile->id = $user_auth->id; // 保存 $user_profile = UserProfileModel::createProfile($user_profile); } $request = $this->getRequest(); $posts = $request->request; $avatar = $posts->get('avatar'); $user_profile->avatar = $avatar; // 保存 UserProfileModel::saveProfile($user_profile); }
public function user_by_id($value, $args, $context, ResolveInfo $info) { /*$user = array( 'auth' => array(), 'profile' => array(), ); $user_auth = UserAuthModel::getAuthByUsername($args['username_like']); if ($user_auth) { $user['auth'] = $user_auth->toArray(); $user_profile = UserProfileModel::getProfile($user_auth->id); $user['profile'] = $user_profile->toArray(); }*/ $user = array(); $user_auth = UserAuthModel::getAuth($args['id']); if ($user_auth) { $user = $user_auth->toArray(); $user_profile = UserProfileModel::getProfile($user_auth->id); if ($user_profile) { $user += $user_profile->toArray(); } if (!isset($user['avatar']) || empty($user['avatar'])) { // todo $user['avatar'] = 'http://cdn.tachigo.com/user/img/avatar.gif'; } } return $user; }