private function getTableData()
 {
     $houseAds = HouseAdUtil::getHouseAdsByUid($this->user->id);
     foreach ($houseAds as $houseAd) {
         $houseAd->reports = ReportUtil::getReportsByCid($houseAd->id, $this->startDate, $this->endDate);
         $totals = array();
         if (isset($houseAd->reports)) {
             foreach ($houseAd->reports as $report) {
                 if (isset($totals['impressions'])) {
                     $totals['impressions'] += $report['impressions'];
                     $totals['clicks'] += $report['clicks'];
                 } else {
                     $totals['impressions'] = $report['impressions'];
                     $totals['clicks'] = $report['clicks'];
                 }
             }
         }
         if (isset($totals['clicks'])) {
             $totals['ctr'] = sprintf("%.3f", $totals['clicks'] / $totals['impressions']);
         } else {
             $totals = array('ctr' => 'N/A', 'clicks' => '0', 'impressions' => '0');
         }
         $houseAd->totals = $totals;
     }
     return $houseAds;
 }
 public function appHouseAds()
 {
     $this->needsApp();
     $this->breadcrumbs[] = array("text" => "House Ads", "link" => "/apps/oneApp/appHouseAds");
     $appHouseAds = array();
     foreach (AppHouseAdUtil::getAppHouseAdsByAid($this->app->id) as $appHouseAd) {
         $appHouseAds[$appHouseAd->cid] = $appHouseAd;
     }
     $houseAds = array();
     fb("getAllHouseAds", "");
     $allHouseAds = HouseAdUtil::getHouseAdsByUid($this->user->id);
     // fb("houseAds",HouseAdUtil::getHouseAdsByAid($this->app->id));
     fb("gotAllHouseAdsForThisUser", "");
     $houseAdsForThisApp = HouseAdUtil::getHouseAdsByAid($this->app->id, $allHouseAds);
     fb("getAllHouseAdsForThisApp", "");
     foreach ($houseAdsForThisApp as $houseAd) {
         if (array_key_exists($houseAd->id, $appHouseAds)) {
             $houseAds[] = $houseAd;
             $houseAd->weight = $appHouseAds[$houseAd->id]->weight;
             $houseAd->ahid = $appHouseAds[$houseAd->id]->id;
         }
     }
     fb("prepAddableHouseAds", "");
     $addableHouseAds = array('' => 'Choose an Ad');
     foreach ($allHouseAds as $houseAd) {
         if (!array_key_exists($houseAd->id, $appHouseAds)) {
             if ($this->app->platform == '1' && $houseAd->isForiPhone() || $this->app->platform == '2' && $houseAd->isForAndroid()) {
                 $addableHouseAds[$houseAd->id] = $houseAd->name;
             }
         }
     }
     fb("doneAddableHouseAds", $addableHouseAds);
     $networks = $this->app->getNetworks();
     if (array_key_exists('9', $networks) && $networks['9']->adsOn == 1) {
         $this->smarty->assign('houseAdShare', $networks['9']->weight);
     }
     usort($houseAds, create_function('$a,$b', "return strcasecmp(\$a->name, \$b->name);"));
     $this->subtitle = "House Ads";
     $this->smarty->assign('app', $this->app);
     $this->smarty->assign('sideNav_current', 'houseAds');
     $this->smarty->assign('linkLabels', HouseAd::$HOUSEAD_LINKTYPES);
     $this->smarty->assign('houseAds', $houseAds);
     $this->smarty->assign('addableHouseAds', $addableHouseAds);
     $this->smarty->assign('houseAdTypes', HouseAd::$HOUSEAD_TYPES);
     fb("smarty", $this->smarty->get_template_vars());
     return $this->smarty->fetch('../tpl/www/apps/appHouseAds.tpl');
 }
Esempio n. 3
0
 private function needsHouseAd()
 {
     $cid = isset($_REQUEST['cid']) ? $_REQUEST['cid'] : null;
     if ($cid === null) {
         $this->redirect('/houseAds/houseAds/');
     }
     $this->houseAd = new HouseAd($cid);
     $this->breadcrumbs[] = array('text' => $this->houseAd->name, 'link' => '/houseAds/ad/edit?cid=' . $this->houseAd->id);
     $this->needSwitcher = true;
     $this->switcherText = 'Switch House Ad';
     $switchList = array();
     $this->subtitle = $this->houseAd->name;
     foreach (HouseAdUtil::getHouseAdsByUid($this->user->id) as $houseAd) {
         if ($houseAd->id != $cid) {
             $switchList[] = $houseAd;
         }
     }
     $this->switcherList = $switchList;
 }
Esempio n. 4
0
 public function adjustHouseAdNetwork($add_ahid, $del_ahid)
 {
     $retVal = "doNothing";
     fb("adjusthouseAdNet", "start");
     $networks = $this->getNetworks();
     if ($networks != null) {
         foreach ($networks as $type => $network) {
             if ($type == Network::NETWORK_TYPE_HOUSE) {
                 $houseAdNet = $network;
             }
         }
     }
     $appHouseAds = AppHouseAdUtil::getAppHouseAdsByAid($this->id);
     $count = count($appHouseAds);
     if ($count == 0 && $add_ahid != null) {
         $count++;
     } else {
         if ($count == 1 && $appHouseAds['0']->id == $del_ahid) {
             $count--;
         }
     }
     fb("appHouseAds", $appHouseAds);
     fb($count, 'count');
     fb(isset($houseAdNet), 'hasHouseAdNet');
     if ($count > 0 && !isset($houseAdNet)) {
         // add houseAdNet
         fb("Should Add");
         $network = new Network();
         $network->id = SDB::uuid();
         $network->aid = $this->id;
         $network->type = Network::NETWORK_TYPE_HOUSE;
         $network->adsOn = 0;
         $network->weight = 0;
         $network->priority = 99;
         $network->keys = array("_CUSTOMS_");
         $network->put();
         $retVal = "add";
     } else {
         if ($count == 0 && isset($houseAdNet)) {
             // should remove or turn off
             $hasHouseAds = count(HouseAdUtil::getHouseAdsByUid($_SESSION['uid'])) > 0;
             if ($hasHouseAds) {
                 fb("should turn off");
                 $houseAdNet->adsOn = 0;
                 $houseAdNet->put();
                 $retVal = "turnOff";
             } else {
                 fb("Should Remove", $houseAdNet);
                 $houseAdNet->delete();
                 unset($networks['9']);
                 $retVal = "delete";
             }
             App::setWeights($networks);
             App::setPriorities($networks);
         }
     }
     fb("adjustHouseAdNet", "end");
     return $retVal;
 }
 public function __default()
 {
     $this->user->postGet();
     $a = $this->user->getPref('msg_002');
     if (empty($a)) {
         $msg_002 = "<span class='msg'>Learn about our upgraded <a target='_newtab' href='http://helpcenter.adwhirl.com/content/step-6-allocate-your-house-ads'>House Ads</a> functionality</span>";
         $this->smarty->assign('message', $msg_002);
         $this->smarty->assign('msg_id', 'msg_002');
     }
     $this->smarty->assign('returnPage', isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : null);
     $this->styleSheets[] = "/css/preview.css";
     $this->jsFiles[] = "/js/jqsm135.js";
     $this->displayFinalArrowInBreadcrumbs = true;
     $houseAds = HouseAdUtil::getHouseAdsByUid($_SESSION['uid']);
     $apps = AppUtil::getAppsByUid($this->user->id);
     $o = isset($_REQUEST['o']) ? $_REQUEST['o'] : 0;
     $o = intval($o);
     $haveMissingAd = false;
     // Assume we don't have the missing ad until we scan them all
     if (!empty($_REQUEST['n_cid'])) {
         foreach ($houseAds as $houseAd) {
             // if the current ad has the same id, we know we have the missing ad
             $haveMissingAd |= $houseAd->id == $_REQUEST['n_cid'];
             // Stop if we know we have the missing ad
             if ($haveMissingAd) {
                 break;
             }
         }
     } else {
         $haveMissingAd = true;
         // no new ad id passed in, so all ads should be in the DB
     }
     if (!empty($_REQUEST['del_cid'])) {
         foreach ($houseAds as $idx => $houseAd) {
             if ($houseAd->id == $_REQUEST['del_cid']) {
                 unset($houseAds[$idx]);
             }
         }
     }
     fb('haveMissingAd', $haveMissingAd);
     // Do we have all the ads? If not, let's add the missing one.
     if (!$haveMissingAd) {
         $houseAd = new HouseAd();
         $houseAd->id = $_REQUEST['n_cid'];
         $houseAd->name = $_REQUEST['n_name'];
         $houseAd->type = intval($_REQUEST['n_type']);
         $houseAd->linkType = intval($_REQUEST['n_linkType']);
         $houseAds[] = $houseAd;
         fb("houseAd", $houseAd);
     }
     $fields = array('name', 'linkType', 'type');
     $total = count($houseAds);
     if ($total <= 10) {
         $fields[] = 'numApp';
     }
     $sortBy = isset($_REQUEST['sortBy']) ? $_REQUEST['sortBy'] : 'nameAsc';
     if (substr($sortBy, -1) == '?') {
         $sortBy = substr($sortBy, 0, -1);
     }
     $isAsc = substr($sortBy, -3) == 'Asc';
     $sortBy = substr($sortBy, 0, strlen($sortBy) - 3);
     foreach ($fields as $field) {
         $fname = $field;
         if ($field == $sortBy) {
             $val = $fname . ($isAsc ? 'Dsc' : 'Asc');
         } else {
             $val = isset($_REQUEST[$fname]) ? $_REQUEST[$fname] : $field . 'Asc';
         }
         $this->smarty->assign($fname, $val);
     }
     $itemsPerPage = 10;
     if ($sortBy == 'numApp' && $total <= 10) {
         $fname = 'numApp' . ($isAsc ? 'Asc' : 'Dsc');
         foreach ($houseAds as $houseAd) {
             $houseAd->getApps();
         }
         usort($houseAds, $fname);
     } else {
         if ($sortBy == 'numApp') {
             $sortBy = 'name';
             $isAsc = 'true';
         }
         usort($houseAds, makeSortFunction($sortBy, $isAsc));
         $houseAds = array_slice($houseAds, $o, $itemsPerPage);
         foreach ($houseAds as $houseAd) {
             $houseAd->getApps();
         }
     }
     $this->smarty->assign('appsCount', count($apps));
     $this->smarty->assign('current_offset', $o);
     $this->smarty->assign('total', $total);
     $this->smarty->assign('itemsPerPage', $itemsPerPage);
     $this->subtitle = "House Ads";
     $this->smarty->assign('linkLabels', HouseAd::$HOUSEAD_LINKTYPES);
     fb($houseAds);
     $this->smarty->assign('houseAds', $houseAds);
     $this->smarty->assign('houseAdTypes', HouseAd::$HOUSEAD_TYPES);
     fb("smarty", $this->smarty->get_template_vars());
     return $this->smarty->fetch('../tpl/www/houseAds/houseAds.tpl');
 }
Esempio n. 6
0
 public function getHouseAds()
 {
     if ($this->houseAds == null) {
         $this->houseAds = HouseAdUtil::getHouseAdsByUid($this->id);
     }
     return $this->houseAds;
 }