public function setForcedVariation($experimentKey, $userId, $variationKey)
    {

        // check for empty string Variation key
        if (!is_null($variationKey) && !Validator::validateNonEmptyString($variationKey)) {
            $this->_logger->log(Logger::ERROR, sprintf(Errors::INVALID_FORMAT, Optimizely::VARIATION_KEY));
            return false;
        }

        $experiment = $this->getExperimentFromKey($experimentKey);
        $experimentId = $experiment->getId();
        // check if the experiment exists in the datafile (a new experiment is returned if it is not in the datafile)
        if (strlen($experimentId) == 0) {
            // this case is logged in getExperimentFromKey
            return false;
        }

        // clear the forced variation if the variation key is null
        if (is_null($variationKey)) {
            unset($this->_forcedVariationMap[$userId][$experimentId]);
            $this->_logger->log(Logger::DEBUG, sprintf('Variation mapped to experiment "%s" has been removed for user "%s".', $experimentKey, $userId));
            return true;
        }

        $variation = $this->getVariationFromKey($experimentKey, $variationKey);
        $variationId = $variation->getId();
        // check if the variation exists in the datafile (a new variation is returned if it is not in the datafile)
        if (strlen($variationId) == 0) {
            // this case is logged in getVariationFromKey
            return false;
        }

        $this->_forcedVariationMap[$userId][$experimentId] = $variationId;
        $this->_logger->log(Logger::DEBUG, sprintf('Set variation "%s" for experiment "%s" and user "%s" in the forced variation map.', $variationId, $experimentId, $userId));

        return true;
    }
public function setForcedVariation($experimentKey, $userId, $variationKey)
    {

        // check for empty string Variation key
        if (!is_null($variationKey) && !Validator::validateNonEmptyString($variationKey)) {
            $this->_logger->log(Logger::ERROR, sprintf(Errors::INVALID_FORMAT, Optimizely::VARIATION_KEY));
            return false;
        }

        $experiment = $this->getExperimentFromKey($experimentKey);
        $experimentId = $experiment->getId();
        // check if the experiment exists in the datafile (a new experiment is returned if it is not in the datafile)
        if (strlen($experimentId) == 0) {
            // this case is logged in getExperimentFromKey
            return false;
        }

        // clear the forced variation if the variation key is null
        if (is_null($variationKey)) {
            unset($this->_forcedVariationMap[$userId][$experimentId]);
            $this->_logger->log(Logger::DEBUG, sprintf('Variation mapped to experiment "%s" has been removed for user "%s".', $experimentKey, $userId));
            return true;
        }

        $variation = $this->getVariationFromKey($experimentKey, $variationKey);
        $variationId = $variation->getId();
        // check if the variation exists in the datafile (a new variation is returned if it is not in the datafile)
        if (strlen($variationId) == 0) {
            // this case is logged in getVariationFromKey
            return false;
        }

        $this->_forcedVariationMap[$userId][$experimentId] = $variationId;
        $this->_logger->log(Logger::DEBUG, sprintf('Set variation "%s" for experiment "%s" and user "%s" in the forced variation map.', $variationId, $experimentId, $userId));

        return true;
    }
public function setForcedVariation ( $ experimentKey , $ userId , $ variationKey ) { // check for empty string Variation key if ( ! is_null ( $ variationKey ) && ! Validator :: validateNonEmptyString ( $ variationKey ) ) { $ this -> _logger -> log ( Logger :: ERROR , sprintf ( Errors :: INVALID_FORMAT , Optimizely :: VARIATION_KEY ) ) ; return false ; } $ experiment = $ this -> getExperimentFromKey ( $ experimentKey ) ; $ experimentId = $ experiment -> getId ( ) ; // check if the experiment exists in the datafile (a new experiment is returned if it is not in the datafile) if ( strlen ( $ experimentId ) == 0 ) { // this case is logged in getExperimentFromKey return false ; } // clear the forced variation if the variation key is null if ( is_null ( $ variationKey ) ) { unset ( $ this -> _forcedVariationMap [ $ userId ] [ $ experimentId ] ) ; $ this -> _logger -> log ( Logger :: DEBUG , sprintf ( 'Variation mapped to experiment "%s" has been removed for user "%s".' , $ experimentKey , $ userId ) ) ; return true ; } $ variation = $ this -> getVariationFromKey ( $ experimentKey , $ variationKey ) ; $ variationId = $ variation -> getId ( ) ; // check if the variation exists in the datafile (a new variation is returned if it is not in the datafile) if ( strlen ( $ variationId ) == 0 ) { // this case is logged in getVariationFromKey return false ; } $ this -> _forcedVariationMap [ $ userId ] [ $ experimentId ] = $ variationId ; $ this -> _logger -> log ( Logger :: DEBUG , sprintf ( 'Set variation "%s" for experiment "%s" and user "%s" in the forced variation map.' , $ variationId , $ experimentId , $ userId ) ) ; return true ; }
Sets an associative array of user IDs to an associative array of experiments
to forced variations.

@param $experimentKey string Key for experiment.
@param $userId string The user Id.
@param $variationKey string Key for variation. If null, then clear the existing experiment-to-variation mapping.

@return boolean A boolean value that indicates if the set completed successfully.
Sets an associative array of user IDs to an associative array of experiments to forced variations .