本文整理匯總了PHP中bizley\podium\models\User::friendsList方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::friendsList方法的具體用法?PHP User::friendsList怎麽用?PHP User::friendsList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bizley\podium\models\User
的用法示例。
在下文中一共展示了User::friendsList方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionNew
/**
* Adding a new message.
* @param integer $user message receiver's ID
* @return string|\yii\web\Response
*/
public function actionNew($user = null)
{
$podiumUser = User::findMe();
if (Message::tooMany($podiumUser->id)) {
$this->warning(Yii::t('podium/flash', 'You have reached maximum {max_messages, plural, =1{ message} other{ messages}} per {max_minutes, plural, =1{ minute} other{ minutes}} limit. Wait few minutes before sending a new message.', ['max_messages' => Message::SPAM_MESSAGES, 'max_minutes' => Message::SPAM_WAIT]));
return $this->redirect(['messages/inbox']);
}
$model = new Message();
$to = null;
if (!empty($user) && (int) $user > 0 && (int) $user != $podiumUser->id) {
$member = User::find()->where(['id' => (int) $user, 'status' => User::STATUS_ACTIVE])->limit(1)->one();
if ($member) {
$model->receiversId = [$member->id];
$to = $member;
}
}
if ($model->load(Yii::$app->request->post())) {
if ($model->validate()) {
$validated = [];
$errors = false;
if (!empty($model->friendsId)) {
$model->receiversId = array_merge(is_array($model->receiversId) ? $model->receiversId : [], is_array($model->friendsId) ? $model->friendsId : []);
}
if (empty($model->receiversId)) {
$this->addError('receiver_id', Yii::t('podium/view', 'You have to select at least one message receiver.'));
$errors = true;
} else {
foreach ($model->receiversId as $r) {
if ($r == $podiumUser->id) {
$this->addError('receiver_id', Yii::t('podium/view', 'You can not send message to yourself.'));
$errors = true;
} elseif ($podiumUser->isIgnoredBy($r)) {
$this->addError('receiver_id', Yii::t('podium/view', 'One of the selected members ignores you and has been removed from message receivers.'));
$errors = true;
} else {
$member = User::find()->where(['id' => (int) $r, 'status' => User::STATUS_ACTIVE])->limit(1)->one();
if ($member) {
$validated[] = $member->id;
if (count($validated) > Message::MAX_RECEIVERS) {
$this->addError('receiver_id', Yii::t('podium/view', 'You can send message up to a maximum of 10 receivers at once.'));
$errors = true;
break;
}
}
}
}
$model->receiversId = $validated;
}
if (!$errors) {
if ($model->send()) {
$this->success(Yii::t('podium/flash', 'Message has been sent.'));
return $this->redirect(['messages/inbox']);
} else {
$this->error(Yii::t('podium/flash', 'Sorry! There was some error while sending your message.'));
}
}
}
}
return $this->render('new', ['model' => $model, 'to' => $to, 'friends' => User::friendsList()]);
}