Reads the crontab file and returns the output. Default: current user.

@param string $user

@return string
966810
private function read($user = null)
    {
        $process = new Process($this->getCommand() . ' -l');

        $process->run();

        return $process->getOutput();
    }
732972
public static function getNonBlameds($user = null)
    {
        $noInit = static::buildNoInitModel();
        /* @var $noInit static */
        $createdByAttribute = $noInit->createdByAttribute;
        if (!$user) {
            $user = \Yii::$app->user->identity;
        }
        $cond = [
            $createdByAttribute => $user->getGUID(),
            $noInit->multiBlamesAttribute => ''
        ];
        return static::find()->where($cond)->all();
    }
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'];
    }
1008408
protected function tryChangeUser($user)
    {
        $changed_user = false;
        // Check user can be changed?
        if ($user && posix_getuid() > 0) {
            // Not root
            throw new \RuntimeException('Only root can change user to spawn the process');
        }

        // Check user if exists?
        if ($user && !($changed_user = posix_getpwnam($user))) {
            throw new \RuntimeException('Can not look up user: ' . $user);
        }

        return $changed_user;
    }
706396
public function getGroupDateTimeEntered($user)
    {
        if (is_object($user)) {
            $userID = (int) $user->getUserID();
        } elseif (is_numeric($user)) {
            $userID = (int) $user;
        } else {
            $userID = 0;
        }
        $result = null;
        if ($userID !== 0) {
            $db = Application::getFacadeApplication()->make(Connection::class);
            /* @var Connection $db */
            $value = $db->fetchColumn(
                'select ugEntered from UserGroups where gID = ? and uID = ?',
                [$this->gID, $userID]
            );
            if ($value) {
                $result = $value;
            }
        }

        return $result;
    }
328804
private function getUserFullName($user)
    {
        $strReturn = '';
        if ($user && method_exists($user, 'getContact')) {
            $strReturn = $user->getContact()->getFirstName() . ' ' . $user->getContact()->getLastName();
        }

        return $strReturn;
    }
316409
public static function getUserCrlf()
    {
        static $crlf = null;
        if ($crlf !== null) {
            return $crlf;
        }
        
        if(empty($_SERVER['HTTP_USER_AGENT'])) {
            return $crlf = "\n";
        }
        
        if (stristr($_SERVER['HTTP_USER_AGENT'], 'Win')) {
            $crlf = "\r\n";
        } elseif (stristr($_SERVER['HTTP_USER_AGENT'], 'Mac')) {
            $crlf = "\r"; // for old MAC OS
        } else {
            $crlf = "\n";
        }
        
        return $crlf;
    }
104629
public static function changeUser($user)
    {
        $currentUser = self::getCurrentUser();

        if ($currentUser != $user) {
            $user = posix_getpwnam($user);
            if ($user) {
                posix_setuid($user['uid']);
                posix_setgid($user['gid']);
            }
        }
    }
1184964
public function getLocaleAccess($locale, $user = 'current')
    {
        $result = self::NONE;
        $user = $this->getUser($user);
        if ($user === null) {
            $result = self::NOT_LOGGED_IN;
        } else {
            $result = self::NONE;
            if ($user->getUserID() == USER_SUPER_ID) {
                $result = self::GLOBAL_ADMIN;
            } elseif ($user->inGroup($this->groups->getGlobalAdministrators())) {
                $result = self::GLOBAL_ADMIN;
            } else {
                $locale = $this->getLocale($locale);
                if ($locale !== null) {
                    if ($user->inGroup($this->groups->getAdministrators($locale))) {
                        $result = self::ADMIN;
                    } elseif ($user->inGroup($this->groups->getTranslators($locale))) {
                        $result = self::TRANSLATE;
                    } elseif ($user->inGroup($this->groups->getAspiringTranslators($locale))) {
                        $result = self::ASPRIRING;
                    }
                }
            }
        }

        return $result;
    }
965189
private function serializePermissions(User $user)
    {
        $currentUser = $this->tokenStorage->getToken()->getUser();

        $isOwner = $currentUser instanceof User && $currentUser->getUuid() === $user->getUuid();
        $isAdmin = $this->authChecker->isGranted('ROLE_ADMIN'); // todo maybe add those who have access to UserManagement tool

        // todo : move role check elsewhere
        $profileConfig = $this->config->getParameter('profile');
        $editRoles = [];
        if (!empty($profileConfig['roles_edition'])) {
            $editRoles = array_filter($this->tokenStorage->getToken()->getRoles(), function (BaseRole $role) use ($profileConfig) {
                return in_array($role->getRole(), $profileConfig['roles_edition']);
            });
        }

        return [
            'contact' => !$isOwner,
            'edit' => $isAdmin || !empty($editRoles),
            'administrate' => $isAdmin,
            'delete' => $isOwner || $isAdmin, // todo check platform param to now if current user can destroy is account
        ];
    }
571405
public function fetchUser(User $user)
    {
        $response = $this->getResponse(
            sprintf('%s.json',
                $user->getUsername()
            )
        );

        return $this->hydrator->hydrate($user, $response);
    }
479434
public function countUnread(User $user)
    {
        return $this->createQueryBuilder('m')
            ->select('count(m)')
            ->join('m.userMessages', 'um')
            ->where('m.user != :sender')
            ->orWhere('m.user IS NULL')
            ->andWhere('um.user = :user')
            ->andWhere('um.isRead = 0')
            ->andWhere('um.isRemoved = 0')
            ->setParameter(':user', $user)
            ->setParameter(':sender', $user)
            ->getQuery()
            ->getSingleScalarResult();
    }
475840
protected function _setCurrentUser($user = null)
    {
        if ($user === null && !empty($this->Auth)) {
            $user = $this->Auth->user();
        }

        if (!$user) {
            return false;
        }

        $this->_currentUserInstance = $this->_getUserInstance($user);

        return $this->_currentUserInstance;
    }
1186197
public function forUser($user)
    {
        $callback = function () use ($user)
        {
            return $user;
        };

        return new static(
            $this->container, $callback, $this->abilities,
            $this->policies, $this->beforeCallbacks, $this->afterCallbacks
        );
    }
960467
private function update_picture($user) {
        global $CFG, $DB, $USER;

        require_once($CFG->libdir . '/filelib.php');
        require_once($CFG->libdir . '/gdlib.php');
        require_once($CFG->dirroot . '/user/lib.php');

        $fs = get_file_storage();
        $userid = $user->id;
        if (!empty($user->picture)) {
            return false;
        }
        if (!empty($CFG->enablegravatar)) {
            return false;
        }

        $picture = $this->get_static_user_picture();
        if (empty($picture)) {
            return false;
        }

        $context = \context_user::instance($userid, MUST_EXIST);
        $fs->delete_area_files($context->id, 'user', 'newicon');

        $filerecord = array(
            'contextid' => $context->id,
            'component' => 'user',
            'filearea' => 'newicon',
            'itemid' => 0,
            'filepath' => '/',
            'filename' => 'image'
        );

        try {
            $fs->create_file_from_string($filerecord, $picture);
        } catch (\file_exception $e) {
            return get_string($e->errorcode, $e->module, $e->a);
        }

        $iconfile = $fs->get_area_files($context->id, 'user', 'newicon', false, 'itemid', false);

        // There should only be one.
        $iconfile = reset($iconfile);

        // Something went wrong while creating temp file - remove the uploaded file.
        if (!$iconfile = $iconfile->copy_content_to_temp()) {
            $fs->delete_area_files($context->id, 'user', 'newicon');
            return false;
        }

        // Copy file to temporary location and the send it for processing icon.
        $newpicture = (int) process_new_icon($context, 'user', 'icon', 0, $iconfile);
        // Delete temporary file.
        @unlink($iconfile);
        // Remove uploaded file.
        $fs->delete_area_files($context->id, 'user', 'newicon');
        // Set the user's picture.
        $updateuser = new stdClass();
        $updateuser->id = $userid;
        $updateuser->picture = $newpicture;
        $USER->picture = $newpicture;
        user_update_user($updateuser);
        return true;
    }
202372
protected function _getCurrentUser($user = null)
    {
        $this->_setCurrentUser($user);

        if (!$this->_currentUserInstance &&
            isset($this->_currentUserViewVar) &&
            !empty($this->viewVars[$this->_currentUserViewVar])
        ) {
            $this->_currentUserInstance = $this->viewVars[$this->_currentUserViewVar];
        }

        return $this->_currentUserInstance;
    }
56144
private function fetchFromCache(User $user)
    {
        return $this->hasCache($user) ? self::$cache[$user->getId()] : null;
    }