本文整理汇总了PHP中common\models\User::thisUser方法的典型用法代码示例。如果您正苦于以下问题:PHP User::thisUser方法的具体用法?PHP User::thisUser怎么用?PHP User::thisUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\User
的用法示例。
在下文中一共展示了User::thisUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Creates a form model given a token.
*
* @param array $config name-value pairs that will be used to initialize the object properties
* @throws \yii\base\InvalidParamException if token is empty or not valid
*/
public function __construct($config = [])
{
$this->_user = User::thisUser();
if (!$this->_user) {
throw new InvalidParamException('Wrong password reset token.');
}
parent::__construct($config);
}
示例2: actionAdd
public function actionAdd()
{
$user = User::thisUser();
if (Yii::$app->request->isPost) {
$img = new Img();
$img->user_id = $user->id;
if ($img->save()) {
$img->imgFile = UploadedFile::getInstance($img, 'imgFile');
if ($img->imgFile instanceof UploadedFile && $img->validate('imgFile')) {
$prefix = Yii::$app->params['prefix'];
if (empty($prefix)) {
$prefix = "no_prefix";
}
$dirName = 'user' . $user->id;
$path = '/' . $prefix . '/img/' . $dirName . '/';
$fileName = 'img_' . $user->id . '_' . $img->id . '.' . pathinfo($img->imgFile->name, PATHINFO_EXTENSION);
if (!empty($prefix)) {
$fileName = $prefix . '_' . $fileName;
}
/** @var YandexDiskComponent $yandexDisk */
$yandexDisk = Yii::$app->yandexDisk;
$yandexDisk->setClientInfoImgDefault();
// Тест папки $path на существование
$pathInfo = $yandexDisk->getProperty($path);
if (!$pathInfo) {
$pathInfoMusic = $yandexDisk->getProperty('/' . $prefix . '/');
if (!$pathInfoMusic) {
$yandexDisk->createDirectory('/' . $prefix . '/');
}
$pathInfoMusic = $yandexDisk->getProperty('/' . $prefix . '/img/');
if (!$pathInfoMusic) {
$yandexDisk->createDirectory('/' . $prefix . '/img/');
}
$yandexDisk->createDirectory($path);
}
$fileInfo = $yandexDisk->getProperty($path . $fileName);
if (!$fileInfo) {
// Такого файла еще нет
$uploadInfo = $yandexDisk->uploadFile($path, (array) $img->imgFile, $fileName);
}
$publishInfo = $yandexDisk->startPublishing($path . $fileName);
if (is_string($publishInfo) && !empty($publishInfo)) {
$img->url = $publishInfo;
$shortUrl = Yii::$app->google->getShortUrl('https://getfile.dokpub.com/yandex/get/' . $publishInfo);
if (!empty($shortUrl['id'])) {
$img->short_url = $shortUrl['id'];
}
}
$img->key = $yandexDisk->key;
$img->entity_key = $yandexDisk::THIS_ENTITY;
$img->save();
}
}
$result = ['id' => $img->id, 'short_url' => $img->short_url];
return json_encode($result);
}
$this->redirect(Url::home());
}
示例3: run
public function run()
{
$query = Comment::find();
if ($this->entity == Comment::ENTITY_ITEM || $this->entity == Comment::ENTITY_EVENT || $this->entity == Comment::ENTITY_SCHOOL) {
$query = $query->andWhere(['entity' => $this->entity, 'entity_id' => $this->entity_id])->orderBy('date_create DESC');
}
$commentsAll = $query->all();
$commentIds = [];
$comments = [];
$commentsParent = [];
$commentsLink = [];
/** @var Comment[] $commentsAll */
foreach ($commentsAll as $comment) {
if ($comment->parent_id == 0) {
// Главный комментарий
$commentsLink[$comment->id] = true;
$commentIds[] = $comment->id;
if ($comment->deleted == 0) {
$comments[] = $comment;
}
} else {
// Ответ на комментарий
$commentsLink[$comment->id] = $comment->parent_id;
}
}
foreach ($commentsAll as $comment) {
if ($comment->deleted == 0) {
$commentId = $comment->parent_id;
while (isset($commentsLink[$commentId])) {
if ($commentsLink[$commentId] === true) {
break;
} else {
if ($commentsLink[$commentId] != $commentId) {
$commentId = $commentsLink[$commentId];
} else {
$commentId = null;
}
}
}
if (!empty($commentId)) {
$commentsParent[$commentId][] = $comment;
$commentIds[] = $comment->id;
}
}
}
$thisUser = User::thisUser();
/** @var Vote[] $voteItemsAll */
$voteItemsAll = !empty($thisUser) ? $thisUser->getVotesByEntity(Vote::ENTITY_COMMENT, $commentIds) : [];
$voteItems = [];
foreach ($voteItemsAll as $voteItem) {
$voteItems[$voteItem->entity_id] = $voteItem;
}
return $this->render('commentsWidget/list', ['comments' => $comments, 'voteItems' => $voteItems, 'commentsParent' => $commentsParent, 'entity' => $this->entity, 'entity_id' => $this->entity_id, 'showDialog' => $this->showDialog]);
}
示例4: actionDelete
public function actionDelete($id)
{
/** @var Comment $comment */
$comment = Comment::findOne($id);
if ($comment && $comment->user_id == User::thisUser()->id) {
$comment->deleted = 1;
if ($comment->save()) {
return json_encode(['content' => \frontend\widgets\CommentsWidget::widget(['entity' => $comment->entity, 'entity_id' => $comment->entity_id, 'showDialog' => false]), 'anchor' => '']);
}
}
return json_encode(['content' => '', 'anchor' => '']);
}
示例5: addAlarm
public static function addAlarm($entity, $entityId, $msg)
{
$countHour = self::find()->where('date_create >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 HOUR))')->count();
if ($countHour < 10) {
$model = new Alarm();
$model->user_id = User::thisUser()->id;
$model->entity = $entity;
$model->entity_id = $entityId;
$model->msg = $msg;
return $model->save();
}
return false;
}
示例6: actionEditavatar
public function actionEditavatar()
{
$user = User::thisUser();
if (Yii::$app->request->isPost) {
$user->imageFile = UploadedFile::getInstance($user, 'imageFile');
if ($user->imageFile instanceof UploadedFile && $user->validate('imageFile')) {
$uploadInfo = Yii::$app->cloudinary->uploadFromFile($user->imageFile->tempName, 'a' . md5("avatar_" . $user->id), ["avatar"]);
$user->avatar_pic = $uploadInfo['url'];
if ($user->save()) {
return Yii::$app->getResponse()->redirect(Url::to(['account/profile']));
}
}
}
return json_encode(['msg' => '']);
}
示例7: actionDelete
public function actionDelete($id)
{
/** @var Event $event */
$event = Event::findOne($id);
if ($event && $event->user_id == User::thisUser()->id) {
$event->deleted = 1;
if ($event->save()) {
return Yii::$app->getResponse()->redirect(['events/all']);
}
}
return Yii::$app->getResponse()->redirect($event->getUrl());
}
示例8: addVote
public static function addVote($entity, $id, $voteAdd)
{
$user = User::thisUser();
$vote = Vote::findOne(['entity' => $entity, 'entity_id' => $id, 'user_id' => $user->id]);
if (empty($vote)) {
$vote = new Vote();
$vote->entity = $entity;
$vote->entity_id = $id;
$vote->user_id = $user->id;
}
/** @var VoteModel $model */
$model = null;
if ($entity == self::ENTITY_ITEM) {
$model = Item::findOne($id);
if ($user->reputation < Item::MIN_REPUTATION_ITEM_VOTE) {
// Если только пользователь не отменяет свои дизлайки
if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
}
}
} else {
if ($entity == self::ENTITY_EVENT) {
$model = Event::findOne($id);
if ($user->reputation < Event::MIN_REPUTATION_EVENT_VOTE) {
// Если только пользователь не отменяет свои дизлайки
if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
}
}
} else {
if ($entity == self::ENTITY_SCHOOL) {
$model = School::findOne($id);
if ($user->reputation < School::MIN_REPUTATION_SCHOOL_VOTE) {
// Если только пользователь не отменяет свои дизлайки
if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
}
}
} else {
if ($entity == self::ENTITY_COMMENT) {
$model = Comment::findOne($id);
if ($user->reputation < Comment::MIN_REPUTATION_COMMENT_VOTE) {
// Если только пользователь не отменяет свои дизлайки
if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
}
}
}
}
}
}
if (!empty($model)) {
if ($vote->vote == self::VOTE_UP) {
if ($voteAdd == self::VOTE_UP) {
// убираем up
$vote->vote = self::VOTE_NONE;
$model->addVote(-1);
$model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP);
} else {
// ставим down
$vote->vote = self::VOTE_DOWN;
$model->addVote(-2);
$model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP);
$model->addReputation(VoteModel::ADD_REPUTATION_DOWN);
}
} elseif ($vote->vote == self::VOTE_DOWN) {
if ($voteAdd == self::VOTE_UP) {
// ставим up
$vote->vote = self::VOTE_UP;
$model->addVote(2);
$model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN);
$model->addReputation(VoteModel::ADD_REPUTATION_UP);
} else {
// убираем down
$vote->vote = self::VOTE_NONE;
$model->addVote(1);
$model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN);
}
} else {
if ($voteAdd == self::VOTE_UP) {
// ставим up
$vote->vote = self::VOTE_UP;
$model->addVote(1);
$model->addReputation(VoteModel::ADD_REPUTATION_UP);
} else {
// ставим down
$vote->vote = self::VOTE_DOWN;
$model->addVote(-1);
$model->addReputation(VoteModel::ADD_REPUTATION_DOWN);
}
}
}
if ($vote->save()) {
if (!empty($model)) {
$model->save();
}
}
return ['vote' => $vote->vote, 'count' => $model->getVoteCount()];
}
示例9: addReputation
public function addReputation($addReputation)
{
$user = User::thisUser();
$modelUserId = $this->user_id;
$paramsSelf = ['entity' => self::THIS_ENTITY, 'itemId' => $this->id, 'userId' => $user->id];
$paramsOther = ['entity' => self::THIS_ENTITY, 'itemId' => $this->id, 'userId' => $modelUserId];
if ($addReputation == VoteModel::ADD_REPUTATION_CANCEL_UP) {
// - хозяину записи за отмену лайка
Reputation::addReputation($modelUserId, Reputation::ENTITY_VOTE_LIKE_SELF_COMMENT_CANCEL, $paramsSelf);
} elseif ($addReputation == VoteModel::ADD_REPUTATION_UP) {
// + хозяину записи за лайк
Reputation::addReputation($modelUserId, Reputation::ENTITY_VOTE_LIKE_SELF_COMMENT, $paramsSelf);
} elseif ($addReputation == VoteModel::ADD_REPUTATION_CANCEL_DOWN) {
// + хозяину записи за отмену дизлайка
Reputation::addReputation($modelUserId, Reputation::ENTITY_VOTE_DISLIKE_SELF_COMMENT_CANCEL, $paramsSelf);
} elseif ($addReputation == VoteModel::ADD_REPUTATION_DOWN) {
// - хозяину записи за дизлайк
Reputation::addReputation($modelUserId, Reputation::ENTITY_VOTE_DISLIKE_SELF_COMMENT, $paramsSelf);
}
}
示例10: actionUloginbind
public function actionUloginbind()
{
$thisUser = \common\models\User::thisUser();
$loginUlogin = Yii::$app->request->post('login_ulogin');
if (!empty($loginUlogin)) {
$ulogin = new Ulogin();
if ($ulogin->loadAuthData($loginUlogin)) {
$modelInBase = Ulogin::findUlogin($ulogin->identity, $ulogin->network);
if (!empty($modelInBase)) {
$modelInBase->user_id = $thisUser->id;
$modelInBase->save();
} else {
$ulogin->user_id = $thisUser->id;
$ulogin->save();
}
$this->redirect(Url::to(['account/settings']));
}
}
}
示例11: actionDelete
public function actionDelete($id)
{
/** @var School $school */
$school = School::findOne($id);
if ($school && $school->user_id == User::thisUser()->id) {
$school->deleted = 1;
if ($school->save()) {
return Yii::$app->getResponse()->redirect(['schools/all']);
}
}
return Yii::$app->getResponse()->redirect($school->getUrl());
}
示例12: actionDelete
public function actionDelete($id)
{
/** @var Item $item */
$item = Item::findOne($id);
$thisUser = User::thisUser();
if ($item && ($item->user_id == $thisUser->id || $thisUser->reputation > Item::MIN_REPUTAION_BAD_ITEM_DELETE && $item->like_count < 0)) {
$item->deleted = 1;
if ($item->save()) {
return Yii::$app->getResponse()->redirect(Url::home());
}
}
return Yii::$app->getResponse()->redirect($item->getUrl());
}
示例13: url
<?php
$langs = Lang::find()->where('id != :current_id', [':current_id' => Lang::getCurrent()->id])->all();
foreach ($langs as $lang) {
echo Html::tag('li', Html::a(Html::img($lang->getImg(), ['height' => '16px']) . ' ' . $lang->name, Yii::$app->UrlManager->toLang($lang)));
}
?>
</ul>
</li>
</ul>
<?php
$menuItems = [];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => Lang::t('main', 'loginSignup'), 'url' => ['site/login']];
} else {
$displayName = User::thisUser()->getDisplayName();
$displayProfile = Html::tag('div', '', ['style' => "background-image: url('" . User::thisUser()->getAvatarPic() . "');", 'class' => 'background-img nav-profile-img']) . " " . (empty($displayName) ? Lang::t('main', 'profile') : $displayName) . ' ' . '<span class="badge">' . User::thisUser()->reputation . '</span>';
$menuItems[] = ['encode' => false, 'label' => $displayProfile, 'url' => ['account/profile']];
$menuItems[] = ['label' => Lang::t('main', 'logout'), 'url' => ['site/logout'], 'linkOptions' => ['data-method' => 'post']];
}
echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right', 'encodeLabels' => false], 'items' => $menuItems]);
NavBar::end();
?>
<div class="container">
<div class="row main-header">
<div class="col-md-12">
<?php
echo Html::a(Html::img(Yii::$app->UrlManager->to('img/logo.png'), ['height' => '100px']), $mainUrl, ['class' => 'pull-left visible-md-block visible-lg-block visible-sm-block']);
?>
<div class="main-right-head-block">
<?php
示例14: addReputation
/**
* @param null $userId Кому изменить
* @param string $entity Действие
* @param array $params Дополнительные параметры
*
* @return bool
*/
public static function addReputation($userId = null, $entity = self::ENTITY_NONE, $params = [])
{
if (empty($userId) || $entity == self::ENTITY_VOTE_DISLIKE_OTHER_ITEM || !($findUser = User::findOne([$userId]))) {
$findUser = User::thisUser();
$userId = $findUser->id;
}
if (empty($findUser)) {
return false;
}
$pItemId = '?';
$itemIdKeys = ['itemId', 'eventId', 'schoolId', 'id'];
foreach ($itemIdKeys as $itemIdKey) {
if (isset($params[$itemIdKey])) {
$pItemId = $params[$itemIdKey];
break;
}
}
$pUserId = $params['userId'] ? $params['userId'] : '?';
if ($pUserId == $userId && in_array($entity, self::notSelfChange())) {
return false;
}
if ($entity == self::ENTITY_VOTE_LIKE_SELF_ITEM) {
$params['msg'] = "Запись {$pItemId} понравилась пользователю {$pUserId}.";
$params['value'] = 5;
} else {
if ($entity == self::ENTITY_VOTE_LIKE_SELF_ITEM_CANCEL) {
$params['msg'] = "Отмена: Запись {$pItemId} понравилась пользователю {$pUserId}.";
$params['value'] = -5;
} else {
if ($entity == self::ENTITY_VOTE_DISLIKE_SELF_ITEM) {
$params['msg'] = "Запись {$pItemId} не понравилась пользователю {$pUserId}.";
$params['value'] = -5;
} else {
if ($entity == self::ENTITY_VOTE_DISLIKE_SELF_ITEM_CANCEL) {
$params['msg'] = "Отмена: Запись {$pItemId} не понравилась пользователю {$pUserId}.";
$params['value'] = 5;
} else {
if ($entity == self::ENTITY_VOTE_DISLIKE_OTHER_ITEM) {
$params['msg'] = "Не понравилась запись {$pItemId}.";
$params['value'] = -1;
} else {
if ($entity == self::ENTITY_VOTE_DISLIKE_OTHER_ITEM_CANCEL) {
$params['msg'] = "Отмена: Не понравилась запись {$pItemId}.";
$params['value'] = 1;
} else {
if ($entity == self::ENTITY_VOTE_LIKE_OTHER_ITEM) {
$params['msg'] = "Понравилась запись {$pItemId}.";
$params['value'] = 1;
} else {
if ($entity == self::ENTITY_VOTE_LIKE_SELF_EVENT) {
$params['msg'] = "Событие {$pItemId} понравилась пользователю {$pUserId}.";
$params['value'] = 5;
} else {
if ($entity == self::ENTITY_VOTE_LIKE_SELF_EVENT_CANCEL) {
$params['msg'] = "Отмена: Событие {$pItemId} понравилась пользователю {$pUserId}.";
$params['value'] = -5;
} else {
if ($entity == self::ENTITY_VOTE_DISLIKE_SELF_EVENT) {
$params['msg'] = "Событие {$pItemId} не понравилась пользователю {$pUserId}.";
$params['value'] = -5;
} else {
if ($entity == self::ENTITY_VOTE_DISLIKE_SELF_EVENT_CANCEL) {
$params['msg'] = "Отмена: Событие {$pItemId} не понравилась пользователю {$pUserId}.";
$params['value'] = 5;
} else {
if ($entity == self::ENTITY_VOTE_DISLIKE_OTHER_EVENT) {
$params['msg'] = "Не понравилось событие {$pItemId}.";
$params['value'] = -1;
} else {
if ($entity == self::ENTITY_VOTE_DISLIKE_OTHER_EVENT_CANCEL) {
$params['msg'] = "Отмена: Не понравилось событие {$pItemId}.";
$params['value'] = 1;
} else {
if ($entity == self::ENTITY_VOTE_LIKE_OTHER_EVENT) {
$params['msg'] = "Понравилось событие {$pItemId}.";
$params['value'] = 1;
} else {
if ($entity == self::ENTITY_VOTE_LIKE_SELF_SCHOOL) {
$params['msg'] = "Школа {$pItemId} понравилась пользователю {$pUserId}.";
$params['value'] = 5;
} else {
if ($entity == self::ENTITY_VOTE_LIKE_SELF_SCHOOL_CANCEL) {
$params['msg'] = "Отмена: Школа {$pItemId} понравилась пользователю {$pUserId}.";
$params['value'] = -5;
} else {
if ($entity == self::ENTITY_VOTE_DISLIKE_SELF_SCHOOL) {
$params['msg'] = "Школа {$pItemId} не понравилась пользователю {$pUserId}.";
$params['value'] = -5;
} else {
if ($entity == self::ENTITY_VOTE_DISLIKE_SELF_SCHOOL_CANCEL) {
$params['msg'] = "Отмена: Школа {$pItemId} не понравилась пользователю {$pUserId}.";
$params['value'] = 5;
} else {
//.........这里部分代码省略.........
示例15: actionSave
public function actionSave()
{
$thisUser = User::thisUser();
$id = Yii::$app->request->post('id');
$music = Music::findOne($id);
if ($music->user_id == $thisUser->id) {
$music->artist = Yii::$app->request->post('artist');
$music->title = Yii::$app->request->post('title');
$music->save();
}
return json_encode(['musicHtml' => SoundWidget::widget(['music' => $music]), 'musicId' => $music->id]);
}