public function getFrendslist() { $id = Yii::$app->user->id; // $id=Yii::$app->user->identity->getId(); $models = Frends::find()->where('user_id=:user_id', ['user_id' => $id])->asArray()->all(); return ArrayHelper::map($models, 'id', 'name'); }
/** * @return \yii\db\ActiveQuery */ public function getFrend() { return $this->hasOne(Frends::className(), ['id' => 'frend_id']); }
/** * Finds the Frends model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Frends the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Frends::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function importAccountFrend() { $account_frends = $this->searchAccountFrends(); foreach ($account_frends as $provider => $frends) { // var_dump($account_frends);die; foreach ($frends as $frend) { if ($provider = 'vkontakte') { $value = []; // var_dump($frend);die; $value['name'] = $frend['first_name']; if (isset($frend['bdate'])) { // var_dump($frend); $value['bothday'] = $this->truedate($frend['bdate'], '.'); } else { $value['bothday'] = null; } $value['user_id'] = Yii::$app->user->id; $value['email'] = ''; $value['enable'] = 1; $value['sex'] = $frend['sex']; $value['prefics'] = $frend['sex'] == 2 ? 'Уважаемый' : 'Уважаемая'; $value['fname'] = $frend['last_name']; $value['photo'] = $frend['photo_50']; $value['nati'] = 0; $value['provider'] = $provider; $value['pid'] = $frend['uid']; if (isset($frends['domain'])) { $value['domain'] = $frend['domain']; } // var_dump($value); $model = new Frends(); $model_frend = $model->find()->andWhere('provider=:provider', [':provider' => $value['provider']])->andWhere('pid=:pid', [':pid' => $value['pid']])->all(); // var_dump($model_frend); if (empty($model_frend)) { $model->load(['Frends' => $value]); $model->save(); } } // if ($provider = 'facebook') { // // } } } }