Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ManagementController extends RazorManagementController
- {
- public $appName = 'WhatsHotApp';
- public $layout = '//layouts/mgmt';
- //TODO:: need write custom widget for generating array with menu item, because this(current) way looks very stupid =)
- public function getMenuItems()
- {
- $pageId = ModelPage::getPage()->fb_page_id;
- return array(
- array(
- 'url' => $this->baseUrl . '/whatsHot/management/design/pageId/' . $pageId,
- 'label' => 'Design'
- ),
- array(
- 'url' => $this->baseUrl . '/whatsHot/management/votingOptions/pageId/' . $pageId,
- 'label' => 'Voting Options'
- ),
- // array(
- // 'url' => $this->baseUrl . "/whatsHot/management/rules/pageId/" . $pageId,
- // 'label' => 'Rules'
- // ),
- array(
- 'url' => $this->baseUrl . "/whatsHot/management/settings/pageId/" . $pageId,
- 'label' => 'Settings'
- ),
- array(
- 'url' => $this->baseUrl . "/whatsHot/management/results/pageId/" . $pageId,
- 'label' => 'Results'
- ),
- array(
- 'url' => $this->baseUrl . "/whatsHot/management/analytics/pageId/" . $pageId,
- 'label' => 'Analytics'
- )
- );
- }
- public function actionDesign()
- {
- if (Yii::app()->user->isGuest) {
- $this->redirect("/management/login");
- }
- if (!empty($_POST)) {
- ModelWhatsHotVideos::ProcessABVideo($_POST['youtube_link_a'], "A");
- ModelWhatsHotVideos::ProcessABVideo($_POST['youtube_link_b'], "B");
- ModelWhatsHotImages::ProcessABImage("A");
- ModelWhatsHotImages::ProcessABImage("B");
- $this->processConfigForm($_POST, "general_conf", "voting_options");
- }
- $this->render("design", array(
- 'video_id_a' => ModelWhatsHotVideos::getYouTubeVideoId("A"),
- 'video_id_b' => ModelWhatsHotVideos::getYouTubeVideoId("B"),
- )
- );
- }
- public function actionVotingOptions()
- {
- if (Yii::app()->user->isGuest) {
- $this->redirect("/management/login");
- }
- if (!empty($_POST)) {
- $this->processConfigForm($_POST, "general_conf", "whatshot_design");
- }
- $this->render("voting_options");
- }
- public function actionRules()
- {
- if (Yii::app()->user->isGuest) {
- $this->redirect("/management/login");
- }
- if (!empty($_POST)) {
- $this->processConfigForm($_POST, "app_rules");
- }
- $this->render("rules");
- }
- public function actionSettings()
- {
- if (Yii::app()->user->isGuest) {
- $this->redirect("/management/login");
- }
- if (!empty($_POST)) {
- $this->processConfigForm($_POST, "general_conf", "whatshot_settings");
- $this->processConfigForm($_POST, "timer_conf", "whatshot_settings");
- }
- $this->render("settings");
- }
- public function actionResults()
- {
- if (Yii::app()->user->isGuest) {
- $this->redirect("/management/login");
- }
- $votes = 0;
- if (!empty($_POST)) {
- $this->processConfigForm($_POST, "timer_conf", "results");
- if( isset($_POST['winner_a']) ){
- ModelPage::getConfiguration()->general_conf->winner = "A";
- }else if( isset($_POST['winner_b']) ) {
- ModelPage::getConfiguration()->general_conf->winner = "B";
- }else{
- ModelPage::getConfiguration()->general_conf->winner = "";
- }
- $this->saveConfiguration();
- if (isset($_POST['winner_a'])) {
- $info = json_decode($_POST['winner_a'], true);
- $className = "WhatshotApp{$info['type']}";
- ModelWhatsHot::setWinners("A", $className, $info);
- } else {
- ModelWhatsHot::setNoWinners("A", 'WhatshotAppImage');
- ModelWhatsHot::setNoWinners("A", 'WhatshotAppVideo');
- }
- if (isset($_POST['winner_b'])) {
- $info = json_decode($_POST['winner_b'], true);
- $className = "WhatshotApp{$info['type']}";
- ModelWhatsHot::setWinners("B", $className, $info);
- } else {
- ModelWhatsHot::setNoWinners("B", 'WhatshotAppImage');
- ModelWhatsHot::setNoWinners("B", 'WhatshotAppVideo');
- }
- }else {
- // Added this special clause to get rid of PHP error on "Results" tab
- ModelPage::getConfiguration()->general_conf->winner = "";
- }
- if (ModelPage::getConfiguration()->general_conf->a_side_type === "true") {
- $a_image = ModelWhatsHotImages::getImage("A");
- if ($a_image === null) {
- $aside = null;
- } else {
- $aside = array(
- 'type' => 'Image',
- 'id' => $a_image->id,
- 'votes' => $a_image->votes,
- 'likes' => $a_image->likes,
- //$a_image->winner
- );
- }
- } elseif (ModelPage::getConfiguration()->general_conf->a_side_type === "false") {
- $a_video = ModelWhatsHotVideos::getVideo("A");
- if ($a_video === null) {
- $aside = null;
- } else {
- $aside = array(
- 'type' => 'Video',
- 'id' => ModelWhatsHotVideos::getVideoId("A"),
- 'votes' => $a_video->votes,
- 'likes' => $a_video->likes,
- );
- }
- }
- if (ModelPage::getConfiguration()->general_conf->b_side_type === "true") {
- $b_image = ModelWhatsHotImages::getImage("B");
- if ($b_image === null) {
- $bside = null;
- } else {
- $bside = array(
- 'type' => 'Image',
- 'id' => $b_image->id,
- 'votes' => $b_image->votes,
- 'likes' => $b_image->likes,
- );
- }
- } elseif (ModelPage::getConfiguration()->general_conf->b_side_type === "false") {
- $b_video = ModelWhatsHotVideos::getVideo("B");
- if ($a_video === null) {
- $bside = null;
- } else {
- $bside = array(
- 'type' => 'Video',
- 'id' => ModelWhatsHotVideos::getVideoId("B"),
- 'votes' => $b_video->votes,
- 'likes' => $b_video->likes,
- );
- }
- }
- if (ModelPage::getConfiguration()->general_conf->a_side_type === "true") {
- $votesArr = ModelWhatsHotImages::getVotingResults();
- } else {
- $votesArr = ModelWhatsHotVideos::getVotingResults();
- }
- if ($votesArr !== null) {
- foreach ($votesArr as $v) {
- $votes += $v;
- }
- }
- // ============== Special code fix to create SetWinner functionality based on votes
- $max_vote = 0;
- $local_winner = ""; // in case if votes == 0
- if($aside['votes'] == $bside['votes']){
- $local_winner = ""; // in case if votes are eqauals
- } else {
- if($aside['votes'] > $max_vote){
- $local_winner = "A";
- $max_vote = $aside['votes'];
- }
- if($bside['votes'] > $max_vote){
- $local_winner = "B";
- $max_vote = $bside['votes'];
- }
- }
- // Save Winner state into config
- ModelPage::getConfiguration()->general_conf->winner = $local_winner;
- // ==============
- $this->render(
- "results", array(
- 'aside' => $aside,
- 'bside' => $bside,
- 'votes' => $votes,
- 'winner' => $local_winner
- )
- );
- }
- public function actionAnalytics()
- {
- if (Yii::app()->user->isGuest) {
- $this->redirect("/management/login");
- }
- $this->render(
- "analytics", array(
- "visitor_analytics" => ModelWhatsHot::getVisitorsAnalytics(),
- "like_analytics" => ModelWhatsHot::getLikesAnalytics(),
- "age_analitics" => ModelWhatsHot::getAgeAnalytics()
- )
- );
- }
- public function getTimerDuration()
- {
- $starttime = strtotime(ModelPage::getConfiguration()->timer_conf->start_time);
- $endtime = strtotime(ModelPage::getConfiguration()->timer_conf->end_time);
- $timediff = $endtime - $starttime;
- $days = intval($timediff / 86400);
- return $days;
- }
- }
Add Comment
Please, Sign In to add comment