Guest User

Untitled

a guest
Feb 20th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.01 KB | None | 0 0
  1. <?php
  2.  
  3. class ManagementController extends RazorManagementController
  4. {
  5.  
  6.     public $appName = 'WhatsHotApp';
  7.     public $layout = '//layouts/mgmt';
  8.  
  9.     //TODO:: need write custom widget for generating array with menu item,  because this(current) way looks very stupid =)
  10.     public function getMenuItems()
  11.     {
  12.         $pageId = ModelPage::getPage()->fb_page_id;
  13.  
  14.         return array(
  15.             array(
  16.                 'url' => $this->baseUrl . '/whatsHot/management/design/pageId/' . $pageId,
  17.                 'label' => 'Design'
  18.             ),
  19.             array(
  20.                 'url' => $this->baseUrl . '/whatsHot/management/votingOptions/pageId/' . $pageId,
  21.                 'label' => 'Voting Options'
  22.             ),
  23. //          array(
  24. //              'url'   => $this->baseUrl . "/whatsHot/management/rules/pageId/" . $pageId,
  25. //              'label' => 'Rules'
  26. //          ),
  27.             array(
  28.                 'url' => $this->baseUrl . "/whatsHot/management/settings/pageId/" . $pageId,
  29.                 'label' => 'Settings'
  30.             ),
  31.             array(
  32.                 'url' => $this->baseUrl . "/whatsHot/management/results/pageId/" . $pageId,
  33.                 'label' => 'Results'
  34.             ),
  35.             array(
  36.                 'url' => $this->baseUrl . "/whatsHot/management/analytics/pageId/" . $pageId,
  37.                 'label' => 'Analytics'
  38.             )
  39.         );
  40.     }
  41.  
  42.     public function actionDesign()
  43.     {
  44.         if (Yii::app()->user->isGuest) {
  45.             $this->redirect("/management/login");
  46.         }
  47.  
  48.         if (!empty($_POST)) {
  49.             ModelWhatsHotVideos::ProcessABVideo($_POST['youtube_link_a'], "A");
  50.             ModelWhatsHotVideos::ProcessABVideo($_POST['youtube_link_b'], "B");
  51.  
  52.             ModelWhatsHotImages::ProcessABImage("A");
  53.             ModelWhatsHotImages::ProcessABImage("B");
  54.  
  55.             $this->processConfigForm($_POST, "general_conf", "voting_options");
  56.         }
  57.  
  58.         $this->render("design", array(
  59.             'video_id_a' => ModelWhatsHotVideos::getYouTubeVideoId("A"),
  60.             'video_id_b' => ModelWhatsHotVideos::getYouTubeVideoId("B"),
  61.             )
  62.         );
  63.     }
  64.  
  65.     public function actionVotingOptions()
  66.     {
  67.         if (Yii::app()->user->isGuest) {
  68.             $this->redirect("/management/login");
  69.         }
  70.  
  71.         if (!empty($_POST)) {
  72.             $this->processConfigForm($_POST, "general_conf", "whatshot_design");
  73.         }
  74.  
  75.         $this->render("voting_options");
  76.     }
  77.  
  78.     public function actionRules()
  79.     {
  80.         if (Yii::app()->user->isGuest) {
  81.             $this->redirect("/management/login");
  82.         }
  83.  
  84.         if (!empty($_POST)) {
  85.             $this->processConfigForm($_POST, "app_rules");
  86.         }
  87.  
  88.         $this->render("rules");
  89.     }
  90.  
  91.     public function actionSettings()
  92.     {
  93.         if (Yii::app()->user->isGuest) {
  94.             $this->redirect("/management/login");
  95.         }
  96.  
  97.         if (!empty($_POST)) {
  98.             $this->processConfigForm($_POST, "general_conf", "whatshot_settings");
  99.             $this->processConfigForm($_POST, "timer_conf", "whatshot_settings");
  100.         }
  101.  
  102.         $this->render("settings");
  103.     }
  104.  
  105.     public function actionResults()
  106.     {
  107.         if (Yii::app()->user->isGuest) {
  108.             $this->redirect("/management/login");
  109.         }
  110.  
  111.         $votes = 0;
  112.  
  113.         if (!empty($_POST)) {
  114.             $this->processConfigForm($_POST, "timer_conf", "results");
  115.  
  116.             if( isset($_POST['winner_a']) ){
  117.                 ModelPage::getConfiguration()->general_conf->winner = "A";
  118.             }else if( isset($_POST['winner_b']) ) {
  119.                 ModelPage::getConfiguration()->general_conf->winner = "B";
  120.             }else{
  121.                 ModelPage::getConfiguration()->general_conf->winner = "";
  122.             }
  123.            
  124.             $this->saveConfiguration();            
  125.            
  126.             if (isset($_POST['winner_a'])) {
  127.                 $info = json_decode($_POST['winner_a'], true);
  128.                 $className = "WhatshotApp{$info['type']}";
  129.                 ModelWhatsHot::setWinners("A", $className, $info);
  130.             } else {
  131.                 ModelWhatsHot::setNoWinners("A", 'WhatshotAppImage');
  132.                 ModelWhatsHot::setNoWinners("A", 'WhatshotAppVideo');
  133.             }
  134.  
  135.             if (isset($_POST['winner_b'])) {
  136.                 $info = json_decode($_POST['winner_b'], true);
  137.                 $className = "WhatshotApp{$info['type']}";
  138.                 ModelWhatsHot::setWinners("B", $className, $info);
  139.             } else {
  140.                 ModelWhatsHot::setNoWinners("B", 'WhatshotAppImage');
  141.                 ModelWhatsHot::setNoWinners("B", 'WhatshotAppVideo');
  142.             }
  143.         }else {
  144.             // Added this special clause to get rid of PHP error on "Results" tab
  145.             ModelPage::getConfiguration()->general_conf->winner = "";
  146.         }
  147.  
  148.         if (ModelPage::getConfiguration()->general_conf->a_side_type === "true") {
  149.             $a_image = ModelWhatsHotImages::getImage("A");
  150.  
  151.             if ($a_image === null) {
  152.                 $aside = null;
  153.             } else {
  154.                 $aside = array(
  155.                     'type' => 'Image',
  156.                     'id' => $a_image->id,
  157.                     'votes' => $a_image->votes,
  158.                     'likes' => $a_image->likes,
  159.                     //$a_image->winner
  160.                 );
  161.             }
  162.         } elseif (ModelPage::getConfiguration()->general_conf->a_side_type === "false") {
  163.             $a_video = ModelWhatsHotVideos::getVideo("A");
  164.  
  165.             if ($a_video === null) {
  166.                 $aside = null;
  167.             } else {
  168.                 $aside = array(
  169.                     'type' => 'Video',
  170.                     'id' => ModelWhatsHotVideos::getVideoId("A"),
  171.                     'votes' => $a_video->votes,
  172.                     'likes' => $a_video->likes,
  173.                 );
  174.             }
  175.         }
  176.  
  177.         if (ModelPage::getConfiguration()->general_conf->b_side_type === "true") {
  178.             $b_image = ModelWhatsHotImages::getImage("B");
  179.  
  180.             if ($b_image === null) {
  181.                 $bside = null;
  182.             } else {
  183.                 $bside = array(
  184.                     'type' => 'Image',
  185.                     'id' => $b_image->id,
  186.                     'votes' => $b_image->votes,
  187.                     'likes' => $b_image->likes,
  188.                 );
  189.             }
  190.         } elseif (ModelPage::getConfiguration()->general_conf->b_side_type === "false") {
  191.             $b_video = ModelWhatsHotVideos::getVideo("B");
  192.  
  193.             if ($a_video === null) {
  194.                 $bside = null;
  195.             } else {
  196.                 $bside = array(
  197.                     'type' => 'Video',
  198.                     'id' => ModelWhatsHotVideos::getVideoId("B"),
  199.                     'votes' => $b_video->votes,
  200.                     'likes' => $b_video->likes,
  201.                 );
  202.             }
  203.         }
  204.  
  205.         if (ModelPage::getConfiguration()->general_conf->a_side_type === "true") {
  206.             $votesArr = ModelWhatsHotImages::getVotingResults();
  207.         } else {
  208.             $votesArr = ModelWhatsHotVideos::getVotingResults();
  209.         }
  210.  
  211.         if ($votesArr !== null) {
  212.             foreach ($votesArr as $v) {
  213.                 $votes += $v;
  214.             }
  215.         }
  216.        
  217.         // ============== Special code fix to create SetWinner functionality based on votes
  218.        
  219.         $max_vote = 0;
  220.         $local_winner = ""; // in case if votes == 0
  221.        
  222.         if($aside['votes'] == $bside['votes']){
  223.             $local_winner = ""; // in case if votes are eqauals
  224.         } else {
  225.            
  226.             if($aside['votes'] > $max_vote){
  227.                 $local_winner = "A";
  228.                 $max_vote = $aside['votes'];
  229.             }
  230.            
  231.             if($bside['votes'] > $max_vote){
  232.                 $local_winner = "B";
  233.                 $max_vote = $bside['votes'];
  234.             }
  235.         }
  236.                
  237.         // Save Winner state into config
  238.         ModelPage::getConfiguration()->general_conf->winner = $local_winner;
  239.        
  240.         // ==============
  241.        
  242.         $this->render(
  243.             "results", array(
  244.             'aside' => $aside,
  245.             'bside' => $bside,
  246.             'votes' => $votes,
  247.             'winner' => $local_winner
  248.             )
  249.         );
  250.     }
  251.  
  252.     public function actionAnalytics()
  253.     {
  254.         if (Yii::app()->user->isGuest) {
  255.             $this->redirect("/management/login");
  256.         }
  257.  
  258.         $this->render(
  259.             "analytics", array(
  260.             "visitor_analytics" => ModelWhatsHot::getVisitorsAnalytics(),
  261.             "like_analytics" => ModelWhatsHot::getLikesAnalytics(),
  262.             "age_analitics" => ModelWhatsHot::getAgeAnalytics()
  263.             )
  264.         );
  265.     }
  266.  
  267.     public function getTimerDuration()
  268.     {
  269.         $starttime = strtotime(ModelPage::getConfiguration()->timer_conf->start_time);
  270.         $endtime = strtotime(ModelPage::getConfiguration()->timer_conf->end_time);
  271.         $timediff = $endtime - $starttime;
  272.  
  273.         $days = intval($timediff / 86400);
  274.  
  275.         return $days;
  276.     }
  277.  
  278. }
Add Comment
Please, Sign In to add comment