本文整理汇总了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()]);
}