/**
  * 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));
 }
 protected function do_build()
 {
     $title = __('Edit Headline Experiment', 'nelioab');
     // Check settings
     require_once NELIOAB_ADMIN_DIR . '/error-controller.php';
     $error = NelioABErrorController::build_error_page_on_invalid_settings();
     if ($error) {
         return;
     }
     // 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;
     } else {
         $experiment = new NelioABHeadlineAlternativeExperiment(-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 page or post
     // ----------------------------------------------
     if (isset($_GET['post-id']) && $_GET['experiment-type'] == NelioABExperiment::HEADLINE_ALT_EXP) {
         $experiment->set_original($_GET['post-id']);
     }
     // Checking whether there are pages or posts available
     // ---------------------------------------------------
     // ...pages...
     $list_of_pages = get_pages();
     $options_for_posts = array('posts_per_page' => 1);
     $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_pages) + count($list_of_posts) == 0) {
         require_once NELIOAB_ADMIN_DIR . '/views/errors/message-page.php';
         $view = new NelioABMessagePage(__('There are no posts available.', 'nelioab'), __('Please, create one post and try again.', 'nelioab'));
         return $view;
     }
     // If everything is OK, we keep going!
     // ---------------------------------------------------
     // Creating the view
     $view = $this->create_view();
     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_original_id($experiment->get_originals_id());
     $view->set_alternatives($experiment->get_json4js_alternatives());
     return $view;
 }