public function actionNewnot() { $user_id = Yii::$app->user->identity->id; //$data = Yii::$app->request->post(); //$res = Message::find()->select('status')->where(['`to`' => $data['usid'], '`status`' => 0, '`from`' => $data['frid']])->asArray()->all(); $res = FriendList::find()->select('status')->where(['`to`' => $user_id, '`status`' => 0])->asArray()->all(); $res = count($res); echo $res; }
public function actionTest() { $sql = 'SELECT * FROM `friend_list` WHERE `from`=' . Yii::$app->user->identity->id . ' and `to`=11 or `from`=11 and `to`=' . Yii::$app->user->identity->id . ''; $res2 = \app\models\FriendList::findBySql($sql)->asArray()->all(); print_r($res2); }
<h1><?php echo Html::encode($this->title); ?> </h1> <?php Pjax::begin(); ?> <div class="row"> <div class="col-sm-5" style=""> <ul class="list-group"> <?php echo ListView::widget(['dataProvider' => $dataProvider, 'summary' => false, 'itemView' => function ($model) { $sql = 'SELECT * FROM `friend_list` WHERE `from`=' . Yii::$app->user->identity->id . ' and `to`=' . $model->id . ' or `from`=' . $model->id . ' and `to`=' . Yii::$app->user->identity->id . ''; $res2 = \app\models\FriendList::findBySql($sql)->asArray()->all(); if ($model->id !== Yii::$app->user->identity->id && $res2[0]['status'] == 0) { if ($model->id == $res2[0]['to']) { $res = \frontend\models\Page::find()->select('pic_name')->where(['user_id' => $model->id, 'status' => 1])->asArray()->all(); $pic_url = empty($res) ? 'uploads/def.jpg' : $res[0]['pic_name']; return '<div class="list-group"> <li class="list-group-item" style="height: 125px;width: 350px;margin-left: 30px;"> ' . Html::img('@web/' . $pic_url, ['alt' => 'Chenge picture', 'style' => ['cursor' => 'pointer', 'width' => '100px', 'height' => '100px', 'display' => 'inline', 'float' => 'left', 'margin-right' => '5px'], 'class' => 'img-thumbnail ']) . ' <a href="/site/profile/' . $model->id . '" <h4 class="list-group-item-heading"> ' . $model->first_name . " " . $model->last_name . '</h4></a> <p class="list-group-item-text">' . $model->country . '</p> <p class="list-group-item-text">' . floor((strtotime(date('Y-m-d')) - strtotime($model->bd_date)) / 60 / 60 / 24 / 365) . ' years' . '</p> <p class="list-group-item-text but" style="margin-top: 6px;"><span class="label label-info">Request sended</span> </p> </li> </div>';