/** * 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(); }
/** * 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; }
/** * 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; }
/** * Provides a searchable user list of all workspace members in json. * */ public function actionSearch() { Yii::$app->response->format = 'json'; $space = $this->getSpace(); if (!$space->isMember()) { throw new HttpException(404, Yii::t('SpaceModule.controllers_SpaceController', 'This action is only available for workspace members!')); } $results = array(); $keyword = Yii::$app->request->get('keyword'); $query = User::find(); $query->leftJoin('space_membership', 'space_membership.user_id=user.id AND space_membership.space_id=:space_id AND space_membership.status=:member', ['space_id' => $space->id, 'member' => Membership::STATUS_MEMBER]); $query->andWhere('space_membership.space_id IS NOT NULL'); $query->joinWith('profile'); $query->limit(10); // Build Search Condition $parts = explode(" ", $keyword); $i = 0; foreach ($parts as $part) { $i++; $query->andWhere("(user.email LIKE :match OR " . "user.username LIKE :match OR " . "profile.firstname LIKE :match OR " . "profile.lastname LIKE :match OR " . "profile.title LIKE :match)", ['match' => '%' . $part . '%']); } foreach ($query->all() as $user) { $userInfo['guid'] = $user->guid; $userInfo['displayName'] = \yii\helpers\Html::encode($user->displayName); $userInfo['email'] = $user->email; $userInfo['image'] = $user->getProfileImage()->getUrl(); $userInfo['link'] = $user->getUrl(); $results[] = $userInfo; } return $results; }
/** * 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; }
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]); } } } }
/** * 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; }
/** * 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); }
/** * 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; }
/** * Broadcast a message to all users */ public function run() { //Send GCM notifications $model = new $this->modelClass(); $records = $model->findBySql("SELECT * FROM gcm_relation")->all(); $params = Yii::$app->getRequest()->getBodyParams(); $data = array('message' => $params['message'], 'url' => $params['url']); $results = array(); foreach ($records as $record) { if ($record->register_key) { //Enviar missatge $gcm = new GoogleCloudMessage(); $gcm->apiKey = Setting::Get('gcmAPIKey', 'gcm'); $gcm->url = Setting::Get('gcmURL', 'gcm'); $result = $gcm->send($data, array($record->register_key)); $results[$record->register_key] = $result; } } //Send mail notificacion $users = User::find()->distinct()->joinWith(['httpSessions', 'profile'])->where(['status' => User::STATUS_ENABLED]); Yii::setAlias('@gcmmodule', Yii::$app->getModule('gcm')->getBasePath()); foreach ($users->each() as $user) { $mail = Yii::$app->mailer->compose(['html' => '@gcmmodule/views/emails/NewMessage'], ['message' => $params['message'], 'url' => $params['url']]); $mail->setFrom([Setting::Get('systemEmailAddress', 'mailing') => Setting::Get('systemEmailName', 'mailing')]); $mail->setTo($user->email); $mail->setSubject('Nova notÃcia al web: ' . $params['message']); $mail->send(); } return true; }
/** * Executes the widgets */ public function run() { $groups = Group::find()->count(); $users = User::find()->count(); $statsAvgMembers = $users / $groups; $statsTopGroup = Group::find()->where('id = (SELECT group_id FROM user GROUP BY group_id ORDER BY count(*) DESC LIMIT 1)')->one(); // Render widgets view return $this->render('groupStats', array('statsTotalGroups' => $groups, 'statsAvgMembers' => round($statsAvgMembers, 1), 'statsTopGroup' => $statsTopGroup, 'statsTotalUsers' => $users)); }
/** * @inheritdoc */ public function auth() { $user = User::find()->where(['username' => $this->login->username])->orWhere(['email' => $this->login->username])->one(); if ($user !== null && $user->currentPassword !== null && $user->currentPassword->validatePassword($this->login->password)) { $this->setUserAttributes(['id' => $user->id]); return true; } return false; }
/** * Returns a user list which contains all users who likes it */ public function actionUserList() { $query = \humhub\modules\user\models\User::find(); $query->leftJoin('like', 'like.created_by=user.id'); $query->where(['like.object_id' => $this->contentId, 'like.object_model' => $this->contentModel]); $query->orderBy('like.created_at DESC'); $title = Yii::t('LikeModule.controllers_LikeController', "<strong>Users</strong> who like this"); return $this->renderAjaxContent(UserListBox::widget(['query' => $query, 'title' => $title])); }
/** * Executes the widgets */ public function run() { // Some member stats $statsTotalUsers = User::find()->active()->count(); $statsUserOnline = \humhub\modules\user\components\Session::getOnlineUsers()->count(); $statsUserFollow = Follow::find()->where(['object_model' => User::className()])->count(); // Render widgets view return $this->render('memberStats', array('statsTotalUsers' => $statsTotalUsers, 'statsUserOnline' => $statsUserOnline, 'statsUserFollow' => $statsUserFollow)); }
public function run() { $range = (int) Setting::Get('shownDays', 'birthday'); $birthdayCondition = "DATE_ADD(profile.birthday, \n INTERVAL YEAR(CURDATE())-YEAR(profile.birthday)\n + IF(DAYOFYEAR(CURDATE()) > DAYOFYEAR(profile.birthday),1,0)\n YEAR) \n BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL " . $range . " DAY);"; $users = User::find()->joinWith('profile')->where($birthdayCondition)->limit(10)->all(); if (count($users) == 0) { return; } return $this->render('birthdayPanel', array('users' => $users)); }
/** * 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->params['humhub']['apiEnabled']) { return; } $controller->stdout("Checking for new HumHub version... "); $latestVersion = libs\HumHubAPI::getLatestHumHubVersion(); if ($latestVersion != "" && version_compare($latestVersion, Yii::$app->version, ">")) { $notification = new notifications\NewVersionAvailable(); $notification->sendBulk(User::find()->where(['super_admin' => 1])); } $controller->stdout('done. ' . PHP_EOL, \yii\helpers\Console::FG_GREEN); }
/** * 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')->marketplaceEnabled) { return; } $controller->stdout("Checking for new HumHub version... "); $onlineModuleManager = new OnlineModuleManager(); $latestVersion = $onlineModuleManager->getLatestHumHubVersion(); if ($latestVersion != "" && version_compare($latestVersion, Yii::$app->version, ">")) { $notification = new notifications\NewVersionAvailable(); $notification->sendBulk(User::find()->where(['super_admin' => 1])); } $controller->stdout('done. ' . PHP_EOL, \yii\helpers\Console::FG_GREEN); }
public function afterSave($insert, $changedAttributes) { if ($insert) { if ($this->content->space !== null) { $query = User::find()->leftJoin('space_membership', 'space_membership.user_id=user.id AND space_membership.space_id=:spaceId AND space_membership.admin_role=1', [':spaceId' => $this->content->space->id])->where(['IS NOT', 'space_membership.space_id', new \yii\db\Expression('NULL')]); } else { $query = User::find()->where(['super_admin' => 1]); } $notification = new \humhub\modules\reportcontent\notifications\NewReportAdmin(); $notification->source = $this; $notification->originator = Yii::$app->user->getIdentity(); $notification->sendBulk($query); } return parent::afterSave($insert, $changedAttributes); }
/** * @inheritdoc */ public function parseRequest($manager, $request) { $pathInfo = $request->getPathInfo(); if (substr($pathInfo, 0, 2) == "u/") { $parts = explode('/', $pathInfo, 3); if (isset($parts[1])) { $user = User::find()->where(['username' => $parts[1]])->one(); if ($user !== null) { if (!isset($parts[2]) || $parts[2] == "") { $parts[2] = $this->defaultRoute; } $params = $request->get(); $params['uguid'] = $user->guid; return [$parts[2], $params]; } } } return false; }
public function actionUserList() { $calendarEntry = $this->getCalendarEntry(Yii::$app->request->get('id')); if ($calendarEntry == null) { throw new HttpException('404', Yii::t('CalendarModule.base', "Event not found!")); } $state = Yii::$app->request->get('state'); $query = User::find(); $query->leftJoin('calendar_entry_participant', 'user.id=calendar_entry_participant.user_id AND calendar_entry_participant.calendar_entry_id=:calendar_entry_id AND calendar_entry_participant.participation_state=:state', [':calendar_entry_id' => $calendarEntry->id, ':state' => $state]); $query->where('calendar_entry_participant.id IS NOT NULL'); $title = ""; if ($state == CalendarEntryParticipant::PARTICIPATION_STATE_ACCEPTED) { $title = Yii::t('CalendarModule.base', 'Attending users'); } elseif ($state == CalendarEntryParticipant::PARTICIPATION_STATE_DECLINED) { $title = Yii::t('CalendarModule.base', 'Declining users'); } elseif ($state == CalendarEntryParticipant::PARTICIPATION_STATE_MAYBE) { $title = Yii::t('CalendarModule.base', 'Maybe attending users'); } return $this->renderAjaxContent(UserListBox::widget(['query' => $query, 'title' => $title])); }
public function actionAssignAllMembers($spaceId) { $space = Space::findOne(['id' => $spaceId]); if ($space == null) { print "Error: Space not found! Check id!\n\n"; return; } $countMembers = 0; $countAssigns = 0; $this->stdout("\nAdding Members:\n\n"); foreach (User::find()->where(['status' => User::STATUS_ENABLED])->all() as $user) { if ($space->isMember($user->id)) { $countMembers++; } else { $this->stdout("\t" . $user->displayName . " added. \n", Console::FG_YELLOW); #Yii::app()->user->setId($user->id); Yii::$app->user->switchIdentity($user); $space->addMember($user->id); $countAssigns++; } } $this->stdout("\nAdded " . $countAssigns . " new members to space " . $space->name . "\n", Console::FG_GREEN); }
/** * Returns a query for received and not responded friend requests of an user * * @param User $user * @return \yii\db\ActiveQuery */ public static function getReceivedRequestsQuery($user) { $query = User::find(); // Users which NOT received a friend requests from given user $query->leftJoin('user_friendship recv', 'user.id=recv.friend_user_id AND recv.user_id=:userId', [':userId' => $user->id]); $query->andWhere(['IS', 'recv.id', new \yii\db\Expression('NULL')]); // Users which send a friend request to given user $query->leftJoin('user_friendship snd', 'user.id=snd.user_id AND snd.friend_user_id=:userId', [':userId' => $user->id]); $query->andWhere(['IS NOT', 'snd.id', new \yii\db\Expression('NULL')]); return $query; }
public static function onCronRun($event) { $controller = $event->sender; $interval = ""; if (Yii::$app->controller->action->id == 'hourly') { $interval = CronController::EVENT_ON_HOURLY_RUN; } elseif (Yii::$app->controller->action->id == 'daily') { $interval = CronController::EVENT_ON_DAILY_RUN; } else { return; } $users = User::find()->distinct()->joinWith(['httpSessions', 'profile'])->where(['status' => User::STATUS_ENABLED]); $totalUsers = $users->count(); $done = 0; $mailsSent = 0; $defaultLanguage = Yii::$app->language; Console::startProgress($done, $totalUsers, 'Sending update e-mails to users... ', false); foreach ($users->each() as $user) { if ($user->email === "") { continue; } // Check user should receive an email Yii::$app->user->switchIdentity($user); if ($user->language != "") { Yii::$app->language = $user->language; } else { Yii::$app->language = $defaultLanguage; } $notifications = Yii::$app->getModule('notification')->getMailUpdate($user, $interval); $activities = Yii::$app->getModule('activity')->getMailUpdate($user, $interval); if ($notifications != "" || $activities != "") { try { $mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/content/views/mails/Update'], ['activities' => $activities, 'notifications' => $notifications]); $mail->setFrom([Setting::Get('systemEmailAddress', 'mailing') => Setting::Get('systemEmailName', 'mailing')]); $mail->setTo($user->email); if ($interval == CronController::EVENT_ON_HOURLY_RUN) { $mail->setSubject(Yii::t('base', "Latest news")); } else { $mail->setSubject(Yii::t('base', "Your daily summary")); } $mail->send(); $mailsSent++; } catch (\Swift_SwiftException $ex) { Yii::error('Could not send mail to: ' . $user->email . ' - Error: ' . $ex->getMessage()); } catch (Exception $ex) { Yii::error('Could not send mail to: ' . $user->email . ' - Error: ' . $ex->getMessage()); } } Console::updateProgress(++$done, $totalUsers); } Console::endProgress(true); $controller->stdout('done - ' . $mailsSent . ' email(s) sent.' . PHP_EOL, \yii\helpers\Console::FG_GREEN); }
/** * Callback to validate module database records. * * @param \yii\base\Event $event */ public static function onIntegrityCheck($event) { $integrityController = $event->sender; $integrityController->showTestHeadline("User Module - Users (" . User::find()->count() . " entries)"); foreach (User::find()->joinWith(['profile'])->all() as $user) { if ($user->profile == null) { $integrityController->showWarning("User with id " . $user->id . " has no profile record!"); } } foreach (GroupUser::find()->joinWith(['user'])->all() as $groupUser) { if ($groupUser->user == null) { if ($integrityController->showFix("Deleting group admin " . $groupUser->id . " without existing user!")) { $groupUser->delete(); } } } $integrityController->showTestHeadline("User Module - Password (" . Password::find()->count() . " entries)"); foreach (Password::find()->joinWith(['user'])->all() as $password) { if ($password->user == null) { if ($integrityController->showFix("Deleting password " . $password->id . " without existing user!")) { $password->delete(); } } } $integrityController->showTestHeadline("User Module - Profile (" . Profile::find()->count() . " entries)"); foreach (Profile::find()->joinWith(['user'])->all() as $profile) { if ($profile->user == null) { if ($integrityController->showFix("Deleting profile " . $profile->user_id . " without existing user!")) { $profile->delete(); } } } $integrityController->showTestHeadline("User Module - Mentioning (" . Mentioning::find()->count() . " entries)"); foreach (Mentioning::find()->joinWith(['user'])->all() as $mentioning) { if ($mentioning->user == null) { if ($integrityController->showFix("Deleting mentioning " . $mentioning->id . " of non existing user!")) { $mentioning->delete(); } } if ($mentioning->getPolymorphicRelation() == null) { if ($integrityController->showFix("Deleting mentioning " . $mentioning->id . " of non target!")) { $mentioning->delete(); } } } $integrityController->showTestHeadline("User Module - Follow (" . Follow::find()->count() . " entries)"); foreach (Follow::find()->joinWith(['user'])->all() as $follow) { if ($follow->user == null) { if ($integrityController->showFix("Deleting follow " . $follow->id . " of non existing user!")) { $follow->delete(); } } if ($follow->getTarget() == null) { if ($integrityController->showFix("Deleting follow " . $follow->id . " of non target!")) { $follow->delete(); } } } $integrityController->showTestHeadline("User Module - Modules (" . models\Module::find()->count() . " entries)"); foreach (models\Module::find()->joinWith(['user'])->all() as $module) { if ($module->user == null) { if ($integrityController->showFix("Deleting user-module " . $module->id . " of non existing user!")) { $module->delete(); } } } }
public static function onCronRun($event) { $controller = $event->sender; $interval = ""; if (Yii::$app->controller->action->id == 'hourly') { $interval = CronController::EVENT_ON_HOURLY_RUN; } elseif (Yii::$app->controller->action->id == 'daily') { $interval = CronController::EVENT_ON_DAILY_RUN; } else { return; } $users = User::find()->distinct()->joinWith(['httpSessions', 'profile'])->where(['status' => User::STATUS_ENABLED]); $totalUsers = $users->count(); $done = 0; $mailsSent = 0; $defaultLanguage = Yii::$app->language; Console::startProgress($done, $totalUsers, 'Sending update e-mails to users... ', false); foreach ($users->each() as $user) { if ($user->email === "") { continue; } // Check user should receive an email Yii::$app->user->switchIdentity($user); if ($user->language != "") { Yii::$app->language = $user->language; } else { Yii::$app->language = $defaultLanguage; } $notifications = Yii::$app->getModule('notification')->getMailUpdate($user, $interval); $activities = Yii::$app->getModule('activity')->getMailUpdate($user, $interval); if ($notifications != "" || $activities != "") { try { /************************************** * TEBPATCH (ADD) @fcasanellas 14/01/2016 * #MSS001 Afegeix enviament via GCM * NEWCODE ***************************/ $gcm = new GoogleCloudMessage(); $gcm->apiKey = Setting::Get('gcmAPIKey', 'gcm'); $gcm->url = Setting::Get('gcmURL', 'gcm'); $data = array('message' => 'Noves publicacions'); foreach (GcmRelation::findAll(array('user_id' => $user->id)) as $pair) { $result = $gcm->send($data, array($pair->register_key)); } /************************************** * END TEBPATCH **********************/ $mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/content/views/mails/Update'], ['activities' => $activities, 'notifications' => $notifications]); $mail->setFrom([Setting::Get('systemEmailAddress', 'mailing') => Setting::Get('systemEmailName', 'mailing')]); $mail->setTo($user->email); if ($interval == CronController::EVENT_ON_HOURLY_RUN) { $mail->setSubject(Yii::t('base', "Latest news")); } else { $mail->setSubject(Yii::t('base', "Your daily summary")); } $mail->send(); $mailsSent++; } catch (\Swift_SwiftException $ex) { Yii::error('Could not send mail to: ' . $user->email . ' - Error: ' . $ex->getMessage()); } catch (Exception $ex) { Yii::error('Could not send mail to: ' . $user->email . ' - Error: ' . $ex->getMessage()); } } Console::updateProgress(++$done, $totalUsers); } Console::endProgress(true); $controller->stdout('done - ' . $mailsSent . ' email(s) sent.' . PHP_EOL, \yii\helpers\Console::FG_GREEN); }
/** * On rebuild of the search index, rebuild all user records * * @param \yii\base\Event $event */ public static function onSearchRebuild($event) { foreach (models\User::find()->all() as $obj) { \Yii::$app->search->add($obj); } }
public function actionAdminUserSearch() { Yii::$app->response->format = 'json'; $keyword = Yii::$app->request->get('keyword'); $group = Group::findOne(Yii::$app->request->get('id')); return UserPicker::filter(['query' => $group->getUsers(), 'keyword' => $keyword, 'fillQuery' => User::find(), 'disableFillUser' => false]); }
/** * Reads out all users from configured ldap backend and creates or update * existing users. * * Also disabling deleted ldap users in humhub */ public function refreshUsers() { $ldapUserIds = array(); try { $items = $this->ldap->search(Setting::Get('userFilter', 'authentication_ldap'), Setting::Get('baseDn', 'authentication_ldap'), \Zend\Ldap\Ldap::SEARCH_SCOPE_SUB); foreach ($items as $item) { $node = \Zend\Ldap\Node::fromArray($item); $user = $this->handleLdapUser($node); if ($user != null) { $ldapUserIds[] = $user->id; } } foreach (User::find()->where(['auth_mode' => User::AUTH_MODE_LDAP])->andWhere(['!=', 'status', User::STATUS_DISABLED])->each() as $user) { if (!in_array($user->id, $ldapUserIds)) { // User no longer available in ldap $user->status = User::STATUS_DISABLED; $user->save(); Yii::warning('Disabled user ' . $user->username . ' (' . $user->id . ') - Not found in LDAP!'); } } } catch (Exception $ex) { Yii::error($ex->getMessage()); } }
/** * Returns an user list which are space members */ public function actionMembersList() { $query = User::find(); $query->join('LEFT JOIN', 'space_membership', 'space_membership.user_id=user.id'); $query->andWhere(['space_membership.status' => Membership::STATUS_MEMBER]); $query->andWhere(['user.status' => User::STATUS_ENABLED]); $query->andWhere(['space_id' => $this->getSpace()->id]); $query->orderBy(['space_membership.group_id' => SORT_DESC]); $title = Yii::t('SpaceModule.controllers_MembershipController', "<strong>Members</strong>"); return $this->renderAjaxContent(UserListBox::widget(['query' => $query, 'title' => $title])); }
data-original-title="<?php echo Html::encode($follower->displayName); ?> "> </a> <?php } ?> </div> </div> <?php } ?> <?php $following = $user->getFollowingObjects(User::find()->limit(16)); if (count($following) > 0) { ?> <div class="panel panel-default follower" id="profile-following-panel"> <!-- Display panel menu widget --> <?php echo \humhub\widgets\PanelMenu::widget(['id' => 'profile-following-panel']); ?> <div class="panel-heading"> <?php echo Yii::t('UserModule.widgets_views_userFollower', '<strong>Following</strong> user'); ?> </div>