user_id != null; } /** * @return array json decoded properties */ public function getDecodedData() { if ($this->data !== null && $this->decodedData === null) { $this->decodedData = json_decode($this->data); } return $this->decodedData; } /** * @return string the connection url */ public function getConnectionUrl() { $code = Yii::$app->security->generateRandomString(); $this->updateAttributes(['code' => md5($code)]); return Url::to(['/usr/registration/connect', 'code' => $code]); } /** * Connects account to a user. * * @param User $user * * @return int */ public function connect(User $user) { return $this->updateAttributes( [ 'username' => null, 'email' => null, 'code' => null, 'user_id' => $user->id, ] ); } /** * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne($this->getClassMap()->get(User::class), ['id' => 'user_id']); } /** * @return SocialNetworkAccountQuery */ public static function find() { return new SocialNetworkAccountQuery(static::class); } }