/**
  * Returns the list of experiments.
  *
  * If the experiments are not cached and it's the first time we call the
  * operation in a specific request, the function accesses AppEngine and
  * retrieves the list of experiments from there.
  *
  * @return array the list of experiments.
  *
  * @since 1.0.10
  */
 public static function get_experiments()
 {
     require_once NELIOAB_MODELS_DIR . '/goals/goals-manager.php';
     // Retrieve the experiments from the current static class
     if (self::$experiments) {
         return self::$experiments;
     }
     if (self::CACHE_ALL_EXPERIMENTS) {
         // If they are not yet loaded, retrieve them from the cache
         self::$experiments = get_option('nelioab_experiments', false);
         if (self::$experiments) {
             return self::$experiments;
         }
     }
     // If the cache does not yet contain the experiments, get them from AE
     require_once NELIOAB_UTILS_DIR . '/backend.php';
     $json_data = NelioABBackend::remote_get(sprintf(NELIOAB_BACKEND_URL . '/site/%s/exp', NelioABAccountSettings::get_site_id()));
     $json_data = json_decode($json_data['body']);
     self::$experiments = array();
     if (isset($json_data->items)) {
         foreach ($json_data->items as $json_exp) {
             /** @var NelioABExperiment $exp */
             $exp = NULL;
             $id = $json_exp->key->id;
             $type = NelioABExperiment::kind_to_type($json_exp->kind);
             switch ($type) {
                 case NelioABExperiment::POST_ALT_EXP:
                 case NelioABExperiment::PAGE_ALT_EXP:
                 case NelioABExperiment::PAGE_OR_POST_ALT_EXP:
                 case NelioABExperiment::CPT_ALT_EXP:
                     /** @var NelioABPostAlternativeExperiment $aux */
                     $aux = new NelioABPostAlternativeExperiment($id);
                     if (isset($json_exp->originalPost)) {
                         $aux->set_original($json_exp->originalPost);
                     }
                     $exp = $aux;
                     break;
                 case NelioABExperiment::HEADLINE_ALT_EXP:
                     /** @var NelioABHeadlineAlternativeExperiment $aux */
                     $aux = new NelioABHeadlineAlternativeExperiment($id);
                     if (isset($json_exp->originalPost)) {
                         $aux->set_original($json_exp->originalPost);
                     }
                     $exp = $aux;
                     break;
                 case NelioABExperiment::WC_PRODUCT_SUMMARY_ALT_EXP:
                     /** @var NelioABHeadlineAlternativeExperiment $aux */
                     $aux = new NelioABProductSummaryAlternativeExperiment($id);
                     if (isset($json_exp->originalPost)) {
                         $aux->set_original($json_exp->originalPost);
                     }
                     $exp = $aux;
                     break;
                 case NelioABExperiment::THEME_ALT_EXP:
                     $exp = new NelioABThemeAlternativeExperiment($id);
                     break;
                 case NelioABExperiment::CSS_ALT_EXP:
                     $exp = new NelioABCssAlternativeExperiment($id);
                     break;
                 case NelioABExperiment::WIDGET_ALT_EXP:
                     $exp = new NelioABWidgetAlternativeExperiment($id);
                     break;
                 case NelioABExperiment::MENU_ALT_EXP:
                     $exp = new NelioABMenuAlternativeExperiment($id);
                     break;
                 case NelioABExperiment::HEATMAP_EXP:
                     /** @var NelioABHeatmapExperiment $aux */
                     $aux = new NelioABHeatmapExperiment($id);
                     if (isset($json_exp->originalPost)) {
                         $aux->set_post_id($json_exp->originalPost);
                     }
                     $exp = $aux;
                     break;
             }
             if (!$exp) {
                 continue;
             }
             $exp->set_type($type);
             $exp->set_name($json_exp->name);
             $exp->set_status($json_exp->status);
             if (self::CACHE_ALL_EXPERIMENTS && $exp->get_status() == NelioABExperiment::STATUS_RUNNING) {
                 $exp = self::load_experiment_by_id($id, $type);
             }
             if (isset($json_exp->description)) {
                 $exp->set_description($json_exp->description);
             }
             if (isset($json_exp->creation)) {
                 try {
                     $exp->set_creation_date($json_exp->creation);
                 } catch (Exception $exception) {
                 }
             }
             if (isset($json_exp->start)) {
                 try {
                     $exp->set_start_date($json_exp->start);
                 } catch (Exception $exception) {
                 }
             }
             if (isset($json_exp->finalization)) {
                 try {
                     $exp->set_end_date($json_exp->finalization);
                 } catch (Exception $exception) {
                 }
             }
             if (isset($json_exp->daysFinished)) {
                 try {
                     $exp->set_days_since_finalization($json_exp->daysFinished);
                 } catch (Exception $exception) {
                 }
             }
             array_push(self::$experiments, $exp);
         }
     }
     if (self::CACHE_ALL_EXPERIMENTS) {
         update_option('nelioab_experiments', self::$experiments);
     }
     return self::$experiments;
 }
 public function build_experiment_from_post_data()
 {
     $exp = new NelioABHeatmapExperiment($_POST['exp_id']);
     $exp->set_name(stripslashes($_POST['exp_name']));
     $exp->set_description(stripslashes($_POST['exp_descr']));
     $exp->set_post_id(stripslashes($_POST['exp_post_id']));
     global $nelioab_admin_controller;
     $nelioab_admin_controller->data = $exp;
 }
 public static function load($id)
 {
     $json_data = NelioABBackend::remote_get(NELIOAB_BACKEND_URL . '/exp/hm/' . $id);
     $json_data = json_decode($json_data['body']);
     $exp = new NelioABHeatmapExperiment($json_data->key->id);
     $exp->set_type_using_text($json_data->kind);
     $exp->set_name($json_data->name);
     $exp->set_post_id($json_data->post);
     if (isset($json_data->description)) {
         $exp->set_description($json_data->description);
     }
     $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);
     }
     if (isset($json_data->goals)) {
         NelioABExperiment::load_goals_from_json($exp, $json_data->goals);
     }
     return $exp;
 }