Example #1
0
 /**
  * Choose a variant and set in the variant property
  *
  * @since 0.4.0
  */
 protected function choose()
 {
     $variant_id = $this->bandit->choose();
     $variant = variant::read($variant_id);
     if (is_array($variant)) {
         $this->variant = $variant;
     } else {
         //@todo
     }
 }
Example #2
0
 /**
  * Get variant ID, by group ID.
  *
  * If no variant chosen, makes selection
  *
  * @since 1.1.0
  *
  * @param int $group_id Group ID to get variant for
  *
  * @return int
  */
 public static function get_test($group_id)
 {
     if (!isset(self::$tests[$group_id])) {
         if (!cookie::get_cookie($group_id)) {
             $group = group::read($group_id);
             if (group::valid($group) && !empty($group['variants'])) {
                 $bandit = new content($group_id);
                 $variant = $bandit->choose();
                 if (is_a($variant, 'MaBandit\\Lever')) {
                     /** @var \MaBandit\Lever $variant */
                     $variant = $variant->getValue();
                 }
                 if (is_numeric($variant)) {
                     cookie::set_cookie($group_id, $variant);
                 }
             } else {
                 return false;
             }
         } else {
             $variant = cookie::get_cookie($group_id);
         }
         self::$tests[$group_id] = $variant;
     }
     return self::$tests[$group_id];
 }
Example #3
0
 /**
  * Choose a variant and set in the variant property
  *
  * @since 0.4.0
  */
 protected function choose()
 {
     $variant = $this->bandit->choose();
     $this->set_variant($variant);
 }