PageRenderTime 68ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/application/controllers/monetization.php

https://bitbucket.org/justin_anastos/blackjack
PHP | 704 lines | 483 code | 167 blank | 54 comment | 36 complexity | c0217c67c0c2e5766b92a18c424e766f MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Monetization extends MY_Controller
  3. {
  4. private $guest = NULL;
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. if ($this->ion_auth->logged_in())
  9. {
  10. $this->setLayout('layout/member');
  11. $this->layoutData['member_page'] = 'CHANGE ME [' . $this->router->method . ']';
  12. $this->guest = FALSE;
  13. }
  14. else
  15. {
  16. $this->guest = TRUE;
  17. $referrerId = get_cookie('ref');
  18. $referrerData = $referrerId ? $this->ion_auth->user($referrerId)->row() : null;
  19. $this->layoutData['registerForm'] = $this->loadPartialView('partial/register', compact('referrerData'));
  20. $this->layoutData['loginForm'] = $this->loadPartialView('partial/login');
  21. $this->layoutData['forgotForm'] = $this->loadPartialView('partial/forgot');
  22. $this->layoutData['activationForm'] = $this->loadPartialView('partial/activation');
  23. }
  24. $this->load->model('monetization_model', 'Monetization');
  25. $this->load->model('payment_method_model', 'PaymentMethod');
  26. $this->load->model('investment_model', 'Investment');
  27. $this->load->model('game_model', 'Game');
  28. $this->load->model('games/coin_flip_model', 'CoinFlip');
  29. $this->load->model('games/blackjack_model', 'Blackjack');
  30. $this->load->library('table');
  31. $this->load->library('AccountObject');
  32. $this->load->driver('cache', array('adapter' => 'file'));
  33. //$this->output->enable_profiler(true);
  34. }
  35. //Monetization Portfolio
  36. public function index()
  37. {
  38. $guest = $this->guest;
  39. $balances = $this->PaymentMethod->getList();
  40. $cashier = array();
  41. $gaming = array();
  42. $sumRevenues = 0;
  43. $sumSufficient = 0;
  44. $sumBuildCost = 0;
  45. foreach ($balances as $balance)
  46. {
  47. $revenues = $this->Monetization->sumAllRevenues($balance->code);
  48. $otherCosts = $this->Monetization->sumAllOtherCosts($balance->code);
  49. $moduleInfo = $this->Monetization->getModuleDetails($balance->code);
  50. $cost = $revenues->cost - $otherCosts->other_cost;
  51. $row = array();
  52. $row[] = anchor('monetization/method/' . $balance->code . '.html', $balance->name);
  53. $row[] = money($moduleInfo->installation_cost);
  54. $row[] = money($cost);
  55. $row[] = money($moduleInfo->installation_cost / MON_VAL_1);
  56. $row[] = money($cost > 0 ? $cost / MON_VAL_2 : 0);
  57. $cashier[$balance->code] = $row;
  58. $sumRevenues = $sumRevenues + $cost;
  59. $sumSufficient = $sumSufficient + ($cost / MON_VAL_2);
  60. $sumBuildCost = $sumBuildCost + $moduleInfo->installation_cost;
  61. }
  62. // Shares
  63. $revenues = $this->Monetization->sumAllShareRevenues();
  64. $moduleInfo = $this->Monetization->getModuleDetails('shares');
  65. $cost = $revenues->fee;
  66. $shares = array(
  67. 'buildCost' => money($moduleInfo->installation_cost),
  68. 'cost' => money($cost),
  69. 'investmentConsumed' => money($moduleInfo->installation_cost / MON_VAL_1),
  70. 'investmentRepaid' => money($cost > 0 ? $cost / MON_VAL_2 : 0)
  71. );
  72. // Do the Games
  73. $games = $this->Game->getAll();
  74. foreach ($games as $game)
  75. {
  76. $revenues = $this->Monetization->sumAllGameRevenues($game->code);
  77. $moduleInfo = $this->Monetization->getModuleDetails($game->code);
  78. $cost = $revenues;
  79. $row = array();
  80. $row[] = anchor('monetization/game/' . $game->code . '.html', $game->name);
  81. $row[] = money($moduleInfo->installation_cost);
  82. $row[] = money($cost);
  83. $row[] = money($moduleInfo->installation_cost / MON_VAL_1);
  84. $row[] = money($cost > 0 ? $cost / MON_VAL_2 : 0);
  85. $gaming[$game->code] = $row;
  86. $sumRevenues = $sumRevenues + $cost;
  87. $sumSufficient = $sumSufficient + ($cost / MON_VAL_2);
  88. $sumBuildCost = $sumBuildCost + $moduleInfo->installation_cost;
  89. }
  90. // Coin flip game. Use this function to model all future games so they fit
  91. // here nicely.
  92. $gameMonetizationData = $this->CoinFlip->getGameMonetizationData();
  93. $sumRevenues += $gameMonetizationData->cost;
  94. $sumSufficient += $sumSufficient + ($gameMonetizationData->cost / MON_VAL_2);
  95. $sumBuildCost += $gameMonetizationData->moduleInfo->installation_cost;
  96. $gaming[$gameMonetizationData->gameData->code] = $gameMonetizationData->viewRows;
  97. // Blackjack
  98. $gameMonetizationData = $this->Blackjack->getGameMonetizationData();
  99. $sumRevenues += $gameMonetizationData->cost;
  100. $sumSufficient += $sumSufficient + ($gameMonetizationData->cost / MON_VAL_2);
  101. $sumBuildCost += $gameMonetizationData->moduleInfo->installation_cost;
  102. $gaming[$gameMonetizationData->gameData->code] = $gameMonetizationData->viewRows;
  103. // [ADD OTHER GAMES HERE]
  104. $totalInvested = $this->Investment->getTotalInvested();
  105. $this->layoutData['member_page'] = 'Monetization Portfolio';
  106. $this->loadView('monetization/index', 'My Traffic Value: Monetization Portfolio', compact('guest', 'cashier', 'shares', 'gaming', 'sumRevenues', 'sumSufficient', 'sumBuildCost', 'totalInvested'));
  107. }
  108. //Monetization Portfolio -> view details of deposit method
  109. public function revenue_method($code, $page = 1)
  110. {
  111. $moduleDetails = $this->Monetization->getModuleDetails($code);
  112. $guest = $this->guest;
  113. if (!$moduleDetails) show_404();
  114. $monthInstall = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), 1, date("Y", $moduleDetails->installation_date));
  115. // Work out how many pages we will have from the installation date until now
  116. $pages = 0;
  117. while ($monthInstall < now())
  118. {
  119. $pages++;
  120. $monthInstall = strtotime("+1 month", $monthInstall);
  121. }
  122. // We need to calculate the start of the month depending on the page we are on
  123. $_page = $page - 1;
  124. $pageDate = $_page ? strtotime("-$_page month", now()) : now();
  125. // A few dates to help with the data to display
  126. $now = mktime(0, 0, 0, date("n", now()), date("j", now()), date("Y", now()));
  127. $installDay = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), date("j", $moduleDetails->installation_date), date("Y", $moduleDetails->installation_date));
  128. $startMonth = mktime(0, 0, 0, date("n", $pageDate), 1, date("Y", $pageDate));
  129. $nextMonth = strtotime("+1 month", $startMonth);
  130. $dailyResults = $this->Monetization->getMonetizationDays($code, $startMonth);
  131. // Last day of the month to display
  132. $lastDay = strtotime("-1 day", $nextMonth);
  133. // But are we in the current month and is the last day in the future? if Yes then stop at today
  134. $lastDay = min($lastDay, $now);
  135. // The first day in the list will either be the 1st of the month OR the installation date - whichever is greater
  136. $firstDay = max($startMonth, $installDay);
  137. $paging = generatePagination(site_url('monetization/revenue_method/' . $code), $pages, $page, 1, true);
  138. $hasPages = $pages;
  139. $breakdown = $this->loadPartialView('monetization/partial/revenue_method', compact('guest', 'code', 'dailyResults', 'lastDay', 'firstDay', 'paging', 'hasPages'));
  140. if ($this->input->is_ajax_request())
  141. {
  142. echo $breakdown;
  143. }
  144. else
  145. {
  146. $revenues = $this->Monetization->sumAllrevenues($code);
  147. $otherCosts = $this->Monetization->sumAllOtherCosts($code);
  148. $uniqueUsers = $this->Monetization->getUniqueUsers($code);
  149. $billing = $this->PaymentMethod->getLatestBillDetails($code);
  150. $methodName = $this->PaymentMethod->getNameFromCode($code);
  151. $this->addJavascript(asset('scripts/paging.js'));
  152. $this->layoutData['member_page'] = anchor('monetization.html', 'Monetization Portfolio') . ' - ' . $methodName;
  153. $this->loadView('monetization/revenue_method', 'My Traffic Value: Monetization Portfolio - ' . $methodName, compact('guest', 'methodName', 'moduleDetails', 'revenues', 'otherCosts', 'breakdown', 'uniqueUsers', 'billing'));
  154. }
  155. }
  156. //Monetization Portfolio -> Deposit Method -> view date
  157. public function daily_revenue_method($code, $day, $type = null, $page = 1, $perpage = 20)
  158. {
  159. $date = strtotime($day);
  160. $this->load->model('transaction_model', 'Transaction');
  161. if (!$type || $type == 'deposit')
  162. {
  163. $count = $this->Transaction->countTransactions($code, 'deposit', 'ok', $date);
  164. $data = $this->Transaction->getDepositsSubset($code, 'ok', $page, $perpage, $date);
  165. $transactionType = 'deposit';
  166. $paging = generatePagination(site_url('monetization/daily_revenue_method/' . $code . '/' . $day . '/' . $transactionType), $count, $page, $perpage, true);
  167. $hasPages = $count > $perpage;
  168. $deposits = $this->loadPartialView('monetization/partial/daily_revenue_method_transactions', compact('date', 'transactionType', 'paging', 'hasPages', 'count', 'data'));
  169. if ($this->input->is_ajax_request())
  170. {
  171. echo $deposits;
  172. return;
  173. }
  174. }
  175. if (!$type || $type == 'cashout')
  176. {
  177. $count = $this->Transaction->countTransactions($code, 'cashout', 'ok', $date);
  178. $data = $this->Transaction->getCashoutsSubset($code, 'ok', $page, $perpage, $date);
  179. $transactionType = 'cashout';
  180. $paging = generatePagination(site_url('monetization/daily_revenue_method/' . $code . '/' . $day . '/' . $transactionType), $count, $page, $perpage, true);
  181. $hasPages = $count > $perpage;
  182. $cashouts = $this->loadPartialView('monetization/partial/daily_revenue_method_transactions', compact('date', 'transactionType', 'paging', 'hasPages', 'count', 'data'));
  183. if ($this->input->is_ajax_request())
  184. {
  185. echo $cashouts;
  186. return;
  187. }
  188. }
  189. $guest = $this->guest;
  190. $billing = $this->PaymentMethod->getLatestBillDetails($code, $date);
  191. $methodName = $this->PaymentMethod->getNameFromCode($code);
  192. $depositRevenues = $this->Monetization->sumAllrevenues($code, 'deposit', $date);
  193. $cashoutRevenues = $this->Monetization->sumAllrevenues($code, 'cashout', $date);
  194. $otherCosts = $this->Monetization->sumAllOtherCosts($code, $date);
  195. $this->addJavascript(asset('scripts/paging.js'));
  196. $this->layoutData['member_page'] = anchor ('monetization.html', 'Monetization Portfolio') . ' - ' . anchor('monetization/method/' . $code . '.html', $methodName) . ' - ' . $day;
  197. $this->loadView('monetization/daily_revenue_method', "My Traffic Value: Monetization Portfolio - $methodName - DATE", compact('guest', 'methodName', 'deposits', 'cashouts', 'otherCosts', 'billing', 'date', 'depositRevenues', 'cashoutRevenues'));
  198. }
  199. // Share Transfers
  200. public function share_transfers($page = 1)
  201. {
  202. $moduleDetails = $this->Monetization->getModuleDetails('shares');
  203. $guest = $this->guest;
  204. if (!$moduleDetails) show_404();
  205. $monthInstall = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), 1, date("Y", $moduleDetails->installation_date));
  206. // Work out how many pages we will have from the installation date until now
  207. $pages = 0;
  208. while ($monthInstall < now())
  209. {
  210. $pages++;
  211. $monthInstall = strtotime("+1 month", $monthInstall);
  212. }
  213. // We need to calculate the start of the month depending on the page we are on
  214. $_page = $page - 1;
  215. $pageDate = $_page ? strtotime("-$_page month", now()) : now();
  216. // A few dates to help with the data to display
  217. $now = mktime(0, 0, 0, date("n", now()), date("j", now()), date("Y", now()));
  218. $installDay = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), date("j", $moduleDetails->installation_date), date("Y", $moduleDetails->installation_date));
  219. $startMonth = mktime(0, 0, 0, date("n", $pageDate), 1, date("Y", $pageDate));
  220. $nextMonth = strtotime("+1 month", $startMonth);
  221. $dailyResults = $this->Monetization->getMonetizationSharesDays($startMonth);
  222. // Last day of the month to display
  223. $lastDay = strtotime("-1 day", $nextMonth);
  224. // But are we in the current month and is the last day in the future? if Yes then stop at today
  225. $lastDay = min($lastDay, $now);
  226. // The first day in the list will either be the 1st of the month OR the installation date - whichever is greater
  227. $firstDay = max($startMonth, $installDay);
  228. $paging = generatePagination(site_url('monetization/share_transfers'), $pages, $page, 1, true);
  229. $hasPages = $pages;
  230. $breakdown = $this->loadPartialView('monetization/partial/share_transfers', compact('guest', 'dailyResults', 'lastDay', 'firstDay', 'paging', 'hasPages'));
  231. if ($this->input->is_ajax_request())
  232. {
  233. echo $breakdown;
  234. }
  235. else
  236. {
  237. $revenues = $this->Monetization->sumAllShareRevenues();
  238. $uniqueUsers = $this->Monetization->getUniqueShareUsers();
  239. $this->addJavascript(asset('scripts/paging.js'));
  240. $this->layoutData['member_page'] = anchor('monetization.html', 'Monetization Portfolio') . ' - Share Transfers';
  241. $this->loadView('monetization/share_transfers', 'My Traffic Value: Monetization Portfolio - Share Transfers', compact('guest', 'moduleDetails', 'revenues', 'breakdown', 'uniqueUsers'));
  242. }
  243. }
  244. // Daily Share Transfers
  245. public function daily_revenue_shares($day, $page = 1, $perpage = 20)
  246. {
  247. $date = strtotime($day);
  248. $this->load->model('shares_model', 'Shares');
  249. $count = $this->Shares->getTransfersCount(false, $date, 'ok');
  250. $data = $this->Shares->getTransfersSubset($page, $perpage, false, $date, 'ok');
  251. $paging = generatePagination(site_url('monetization/daily_revenue_shares/' . $day), $count, $page, $perpage, true);
  252. $hasPages = $count > $perpage;
  253. $transfers = $this->loadPartialView('monetization/partial/daily_revenue_shares', compact('date', 'transactionType', 'paging', 'hasPages', 'count', 'data'));
  254. if ($this->input->is_ajax_request())
  255. {
  256. echo $transfers;
  257. return;
  258. }
  259. $guest = $this->guest;
  260. $this->addJavascript(asset('scripts/paging.js'));
  261. $this->layoutData['member_page'] = anchor ('monetization.html', 'Monetization Portfolio') . ' - ' . anchor('monetization/shares.html', 'Share Transfers') . ' - ' . $day;
  262. $this->loadView('monetization/daily_revenue_shares', "My Traffic Value: Monetization Portfolio - Share Transfers - $day", compact('guest', 'transfers', 'date'));
  263. }
  264. // Investment
  265. public function direct_investment($page = 1)
  266. {
  267. $moduleDetails = $this->Monetization->getModuleDetails('invest');
  268. $guest = $this->guest;
  269. if (!$moduleDetails) show_404();
  270. $monthInstall = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), 1, date("Y", $moduleDetails->installation_date));
  271. // Work out how many pages we will have from the installation date until now
  272. $pages = 0;
  273. while ($monthInstall < now())
  274. {
  275. $pages++;
  276. $monthInstall = strtotime("+1 month", $monthInstall);
  277. }
  278. // We need to calculate the start of the month depending on the page we are on
  279. $_page = $page - 1;
  280. $pageDate = $_page ? strtotime("-$_page month", now()) : now();
  281. // A few dates to help with the data to display
  282. $now = mktime(0, 0, 0, date("n", now()), date("j", now()), date("Y", now()));
  283. $installDay = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), date("j", $moduleDetails->installation_date), date("Y", $moduleDetails->installation_date));
  284. $startMonth = mktime(0, 0, 0, date("n", $pageDate), 1, date("Y", $pageDate));
  285. $nextMonth = strtotime("+1 month", $startMonth);
  286. $dailyResults = $this->Monetization->getMonetizationInvestmentDays($startMonth);
  287. // Last day of the month to display
  288. $lastDay = strtotime("-1 day", $nextMonth);
  289. // But are we in the current month and is the last day in the future? if Yes then stop at today
  290. $lastDay = min($lastDay, $now);
  291. // The first day in the list will either be the 1st of the month OR the installation date - whichever is greater
  292. $firstDay = max($startMonth, $installDay);
  293. $paging = generatePagination(site_url('monetization/direct_investment'), $pages, $page, 1, true);
  294. $hasPages = $pages;
  295. $breakdown = $this->loadPartialView('monetization/partial/direct_investments', compact('guest', 'dailyResults', 'lastDay', 'firstDay', 'paging', 'hasPages'));
  296. if ($this->input->is_ajax_request())
  297. {
  298. echo $breakdown;
  299. }
  300. else
  301. {
  302. $uniqueUsers = $this->Monetization->getUniqueInvestmentUsers();
  303. $this->addJavascript(asset('scripts/paging.js'));
  304. $this->layoutData['member_page'] = anchor('monetization.html', 'Monetization Portfolio') . ' - Direct Invest Contributions';
  305. $this->loadView('monetization/direct_investment', 'My Traffic Value: Monetization Portfolio - Direct Invest Contributions', compact('guest', 'moduleDetails', 'breakdown', 'uniqueUsers'));
  306. }
  307. }
  308. // Daily Share Transfers
  309. public function daily_direct_investment($day, $page = 1, $perpage = 20)
  310. {
  311. $date = strtotime($day);
  312. $this->load->model('investment_model', 'Investment');
  313. $count = $this->Investment->getUnitsCount($date);
  314. $data = $this->Investment->getUnitsSubset($date, $page, $perpage);
  315. $paging = generatePagination(site_url('monetization/daily_direct_investment/' . $day), $count, $page, $perpage, true);
  316. $hasPages = $count > $perpage;
  317. $investments = $this->loadPartialView('monetization/partial/daily_direct_investment', compact('date', 'paging', 'hasPages', 'count', 'data'));
  318. if ($this->input->is_ajax_request())
  319. {
  320. echo $investments;
  321. return;
  322. }
  323. $guest = $this->guest;
  324. $this->addJavascript(asset('scripts/paging.js'));
  325. $this->layoutData['member_page'] = anchor ('monetization.html', 'Monetization Portfolio') . ' - ' . anchor('monetization/investment.html', 'Direct Invest Contributions') . ' - ' . $day;
  326. $this->loadView('monetization/daily_direct_investment', "My Traffic Value: Monetization Portfolio - Direct Invest Contributions - $day", compact('guest', 'investments', 'date'));
  327. }
  328. // Change Game
  329. public function standard_game($code, $page = 1)
  330. {
  331. $gameData = $this->Game->getGameData($code);
  332. if (!$gameData) show_404();
  333. $moduleDetails = $this->Monetization->getModuleDetails($code);
  334. $guest = $this->guest;
  335. if (!$moduleDetails) show_404();
  336. $monthInstall = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), 1, date("Y", $moduleDetails->installation_date));
  337. // Work out how many pages we will have from the installation date until now
  338. $pages = 0;
  339. while ($monthInstall < now())
  340. {
  341. $pages++;
  342. $monthInstall = strtotime("+1 month", $monthInstall);
  343. }
  344. // We need to calculate the start of the month depending on the page we are on
  345. $_page = $page - 1;
  346. $pageDate = $_page ? strtotime("-$_page month", now()) : now();
  347. // A few dates to help with the data to display
  348. $now = mktime(0, 0, 0, date("n", now()), date("j", now()), date("Y", now()));
  349. $installDay = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), date("j", $moduleDetails->installation_date), date("Y", $moduleDetails->installation_date));
  350. $startMonth = mktime(0, 0, 0, date("n", $pageDate), 1, date("Y", $pageDate));
  351. $nextMonth = strtotime("+1 month", $startMonth);
  352. $dailyResults = $this->Monetization->getMonetizationGameDays($code, $startMonth);
  353. // Last day of the month to display
  354. $lastDay = strtotime("-1 day", $nextMonth);
  355. // But are we in the current month and is the last day in the future? if Yes then stop at today
  356. $lastDay = min($lastDay, $now);
  357. // The first day in the list will either be the 1st of the month OR the installation date - whichever is greater
  358. $firstDay = max($startMonth, $installDay);
  359. $paging = generatePagination(site_url('monetization/standard_game/' . $code), $pages, $page, 1, true);
  360. $hasPages = $pages;
  361. $breakdown = $this->loadPartialView('monetization/partial/standard_game', compact('guest', 'dailyResults', 'lastDay', 'firstDay', 'paging', 'hasPages', 'gameData'));
  362. if ($this->input->is_ajax_request())
  363. {
  364. echo $breakdown;
  365. }
  366. else
  367. {
  368. $uniqueUsers = $this->Monetization->getUniqueGameUsers($code);
  369. $revenues = $this->Monetization->sumAllGameRevenues($code);
  370. $this->addJavascript(asset('scripts/paging.js'));
  371. $this->layoutData['member_page'] = anchor('monetization.html', 'Monetization Portfolio') . ' - The ' . $gameData->name;
  372. $this->loadView('monetization/standard_game', 'My Traffic Value: Monetization Portfolio - The ' . $gameData->name, compact('guest', 'moduleDetails', 'breakdown', 'uniqueUsers', 'revenues', 'gameData'));
  373. }
  374. }
  375. // Con flip Game
  376. public function coin_flip_game($page = 1)
  377. {
  378. $code = "coin_flip";
  379. $paginationTitle = "coin_flip_game";
  380. $gameMonetizationData = $this->CoinFlip->getGameMonetizationData();
  381. $revenues = $gameMonetizationData->revenues;
  382. $houseEdge = $gameMonetizationData->houseEdge;
  383. $uniqueUsers = $gameMonetizationData->uniqueUsers;
  384. $gameData = $this->Game->getGameData($code);
  385. if (!$gameData) show_404();
  386. $moduleDetails = $this->Monetization->getModuleDetails($code);
  387. $guest = $this->guest;
  388. if (!$moduleDetails) show_404();
  389. $monthInstall = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), 1, date("Y", $moduleDetails->installation_date));
  390. // Work out how many pages we will have from the installation date until now
  391. $pages = 0;
  392. while ($monthInstall < now())
  393. {
  394. $pages++;
  395. $monthInstall = strtotime("+1 month", $monthInstall);
  396. }
  397. // We need to calculate the start of the month depending on the page we are on
  398. $_page = $page - 1;
  399. $pageDate = $_page ? strtotime("-$_page month", now()) : now();
  400. // A few dates to help with the data to display
  401. $now = mktime(0, 0, 0, date("n", now()), date("j", now()), date("Y", now()));
  402. $installDay = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), date("j", $moduleDetails->installation_date), date("Y", $moduleDetails->installation_date));
  403. $startMonth = mktime(0, 0, 0, date("n", $pageDate), 1, date("Y", $pageDate));
  404. $nextMonth = strtotime("+1 month", $startMonth);
  405. $dailyResults = $this->CoinFlip->getMonetizationGameDays($startMonth);
  406. // Last day of the month to display
  407. $lastDay = strtotime("-1 day", $nextMonth);
  408. // But are we in the current month and is the last day in the future? if Yes then stop at today
  409. $lastDay = min($lastDay, $now);
  410. // The first day in the list will either be the 1st of the month OR the installation date - whichever is greater
  411. $firstDay = max($startMonth, $installDay);
  412. $paging = generatePagination(site_url("monetization/$paginationTitle"), $pages, $page, 1, true);
  413. $hasPages = $pages;
  414. $breakdown = $this->loadPartialView('monetization/partial/standard_game', compact('guest', 'dailyResults', 'lastDay', 'firstDay', 'paging', 'hasPages', 'gameData', 'houseEdge'));
  415. if ($this->input->is_ajax_request())
  416. {
  417. echo $breakdown;
  418. }
  419. else
  420. {
  421. $this->addJavascript(asset('scripts/paging.js'));
  422. $this->layoutData['member_page'] = anchor('monetization.html', 'Monetization Portfolio') . ' - The ' . $gameData->name;
  423. $this->loadView('monetization/standard_game', 'My Traffic Value: Monetization Portfolio - The ' . $gameData->name, compact('guest', 'moduleDetails', 'breakdown', 'uniqueUsers', 'revenues', 'gameData'));
  424. }
  425. }
  426. // Blackjack
  427. public function blackjack_game($page = 1)
  428. {
  429. $code = "blackjack";
  430. $paginationTitle = "blackjack_game";
  431. $gameMonetizationData = $this->Blackjack->getGameMonetizationData();
  432. $revenues = $gameMonetizationData->revenues;
  433. $houseEdge = $gameMonetizationData->houseEdge;
  434. $uniqueUsers = $gameMonetizationData->uniqueUsers;
  435. $gameData = $this->Game->getGameData($code);
  436. if (!$gameData) show_404();
  437. $moduleDetails = $this->Monetization->getModuleDetails($code);
  438. $guest = $this->guest;
  439. if (!$moduleDetails) show_404();
  440. $monthInstall = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), 1, date("Y", $moduleDetails->installation_date));
  441. // Work out how many pages we will have from the installation date until now
  442. $pages = 0;
  443. while ($monthInstall < now())
  444. {
  445. $pages++;
  446. $monthInstall = strtotime("+1 month", $monthInstall);
  447. }
  448. // We need to calculate the start of the month depending on the page we are on
  449. $_page = $page - 1;
  450. $pageDate = $_page ? strtotime("-$_page month", now()) : now();
  451. // A few dates to help with the data to display
  452. $now = mktime(0, 0, 0, date("n", now()), date("j", now()), date("Y", now()));
  453. $installDay = mktime(0, 0, 0, date("n", $moduleDetails->installation_date), date("j", $moduleDetails->installation_date), date("Y", $moduleDetails->installation_date));
  454. $startMonth = mktime(0, 0, 0, date("n", $pageDate), 1, date("Y", $pageDate));
  455. $nextMonth = strtotime("+1 month", $startMonth);
  456. $dailyResults = $this->Blackjack->getMonetizationGameDays($startMonth);
  457. // Last day of the month to display
  458. $lastDay = strtotime("-1 day", $nextMonth);
  459. // But are we in the current month and is the last day in the future? if Yes then stop at today
  460. $lastDay = min($lastDay, $now);
  461. // The first day in the list will either be the 1st of the month OR the installation date - whichever is greater
  462. $firstDay = max($startMonth, $installDay);
  463. $paging = generatePagination(site_url("monetization/$paginationTitle"), $pages, $page, 1, true);
  464. $hasPages = $pages;
  465. $breakdown = $this->loadPartialView('monetization/partial/standard_game', compact('guest', 'dailyResults', 'lastDay', 'firstDay', 'paging', 'hasPages', 'gameData', 'houseEdge'));
  466. if ($this->input->is_ajax_request())
  467. {
  468. echo $breakdown;
  469. }
  470. else
  471. {
  472. $this->addJavascript(asset('scripts/paging.js'));
  473. $this->layoutData['member_page'] = anchor('monetization.html', 'Monetization Portfolio') . ' - The ' . $gameData->name;
  474. $this->loadView('monetization/standard_game', 'My Traffic Value: Monetization Portfolio - The ' . $gameData->name, compact('guest', 'moduleDetails', 'breakdown', 'uniqueUsers', 'revenues', 'gameData'));
  475. }
  476. }
  477. public function daily_coin_flip($day, $page = 1, $perpage = 20)
  478. {
  479. $code = "coin_flip";
  480. $gameData = $this->CoinFlip->getGameData();
  481. $date = strtotime($day);
  482. $count = $this->CoinFlip->getPlaysCount($date);
  483. $data = $this->CoinFlip->getPlaysSubset($date, $page, $perpage);
  484. $paging = generatePagination(site_url("monetization/daily_$code/" . $day), $count, $page, $perpage, true);
  485. $hasPages = $count > $perpage;
  486. $plays = $this->loadPartialView("monetization/partial/daily_$code", compact('date', 'paging', 'hasPages', 'count', 'data', 'gameData'));
  487. if ($this->input->is_ajax_request())
  488. {
  489. echo $plays;
  490. return;
  491. }
  492. $guest = $this->guest;
  493. $this->addJavascript(asset('scripts/paging.js'));
  494. $this->layoutData['member_page'] = anchor ('monetization.html', 'Monetization Portfolio') . ' - ' . anchor('monetization/game/' . $code . '.html', 'The ' . $gameData->name) . ' - ' . $day;
  495. $this->loadView('monetization/daily_standard_game', "My Traffic Value: Monetization Portfolio - The ' . $gameData->name . ' - $day", compact('guest', 'plays', 'date', 'gameData'));
  496. }
  497. public function daily_blackjack($day, $page = 1, $perpage = 20)
  498. {
  499. $gameData = $this->Blackjack->getGameData();
  500. $code = $gameData->code;
  501. $date = strtotime($day);
  502. $count = $this->Blackjack->getPlaysCount($date);
  503. $data = $this->Blackjack->getPlaysSubset($date, $page, $perpage);
  504. $paging = generatePagination(site_url("monetization/daily_$code/" . $day), $count, $page, $perpage, true);
  505. $hasPages = $count > $perpage;
  506. $plays = $this->loadPartialView("monetization/partial/daily_$code", compact('date', 'paging', 'hasPages', 'count', 'data', 'gameData'));
  507. if ($this->input->is_ajax_request())
  508. {
  509. echo $plays;
  510. return;
  511. }
  512. $guest = $this->guest;
  513. $this->addJavascript(asset('scripts/paging.js'));
  514. $this->layoutData['member_page'] = anchor ('monetization.html', 'Monetization Portfolio') . ' - ' . anchor('monetization/game/' . $code . '.html', 'The ' . $gameData->name) . ' - ' . $day;
  515. $this->loadView('monetization/daily_standard_game', "My Traffic Value: Monetization Portfolio - The ' . $gameData->name . ' - $day", compact('guest', 'plays', 'date', 'gameData'));
  516. }
  517. // Daily Share Transfers
  518. public function daily_standard_game($code, $day, $page = 1, $perpage = 20)
  519. {
  520. $gameData = $this->Game->getGameData($code);
  521. $date = strtotime($day);
  522. $count = $this->Game->getPlaysCount($code, $date);
  523. $data = $this->Game->getPlaysSubset($code, $date, $page, $perpage);
  524. $paging = generatePagination(site_url("monetization/daily_standard_game/" . $code . "/" . $day), $count, $page, $perpage, true);
  525. $hasPages = $count > $perpage;
  526. $plays = $this->loadPartialView("monetization/partial/daily_standard_game", compact('date', 'paging', 'hasPages', 'count', 'data', 'gameData'));
  527. if ($this->input->is_ajax_request())
  528. {
  529. echo $plays;
  530. return;
  531. }
  532. $guest = $this->guest;
  533. $this->addJavascript(asset('scripts/paging.js'));
  534. $this->layoutData['member_page'] = anchor ('monetization.html', 'Monetization Portfolio') . ' - ' . anchor('monetization/game/' . $code . '.html', 'The ' . $gameData->name) . ' - ' . $day;
  535. $this->loadView('monetization/daily_standard_game', "My Traffic Value: Monetization Portfolio - The ' . $gameData->name . ' - $day", compact('guest', 'plays', 'date', 'gameData'));
  536. }
  537. }