Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/skyweb24.popuppro/lib/abtest/ |
Upload File : |
<? namespace Skyweb24\Popuppro\Abtest; use \Bitrix\Main\Application; use \Bitrix\Main\Localization\Loc; use \Bitrix\Main\Page\Asset; Loc::loadMessages(__FILE__); class Controller { private $abList = []; function __construct() { $popupListActiveIds = []; $rsPopups = \Skyweb24\Popuppro\Entity\PopupproTable::getList([ "select" => ["id"], "filter" => ["active" => "Y"] ]); while ($arPopup = $rsPopups->fetch()) { array_push($popupListActiveIds, $arPopup['id']); } $abListRes = \Skyweb24\Popuppro\Entity\AbtestTable::getList([ "filter" => [ "active" => "Y" ] ]); while ($row = $abListRes->fetch()) { $this->abList[$row['id']] = [ "A" => $row['popup_id_a'], "B" => in_array($row['popup_id_b'], $popupListActiveIds) ? $row['popup_id_b'] : $row['popup_id_a'], "show" => $this->roll($row['chance']), ]; } } public function filter(&$popupList) { global $request; if (empty($popupList)) { return false; } foreach ($this->abList as $abItem) { if( $request->getCookie("skyweb24PopupFilling_" . $abItem['A']) OR $request->getCookie("skyweb24PopupFilling_" . $abItem['B']) ) { unset($popupList[$abItem["A"]]); unset($popupList[$abItem["B"]]); } if(in_array($abItem['A'], array_keys($popupList))) { if ($abItem['show'] == "B") { $popupList[$abItem['A']]['id'] = $popupList[$abItem['B']]['id']; if($abItem['B'] != $abItem['A']) { unset($popupList[$abItem["B"]]); } } else { if($abItem['B'] != $abItem['A']) { unset($popupList[$abItem["B"]]); } } } elseif (in_array($abItem['B'], array_keys($popupList))) { unset($popupList[$abItem["B"]]); } } } public function roll($chance) { return ($chance >= rand(0, 100)) ? "B" : "A"; } public function isMember($popupID) { if (!empty($this->abList)) { foreach ($this->abList as $abItemId => $abItem) { if ($abItem['A'] == $popupID OR $abItem['B'] == $popupID) { return $abItemId; } } } return false; } public static function getAbTestUseId($popupId) { $abTest = \Skyweb24\Popuppro\Entity\AbtestTable::getList([ "filter" => [ "active" => "Y", [ "LOGIC" => "OR", "popup_id_a" => $popupId, "popup_id_b" => $popupId ] ] ])->fetch(); return $abTest['id'] ?: false; } }