本文整理汇总了PHP中humhub\modules\user\models\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionAuto
public function actionAuto()
{
$this->stdout("Install:\n\n", Console::FG_YELLOW);
\humhub\modules\installer\libs\InitialData::bootstrap();
Yii::$app->settings->set('name', "HumHub Test");
Yii::$app->settings->set('mailer.systemEmailName', "humhub@example.com");
Yii::$app->settings->set('mailer.systemEmailName', "humhub@example.com");
Yii::$app->settings->set('secret', \humhub\libs\UUID::v4());
$user = new User();
//$user->group_id = 1;
$user->username = "Admin";
$user->email = 'humhub@example.com';
$user->status = User::STATUS_ENABLED;
$user->language = '';
$user->last_activity_email = new \yii\db\Expression('NOW()');
if (!$user->save()) {
throw new \yii\base\Exception("Could not save user");
}
$user->profile->title = "System Administration";
$user->profile->firstname = "John";
$user->profile->lastname = "Doe";
$user->profile->save();
$password = new Password();
$password->user_id = $user->id;
$password->setPassword('test');
$password->save();
// Assign to system admin group
Group::getAdminGroup()->addUser($user);
return self::EXIT_CODE_NORMAL;
}
示例2: run
/**
* @inheritdoc
*/
public function run()
{
if ($this->user->isCurrentUser() || \Yii::$app->user->isGuest) {
return;
}
if (Yii::$app->getModule('friendship')->getIsEnabled()) {
// Don't show follow button, when friends
if (Friendship::getFriendsQuery($this->user)->one() !== null) {
return;
}
}
// Add class for javascript handling
$this->followOptions['class'] .= ' followButton';
$this->unfollowOptions['class'] .= ' unfollowButton';
// Hide inactive button
if ($this->user->isFollowedByUser()) {
$this->followOptions['style'] .= ' display:none;';
} else {
$this->unfollowOptions['style'] .= ' display:none;';
}
// Add UserId Buttons
$this->followOptions['data-userid'] = $this->user->id;
$this->unfollowOptions['data-userid'] = $this->user->id;
$this->view->registerJsFile('@web/resources/user/followButton.js');
return Html::a($this->unfollowLabel, $this->user->createUrl('/user/profile/unfollow'), $this->unfollowOptions) . Html::a($this->followLabel, $this->user->createUrl('/user/profile/follow'), $this->followOptions);
}
示例3: getMailUpdate
public function getMailUpdate(User $user, $interval)
{
$output = "";
foreach (Session::find()->where(['<', 'expire', time()])->all() as $session) {
$session->delete();
}
$receive_email_notifications = $user->getSetting("receive_email_notifications", 'core', Setting::Get('receive_email_notifications', 'mailing'));
// Never receive notifications
if ($receive_email_notifications == User::RECEIVE_EMAIL_NEVER) {
return "";
}
// We are in hourly mode and user wants daily
if ($interval == CronController::EVENT_ON_HOURLY_RUN && $receive_email_notifications == User::RECEIVE_EMAIL_DAILY_SUMMARY) {
return "";
}
// We are in daily mode and user dont wants daily reports
if ($interval == CronController::EVENT_ON_DAILY_RUN && $receive_email_notifications != User::RECEIVE_EMAIL_DAILY_SUMMARY) {
return "";
}
// User wants only when offline and is online
if ($interval == CronController::EVENT_ON_HOURLY_RUN) {
$isOnline = count($user->httpSessions) > 0;
if ($receive_email_notifications == User::RECEIVE_EMAIL_WHEN_OFFLINE && $isOnline) {
return "";
}
}
$query = Notification::find()->where(['user_id' => $user->id])->andWhere(['!=', 'seen', 1])->andWhere(['!=', 'emailed', 1]);
foreach ($query->all() as $notification) {
$output .= $notification->getClass()->render(BaseNotification::OUTPUT_MAIL);
$notification->emailed = 1;
$notification->save();
}
return $output;
}
示例4: init
/**
* @inheritdoc
*/
public function init()
{
$this->addItemGroup(array('id' => 'profile', 'label' => Yii::t('UserModule.widgets_ProfileMenuWidget', '<strong>Profile</strong> menu'), 'sortOrder' => 100));
$this->addItem(array('label' => Yii::t('UserModule.widgets_ProfileMenuWidget', 'Stream'), 'group' => 'profile', 'url' => $this->user->createUrl('//user/profile/home'), 'sortOrder' => 200, 'isActive' => Yii::$app->controller->id == "profile" && (Yii::$app->controller->action->id == "index" || Yii::$app->controller->action->id == "home")));
if ($this->user->permissionManager->can(new \humhub\modules\user\permissions\ViewAboutPage())) {
$this->addItem(array('label' => Yii::t('UserModule.widgets_ProfileMenuWidget', 'About'), 'group' => 'profile', 'url' => $this->user->createUrl('//user/profile/about'), 'sortOrder' => 300, 'isActive' => Yii::$app->controller->id == "profile" && Yii::$app->controller->action->id == "about"));
}
parent::init();
}
示例5: testAutoWallCreation
public function testAutoWallCreation()
{
$user = new User();
$user->username = "wallTest";
$user->email = "wall@example.com";
$this->assertTrue($user->save());
$this->assertNotNull($user->wall_id);
$wall = Wall::findOne(['id' => $user->wall_id]);
$this->assertNotNull($wall);
}
示例6: run
/**
* @inheritdoc
*/
public function run()
{
$friendshipsEnabled = Yii::$app->getModule('friendship')->getIsEnabled();
$countFriends = 0;
if ($friendshipsEnabled) {
$countFriends = Friendship::getFriendsQuery($this->user)->count();
}
$countFollowing = $this->user->getFollowingCount(User::className()) + $this->user->getFollowingCount(Space::className());
$countUserSpaces = Membership::getUserSpaceQuery($this->user)->andWhere(['!=', 'space.visibility', Space::VISIBILITY_NONE])->andWhere(['space.status' => Space::STATUS_ENABLED])->count();
return $this->render('profileHeader', array('user' => $this->user, 'isProfileOwner' => $this->isProfileOwner, 'friendshipsEnabled' => $friendshipsEnabled, 'countFriends' => $countFriends, 'countFollowers' => $this->user->getFollowerCount(), 'countFollowing' => $countFollowing, 'countSpaces' => $countUserSpaces));
}
示例7: up
public function up()
{
$spaces = Space::find()->all();
$users = User::find()->all();
$containers = array_merge($users == null ? [] : $users, $spaces == null ? [] : $spaces);
foreach ($containers as $container) {
$created_by = $container instanceof User ? $container->id : $container instanceof Space ? $container->created_by : 1;
$created_by = $created_by == null ? 1 : $created_by;
if ($container->isModuleEnabled('cfiles')) {
$this->insert('cfiles_folder', ['title' => Module::ROOT_TITLE, 'description' => Module::ROOT_DESCRIPTION, 'parent_folder_id' => 0, 'has_wall_entry' => false, 'type' => Folder::TYPE_FOLDER_ROOT]);
$root_id = Yii::$app->db->getLastInsertID();
$this->insert('content', ['guid' => \humhub\libs\UUID::v4(), 'object_model' => Folder::className(), 'object_id' => $root_id, 'visibility' => 0, 'sticked' => 0, 'archived' => 0, 'created_at' => new \yii\db\Expression('NOW()'), 'created_by' => $created_by, 'updated_at' => new \yii\db\Expression('NOW()'), 'updated_by' => $created_by, 'contentcontainer_id' => $container->contentcontainer_id]);
$this->insert('cfiles_folder', ['title' => Module::ALL_POSTED_FILES_TITLE, 'description' => Module::ALL_POSTED_FILES_DESCRIPTION, 'parent_folder_id' => $root_id, 'has_wall_entry' => false, 'type' => Folder::TYPE_FOLDER_POSTED]);
$allpostedfiles_id = Yii::$app->db->getLastInsertID();
$this->insert('content', ['guid' => \humhub\libs\UUID::v4(), 'object_model' => Folder::className(), 'object_id' => $allpostedfiles_id, 'visibility' => 0, 'sticked' => 0, 'archived' => 0, 'created_at' => new \yii\db\Expression('NOW()'), 'created_by' => $created_by, 'updated_at' => new \yii\db\Expression('NOW()'), 'updated_by' => $created_by, 'contentcontainer_id' => $container->contentcontainer_id]);
$posted_content_id = Yii::$app->db->getLastInsertID();
$filesQuery = File::find()->joinWith('baseFile')->contentContainer($container);
$foldersQuery = Folder::find()->contentContainer($container);
$filesQuery->andWhere(['cfiles_file.parent_folder_id' => 0]);
// user maintained folders
$foldersQuery->andWhere(['cfiles_folder.parent_folder_id' => 0]);
// do not return any folders here that are root or allpostedfiles
$foldersQuery->andWhere(['cfiles_folder.type' => null]);
$rootsubfiles = $filesQuery->all();
$rootsubfolders = $foldersQuery->all();
foreach ($rootsubfiles as $file) {
$this->update('cfiles_file', ['cfiles_file.parent_folder_id' => $root_id], ['id' => $file->id]);
}
foreach ($rootsubfolders as $folder) {
$this->update('cfiles_folder', ['parent_folder_id' => $root_id], ['id' => $folder->id]);
}
}
}
}
示例8: actionJson
/**
* JSON Search for Users
*
* Returns an array of users with fields:
* - guid
* - displayName
* - image
* - profile link
*/
public function actionJson()
{
Yii::$app->response->format = 'json';
$maxResults = 10;
$keyword = Yii::$app->request->get('keyword');
$query = User::find()->limit($maxResults)->joinWith('profile');
foreach (explode(" ", $keyword) as $part) {
$query->orFilterWhere(['like', 'user.email', $part]);
$query->orFilterWhere(['like', 'user.username', $part]);
$query->orFilterWhere(['like', 'profile.firstname', $part]);
$query->orFilterWhere(['like', 'profile.lastname', $part]);
$query->orFilterWhere(['like', 'profile.title', $part]);
}
$query->active();
$results = [];
foreach ($query->all() as $user) {
if ($user != null) {
$userInfo = array();
$userInfo['guid'] = $user->guid;
$userInfo['displayName'] = Html::encode($user->displayName);
$userInfo['image'] = $user->getProfileImage()->getUrl();
$userInfo['link'] = $user->getUrl();
$results[] = $userInfo;
}
}
return $results;
}
示例9: onCronDailyRun
/**
* Check if there is a new Humhub Version available and sends a notification
* to super admins
*
* @param \yii\base\Event $event
*/
public static function onCronDailyRun($event)
{
$controller = $event->sender;
if (!Yii::$app->getModule('admin')->dailyCheckForNewVersion) {
return;
}
if (!Yii::$app->params['humhub']['apiEnabled']) {
return;
}
$controller->stdout("Checking for new HumHub version... ");
$latestVersion = libs\HumHubAPI::getLatestHumHubVersion();
if ($latestVersion != "") {
$adminUserQuery = User::find()->where(['super_admin' => 1]);
$latestNotifiedVersion = Setting::Get('lastVersionNotify', 'admin');
$adminsNotified = !($latestNotifiedVersion == "" || version_compare($latestVersion, $latestNotifiedVersion, ">"));
$newVersionAvailable = version_compare($latestVersion, Yii::$app->version, ">");
$updateNotification = new notifications\NewVersionAvailable();
// Cleanup existing notifications
if (!$newVersionAvailable || $newVersionAvailable && !$adminsNotified) {
foreach ($adminUserQuery->all() as $admin) {
$updateNotification->delete($admin);
}
}
// Create new notification
if ($newVersionAvailable && !$adminsNotified) {
$updateNotification->sendBulk($adminUserQuery);
Setting::Set('lastVersionNotify', $latestVersion, 'admin');
}
}
$controller->stdout('done. ' . PHP_EOL, \yii\helpers\Console::FG_GREEN);
}
示例10: getOnlineUsers
/**
* Returns all current logged in users.
*
* @return ActiveQueryUser
*/
public static function getOnlineUsers()
{
$query = \humhub\modules\user\models\User::find();
$query->leftJoin('user_http_session', 'user_http_session.user_id=user.id');
$query->andWhere(['IS NOT', 'user_http_session.user_id', new Expression('NULL')]);
return $query;
}
示例11: processCron
/**
* Processes update e-mails for all users
*/
public static function processCron($controller)
{
// Detect the mailing interval we're in
$interval = 0;
if (Yii::$app->controller->action->id == 'hourly') {
$interval = self::INTERVAL_HOURY;
} elseif (Yii::$app->controller->action->id == 'daily') {
$interval = self::INTERVAL_DAILY;
} else {
throw new \yii\console\Exception('Invalid mail update interval!');
}
// Get users
$users = User::find()->distinct()->joinWith(['httpSessions', 'profile'])->where(['user.status' => User::STATUS_ENABLED]);
$totalUsers = $users->count();
$processed = 0;
Console::startProgress($processed, $totalUsers, 'Sending update e-mails to users... ', false);
$mailsSent = 0;
foreach ($users->each() as $user) {
$mailSender = new self();
$mailSender->user = $user;
$mailSender->interval = $interval;
if ($mailSender->send()) {
$mailsSent++;
}
Console::updateProgress(++$processed, $totalUsers);
}
Console::endProgress(true);
$controller->stdout('done - ' . $mailsSent . ' email(s) sent.' . PHP_EOL, Console::FG_GREEN);
// Switch back to system language
self::switchLanguage();
}
示例12: actionEdit
/**
* Edit a karma record
*/
public function actionEdit()
{
$id = (int) Yii::$app->request->get('id');
$user = User::findOne(['id' => $id]);
$karma = Karma::findOne(['id' => $id]);
if ($karma == null) {
throw new \yii\web\HttpException(404, "Karma record not found!");
}
// Build Form Definition
$definition = array();
$definition['elements'] = array();
// Define Form Eleements
$definition['elements']['Karma'] = array('type' => 'form', 'title' => 'Karma', 'elements' => array('name' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'points' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 10), 'description' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 1000)));
// Get Form Definition
$definition['buttons'] = array('save' => array('type' => 'submit', 'label' => 'Save', 'class' => 'btn btn-primary'), 'delete' => array('type' => 'submit', 'label' => 'Delete', 'class' => 'btn btn-danger'));
$form = new HForm($definition);
$form->models['Karma'] = $karma;
if ($form->submitted('save') && $form->validate()) {
if ($form->save()) {
return $this->redirect(Url::toRoute(['edit', 'id' => $karma->id]));
}
}
if ($form->submitted('delete')) {
return $this->redirect(Url::toRoute(['delete', 'id' => $karma->id]));
}
return $this->render('edit', array('hForm' => $form));
}
示例13: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params = [])
{
$query = User::find()->joinWith(['profile', 'group']);
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]);
$dataProvider->setSort(['attributes' => ['group.id', 'username', 'email', 'super_admin', 'profile.firstname', 'profile.lastname', 'created_at']]);
$this->load($params);
if (!$this->validate()) {
$query->where('0=1');
return $dataProvider;
}
/**
* Limit Groups
*/
$groups = $this->getGroups();
$groupIds = [];
foreach ($groups as $group) {
$groupIds[] = $group->id;
}
$query->andWhere(['IN', 'group_id', $groupIds]);
$query->andWhere(['status' => User::STATUS_NEED_APPROVAL]);
$query->andFilterWhere(['id' => $this->id]);
$query->andFilterWhere(['group.id' => $this->getAttribute('group.id')]);
$query->andFilterWhere(['super_admin' => $this->super_admin]);
$query->andFilterWhere(['like', 'id', $this->id]);
$query->andFilterWhere(['like', 'username', $this->username]);
$query->andFilterWhere(['like', 'email', $this->email]);
$query->andFilterWhere(['like', 'profile.firstname', $this->getAttribute('profile.firstname')]);
$query->andFilterWhere(['like', 'profile.lastname', $this->getAttribute('profile.lastname')]);
return $dataProvider;
}
示例14: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find()->joinWith('profile');
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]);
$dataProvider->setSort(['attributes' => ['id', 'username', 'email', 'super_admin', 'last_login', 'profile.firstname', 'profile.lastname', 'created_at']]);
$this->load($params);
if (!$this->validate()) {
$query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id]);
$query->andFilterWhere(['super_admin' => $this->super_admin]);
$query->andFilterWhere(['like', 'id', $this->id]);
$query->andFilterWhere(['like', 'username', $this->username]);
$query->andFilterWhere(['like', 'email', $this->email]);
$query->andFilterWhere(['like', 'profile.firstname', $this->getAttribute('profile.firstname')]);
$query->andFilterWhere(['like', 'profile.lastname', $this->getAttribute('profile.lastname')]);
if ($this->getAttribute('last_login') != "") {
try {
$last_login = Yii::$app->formatter->asDate($this->getAttribute('last_login'), 'php:Y-m-d');
$query->andWhere(['=', new \yii\db\Expression("DATE(last_login)"), new \yii\db\Expression("DATE(:last_login)", [':last_login' => $last_login])]);
} catch (InvalidParamException $e) {
// do not change the query if the date is wrong formatted
}
}
return $dataProvider;
}
示例15: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find()->joinWith('profile');
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]);
$dataProvider->setSort(['attributes' => ['id', 'username', 'email', 'super_admin', 'last_login', 'profile.firstname', 'profile.lastname', 'created_at']]);
$this->load($params);
if (!$this->validate()) {
$query->where('0=1');
return $dataProvider;
}
if (strtolower($this->last_login) == 'yes') {
$query->andWhere(['not', ['last_login' => null]]);
} else {
if (strtolower($this->last_login) == 'no') {
$query->andWhere(['last_login' => null]);
}
}
$query->andFilterWhere(['id' => $this->id]);
$query->andFilterWhere(['super_admin' => $this->super_admin]);
$query->andFilterWhere(['like', 'id', $this->id]);
$query->andFilterWhere(['like', 'username', $this->username]);
$query->andFilterWhere(['like', 'email', $this->email]);
$query->andFilterWhere(['like', 'profile.firstname', $this->getAttribute('profile.firstname')]);
$query->andFilterWhere(['like', 'profile.lastname', $this->getAttribute('profile.lastname')]);
return $dataProvider;
}