public function addAllWebsite()
 {
     $status = TRUE;
     $view = NULL;
     $flightId = Input::get('flightId');
     $flightData = FlightBaseModel::find($flightId);
     // get all website
     $listWebsite = PublisherSiteBaseModel::where('status', 1)->lists('id');
     if (!empty($listWebsite)) {
         foreach ($listWebsite as $websiteId) {
             // check flightWebsite exist
             $exist = FlightWebsiteBaseModel::where(array('flight_id' => $flightId, 'website_id' => $websiteId))->first();
             if (empty($exist)) {
                 $item = new FlightWebsiteBaseModel();
                 $item->flight_id = $flightId;
                 $item->website_id = $websiteId;
                 $item->type = 'adnetwork';
                 $item->created_by = $this->user->id;
                 $item->updated_by = $this->user->id;
                 $item->status = 1;
                 $item->save();
                 (new Delivery())->renewCache('flight_website', $item->id);
             }
         }
     }
     $this->data['flightWebsiteList'] = $flightData->flightWebsite;
     $this->data['totalInventory'] = $flightData->total_inventory;
     $view = View::make('websiteList', $this->data)->render();
     return Response::json(array('status' => $status, 'view' => $view));
 }
 public function showPublisher()
 {
     $start_date = Input::get('start_date') ? date("Y-m-d", strtotime(Input::get('start_date'))) : date('Y-m-d');
     $end_date = Input::get('end_date') ? date("Y-m-d", strtotime(Input::get('end_date'))) : date('Y-m-d');
     $website = Input::get('website');
     $adformat = Input::get('adformat');
     $this->data['lists_website'] = PublisherSiteBaseModel::where("status", '=', 1)->get();
     $this->data['lists_adfortmat'] = AdFormatBaseModel::get();
     $tracking = DB::connection('mongodb')->collection('trackings_summary')->where("created_d", '>=', $start_date)->where("created_d", '<=', $end_date);
     if ($website != "") {
         $tracking = $tracking->where('w', '=', (int) $website);
     }
     if ($adformat != "") {
         $tracking = $tracking->where('af', '=', (int) $adformat);
     }
     $tracking = $tracking->get();
     $list_site = array();
     $list_zone = array();
     $data_ok = array();
     if (!empty($tracking)) {
         foreach ($tracking as $tract) {
             if (isset($tract['ads_request'])) {
                 if (!isset($list_site[$tract['w']])) {
                     $site = PublisherSiteBaseModel::find($tract['w']);
                     if ($site) {
                         $list_site[$tract['w']] = $site;
                     } else {
                         continue;
                     }
                 }
                 if (!isset($list_zone[$tract['az']])) {
                     $adzone = PublisherAdZoneBaseModel::find($tract['az']);
                     if ($adzone) {
                         $list_zone[$tract['az']] = $adzone;
                     } else {
                         continue;
                     }
                 }
                 if (isset($tract['f'])) {
                     $data_ok[$tract['w']][$tract['az']]['ads'][] = $tract['ads_request'];
                 } else {
                     $data_ok[$tract['w']][$tract['az']]['noads'][] = $tract['ads_request'];
                 }
             }
         }
     }
     $this->data['list_zone'] = $list_zone;
     $this->data['list_site'] = $list_site;
     $this->data['data_ok'] = $data_ok;
     $this->data['start_date'] = date("m/d/Y", strtotime($start_date));
     $this->data['end_date'] = date("m/d/Y", strtotime($end_date));
     $this->data['website'] = $website;
     $this->data['adformat'] = $adformat;
     $this->layout->content = View::make('publisher', $this->data);
 }
 public function getListPublisherSite($keyword, $parent, $id)
 {
     $model = new PublisherSiteBaseModel();
     if ($id > 0) {
         $this->data['listPublisherSite'] = $model->where('id', $id)->get();
     } else {
         $this->data['listPublisherSite'] = $model->searchByCapital($keyword, $parent);
     }
     return View::make('listPublisherSite', $this->data)->render();
 }