Example #1
0
 public static function generate_html_content()
 {
     require_once NELIOAB_MODELS_DIR . '/experiments-manager.php';
     $view = new NelioABCssEditPage();
     $exp_id = 0;
     $css_id = 0;
     if (isset($_REQUEST['exp_id'])) {
         $exp_id = $_REQUEST['exp_id'];
     }
     if (isset($_REQUEST['css_id'])) {
         $css_id = $_REQUEST['css_id'];
     }
     try {
         $exp = NelioABExperimentsManager::get_experiment_by_id($exp_id, NelioABExperiment::CSS_ALT_EXP);
         $view->experiment = $exp;
     } catch (Exception $e) {
         require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
         NelioABErrorController::build($e);
     }
     if (isset($_REQUEST['css_save_alt']) && isset($_REQUEST['css_alt_name']) && isset($_REQUEST['css_alt_value'])) {
         require_once NELIOAB_MODELS_DIR . '/alternatives/css-alternative-experiment.php';
         $exp->update_css_alternative($css_id, $_REQUEST['css_alt_name'], urldecode($_REQUEST['css_alt_value']));
     }
     foreach ($view->experiment->get_alternatives() as $alt) {
         if ($alt->get_id() == $css_id) {
             $view->css_alt = $alt;
         }
     }
     $view->do_render();
     die;
 }
 public static function generate_html_content()
 {
     global $nelioab_admin_controller;
     if (isset($nelioab_admin_controller->data)) {
         $exp = $nelioab_admin_controller->data;
         $exp_id = $exp->get_id();
     } else {
         $exp_id = -time();
         if (isset($_REQUEST['exp_id'])) {
             $exp_id = $_REQUEST['exp_id'];
         }
         $exp = null;
         try {
             $exp = NelioABExperimentsManager::get_experiment_by_id($exp_id, NelioABExperiment::THEME_ALT_EXP);
         } catch (Exception $e) {
             require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
             NelioABErrorController::build($e);
         }
     }
     $title = __('Results of the Experiment', 'nelioab');
     $view = new NelioABThemeAltExpProgressPage($title);
     $view->set_experiment($exp);
     $goals = $exp->get_goals();
     $view->set_goals($goals);
     $goal_id = -1;
     if (isset($_REQUEST['goal'])) {
         $goal_id = $_REQUEST['goal'];
     }
     $view->set_current_selected_goal($goal_id);
     $view->render_content();
     die;
 }
 public static function generate_html_content()
 {
     global $nelioab_admin_controller;
     if (isset($nelioab_admin_controller->data)) {
         $exp = $nelioab_admin_controller->data;
         $exp_id = $exp->get_id();
     } else {
         $exp_id = -time();
         if (isset($_REQUEST['exp_id'])) {
             $exp_id = $_REQUEST['exp_id'];
         }
         $exp_type = -1;
         if (isset($_POST['exp_type'])) {
             $exp_type = $_POST['exp_type'];
         }
         $exp = null;
         try {
             $exp = NelioABExperimentsManager::get_experiment_by_id($exp_id, $exp_type);
         } catch (Exception $e) {
             require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
             NelioABErrorController::build($e);
         }
     }
     $title = __('Results of the Experiment', 'nelioab');
     $view = new NelioABWidgetAltExpProgressPage($title);
     $view->set_experiment($exp);
     require_once NELIOAB_EXP_CONTROLLERS_DIR . '/widget-experiment-controller.php';
     $widgets_in_experiments = NelioABWidgetExpAdminController::get_widgets_in_experiments();
     $are_there_alternatives_to_apply = false;
     foreach ($widgets_in_experiments as $info) {
         if ($info['exp'] == $exp->get_id()) {
             $are_there_alternatives_to_apply = true;
         }
     }
     $view->set_there_are_alternatives_to_apply($are_there_alternatives_to_apply);
     $goals = $exp->get_goals();
     $view->set_goals($goals);
     $goal_id = -1;
     if (isset($_REQUEST['goal'])) {
         $goal_id = $_REQUEST['goal'];
     }
     $view->set_current_selected_goal($goal_id);
     $view->render_content();
     die;
 }
 public static function generate_html_content()
 {
     // Obtain DATA from APPSPOT and check its type dynamically
     $experiment = null;
     try {
         $exp_id = -time();
         if (isset($_POST['id'])) {
             $exp_id = $_POST['id'];
         }
         $exp_type = -1;
         if (isset($_POST['exp_type'])) {
             $exp_type = $_POST['exp_type'];
         }
         $experiment = NelioABExperimentsManager::get_experiment_by_id($exp_id, $exp_type);
         global $nelioab_admin_controller;
         $nelioab_admin_controller->data = $experiment;
     } catch (Exception $e) {
         require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
         NelioABErrorController::build($e);
     }
     $type = $experiment->get_type();
     $controller = NelioABSelectExpProgressPageController::get_controller($type);
     call_user_func(array($controller, 'generate_html_content'));
 }
 public function duplicate($new_name)
 {
     $id = parent::duplicate($new_name);
     if (-1 == $id) {
         return $id;
     }
     require_once NELIOAB_EXP_CONTROLLERS_DIR . '/widget-experiment-controller.php';
     require_once NELIOAB_MODELS_DIR . '/experiments-manager.php';
     /** @var NelioABMenuAlternativeExperiment $exp */
     $exp = NelioABExperimentsManager::get_experiment_by_id($id, $this->get_type());
     $alts_src = $this->get_alternatives();
     $alts_dest = $exp->get_alternatives();
     for ($i = 0; $i < count($alts_src); ++$i) {
         /** @var NelioABAlternative $alt_src */
         $alt_src = $alts_src[$i];
         /** @var NelioABAlternative $alt_dest */
         $alt_dest = $alts_dest[$i];
         NelioABWidgetExpAdminController::duplicate_widgets($this->get_id(), $alt_src->get_id(), $exp->get_id(), $alt_dest->get_id());
     }
     return $id;
 }
 public function duplicate($new_name)
 {
     $id = parent::duplicate($new_name);
     if (-1 == $id) {
         return $id;
     }
     require_once NELIOAB_MODELS_DIR . '/experiments-manager.php';
     /** @var NelioABPostAlternativeExperiment $exp */
     $exp = NelioABExperimentsManager::get_experiment_by_id($id, $this->get_type());
     $alts = 0;
     foreach ($exp->get_alternatives() as $alt) {
         /** @var NelioABAlternative $alt */
         $new_id = $exp->create_alternative_copying_content($alt->get_name(), $alt->get_value());
         if ($new_id) {
             $alt->set_value($new_id);
             $alt->mark_as_dirty();
             ++$alts;
         } else {
             $alt->mark_as_removed();
             $alt->mark_as_dirty();
         }
     }
     if (0 == $alts) {
         $exp->set_status(NelioABExperiment::STATUS_DRAFT);
     }
     $exp->save();
     return $exp->get_id();
 }
 public function duplicate($new_name)
 {
     $id = parent::duplicate($new_name);
     if (-1 == $id) {
         return $id;
     }
     require_once NELIOAB_EXP_CONTROLLERS_DIR . '/menu-experiment-controller.php';
     $controller = NelioABMenuExpAdminController::get_instance();
     require_once NELIOAB_MODELS_DIR . '/experiments-manager.php';
     /** @var NelioABMenuAlternativeExperiment $exp */
     $exp = NelioABExperimentsManager::get_experiment_by_id($id, $this->get_type());
     $alts = 0;
     $controller->begin();
     foreach ($exp->get_alternatives() as $alt) {
         /** @var NelioABAlternative $alt */
         $menu_id = $controller->duplicate_menu_and_create_alternative($alt->get_value(), $exp->get_id());
         $body = array('value' => $menu_id);
         try {
             NelioABBackend::remote_post(sprintf(NELIOAB_BACKEND_URL . '/alternative/%s/update', $alt->get_id()), $body);
             $alts++;
         } catch (Exception $e) {
         }
     }
     $controller->commit();
     if (0 == $alts) {
         $exp->set_status(NelioABExperiment::STATUS_DRAFT);
     }
     $exp->save();
     return $exp->get_id();
 }
 public static function duplicate_experiment($new_name, $exp_id, $exp_type)
 {
     $exp = NULL;
     try {
         $action = 'duplicate-' . $exp_id;
         if (!isset($_REQUEST['_nonce']) || !nelioab_verify_onetime_nonce($_REQUEST['_nonce'], $action)) {
             require_once NELIOAB_UTILS_DIR . '/backend.php';
             $err = NelioABErrCodes::INVALID_NONCE;
             throw new Exception(NelioABErrCodes::to_string($err), $err);
         }
         $exp = NelioABExperimentsManager::get_experiment_by_id($exp_id, $exp_type);
     } catch (Exception $e) {
         require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
         NelioABErrorController::build($e);
     }
     try {
         if ($exp == NULL) {
             $err = NelioABErrCodes::INVALID_EXPERIMENT;
             throw new Exception(NelioABErrCodes::to_string($err), $err);
         }
         $exp->duplicate($new_name);
     } catch (Exception $e) {
         global $nelioab_admin_controller;
         switch ($e->getCode()) {
             case NelioABErrCodes::EXPERIMENT_CANNOT_BE_DUPLICATED:
                 $nelioab_admin_controller->error_message = $e->getMessage();
                 return;
             default:
                 require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
                 NelioABErrorController::build($e);
         }
     }
 }
Example #9
0
    if ($_GET['exp_type'] == NelioABExperiment::PAGE_ALT_EXP || $_GET['exp_type'] == NelioABExperiment::POST_ALT_EXP) {
        $show_back_link = true;
    }
}
if (isset($_POST['load_from_appengine'])) {
    try {
        require_once NELIOAB_UTILS_DIR . '/backend.php';
        require_once NELIOAB_MODELS_DIR . '/experiments-manager.php';
        $exp_type = 0;
        if (!isset($_GET['exp_type']) || !isset($_GET['id'])) {
            $err = NelioABErrCodes::TOO_FEW_PARAMETERS;
            throw new Exception(NelioABErrCodes::to_string($err), $err);
        }
        // Get the Heatmap
        $exp_type = $_GET['exp_type'];
        $exp = NelioABExperimentsManager::get_experiment_by_id($_GET['id'], $exp_type);
        if ($exp_type == NelioABExperiment::HEATMAP_EXP) {
            $url = sprintf(NELIOAB_BACKEND_URL . '/exp/hm/%s/result', $exp->get_id());
            $post_id = $exp->get_post_id();
            global $nelioab_controller;
            if ($post_id == NelioABController::FRONT_PAGE__YOUR_LATEST_POSTS) {
                $post_id = false;
            }
        } else {
            if (!isset($_GET['post'])) {
                $err = NelioABErrCodes::TOO_FEW_PARAMETERS;
                throw new Exception(NelioABErrCodes::to_string($err), $err);
            }
            $url = sprintf(NELIOAB_BACKEND_URL . '/exp/post/%s/hm/%s/result', $exp->get_id(), $_GET['post']);
            $post_id = $_GET['post'];
        }