Creates a favourite for given user and resource.

@param User         $user
@param ResourceNode $resourceNode
559528
public function createFavourite(User $user, ResourceNode $resourceNode)
    {
        $favourite = $this->repo->findOneBy(['user' => $user, 'resourceNode' => $resourceNode]);

        if (empty($favourite)) {
            $favourite = new Favourite();
            $favourite->setUser($user);
            $favourite->setResourceNode($resourceNode);
            $this->om->persist($favourite);
            $this->om->flush();
        }
    }
119594
public function formAction($resourceId, User $user)
    {
        $commentManager = $this->getCommentActionManager();
        $criteria = array('resource' => $resourceId);
        $commentsQB = $commentManager->getCommentsForPagination($resourceId);
        $pager = $this->paginateQuery($commentsQB, 1);

        return array('resourceId' => $resourceId, 'pager' => $pager);
    }
1049273
public function generateResourceUserEvaluation(Dropzone $dropzone, User $user)
    {
        $userEval = $this->resourceEvalManager->getResourceUserEvaluation($dropzone->getResourceNode(), $user, false);

        if (empty($userEval)) {
            $userEval = $this->resourceEvalManager->createResourceEvaluation(
                $dropzone->getResourceNode(),
                $user,
                null,
                ['status' => AbstractResourceEvaluation::STATUS_NOT_ATTEMPTED]
            );
        }

        return $userEval;
    }
98571
protected function createResourceFromUser(UserEntity $user)
    {
        $resource = new Resource(
            $this->generateReadUrl($user->getUsernameCanonical()),
            array(
                 'username'   => $user->getUsernameCanonical(),
                 'email'      => $user->getEmail(),
                 'last_login' => $user->getLastLogin() ? $user->getLastLogin()->format('c') : null,
            )
        );

        return $resource;
    }
430363
public static boolean isFavorite(@Nonnull User user, @Nonnull Item item) {
        FavoriteUserProperty fup = user.getProperty(FavoriteUserProperty.class);
        return fup != null && fup.isJobFavorite(item.getFullName());
    }
435459
public function create(UserInterface $user, $resourceClass, $resourceId, array $actions) : UserPermissionInterface
    {
        return new UserPermission($user, $resourceClass, $resourceId, $actions);
    }
594973
public function createComment(Portfolio $portfolio, User $user)
    {
        $comment = new PortfolioComment();
        $comment
            ->setPortfolio($portfolio)
            ->setSender($user)
            ->setSendingDate(new \DateTime());

        return $comment;
    }
1289305
public function createPost(Blog $blog, Post $post, User $user)
    {
        $post
        ->setBlog($blog)
        ->setAuthor($user)
        ->setStatus($blog->isAutoPublishPost() ? Post::STATUS_PUBLISHED : Post::STATUS_UNPUBLISHED)
        ->setCreationDate(new \DateTime())
        ->setModificationDate(new \DateTime());

        if (null === $post->getPublicationDate()) {
            $post->setPublicationDate(new \DateTime());
        }

        //tracking
        $this->trackingManager->dispatchPostCreateEvent($blog, $post);
        if ('anon.' !== $user) {
            $this->trackingManager->updateResourceTracking($blog->getResourceNode(), $user, new \DateTime());
        }

        $this->om->persist($post);
        $this->om->flush();

        return $post;
    }
1342917
public function whereInUserWorkspace(User $user)
    {
        $eol = PHP_EOL;
        $clause =
            "node.workspace IN{$eol}" .
            "({$eol}" .
            "    SELECT aw FROM Claroline\CoreBundle\Entity\Workspace\Workspace aw{$eol}" .
            "    JOIN aw.roles r{$eol}" .
            "    WHERE r IN (SELECT r2 FROM Claroline\CoreBundle\Entity\Role r2 {$eol}".
            "       LEFT JOIN r2.users u {$eol}" .
            "       LEFT JOIN r2.groups g {$eol}" .
            "       LEFT JOIN g.users u2 {$eol}" .
            "       WHERE u.id = :user_id OR u2.id = :user_id {$eol}" .
            "   ) {$eol}" .
            ") {$eol}";
        $this->addWhereClause($clause);
        $this->parameters[':user_id'] = $user->getId();

        return $this;
    }
1339721
public function sendNewUserMail(User $user)
    {
        $parameters = [
            'user' => $user,
            'subject' => $this->translator->trans('user.account_creation', [], 'security'),
            'company' => $this->configuration->getMailerCompany(),
        ];
        $text = $this->twig->render('CleverAgeEAVManagerUserBundle:Email:newUser.txt.twig', $parameters);
        $html = $this->twig->render('CleverAgeEAVManagerUserBundle:Email:newUser.html.twig', $parameters);

        $message = $this->createMessage();
        $message->setSubject($parameters['subject']);
        $message->setTo([$user->getEmail()]);
        $message->setBody($text);
        $message->addPart($html, 'text/html');

        $this->mailer->send($message);
    }
1046609
public function formAction($resourceId, User $user)
    {
        $likeManager = $this->getLikeActionManager();
        $criteria = ['resource' => $resourceId];
        $userLike = $likeManager->getLikeBy($user, null, $criteria);
        $likesQB = $likeManager->getLikesForPagination(null, $criteria);
        $pager = $this->paginateQuery($likesQB, 1);

        return ['resourceId' => $resourceId, 'pager' => $pager, 'userLike' => $userLike];
    }
868677
protected function createNode($resourceUri, $roles) {
        //Break up the uri on the slashes
        $nodes = preg_split('/(\\\|\\/)/', $resourceUri, -1, PREG_SPLIT_NO_EMPTY);

        //foreach node, check if it currently exits, else create it
        $ptr = &$this->config;
        foreach($nodes as $node) {
            if (!isset($ptr[$node])) {
                $ptr[$node] = array('_roles' => $roles);
            }
            $ptr = &$ptr[$node];
        }
    }
424596
public function treePageBlockEdit(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
    {
        $block_id = (int) $request->get('block_id');
        $block    = $this->treeBlock($request, $tree, $user);
        $title    = $block->title() . ' — ' . I18N::translate('Preferences');

        return $this->viewResponse('modules/edit-block-config', [
            'block'      => $block,
            'block_id'   => $block_id,
            'cancel_url' => route('tree-page', ['ged' => $tree->name()]),
            'title'      => $title,
            'tree'       => $tree,
        ]);
    }
233292
public function setUser(User $user): void
    {
        $this->user = $user;
        $this->user->setAcl($this);

        $userRole = $this->user->getRole();
        if ($userRole != null && !empty($this->rules)) {
            foreach ($this->rules as $role => $rules) {
                if ($userRole == $role) {
                    foreach ($rules as $uri => $rules) {
                        $this->user->setPermissionsOf($uri, (array) explode(',', $rules) /* 'read,write' etc. */);
                    }
                    break;
                }
            }
        }
    }
332096
public function create($user, $post)
    {
        return $this->postPolicy->create($user, $post)
            && $user->can('blog.comment.edit');
    }
962323
public function updateResourceTracking(ResourceNode $node, User $user, \DateTime $date)
    {
        $this->evalutionManager->updateResourceUserEvaluationData(
            $node,
            $user,
            $date,
            ['status' => AbstractResourceEvaluation::STATUS_PARTICIPATED]
        );
    }
242567
public function set($key, $value, $user = null)
    {
        $this->getPreferenceOrFail($key);

        $this->backend->setPreference($key, $value, $this->getUserId($user));
    }