public function getApps()
 {
     if ($this->apps == null) {
         $this->apps = HouseAdUtil::getAppsByCid($this->id);
     }
     return $this->apps;
 }
 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');
 }
 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;
 }
 public function getHouseAds()
 {
     if ($this->houseAds == null) {
         $this->houseAds = HouseAdUtil::getHouseAdsByAid($this->id);
     }
     return $this->houseAds;
 }
 public function canDelete()
 {
     $this->printHeader = false;
     $this->printFooter = false;
     $del_cids = isset($_REQUEST['deletes']) ? $_REQUEST['deletes'] : null;
     $hasApps = array();
     fb('del_cids', $del_cids);
     foreach ($del_cids as $del_cid) {
         $apps = HouseAdUtil::getAppsByCid($del_cid);
         $count = count($apps);
         if ($count > 0) {
             $hasApps[] = $del_cid;
         }
     }
     if (count($hasApps) == 0) {
         return 'OK';
     } else {
         return implode(",", $hasApps);
     }
 }