/**
  * PHPDOC
  *
  * @param NelioABHeadlineAlternativeExperiment $exp PHPDOC
  * @param NelioABHeadlineAlternative           $alt PHPDOC
  *
  * @return array PHPDOC
  *
  * @since PHPDOC
  */
 private function add_active_headline_experiment($exp, $alt)
 {
     $exp_id = $exp->get_id();
     $aux = $alt->get_value();
     $alt_id = $aux['id'];
     foreach ($this->applied_headlines as $info) {
         if ($info['exp'] == $exp_id) {
             return;
         }
     }
     array_push($this->applied_headlines, array('exp' => $exp_id, 'alt' => $alt_id));
 }
 /**
  * Loads the experiment from AppEngine.
  *
  * @param int $id   the ID of the experiment we want to retrieve.
  * @param int $type the type of the experiment we want to retrieve.
  *
  * @return NelioABExperiment the experiment whose ID is `$id` and whose type is `$type`.
  *                           Note that the result will be an instance of
  *                           a concrete subclass of `NelioABExperiment`.
  *
  * @throws Exception `EXPERIMENT_ID_NOT_FOUND`
  *                   This exception is thrown if the experiment was not
  *                   found in AppEngine.
  *
  * @see NelioABExperiment::load
  *
  * @since 3.4.0
  */
 private static function load_experiment_by_id($id, $type)
 {
     require_once NELIOAB_MODELS_DIR . '/goals/goals-manager.php';
     /** @var NelioABExperiment $exp */
     switch ($type) {
         case NelioABExperiment::POST_ALT_EXP:
         case NelioABExperiment::PAGE_ALT_EXP:
         case NelioABExperiment::PAGE_OR_POST_ALT_EXP:
         case NelioABExperiment::CPT_ALT_EXP:
             $exp = NelioABPostAlternativeExperiment::load($id);
             break;
         case NelioABExperiment::HEADLINE_ALT_EXP:
             $exp = NelioABHeadlineAlternativeExperiment::load($id);
             break;
         case NelioABExperiment::WC_PRODUCT_SUMMARY_ALT_EXP:
             $exp = NelioABProductSummaryAlternativeExperiment::load($id);
             break;
         case NelioABExperiment::THEME_ALT_EXP:
             $exp = NelioABThemeAlternativeExperiment::load($id);
             break;
         case NelioABExperiment::CSS_ALT_EXP:
             $exp = NelioABCssAlternativeExperiment::load($id);
             break;
         case NelioABExperiment::WIDGET_ALT_EXP:
             $exp = NelioABWidgetAlternativeExperiment::load($id);
             break;
         case NelioABExperiment::MENU_ALT_EXP:
             $exp = NelioABMenuAlternativeExperiment::load($id);
             break;
         case NelioABExperiment::HEATMAP_EXP:
             $exp = NelioABHeatmapExperiment::load($id);
             break;
         default:
             $err = NelioABErrCodes::EXPERIMENT_ID_NOT_FOUND;
             throw new Exception(NelioABErrCodes::to_string($err), $err);
     }
     $exp->mark_as_fully_loaded();
     return $exp;
 }
Esempio n. 3
0
 /**
  * Adds a headline alternative experiment in self::$headline_exps.
  *
  * @param NelioABHeadlineAlternativeExperiment $exp The Headline Alternative Experiment to be added.
  * @param int $alt_index The index of the alternative that this visitor is supposed to see.
  *
  * @since 4.0.0
  */
 private static function add_headline_exp($exp, $alt_index)
 {
     $alt = $exp->get_original();
     if ($alt_index > 0) {
         --$alt_index;
         $alts = $exp->get_alternatives();
         if ($alt_index < count($alts)) {
             $alt = $alts[$alt_index];
         }
     }
     self::$headline_exps[$exp->get_originals_id()] = array('exp' => $exp, 'alt' => $alt);
 }
 public static function load($id)
 {
     $json_data = NelioABBackend::remote_get(NELIOAB_BACKEND_URL . '/exp/post/' . $id);
     $json_data = json_decode($json_data['body']);
     $exp = new NelioABHeadlineAlternativeExperiment($json_data->key->id);
     $exp->set_name($json_data->name);
     if (isset($json_data->description)) {
         $exp->set_description($json_data->description);
     }
     $exp->set_type_using_text($json_data->kind);
     $exp->set_original($json_data->originalPost);
     $exp->set_status($json_data->status);
     $exp->set_finalization_mode($json_data->finalizationMode);
     if (isset($json_data->finalizationModeValue)) {
         $exp->set_finalization_value($json_data->finalizationModeValue);
     }
     $exp->track_heatmaps(false);
     if (isset($json_data->showHeatmap) && $json_data->showHeatmap) {
         $exp->track_heatmaps($json_data->showHeatmap);
     }
     if (isset($json_data->goals)) {
         NelioABExperiment::load_goals_from_json($exp, $json_data->goals);
     }
     $alternatives = array();
     if (isset($json_data->alternatives)) {
         foreach ($json_data->alternatives as $json_alt) {
             $alt = new NelioABHeadlineAlternative($json_alt->key->id);
             $alt->set_name($json_alt->name);
             $alt->set_value(json_decode($json_alt->value, true));
             array_push($alternatives, $alt);
         }
     }
     $exp->set_appspot_alternatives($alternatives);
     return $exp;
 }
 public function build_experiment_from_post_data()
 {
     $exp = new NelioABHeadlineAlternativeExperiment($_POST['exp_id']);
     $exp->set_original($_POST['exp_original']);
     $exp = $this->compose_basic_alt_exp_using_post_data($exp);
     global $nelioab_admin_controller;
     $nelioab_admin_controller->data = $exp;
 }