/** * @param IQuarkModel $model * @param string $key * * @return QuarkModel|IQuarkModel */ public function User(IQuarkModel $model, $key) { /** * @var QuarkModel|SocialNetwork $profile */ $profile = QuarkModel::FindOne($this, array('social' => (string) $this->Name(), 'id' => (string) $this->id)); if ($profile == null && $this->id != '' && $this->accessToken != '') { $profile = new QuarkModel($this); $profile->Create(); } if ($profile == null) { return null; } $profile->accessToken = (string) $this->accessToken; $profile->Save(); $user = QuarkModel::FindOne($model, array($key => $this->Pk())); if ($user == null) { $user = new QuarkModel($model, QuarkModel::StructureFromKey($key, $profile)); $this->_newUser = true; } return $user; }