Note that this method is not transaction safe so there may be collisions.
This implementation supposed to provide approximate position in the queue
@param QueuedAction $action
@param User $user
@return integer
@throws
977570
public function getPosition(QueuedAction $action, User $user = null)
    {
        $action->setServiceLocator($this->getServiceManager());
        $positions = $this->getPositions($action);
        return count($positions);
    }
72994
public static function hasAccess(User $user, $controller, $action, $parameters) {
        $access = true;
        foreach (self::getImplementations() as $impl) {
            $access = $access && $impl->hasAccess($user, $controller, $action, $parameters);
        }
        return $access;
    }
484989
protected function checkPermission(User $user, $model, $action)
    {
        $regex = str_replace('/', '\/', preg_quote(route('admin.dashboard')));
        $slug = preg_replace('/'.$regex.'/', '', $model->link(true));
        $slug = str_replace('/', '', explode('/', ltrim($slug, '/'))[0]);

        if (!isset(self::$datatypes[$slug])) {
            self::$datatypes[$slug] = DataType::where('slug', $slug)->first();
        }

        if ($str = self::$datatypes[$slug]) {
            $slug = $str->slug;
        }

        if ($slug == '') {
            $slug = 'admin';
        }

        // If permission doesn't exist, we can't check it!
        if (!Admin::model('Permission')->where('key', 'browse_'.$slug)->exists()) {
            return true;
        }

        return $user->hasPermission('browse_'.$slug);
    }
192139
public function add_user_permission($user, $action)
	{
		$db =  \App::get('db');

		if ($user == 'anonymous')
		{
			$user = '0';
		}

		if (!is_numeric($user))
		{
			$query = "SELECT id FROM `#__users` WHERE username=" . $db->quote($user) . ";";
			$db->setQuery($query);
			$user_id = $db->loadResult();

			if ($user_id === false)
			{
				$this->_error("Unknown user $user");
				return false;
			}
		}
		else
		{
			$user_id = $user;
		}

		$quoted_project_id = $db->quote($this->id);
		$quoted_user_id = $db->quote($user_id);
		$values = '';

		foreach ((array) $action as $a)
		{
			if (!empty($values))
			{
				$values .= ',';
			}
			$values .= "($quoted_project_id,$quoted_user_id," . $db->quote($a) .")";
		}

		$query = "INSERT IGNORE INTO `#__trac_user_permission` (trac_project_id,user_id,action) VALUES " .  $values . ";";

		$db->setQuery($query);
		$db->query();
	}
426606
public static function can_create_data_request_for_user($user, $requester = null) {
        $usercontext = \context_user::instance($user);

        return has_capability('tool/dataprivacy:makedatarequestsforchildren', $usercontext, $requester);
    }
571730
public function view(User $user, Category $category)
    {

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

        return $user->id == $category->user_id;
    }
441654
public function getNotificationsReadAction(User $user)
    {
        $this->notificationManager->markAllNotificationsAsViewed($user->getId());

        return $this->notificationManager->getUserNotifications($user);
    }
122900
public function hasAccess(MenuAction $action, common_user_User $user, array $node){

        $resolvedAction = $this->getResolvedAction($action);
        if(!is_null($resolvedAction) && !is_null($user)){
            if($node['type'] = $resolvedAction['context'] || $resolvedAction['context'] == 'resource') {
                foreach($resolvedAction['required'] as $key){
                    if(!array_key_exists($key, $node)){
                        //missing required key
                        return self::ACCESS_UNDEFINED;
                    }
                }
                try {
                    if(AclProxy::hasAccess($user, $resolvedAction['controller'], $resolvedAction['action'], $node)){
                        return self::ACCESS_GRANTED;
                    }
                    return self::ACCESS_DENIED;
                } catch(\Exception $e){

                    \common_Logger::w('Unable to resolve permission for action ' . $action->getId() . ' : ' . $e->getMessage() );
                }
            }
        }
        return self::ACCESS_UNDEFINED;
    }
186043
function ReportUserAction(User $user, Enums\Action $action)
    {
        $logItem = $this->CreateLogItem(Enums\ObjectType::User(), $action);       
        if (!$action->Equals(Enums\Action::Delete()))
        {
            $logUser = new LogUser();
            $logUser->SetLogItem($logItem);
            $logUser->SetUser($user);
            $logUser->Save();
        }
    }
1288435
public function isActionAvailable($action)
    {
        $order = $this->getOrder();

        $availableActions = $this->getAvailableAction($order->getTransactionMode());

        $isAvailable = in_array($action, $availableActions);

        if ($isAvailable) {
            $isAvailable = false;

            switch ($action) {
                case 'capture':
                case 'reauthorize':
                case 'void':
                    if ($order->getRemainingOrderSum() > 0 && $order->getVoidedAmount() < $order->getRemainingOrderSum()) {
                        $isAvailable = true;
                    }
                    break;
            }
        }

        return $isAvailable;
    }
1001935
public function countUserFinishedPapers(Exercise $exercise, User $user)
    {
        return (int) $this->getEntityManager()
            ->createQuery('
                SELECT COUNT(p)
                FROM UJM\ExoBundle\Entity\Attempt\Paper AS p
                WHERE p.user = :user
                  AND p.exercise = :exercise
                  AND p.end IS NOT NULL
            ')
            ->setParameters([
                'user' => $user,
                'exercise' => $exercise,
            ])
            ->getSingleScalarResult();
    }
487239
public function bulletinPointsDiversWidgetAction(User $user)
    {
        $pointsDivers = $this->totauxManager->getMoyennePointsDivers($user);

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

        return $this->render('LaurentBulletinBundle::BulletinPointsDiversWidget.html.twig', $params);
    }
56144
private function fetchFromCache(User $user)
    {
        return $this->hasCache($user) ? self::$cache[$user->getId()] : null;
    }
1102391
public static function forUser(User $user)
    {
        if ($user->getIsGuest()) {
            return Yii::$app->session;
        }

        return Yii::createObject(['class' => RemoteCartStorage::class, 'sessionCartId' => 'yz\shoppingcart\ShoppingCart']);
    }
630666
private function checkView(TokenInterface $token, User $user)
    {
        return $this->isOrganizationManager($token, $user) ?
              VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED;
    }
1194967
public function findActiveValidationByUser(User $user, $sort = null)
    {
        $dql = 'SELECT b
            FROM Phraseanet:Basket b
            JOIN b.elements e
            JOIN e.validation_datas v
            JOIN b.validation s
            JOIN s.participants p
            WHERE b.user != ?1 AND p.user = ?2
             AND (s.expires IS NULL OR s.expires > CURRENT_TIMESTAMP()) ';

        if ($sort == 'date') {
            $dql .= ' ORDER BY b.created DESC';
        } elseif ($sort == 'name') {
            $dql .= ' ORDER BY b.name ASC';
        }

        $query = $this->_em->createQuery($dql);
        $query->setParameters([1 => $user->getId(), 2 => $user->getId()]);

        return $query->getResult();
    }
126271
public function action($action)
    {
        $a = func_get_args();
        $controllerPath = $this->controller->getControllerActionPath();
        array_unshift($a, $controllerPath);
        $ret = call_user_func_array([$this, 'url'], $a);

        return $ret;
    }