/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findByUsername($this->username); } return $this->_user; }
/** * Lists all YBoardMember models. * @return mixed */ public function actionIndex() { if (!Yii::$app->user->can('app.forum.member.index')) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.')); } $user = new User(); $qstring = Yii::$app->request->get($user->formName())['username']; $user->username = $qstring; $userIds = User::find()->select('id')->asArray()->filterWhere(['like', 'username', $qstring])->all(); $query = YBoardMember::find(); foreach ($userIds as $id) { $query->orWhere(['id' => $id['id']]); } $dataProvider = new ActiveDataProvider(['query' => $query]); //if ($searchModel->load(Yii::$app->request->getQueryParams())) { // $query->andFilterWhere(['like','id', $searchModel->id]); //} return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $user]); }
/** * Creates a new YBoardMessage model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (!Yii::$app->user->can('app.forum.message.create')) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.')); } $model = new YBoardMessage(); $model->load(Yii::$app->request->post()); $model->setAttributes(['ip' => Yii::$app->request->getUserIP(), 'create_time' => new \yii\db\Expression('NOW()')]); $json = []; //are we sending single or multiple messages? if ($model->usernames != null) { $usernames = explode(',', $model->usernames); $json['success'] = 'no'; $str = ''; foreach ($usernames as $usr) { $userModel = User::find()->where(['username' => $usr])->one(); if ($userModel != null) { $model->setAttribute('sendto', $userModel->id); $model->id = null; $model->isNewRecord = true; if ($model->save()) { $str .= YBoard::t('yboard', 'Message sent to {usr}', ['usr' => $usr]); $str .= "\n"; } else { $str .= YBoard::t('yboard', 'Message not sent to {usr}', ['usr' => $usr]); $str .= "\n"; } } } $json['message'] = $str; } else { if ($model->save()) { $json['success'] = 'yes'; $json['message'] = YBoard::t('yboard', 'PM Sent Successfully'); } else { $json['success'] = 'no'; $json['message'] = YBoard::t('yboard', 'Could not send your private message. Try again') . json_encode($_POST) . " ===== " . json_encode($model->errors); } } echo json_encode($json); Yii::$app->end(); }
/** * @return \yii\db\ActiveQuery */ public function getProfile() { return $this->hasOne(User::className(), ['id' => 'id']); }
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\jui\Dialog; use yii\web\JsExpression; use yii\jui\AutoComplete; use app\modules\yboard\models\YBoardMessage; use app\components\ckeditor\CKEditor; use kartik\widgets\Select2; use yii\helpers\ArrayHelper; use hosanna\profile\models\User; use app\modules\yboard\YBoard; $model = new YBoardMessage(['sendfrom' => Yii::$app->user->identity->id]); $data = User::find()->select(['username'])->where('id<>' . Yii::$app->user->id)->asArray()->all(); //format them for Input Widget $data = ArrayHelper::getColumn($data, 'username'); Dialog::begin(['id' => 'dlgPrivateMsg', 'clientOptions' => ['modal' => true, 'title' => YBoard::t('yboard', 'Send Private Message'), 'autoOpen' => false, 'height' => '400', 'width' => '400', 'buttons' => [['text' => YBoard::t('yboard', 'Send'), 'class' => 'btn btn-sm btn-success', 'click' => new \yii\web\JsExpression('function(){ for(instance in CKEDITOR.instances) { CKEDITOR.instances[instance].updateElement(); } sendPMForm(); }')], ['text' => YBoard::t('yboard', 'Cancel'), 'class' => 'btn btn-sm btn-danger', 'click' => new \yii\web\JsExpression(' function() { $( this ).dialog( "close" ); }')]]]]); ?> <div class="yboard-message-form"> <?php $form = ActiveForm::begin(['id' => 'pm-form']); ?>