public function getLivePageVersionByDiceRoll($page) { $liveVersion = null; $versions = $this->getPageVersionsByAB($page); $diceroll = array(); foreach ($versions as $index => $version) { $diceroll = array_merge(array_fill(0, $version->ab_testing_amount, $index), $diceroll); } if (count($diceroll) == 0) { return null; } $diceroll = $diceroll[array_rand($diceroll)]; if (isset($versions[$diceroll])) { $liveVersion = $versions[$diceroll]; $this->Cookie->queue('dvs-ab-testing-' . $page->id, $liveVersion->id); } return $liveVersion; }