Display the interface for message preferences

@param object $user instance of a user
@return string The text to render
347020
public function render_user_message_preferences($user) {
        global $CFG;

        // Filter out enabled, available system_configured and user_configured processors only.
        $readyprocessors = array_filter(get_message_processors(), function($processor) {
            return $processor->enabled &&
                $processor->configured &&
                $processor->object->is_user_configured() &&
                // Filter out processors that don't have and message preferences to configure.
                $processor->object->has_message_preferences();
        });

        $providers = array_filter(message_get_providers_for_user($user->id), function($provider) {
            return $provider->component === 'moodle';
        });
        $preferences = \core_message\api::get_all_message_preferences($readyprocessors, $providers, $user);
        $notificationlistoutput = new \core_message\output\preferences\message_notification_list($readyprocessors,
            $providers, $preferences, $user);
        $context = $notificationlistoutput->export_for_template($this);

        // Get the privacy settings options for being messaged.
        $privacysetting = \core_message\api::get_user_privacy_messaging_preference($user->id);
        $choices = array();
        $choices[] = [
            'value' => \core_message\api::MESSAGE_PRIVACY_ONLYCONTACTS,
            'text' => get_string('contactableprivacy_onlycontacts', 'message'),
            'checked' => ($privacysetting == \core_message\api::MESSAGE_PRIVACY_ONLYCONTACTS)
        ];
        $choices[] = [
            'value' => \core_message\api::MESSAGE_PRIVACY_COURSEMEMBER,
            'text' => get_string('contactableprivacy_coursemember', 'message'),
            'checked' => ($privacysetting == \core_message\api::MESSAGE_PRIVACY_COURSEMEMBER)
        ];
        if (!empty($CFG->messagingallusers)) {
            // Add the MESSAGE_PRIVACY_SITE option when site-wide messaging between users is enabled.
            $choices[] = [
                'value' => \core_message\api::MESSAGE_PRIVACY_SITE,
                'text' => get_string('contactableprivacy_site', 'message'),
                'checked' => ($privacysetting == \core_message\api::MESSAGE_PRIVACY_SITE)
            ];
        }
        $context['privacychoices'] = $choices;

        return $this->render_from_template('message/message_preferences', $context);
    }
1300831
public function config_form($preferences) {
        global $CFG, $OUTPUT, $USER, $PAGE;

        $systemcontext = context_system::instance();
        if (!has_capability('message/airnotifier:managedevice', $systemcontext)) {
            return get_string('nopermissiontomanagedevices', 'message_airnotifier');
        }

        if (!$this->is_system_configured()) {
            return get_string('notconfigured', 'message_airnotifier');
        } else {

            $airnotifiermanager = new message_airnotifier_manager();
            $devicetokens = $airnotifiermanager->get_user_devices($CFG->airnotifiermobileappname, $USER->id);

            if (!empty($devicetokens)) {
                $output = '';

                foreach ($devicetokens as $devicetoken) {

                    if ($devicetoken->enable) {
                        $hideshowiconname = 't/hide';
                        $dimmed = '';
                    } else {
                        $hideshowiconname = 't/show';
                        $dimmed = 'dimmed_text';
                    }

                    $hideshowicon = $OUTPUT->pix_icon($hideshowiconname, get_string('showhide', 'message_airnotifier'));
                    $name = "{$devicetoken->name} {$devicetoken->model} {$devicetoken->platform} {$devicetoken->version}";

                    $output .= html_writer::start_tag('li', array('id' => $devicetoken->id,
                                                                    'class' => 'airnotifierdevice ' . $dimmed)) . "\n";
                    $output .= html_writer::label($name, 'deviceid-' . $devicetoken->id, array('class' => 'devicelabel ')) . ' ' .
                        html_writer::link('#', $hideshowicon, array('class' => 'hidedevice', 'alt' => 'show/hide')) . "\n";
                    $output .= html_writer::end_tag('li') . "\n";
                }

                // Include the AJAX script to automatically trigger the action.
                $airnotifiermanager->include_device_ajax();

                $output = html_writer::tag('ul', $output, array('class' => 'list-unstyled unstyled',
                    'id' => 'airnotifierdevices'));
            } else {
                $output = get_string('nodevices', 'message_airnotifier');
            }
            return $output;
        }
    }
2397
private function serializePublic(User $user)
    {
        $settingsProfile = $this->facetManager->getVisiblePublicPreference();
        $publicUser = [];

        foreach ($settingsProfile as $property => $isViewable) {
            if ($isViewable || $user === $this->tokenStorage->getToken()->getUser()) {
                switch ($property) {
                    case 'baseData':
                        $publicUser['lastName'] = $user->getLastName();
                        $publicUser['firstName'] = $user->getFirstName();
                        $publicUser['fullName'] = $user->getFirstName().' '.$user->getLastName();
                        $publicUser['username'] = $user->getUsername();
                        $publicUser['picture'] = $user->getPicture();
                        $publicUser['description'] = $user->getDescription();
                        break;
                    case 'email':
                        $publicUser['mail'] = $user->getEmail();
                        break;
                    case 'phone':
                        $publicUser['phone'] = $user->getPhone();
                        break;
                    case 'sendMail':
                        $publicUser['mail'] = $user->getEmail();
                        $publicUser['allowSendMail'] = true;
                        break;
                    case 'sendMessage':
                        $publicUser['allowSendMessage'] = true;
                        $publicUser['id'] = $user->getId();
                        break;
                }
            }
        }

        $publicUser['groups'] = [];
        //this should be protected by the visiblePublicPreference but it's not yet the case
        foreach ($user->getGroups() as $group) {
            $publicUser['groups'][] = ['name' => $group->getName(), 'id' => $group->getId()];
        }

        return $publicUser;
    }
1333309
private function serializeMeta(User $user)
    {
        $locale = $user->getLocale();
        if (empty($locale)) {
            $locale = $this->config->getParameter('locale_language');
        }

        return [
            'publicUrl' => $user->getPublicUrl(),
            'publicUrlTuned' => $user->hasTunedPublicUrl(),
            'acceptedTerms' => $user->hasAcceptedTerms(),
            'lastLogin' => $user->getLastLogin() ? $user->getLastLogin()->format('Y-m-d\TH:i:s') : null,
            'created' => $user->getCreated() ? $user->getCreated()->format('Y-m-d\TH:i:s') : null,
            'description' => $user->getDescription(),
            'mailValidated' => $user->isMailValidated(),
            'mailNotified' => $user->isMailNotified(),
            'mailWarningHidden' => $user->getHideMailWarning(),
            'authentication' => $user->getAuthentication(),
            'personalWorkspace' => (bool) $user->getPersonalWorkspace(),
            'removed' => $user->isRemoved(),
            'locale' => $locale,
            'loggedIn' => $user === $this->tokenStorage->getToken()->getUser(),
        ];
    }
579161
public function sendCreationEmailMessage(UserInterface $user, $password)
    {
        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */
        $siteName  = $this->settingsManager->getParameter('general.site_name');
        $userName = sprintf('%s %s', $user->getFirstName(), $user->getLastName());
        $login = $user->getUsername();

        if (0 === strlen($password)) {
            return 0;
        }

        if (null === $loginUrl = $this->getLoginUrl($user)) {
            return 0;
        }

        $rendered = $this->templating->render(
            'EkynaUserBundle:Admin/User:creation_email.html.twig',
            [
                'username'  => $userName,
                'sitename'  => $siteName,
                'login_url' => $loginUrl,
                'login'     => $login,
                'password'  => $password,
            ]
        );

        $subject = $this->translator->trans(
            'ekyna_user.email.creation.subject',
            ['%sitename%' => $siteName]
        );

        return $this->sendEmail($rendered, $user->getEmail(), $userName, $subject);
    }
1313438
public function showTeamMemberView(User $user)
    {
        return View::make('dashboard.team.edit')
            ->withPageTitle(trans('dashboard.team.edit.title').' - '.trans('dashboard.dashboard'))
            ->withUser($user);
    }
615944
function GetUserTokenSerialNumber(
      $user = ''
  ) {
      if($user != '') {
          $this->SetUser($user);
      }
      return mb_strtolower(isset($this->_user_data['token_serial']) ? $this->_user_data['token_serial'] : '');
  }
573304
private function _init_user(bbn\user $user): preferences
  {
    $this->user = $user;
    $this->id_user = $this->user->get_id();
    $this->id_group = $this->user->get_group();
    return $this;
  }
644680
function getAbsDir($user)
    {
        if (!$this->users[$user]['chroot'])
        {
            $rdir = $this->users[$user]['pwd'];
        }
        else
        {
            $rdir = $this->users[$user]['home'].$this->users[$user]['pwd'];
        }
        return $rdir;
    }
178960
public function GenerateSmsToken($user = '') {
        $userName = $user;
        $nowEpoch = time();
        $smsNowSteps = $nowEpoch;
        $smsDigits = 6;
        $userTokenSeed = substr(md5(date("YmdHis").mt_rand(100000,999999)),0,20).substr(md5(mt_rand(100000,999999).date("YmdHis")),0,20);
        $smsSeedBin = hex2bin(md5('sMs'.$this->GetEncryptionKey().$userTokenSeed.$userName.$nowEpoch));
        $smsToken = $this->GenerateOathHotp($smsSeedBin,$smsNowSteps,$smsDigits);
        $smsNiceToken = $this->ConvertToNiceToken($smsToken);
        return $smsNiceToken;
    }
552663
public function bulletinComportementWidgetAction(User $user)
    {
        $comportements = $this->totauxManager->getMoyenneComportement($user);

        $params = array('comportements' => $comportements);

        return $this->render('LaurentBulletinBundle::BulletinComportementWidget.html.twig', $params);
    }
1068188
private function invitationHandlerArguments($user)
    {
        return [
            $this->container->getDefinition(
                'bengor.user.infrastructure.persistence.' . $user . '_repository'
            ),
            $this->container->getDefinition(
                'bengor.user.infrastructure.security.symfony.' . $user . '_password_encoder'
            ),
        ];
    }
148862
public function showProfileAction(DacorpUser $user)
    {
        $em = $this->getDoctrine()->getManager();

        if ($user instanceof DacorpUser)
            $chosenAvatarFilename = ($user->getCurrentAvatar()) ? $em->getRepository('DacorpExtraBundle:DacorpMedia')->find($user->getCurrentAvatar())->getFilename() : null;

        return $this->render('DacorpExtraBundle:User:showUserProfile.html.twig', array(
            'user' => $user,
            'avatar' => $chosenAvatarFilename
        ));
    }
973605
public function setUserLoggedIn(AdminUser $user): string
    {
        $_SESSION['admin_logged'] = true;
        $_SESSION['admin_id'] = $user->getId();
        $_SESSION['admin_login'] = $user->getLogin();
        $_SESSION['admin_sid'] = Users::getInstance()->startSession($user->getId());

        if (!defined('USER_ID')) {
            define('USER_ID', $user->getId());
        }

        App::add('User "' . $user->getLogin() . '" logged in.');

        return $_SESSION['admin_sid'];
    }
661503
private function set_notification_language($user) {
        global $CFG;

        // Copied from current_language().
        if (!empty($user->lang)) {
            $lang = $user->lang;
        } else if (isset($CFG->lang)) {
            $lang = $CFG->lang;
        } else {
            $lang = 'en';
        }
        force_current_language($lang);
    }
1046190
public static function export_user_preferences(int $userid) {
        $user = \core_user::get_user($userid);

        switch ($user->maildigest) {
            case 1:
                $digestdescription = get_string('emaildigestcomplete');
                break;
            case 2:
                $digestdescription = get_string('emaildigestsubjects');
                break;
            case 0:
            default:
                $digestdescription = get_string('emaildigestoff');
                break;
        }
        writer::export_user_preference('mod_forum', 'maildigest', $user->maildigest, $digestdescription);

        switch ($user->autosubscribe) {
            case 0:
                $subscribedescription = get_string('autosubscribeno');
                break;
            case 1:
            default:
                $subscribedescription = get_string('autosubscribeyes');
                break;
        }
        writer::export_user_preference('mod_forum', 'autosubscribe', $user->autosubscribe, $subscribedescription);

        switch ($user->trackforums) {
            case 0:
                $trackforumdescription = get_string('trackforumsno');
                break;
            case 1:
            default:
                $trackforumdescription = get_string('trackforumsyes');
                break;
        }
        writer::export_user_preference('mod_forum', 'trackforums', $user->trackforums, $trackforumdescription);

        $markasreadonnotification = get_user_preferences('markasreadonnotification', null, $user->id);
        if (null !== $markasreadonnotification) {
            switch ($markasreadonnotification) {
                case 0:
                    $markasreadonnotificationdescription = get_string('markasreadonnotificationno', 'mod_forum');
                    break;
                case 1:
                default:
                    $markasreadonnotificationdescription = get_string('markasreadonnotificationyes', 'mod_forum');
                    break;
            }
            writer::export_user_preference('mod_forum', 'markasreadonnotification', $markasreadonnotification,
                    $markasreadonnotificationdescription);
        }

        $vaultfactory = \mod_forum\local\container::get_vault_factory();
        $discussionlistvault = $vaultfactory->get_discussions_in_forum_vault();
        $discussionlistsortorder = get_user_preferences('forum_discussionlistsortorder',
            $discussionlistvault::SORTORDER_LASTPOST_DESC);
        switch ($discussionlistsortorder) {
            case $discussionlistvault::SORTORDER_LASTPOST_DESC:
                $discussionlistsortorderdescription = get_string('discussionlistsortbylastpostdesc',
                    'mod_forum');
                break;
            case $discussionlistvault::SORTORDER_LASTPOST_ASC:
                $discussionlistsortorderdescription = get_string('discussionlistsortbylastpostasc',
                    'mod_forum');
                break;
            case $discussionlistvault::SORTORDER_CREATED_DESC:
                $discussionlistsortorderdescription = get_string('discussionlistsortbycreateddesc',
                    'mod_forum');
                break;
            case $discussionlistvault::SORTORDER_CREATED_ASC:
                $discussionlistsortorderdescription = get_string('discussionlistsortbycreatedasc',
                    'mod_forum');
                break;
            case $discussionlistvault::SORTORDER_REPLIES_DESC:
                $discussionlistsortorderdescription = get_string('discussionlistsortbyrepliesdesc',
                    'mod_forum');
                break;
            case $discussionlistvault::SORTORDER_REPLIES_ASC:
                $discussionlistsortorderdescription = get_string('discussionlistsortbyrepliesasc',
                    'mod_forum');
                break;
        }
        writer::export_user_preference('mod_forum', 'forum_discussionlistsortorder',
            $discussionlistsortorder, $discussionlistsortorderdescription);
    }
312251
public function getAllGroupConversations($user)
    {
        $conversations = $this->query()->withCount('users')
            ->with([
                'messages' => function ($query) {
                    return $query->latest();
                }, 'users',
            ])->whereHas('users', function ($query) use ($user) {
                $query->where('id', $user);
            })->get();

        return $conversations;
    }