public function countTotal() { $ads = Ad_Web::all(); $iterator = 0; foreach ($ads as $ad) { $iterator += count(glob(base_path('myFiles/' . $ad->id . '/*.txt'), GLOB_BRACE)); } return $iterator; }
function borrar() { $ads = Ad_Web::all(); foreach ($ads as $ad) { $iterator = count(glob(base_path('myFiles/' . $ad->id . '/*.txt'), GLOB_BRACE)); $ad = Ad_Web::find($ad->id); //$fecha = date('Y-m-d',strtotime(Carbon::today())); $reporte = new Report(); $reporte->ad_web_id = $ad->id; $reporte->impresiones = $iterator; $reporte->fecha = Carbon::today()->subDay(1)->addMinutes(1); $reporte->save(); $ad->created_at = Carbon::tomorrow(); $ad->save(); $files = glob(base_path('myFiles/' . $ad->id . '/*.txt')); // get all file names foreach ($files as $file) { // iterate files if (is_file($file)) { unlink($file); } // delete file } } }
/** * Display a listing of the resource. * * @return Response */ public function index() { $startDate = new \DateTime(Carbon::parse(Carbon::today()->subDay())); $endDate = new \DateTime(Carbon::parse(Carbon::today()->subMinutes(1))); $metrics = 'ga:pageviews,ga:totalEvents'; //$analytics = \LaravelAnalytics::performQuery($startDate, $endDate, $metrics, $others = array( 'dimensions' => 'ga:country')); //$analytics = \LaravelAnalytics::getMostVisitedPages($numberOfDays = 1, $maxResults = 20); $analytics = \LaravelAnalytics::performQuery($startDate, $endDate, $metrics, $others = array("dimensions" => "ga:pagePath", "sort" => "-ga:pageviews")); $ads = Ad_Web::all(); $pila = array(); $ids = array(); $a = 0; for ($x = 0; $x < count($analytics["rows"]); $x++) { $comma_separated = implode("/", $analytics['rows'][$x]); $pieces = explode("/", $comma_separated); //primer error si no existe el imp osea esta / o advertiserw foreach ($ads as $ad) { if ($a == 0) { array_push($ids, $ad->id); } if (empty($pieces[1])) { } else { if ($pieces[2] == $ad->id) { array_push($pila, $ad->id); // echo "id = $pieces[2]"." Impresiones = $pieces[3]<br/ >"; $reporte = new Report(); $reporte->ad_web_id = $ad->id; if (empty($pieces[3])) { $reporte->impresiones = 0; $reporte->ctr = 0; $reporte->click = 0; } else { $reporte->impresiones = $pieces[3]; $reporte->ctr = $pieces[4] / $pieces[3]; $reporte->click = $pieces[4]; } $reporte->fecha = Carbon::today()->subDay(1)->addMinutes(1); $reporte->save(); $ad->created_at = Carbon::tomorrow(); $ad->save(); } } } $a++; } $result = array_diff($ids, $pila); foreach ($result as $r) { $ad = Ad_Web::find($r); $reporte = new Report(); $reporte->ad_web_id = $ad->id; $reporte->impresiones = 0; $reporte->click = 0; $reporte->ctr = 0; $reporte->fecha = Carbon::today()->subDay(1)->addMinutes(1); $reporte->save(); $ad->created_at = Carbon::tomorrow(); $ad->save(); } /* $pieces = array(); foreach ($analytics['rows'] as $row){ $pieces = array_merge(explode("/imp/",$row[0]),$pieces); } for($x = 0 ; $x < count($pieces); $x++){ foreach($ads as $ad){ if($ad->id == $pieces[$x]){ echo $pieces[$x]."<br/>"; } } }*/ }