function getDashboardHQ() { $flight_dates = FlightDateBaseModel::with('flight.campaign')->where("start", "<=", date("Y-m-d"))->Where("end", ">=", date("Y-m-d"))->orderBy("flight_id", "DESC")->get(); $data["data"] = array(); $campaignIds = null; $flightIds = null; $adIds = null; foreach ($flight_dates as $flight_date) { $flight = $flight_date->flight; $campagin = $flight->campaign; $campaignIds[] = $flight->campaign->id; $flightIds[] = $flight->id; $adIds[] = $flight->ad_id; $flight->daily_inventory = $flight_date->daily_inventory; if ($flight->cost_type == 'cpm') { $flight->daily_inventory = $flight_date->daily_inventory * 1000; } $data["datas"][$campagin->name][$flight->id] = $flight; } $dailyInventories = FlightBaseModel::getDailyInventories($campaignIds, $flightIds, $adIds); $totalInventories = TrackingSummaryBaseModel::getFlightSummaryByIDs($flightIds); //var_dump($totalInventories); die(); $data['dailyInventories'] = $dailyInventories; $data['totalInventories'] = $totalInventories; return View::make('dashboard_hq', $data); }
function flightdatedelete() { if (Request::ajax()) { $id = $_POST['fid']; $item = FlightDateBaseModel::find($id); if ($item) { $flight = FlightBaseModel::find($item->flight_id); $flight->day = $flight->day - $item->diff; $flight->save(); (new Delivery())->renewCache('flight', $item->flight_id); $item->delete(); (new Delivery())->renewCache('flight_date', $item->flight_id); } } }
/** * check inventory limit of requested flight */ public function checkInventory($flight, $flightWebsite, $event, $dateRange) { $RawTrackingSummarry = new RawTrackingSummary(); $rate = $flight->cost_type == 'cpm' ? 1000 : 1; $flightWebsiteInventory = !empty($flightWebsite) ? $flightWebsite->total_inventory * $rate : 0; $flightInventory = $flight->total_inventory * $rate; if ($flightWebsiteInventory > 0) { // tổng số inventory của flightWebsite (all time) $totalAdZoneInventory = $RawTrackingSummarry->getTotalAdZoneInventory($flight->id, $flightWebsite->id, $event); if ($totalAdZoneInventory >= $flightWebsiteInventory) { return self::RESPONSE_TYPE_AD_ZONE_INVENTORY_LIMIT; } } // tổng số inventory của flight (all time) $flightInventoryAllTime = $RawTrackingSummarry->getTotalInventory($flight->id, $event); if ($flightInventoryAllTime >= $flightInventory) { return self::RESPONSE_TYPE_INVENTORY_LIMIT; } if ($flight->is_fix_inventory == 1 && $flight->day) { $flightInventoryPerDay = ceil($flightInventory / $flight->day); $flightInventoryThisTime = 0; $inventory = FlightBaseModel::getCurrentDayRun($dateRange, $flightInventoryPerDay); $flightInventoryThisTime = $inventory['inventory_current'] * $rate; $flightInventoryInDay = $RawTrackingSummarry->getTotalInventoryInDay($flight->id, $event); $flightInventoryAllTimeExp = ($inventory['inventory_exp'] + $inventory['inventory_current']) * $rate; if ($flightInventoryAllTime >= $flightInventoryAllTimeExp && $flightInventoryInDay >= $flightInventoryThisTime) { return self::RESPONSE_TYPE_AD_ZONE_DAILY_INVENTORY_LIMIT; } } return true; }
/** * handle form add/update agency * @param integer $id */ function postUpdate($id = 0) { // check validate $validate = Validator::make(Input::all(), $this->model->getUpdateRules(), $this->model->getUpdateLangs()); if ($validate->passes()) { $campaignName = Input::get('campaign'); $adFormatID = Input::get('ad_format_id'); $adFormat = AdFormatBaseModel::find($adFormatID); if ('HTML' == $adFormat->name && 'video' == Input::get('ad_type')) { $campaign_id = Input::get('campaign_id'); $name = Input::get('name'); if (!isset($_FILES['vast_file']) || empty($_FILES['vast_file']['name'])) { if (!empty($campaign_id) && !empty($name)) { $file_name = str_replace(' ', '_', strtolower($name)) . '.xml'; $url = "http://static.yomedia.vn/xml/{$campaign_id}/{$file_name}"; $file_headers = @get_headers($url); if ($file_headers[0] == 'HTTP/1.1 404 Not Found') { Session::flash('flash-message', "Vast file is required"); return FALSE; } } } else { $file = $_FILES['vast_file']; if (isset($file['name']) && $file['name'] != "") { $ftp = new MyFTP(); $type = substr($file['name'], strrpos($file['name'], '.'), strlen($file['name'])); if ('.xml' != $type) { Session::flash('flash-message', "Extension of vast file error"); return FALSE; } $file_name = str_replace(' ', '_', strtolower(Input::get('name'))) . '.xml'; $dirUpload = "xml/{$campaign_id}/"; if (!$ftp->uploadFtp($dirUpload, $file['tmp_name'], $file_name)) { Session::flash('flash-message', "Upload file error"); return FALSE; } } } } $updateData = array('campaign_id' => Input::get('campaign_id'), 'name' => Input::get('name'), 'ad_format_id' => $adFormatID, 'ad_type' => Input::get('ad_type'), 'width' => Input::get('width'), 'height' => Input::get('height'), 'width_2' => Input::get('width_2'), 'height_2' => Input::get('height_2'), 'width_after' => Input::get('width_after'), 'height_after' => Input::get('height_after'), 'source_url' => Input::get('source_url'), 'source_url2' => Input::get('source_url2'), 'destination_url' => Input::get('destination_url'), 'flash_wmode' => Input::get('flash_wmode', 'none'), 'video_duration' => Input::get('video_duration'), 'video_linear' => Input::get('video_linear'), 'video_type_vast' => Input::get('video_type_vast'), 'video_wrapper_tag' => Input::get('video_wrapper_tag'), 'third_impression_track' => Input::get('third_impression_track'), 'third_click_track' => Input::get('third_click_track'), 'video_bitrate' => Input::get('video_bitrate'), 'third_party_tracking' => Input::get('tracking') == "" ? "" : json_encode(Input::get('tracking')), 'main_source' => Input::get('main_source'), 'updated_by' => $this->user->id, 'platform' => json_encode(Input::get('platform')), 'ad_view_type' => Input::get('ad_view_type'), 'source_url_backup' => Input::get('source_url_backup'), 'html_source' => Input::get('html_source'), 'skipads' => Input::get('skipads'), 'display_type' => Input::get('display_type'), 'bar_height' => Input::get('bar_height'), 'vast_include' => Input::get('vast_include', 0), 'audience_id' => Input::get('audience_id', 0), 'position' => Input::get('position')); if (!$updateData['ad_view_type']) { if ($adFormat->ad_view) { $updateData['ad_view'] = $adFormat->ad_view; } else { $updateData['ad_view'] = ''; } } else { $updateData['ad_view'] = Input::get('ad_view'); } // Upload FILE FTP if (isset($_FILES['file_source_url'])) { $file = $_FILES['file_source_url']; if (isset($file['name']) && $file['name'] != "") { $ftp = new MyFTP(); $file_name = time() . $file['name']; if (!$ftp->uploadFtp("", $file['tmp_name'], $file_name)) { Session::flash('flash-message', "Extension file error"); return FALSE; } $updateData['source_url'] = STATIC_URL . date("Y") . "/" . date("m") . "/" . $file_name; } } // Upload FILE FTP if (isset($_FILES['file_source_url_2'])) { $file = $_FILES['file_source_url_2']; if (isset($file['name']) && $file['name'] != "") { $ftp = new MyFTP(); $type = substr($file['name'], strrpos($file['name'], '.'), strlen($file['name'])); $file_name = time() . $file['name']; $ftp->uploadFtp("", $file['tmp_name'], $file_name); if (!$ftp->uploadFtp("", $file['tmp_name'], $file_name)) { Session::flash('flash-message', "Extension file error"); return FALSE; } $updateData['source_url2'] = STATIC_URL . date("Y") . "/" . date("m") . "/" . $file_name; } } // Upload FILE BACKUP if (isset($_FILES['file_source_backup_url'])) { $file = $_FILES['file_source_backup_url']; if (isset($file['name']) && $file['name'] != "") { $ftp = new MyFTP(); $type = substr($file['name'], strrpos($file['name'], '.'), strlen($file['name'])); $file_name = time() . $file['name']; if (!$ftp->uploadFtp("", $file['tmp_name'], $file_name)) { Session::flash('flash-message', "Extension file error"); return FALSE; } $updateData['source_url_backup'] = STATIC_URL . date("Y") . "/" . date("m") . "/" . $file_name; } } $mime = ''; if ($updateData['ad_type'] == 'html') { $mime = 'text/html'; } else { if (!empty($updateData['source_url'])) { $ch = curl_init($updateData['source_url']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_exec($ch); $mime = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); } } $updateData['mime'] = $mime; // if (!empty($campaignName) || !empty($adFormatName)) { // $updateData['name'] = $campaignName . ' ' . $adFormatName; // } if ($id == 0) { // INSERT $updateData['created_by'] = $this->user->id; if ($item = $this->model->create($updateData)) { $this->data['id'] = $item->id; (new Delivery())->renewCache('ad', $item->id); Session::flash('flash-message', 'Create Ad Success!'); return TRUE; } } else { // UPDATE // GET CURRENT ITEM $item = $this->model->find($id); if ($item) { if ($this->model->where("id", $id)->update($updateData)) { //update audience id $this->audience->updateCampaign($id, Input::get('campaign_id')); $flights = FlightBaseModel::where('ad_id', $item->id)->get(); if ($flights) { foreach ($flights as $flight) { (new Delivery())->removeCache('flight', $flight->id); $flight->ad_format_id = $updateData['ad_format_id']; if ($flight->save()) { (new Delivery())->renewCache('flight', $flight->id); } } } (new Delivery())->renewCache('ad', $id); Session::flash('flash-message', 'Update Ad Success!'); return TRUE; } } } } else { $this->data['errors'] = $validate->messages(); } return FALSE; }
public function getFlights() { $campaign_ids = Input::get('campaigns', array()); $flights = FlightBaseModel::whereIn('campaign_id', $campaign_ids)->orderBy('name')->lists('name', 'id'); return Response::json($flights); }
public function reportExport() { $this->layout = null; $input = Input::all(); if (!empty($input['option'])) { $options = $input['option']; $campaignId = $input['campaignId']; $flightModel = new FlightBaseModel(); $campaignModel = new CampaignBaseModel(); $trackingSummaryModel = new TrackingSummaryBaseModel(); $campaign = $campaignModel->getCampaignById($campaignId); if (!empty($campaign)) { $range = $campaign->getListFlightId(); $listFlight = $flightModel->getByRangeId($range); $excel = Excel::create($campaign->name); if (in_array("campaign", $options)) { $campaignTracking = $trackingSummaryModel->getCampaignTracking($range); $excel = $this->reportExportCampaign($excel, array('campaign' => $campaign, 'campaignTracking' => $campaignTracking, 'filter' => $input)); } if (in_array("flight", $options)) { $listFlightTracking = $trackingSummaryModel->getListFlightTracking($range); $excel = $this->reportExportFlight($excel, array('campaign' => $campaign, 'listFlight' => $listFlight, 'listFlightTracking' => $listFlightTracking, 'filter' => $input)); } if (in_array("website", $options)) { $listWebsiteTracking = $trackingSummaryModel->getListWebsiteTracking($range); $excel = $this->reportExportWebsite($excel, array('campaign' => $campaign, 'listFlight' => $listFlight, 'listWebsiteTracking' => $listWebsiteTracking)); } $excel->export('xls'); } else { return Redirect::to($this->moduleURL . 'show-list'); } } }
public function showPreview($fwid = 0, $id = 0) { if ($fwid != 0 && $id != 0) { $item = FlightBaseModel::with('ad', 'flightWebsite')->find($id); $flightWebsite = FlightWebsiteBaseModel::find($fwid); $isActive = isset($flightWebsite->status) ? $flightWebsite->status : 0; if ($item) { $data = $item; switch ($item->ad_format_id) { case '8': $view = View::make('previewVideo', compact('data', 'isActive')); break; case '9': $view = ''; break; case '12': $view = View::make('previewBalloon', compact('data', 'isActive')); break; case '14': $view = ''; break; case '16': $view = View::make('previewImage', compact('data', 'isActive')); break; default: $view = ''; break; } return $view; } } }