@param bool $user
@param bool $opcode

@return array
338160
public static function clearCache($user = true, $opcode = true)
    {
        if (!$user && !$opcode) {
            throw new \InvalidArgumentException('No caches to clear.');
        }

        $messages = array('Clear PHP Accelerator Cache...');
        $success = true;

        if ($user) {
            try {
                $messages[] = self::clearUserCache();
            } catch (\RuntimeException $e) {
                $success = false;
                $messages[] = $e->getMessage();
            }
        }

        if ($opcode) {
            try {
                $messages[] = self::clearOpcodeCache();
            } catch (\RuntimeException $e) {
                $success = false;
                $messages[] = $e->getMessage();
            }
        }

        return array('success' => $success, 'message' => implode(' ', $messages));
    }
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
        ];
    }
689104
private function loadAllUserGroupsIdsOfUser(User $user): array
    {
        $allUserGroups = [];
        $offset = 0;

        do {
            $userGroups = $this->userService->loadUserGroupsOfUser($user, $offset, self::USER_GROUPS_LIMIT);
            foreach ($userGroups as $userGroup) {
                $allUserGroups[] = $userGroup->contentInfo->id;
            }
            $offset += self::USER_GROUPS_LIMIT;
        } while (\count($userGroups) === self::USER_GROUPS_LIMIT);

        return $allUserGroups;
    }
742759
public function activate(User $user)
    {
        $this->authorize(UsersPolicy::PERMISSION_UPDATE);

        try {
            ($active = $user->isActive()) ? $user->deactivate() : $user->activate();

            $message = $this->transNotification(
                $active ? 'disabled' : 'enabled',
                ['name' => $user->full_name],
                $user->toArray()
            );

            return $this->jsonResponseSuccess(compact('message'));
        }
        catch (\Exception $e) {
            return $this->jsonResponseError(['message' => $e->getMessage()], 500);
        }
    }
146762
public function transform(User $user)
    {
        return [
            'selectedContextId' => $user->selected_context_id,
            'email' => $user->email,
            'id' => $user->id,
            'name' => $user->name,
            'role' => $user->role,
            'status' => $user->status,
        ];
    }
261128
public function getQbLastByUser(User $user)
    {
        $qb = $this->createQueryBuilder('d')
            ->where('d.createdBy = :user1 OR d.updatedBy = :user2')
            ->orderBy('d.updatedAt', 'desc')
            ->setParameters(
                [
                    'user1' => $user,
                    'user2' => $user,
                ]
            );

        return $qb;
    }
208444
public function branches(string $user, string $repo): array
    {
        $default = [];
        $api = $this->client->api('git_data')->references();
        $params = [$api, 'branches', [$user, $repo]];

        $refs = $this->callGitHub([$this->pager, 'fetchAll'], $params, $default);

        array_walk($refs, function (&$data) {
            $data['name'] = str_replace('refs/heads/', '', $data['ref']);
        });

        usort($refs, $this->branchSorter());

        return $refs;
    }
450999
public function checkCode(UserInterface $user, $code)
    {
        return $this->authenticator->checkCode($user->getTwoStepVerificationCode(), $code);
    }
1284433
private function get_favourites(stdClass $user) : array {
        $ids = [];

        if (isloggedin()) {
            $usercontext = \context_user::instance($user->id);
            $ufservice = \core_favourites\service_factory::get_service_for_user_context($usercontext);
            $favourites = $ufservice->find_favourites_by_type('mod_forum', 'discussions');
            foreach ($favourites as $favourite) {
                $ids[] = $favourite->itemid;
            }
        }

        return $ids;
    }
644897
public static function get_course_completion_info(\stdClass $user, \stdClass $course) : array {
        $completioninfo = new \completion_info($course);
        $completion = $completioninfo->is_enabled();

        if ($completion != COMPLETION_ENABLED) {
            return [];
        }

        $coursecomplete = $completioninfo->is_course_complete($user->id);

        if ($coursecomplete) {
            $status = get_string('complete');
        } else {
            $criteriacomplete = $completioninfo->count_course_user_data($user->id);
            $ccompletion = new \completion_completion(['userid' => $user->id, 'course' => $course->id]);

            if (!$criteriacomplete && !$ccompletion->timestarted) {
                $status = get_string('notyetstarted', 'completion');
            } else {
                $status = get_string('inprogress', 'completion');
            }
        }

        $completions = $completioninfo->get_completions($user->id);
        $overall = get_string('nocriteriaset', 'completion');
        if (!empty($completions)) {
            if ($completioninfo->get_aggregation_method() == COMPLETION_AGGREGATION_ALL) {
                $overall = get_string('criteriarequiredall', 'completion');
            } else {
                $overall = get_string('criteriarequiredany', 'completion');
            }
        }

        $coursecompletiondata = [
            'status' => $status,
            'required' => $overall,
        ];

        $coursecompletiondata['criteria'] = array_map(function($completion) use ($completioninfo) {
            $criteria = $completion->get_criteria();
            $aggregation = $completioninfo->get_aggregation_method($criteria->criteriatype);
            $required = ($aggregation == COMPLETION_AGGREGATION_ALL) ? get_string('all', 'completion') :
                    get_string('any', 'completion');
            $data = [
                'required' => $required,
                'completed' => transform::yesno($completion->is_complete()),
                'timecompleted' => isset($completion->timecompleted) ? transform::datetime($completion->timecompleted) : ''
            ];
            $details = $criteria->get_details($completion);
            $data = array_merge($data, $details);
            return $data;
        }, $completions);
        return $coursecompletiondata;
    }
1133155
public function getFavouriteWorkspacesByUser(User $user)
    {
        $workspaces = array();
        $favourites = $this->workspaceFavouriteRepo
            ->findFavouriteWorkspacesByUser($user);

        foreach ($favourites as $favourite) {
            $workspace = $favourite->getWorkspace();
            $workspaces[$workspace->getId()] = $workspace;
        }

        return $workspaces;
    }
590724
public function findByUser(User $user, $asArray = true)
    {
        $groupQb = $this->_em->createQueryBuilder()
            ->select('g')
            ->from('Claroline\CoreBundle\Entity\Group', 'g')
            ->join('g.users', 'gu')
            ->where('gu = :user');

        $select = $asArray ? 'o.id, o.name, op.percentage AS progress, COUNT(oc) AS competencyCount' : 'o';

        $query = $this->createQueryBuilder('o')
            ->select($select)
            ->leftJoin('o.objectiveCompetencies', 'oc')
            ->leftJoin('o.users', 'ou')
            ->leftJoin('o.groups', 'og')
            ->leftJoin(
                'HeVinci\CompetencyBundle\Entity\Progress\ObjectiveProgress',
                'op',
                'WITH',
                'op.user = :user AND op.objective = o'
            )
            ->andWhere($groupQb->expr()->orX(
                'ou = :user',
                $groupQb->expr()->in('og', $groupQb->getQuery()->getDQL())
            ))
            ->groupBy('o.id')
            ->setParameter(':user', $user)
            ->getQuery();

        return $query->{$asArray ? 'getArrayResult' : 'getResult'}();
    }
695985
protected function editor(User $user)
    {
        // store props
        $oldProps = new UserUpdater($user);
        $newProps = $this->getNewValues($user);

        // confirm
        $ln = <<<EOL
Summary
-------
Username: "{$newProps->getUsername()}"
Email:    "{$newProps->getEmail()}"
Password: "{$newProps->getPassword()}"
EOL;
        $this->logger->block($ln);

        // check changes
        $changedValues = $oldProps->getChanged($newProps);
        if (empty($changedValues)) {
            $this->logger->note('Nothing changed, exiting.');

            return;
        }
        // persist
        if ($persist = $this->ask(new ConfirmationQuestion('Confirm user update?'))) {
            $this->userEditor->updateUser($user, $newProps);
            $this->logger->success('User updated!');
        }
        // send mail
        if ($persist) {
            $dontSend = 'Don\'t send';
            $emailChoices = [$dontSend, $oldProps->getEmail()];
            if (isset($changedValues['email'])) {
                $emailChoices[] = $changedValues['email'];
            }
            $to = $this->ask(new ChoiceQuestion('Send notification to', $emailChoices));
            if ($to !== $dontSend) {
                $this->sendNotification($to, $changedValues);
            }
        }
    }
151774
public static function getMySets($user = false)
    {
        $app = Facade::getFacadeApplication();

        if ($user === false) {
            $user = $app->make(User::class);
        }

        /** @var $database \Concrete\Core\Database\Connection\Connection */
        $database = $app->make('database')->connection();
        $fileSets = array();

        $queryBuilder = $database->createQueryBuilder();
        $results = $queryBuilder->select('*')->from('FileSets')->where(
            $queryBuilder->expr()->eq('fsType', self::TYPE_PUBLIC)
            )->orWhere(
                $queryBuilder->expr()->andX(
                    $queryBuilder->expr()->in('fsType',[self::TYPE_PRIVATE, self::TYPE_STARRED, self::TYPE_PUBLIC]),
                    $queryBuilder->expr()->eq('uID', $user->getUserID())
                )
            )->orderBy('fsName', 'ASC')->execute();


        while ($row = $results->fetch()) {
            $fileSet = new static();
            $fileSet = array_to_object($fileSet, $row);
            $fileSets[] = $fileSet;
        }

        return $fileSets;
    }
607050
public static function multiToAssocWithSpecificOpr(array $arrays, $opr = null)
    {
        $results = [];
        foreach ($arrays as $key => $value) {
            if (self::isReallyArray($value) === true) {
                $results = array_merge($results, self::multiToAssocWithSpecificOpr($value, $key.$opr));
            } else {
                $key = $opr.$key;
                $key = ($key[0] === '.' || $key[0] === '@' ? substr($key, 1) : $key);
                $results[$key] = $value;
            }
        }

        return $results;
    }
366560
public function getResumableDeliveries(User $user)
    {
        $deliveryExecutionService = ServiceProxy::singleton();
        $resumable = array();
        foreach ($this->getResumableStates() as $state) {
            foreach ($deliveryExecutionService->getDeliveryExecutionsByStatus($user->getIdentifier(), $state) as $execution) {
                $delivery = $execution->getDelivery();
                if ($delivery->exists()) {
                    $resumable[] = $execution;
                }
            }
        }
        return $resumable;
    }
30111
public function deserialize($data, User $user = null, array $options = [])
    {
        if (empty($user)) {
            /** @var User $user */
            $user = $this->om->getRepository(User::class)->findOneBy(['uuid' => $data['id']]);
        }

        return $user;
    }