/** * Process unfollow user request * * @param User $User who is following * @param int $userid id user user being unfollowed * @throws \InvalidArgumentException * * @return object $this */ public function unfollowUser(User $User, $userid) { if (!is_int($userid)) { throw new \InvalidArgumentException('$userid must be an integer'); } $aFollowed = $User['a_f_u']; d('$aFollowed: ' . \json_encode($aFollowed)); if (false !== ($key = \array_search($userid, $aFollowed))) { d('cp unsetting key: ' . $key); array_splice($aFollowed, $key, 1); $User['a_f_u'] = $aFollowed; $User->save(); $this->Registry->Mongo->USERS->update(array('_id' => $userid), array('$inc' => array('i_flwrs' => -1))); $this->Registry->Dispatcher->post($User, 'onUserUnfollow', array('uid' => $userid)); } else { d('tag ' . $userid . ' is not among the followed users of this userID: ' . $User->getUid()); } return $this; }
/** * Update User object if necessary: * Always add the google_token value (json token string) * * if user does not have avatar_external set one from Google Info * If user does not have locale set from info * If user does not have fn or ln set from Google Info * If user does not have gender set from Google Info * If User does not have url set from Google Info profile url * * @param \Lampcms\User $User * * @return object $this */ protected function updateUser(\Lampcms\User $User) { $User['google_id'] = (string) $this->userInfo['id']; /** * Update the following field ONLY * if they DON'T already exists in this user's record! * * This means that if record exists and is an empty * string - don't update this because it usually means * that user did have this field before and then removed * the value by editing profile. */ if (null === $User[Schema::EXTERNAL_AVATAR] && !empty($this->userInfo['picture'])) { $User[Schema::EXTERNAL_AVATAR] = $this->userInfo['picture'] . '?sz=50'; } if (null === $User[Schema::FIRST_NAME] && !empty($this->userInfo['given_name'])) { $User[Schema::FIRST_NAME] = $this->userInfo['given_name']; } if (null === $User[Schema::LAST_NAME] && !empty($this->userInfo['family_name'])) { $User[Schema::LAST_NAME] = $this->userInfo['family_name']; } if (null === $User[Schema::GENDER] && !empty($this->userInfo['gender'])) { $User[Schema::GENDER] = 'male' === $this->userInfo['gender'] ? 'M' : 'F'; } if (null === $User[Schema::URL] && !empty($this->userInfo['link'])) { $User[Schema::URL] = $this->userInfo['link']; } $User->save(); return $this; }