protected function do_build() { // Check settings require_once NELIOAB_ADMIN_DIR . '/error-controller.php'; $error = NelioABErrorController::build_error_page_on_invalid_settings(); if ($error) { return; } // Preparing labels for CUSTOM POST alternatives // ---------------------------------------------- $alt_type = NelioABExperiment::CPT_ALT_EXP; $title = __('Edit Custom Post Type Experiment', 'nelioab'); // We recover the experiment (if any) // ---------------------------------------------- global $nelioab_admin_controller; $experiment = NULL; $other_names = array(); if (!empty($nelioab_admin_controller->data)) { $experiment = $nelioab_admin_controller->data; $alt_type = $experiment->get_type(); } else { $experiment = new NelioABPostAlternativeExperiment(-time()); $experiment->clear(); } // ...and we also recover other experiment names (if any) if (isset($_POST['other_names'])) { $other_names = json_decode(urldecode($_POST['other_names'])); } else { foreach (NelioABExperimentsManager::get_experiments() as $aux) { if ($aux->get_id() != $experiment->get_id()) { array_push($other_names, $aux->get_name()); } } } // Get id of Original custom post type // ---------------------------------------------- if (isset($_GET['post-id']) && $_GET['experiment-type'] == NelioABExperiment::CPT_ALT_EXP) { $experiment->set_original($_GET['post-id']); } // Checking whether there are custom post types available // --------------------------------------------------- require_once NELIOAB_UTILS_DIR . '/wp-helper.php'; $post_types = NelioABWpHelper::get_custom_post_types(); if ($alt_type == NelioABExperiment::CPT_ALT_EXP && count($post_types) == 0) { require_once NELIOAB_ADMIN_DIR . '/views/errors/message-page.php'; $view = new NelioABMessagePage(__('There are no custom post types available.', 'nelioab'), __('You have to create a public custom post type and publish some custom posts first to use this type of experiment.', 'nelioab')); return $view; } $found = false; foreach ($post_types as $post_type) { $options_for_posts = array('posts_per_page' => 1, 'post_type' => $post_type->name, 'post_status' => 'publish'); $list_of_posts = get_posts($options_for_posts); require_once NELIOAB_UTILS_DIR . '/data-manager.php'; NelioABArrays::sort_posts($list_of_posts); if (count($list_of_posts) > 0) { $found = true; break; } } if ($alt_type == NelioABExperiment::CPT_ALT_EXP && !$found) { require_once NELIOAB_ADMIN_DIR . '/views/errors/message-page.php'; $view = new NelioABMessagePage(__('There are no custom posts available.', 'nelioab'), __('Please, create one custom post and try again.', 'nelioab')); return $view; } // If everything is OK, we keep going! // --------------------------------------------------- // Creating the view $view = $this->create_view($alt_type); foreach ($other_names as $name) { $view->add_another_experiment_name($name); } // Experiment information $view->set_basic_info($experiment->get_id(), $experiment->get_name(), $experiment->get_description(), $experiment->get_finalization_mode(), $experiment->get_finalization_value()); // Experiment specific variables and alternatives $view->set_custom_post_type($experiment->get_post_type()); $view->set_original_id($experiment->get_originals_id()); $view->set_alternatives($experiment->get_json4js_alternatives()); // Goals $goals = $experiment->get_goals(); foreach ($goals as $goal) { $view->add_goal($goal->json4js()); } return $view; }