@param Basket $basket
@param User   $user

@return Token
508293
public function createBasketAccessToken(Basket $basket, User $user)
    {
        return $this->create($user, self::TYPE_VIEW, null, $basket->getId());
    }
953397
public function setBasketDescriptionAction(Request $request, Basket $basket)
    {
        $basket->setDescription($request->get('description'));

        /** @var EntityManager $em */
        $em = $this->app['orm.em'];
        $em->persist($basket);
        $em->flush();

        return Result::create($request, ["basket" => $this->listBasket($basket)])->createResponse();
    }
980514
public function update(User $user, Block $block)
    {

        if ($user->canDo('block.block.update') && $user->isAdmin()) {
            return true;
        }

        return $user->id == $block->user_id;
    }
1010063
public function updateWithSelectedShippingAddress(\TShopBasket $basket, \TdbDataExtranetUser $user)
    {
        $amazonOrderRef = $this->config->amazonOrderReferenceObjectFactory($basket->getAmazonOrderReferenceId());

        $details = $amazonOrderRef->getOrderReferenceDetails(
            array(
                AmazonOrderReferenceObject::CONSTRAINT_AMOUNT_NOT_SET,
                AmazonOrderReferenceObject::CONSTRAINT_PAYMENT_PLAN_NOT_SET,
                AmazonOrderReferenceObject::CONSTRAINT_UNKNOWN,
            )
        );

        /** @var \OffAmazonPaymentsService_Model_Destination $destination */
        $destination = $details->getDestination();
        /** @var \OffAmazonPaymentsService_Model_Address $physicalDestination */
        $physicalDestination = $destination->getPhysicalDestination();

        $countryId = null;
        $countryCode = $physicalDestination->getCountryCode();
        try {
            $countryId = $this->converter->getCountryIdFromAmazonCountryCode($countryCode, AmazonDataConverter::ORDER_ADDRESS_TYPE_SHIPPING);
        } catch (\InvalidArgumentException $e) {
            throw new \TPkgCmsException_LogAndMessage(self::ERROR_CODE_INVALID_ADDRESS, array('countryCode' => $countryCode),
                'User selected a shipping address in a country to which shipment is not supported', array(
                    'user' => $user,
                    'apiResponse' => $details,
                )
            );
        }
        $adrData = $this->converter->convertAddressFromAmazonObjectToLocal($physicalDestination, AmazonDataConverter::ORDER_ADDRESS_TYPE_SHIPPING);

        // we get this far, we have all the data we need to update the user
        $address = new \TdbDataExtranetUserAddress();
        $address->setIsAmazonShippingAddress(true);
        $address->LoadFromRow($adrData);

        $user->setAmazonShippingAddress($address);
    }
803372
public function createTokenRequest(User $user, $issuer)
    {
        $idAttribution = $user->getCurrentAttribution() ? $user->getCurrentAttribution()->getId() : null;

        return (new TokenRequest())
            ->setUsername($user->getUserName())
            ->setAttributionId($idAttribution)
            ->setIssuer($issuer);
    }
1173382
public function persistUser(User $user)
    {
        $this->objectManager->persist($user);
        $this->objectManager->flush();

        return $user;
    }
1198105
public function findUserBasket($basket_id, User $user, $requireOwner)
    {
        $dql = 'SELECT b
            FROM Phraseanet:Basket b
            LEFT JOIN b.elements e
            WHERE b.id = :basket_id';

        $query = $this->_em->createQuery($dql);
        $query->setParameters(['basket_id' => $basket_id]);

        $basket = $query->getOneOrNullResult();

        if (null === $basket) {
            throw new NotFoundHttpException($this->trans('Basket is not found'));
        }

        /* @var Basket $basket */
        if ($basket->getUser()->getId() != $user->getId()) {
            $participant = false;

            if ($basket->getValidation() && !$requireOwner) {
                try {
                    $basket->getValidation()->getParticipant($user);
                    $participant = true;
                } catch (\Exception $e) {

                }
            }
            if (!$participant) {
                throw new AccessDeniedHttpException($this->trans('You have not access to this basket'));
            }
        }

        return $basket;
    }
179592
public function blocks($user, $token = null)
    {
        return $this->sendRequest('GET', 'users/'.$user.'/blocks', $this->getToken($token));
    }
1311203
public function getUserCart(
        $user = null,
        $locale = null,
        $currency = null,
        $persistEmptyCart = false,
        $updatePrices = false
    ) {
        // cart by session ID
        if (!$user) {
            // TODO: get correct locale
            $locale = 'de';
            $cartsArray = $this->findCartBySessionId();
        } else {
            // TODO: check if cart for this sessionId exists and assign it to user

            // default locale from user
            $locale = $locale ?: $user->getLocale();
            // get carts
            $cartsArray = $this->findCartsByUser($user, $locale);
        }

        // cleanup cart array: remove duplicates and expired carts
        $this->cleanupCartsArray($cartArray);

        // check if cart exists
        if ($cartsArray && count($cartsArray) > 0) {
            // multiple carts found, do a cleanup
            $cart = $cartsArray[0];
        } else {
            // user has no cart - return empty one
            $cart = $this->createEmptyCart($user, $persistEmptyCart);
        }

        // check if all products are still available
        $cartNoRemovedProducts = $this->checkProductsAvailability($cart);

        // create api entity
        $apiOrder = $this->orderFactory->createApiEntity($cart, $locale);

        if (!$cartNoRemovedProducts) {
            $apiOrder->addCartErrorCode(self::CART_STATUS_PRODUCT_REMOVED);
        }

        $this->orderManager->updateApiEntity($apiOrder, $locale);

        // check if prices have changed
        if ($apiOrder->hasChangedPrices()) {
            $apiOrder->addCartErrorCode(self::CART_STATUS_PRICE_CHANGED);
        }

        if ($updatePrices) {
            $this->updateCartPrices($apiOrder->getItems());
        }

        return $apiOrder;
    }
443627
public function setBasket(Basket $basket = null)
    {
        if ($this->basket) {
            $this->basket->setOrder(null);
        }

        $this->basket = $basket;

        if ($basket) {
            $basket->setOrder($this);
        }

        return $this;
    }
1357245
public function putBlock($user, $target, $token = null)
    {
        return $this->sendRequest('PUT', 'users/'.$user.'/blocks/'.$target, $this->getToken($token));
    }
118982
public function setCoins(UserInterface $user, $coins)
    {
        $coinsEntry = $this->getCoinsEntry($user);

        if (!$coinsEntry) {
            $class = $this->getGameOptions()->getEntityBillingClass();
            /** @var \GameBackend\Entity\CrossFire\Billing $coinsEntry */
            $coinsEntry = new $class($user);
        }

        $coinsEntry->setCash($coinsEntry->getCash() + $coins);
        if ($coinsEntry->getCash() < 0) {
            return false;
        }

        $accEntityManager = $this->getBillingEntityManager();
        $accEntityManager->persist($coinsEntry);
        $accEntityManager->flush();

        return true;
    }
1187980
private function createRegisterForm(User $user)
    {
        $form = $this->createForm(new UserRegisterType(), $user, array(
            'action' => $this->generateUrl('amulen_user_register_do'),
            'method' => 'POST',
        ));

        $form->add('submit', 'submit', array('label' => 'Register'));

        return $form;
    }
528061
public function createDownloadToken(User $user, $data)
    {
        return $this->create($user, self::TYPE_DOWNLOAD, new \DateTime('+3 hours'), $data);
    }
452976
public static function markBasketPaid(Basket $basket)
    {
        $basket->Status = Basket::STATUS_COMPLETED;
        $basket->save();
        $session = SuperCMSSession::singleton();
        $session->basketId = 0;
        $session->storeSession();
    }
334002
protected function CanEdit(User $user)
    {
        return self::Guard()->Allow(BackendAction::Edit(), $user)&&
            self::Guard()->Allow(BackendAction::UseIt(), new UserForm());
    }
1332634
public function createCasUser($casLogin, User $user)
    {
        $casUser = new CasUser($casLogin, $user);
        $this->om->persist($casUser);
        $this->om->flush();

        return $casUser;
    }