/**
     * @param MMSelections[] $userSelection
     * @param int $offset
     * @return array
     */
    public function manageResults( $userSelection, $offset = 0 )
    {
        $limit  = $this->applicationObject->configurationContentService->attribute('nb_of_articles_per_page');
        $facets = array('applications' => null);
        $db     = eZDB::instance();
        $query  = "select id from ezcontentobject where remote_id = '%s'";
        $isRemoved = false;

        /** @var MMSelections $selection */
        foreach( $userSelection as $key => $selection )
        {
            $result = $db->arrayQuery(sprintf(
                $query,
                $selection->attribute("remote_id")
            ));

            if ( count($result) == 1 )
            {
                $objectId = $result[0]['id'];
                $isVisible = ObjectVisibilityManager::isVisible($objectId);

                if (!$isVisible)
                {
                    unset($userSelection[$key]);
                    $selection->remove();
                    $isRemoved = true;
                    continue;
                }
            }

            $applicationIdentifier = $selection->attribute('application');
            if( $applicationIdentifier != null )
            {
                if( (CacheApplicationTool::buildLocalizedApplicationByIdentifier( $applicationIdentifier ) instanceof ApplicationLocalized) ) {
                    if( !isset( $facets['applications'][$applicationIdentifier] ) )
                        $facets['applications'][$applicationIdentifier] = 1;
                    else
                        $facets['applications'][$applicationIdentifier]++;
                } else {
                    unset($userSelection[$key]);
                    $selection->remove();
                    $isRemoved = true;
                }
            }
        }
        if ( $isRemoved ) {
            MMSelections::setCookie();
        }

        $total = count( $userSelection );

        if( $offset != 0 )
            $userSelection = array_slice( $userSelection, $offset );

        uksort( $facets['applications'], function($a, $b){
            return strnatcasecmp( ezpI18n::tr('merck/application', $a), ezpI18n::tr('merck/application', $b) );
        });

        if( $total > $limit )
            $userSelection = array_slice( $userSelection, 0, $limit );

        return array( 'items' => $userSelection, 'total' => $total, 'facets' => $facets );
    }
    /**
     * Logs in the user if applied username and password is
     * valid. The userID is returned if successful, false if not.
     *
     * @param array $params
     * @return bool
     */
    public static function loginUser($params = null)
    {
        $uncryptedTicket = array();

        if($params)
        {
            $uncryptedTicket["uuid"]           = $params["Username"];
            $uncryptedTicket["customerType"]   = $params["Customer_type"];
            $uncryptedTicket["userSpeciality"] = $params["User_specialty"];
            $uncryptedTicket["state"]          = $params["Province"];
            $uncryptedTicket["country"]        = $params["Country_of_registration"];
            $uncryptedTicket['toUValidated']   = isset( $params['toUValidated'] ) ? $params['toUValidated'] : true;
            $uncryptedTicket['autologin']      = isset( $params['autologin'] ) ? $params['autologin'] : false;
        }
        else
        {
            $http = eZHTTPTool::instance();

            $hashedTicket = $http->getVariable( 't' );
            if ( empty( $hashedTicket ) )
            {
                return false;
            }

            $uncryptedTicket = self::uncryptTicket ( $hashedTicket );
        }
        
        if ( !self::validateTicket($uncryptedTicket) )
        {
            return false;
        }

        $mmUser = self::createOrUpdateMMUser($uncryptedTicket);
        if( isset($uncryptedTicket['toUValidated']) )
        {
            $mmUser->toUValidated( $uncryptedTicket['toUValidated'] );
        }
        if( isset($uncryptedTicket['autologin']) )
        {
            $mmUser->isAutologin( $uncryptedTicket['autologin'] );
        }
        MMUsers::setCurrentUserObject($mmUser);

        AppBarControl::instance()->store();
        MMSelections::setCookie();
        MMUsers::setCookieUserPreferences();

        $catchUpSpe = $mmUser->getPreference( 'catchUpSpe' );
        if ( !empty( $catchUpSpe ) )
        {
            setcookie ('catchUpSpe', '1', CookieTool::getDefaultCookieExpiration(), '/', CookieTool::getCookieDomain() );
        }
        return true;
    }