/** * Store a newly created resource in storage. * * @return Response */ public function store() { $url = new LandingPageUrl(array('landingpageurl' => Input::get('landingpageurl'))); $dataaccount = DataAccount::find(Input::get('dataaccount')); $url->dataAccount()->associate($dataaccount); return Response::json($url->save()); }
public function refreshPhrases($dataaccountid) { //$result = DB::statement(" call keyword_count( 1 ) " ); /* $result = DB::statement(" call keyword_count( '". $dataaccountid ."', 2 ) " ); return " call keyword_count( '". $dataaccountid ."', 2 ) "; return ( array('success' => true) ); */ $startTime = microtime(true); $keywords = Keyword::where('dataAccount', $dataaccountid)->get(); $wordCloud = Word::where('dataAccount', $dataaccountid)->get(); $landingPageIds = DataAccount::find($dataaccountid)->landingPageUrls()->get(); // Laravel's magic $landingPageWordCloud = []; foreach ($landingPageIds as $lp) { $landingPageWordCloud[$lp->landingpageurl] = DB::table('landingpagewordcloud')->where('landing_page_urls_id', $lp->id)->orderBy('freq', 'DESC')->get(array('word', 'freq')); } //return $landingPageWordCloud; $insertData = []; DB::table('keywords_segment')->truncate(); foreach ($keywords as $keyword) { $seg = ''; $brand = 0; $compete = 0; foreach ($wordCloud as $word) { //if(strpos($keyword['keyword'], $word['word']) !== false) // found word (cloud) found in keyword if (preg_match("/\\b" . $word['word'] . "\\b/", $keyword['keyword']) === 1) { //$seg .= $word['segment'] . ','; if ($word['segment'] != '' && $word['segment'] != null && $word['segment'] != ' ') { $seg .= $word['segment'] . ','; } $brand = $brand || $word['brand']; $compete = $compete || $word['compete']; } } if ($seg != '') { $seg = substr($seg, 0, -1); } $seg = array_unique(explode(',', $seg)); // remove duplicates and sort sort($seg); $seg = implode(",", $seg); //return calcLPScore($keyword['keyword'], $landingPageWordCloud); $insertData[] = array('adGroup' => $keyword['adGroup'], 'keyword' => $keyword['keyword'], 'lpscore' => $this->calcLPScore($keyword['keyword'], $landingPageWordCloud), 'currency' => $keyword['currency'], 'avMonthlySearches' => $keyword['avMonthlySearches'], 'competition' => $keyword['competition'], 'suggestedBid' => $keyword['suggestedBid'], 'impressionShare' => $keyword['impressionShare'], 'inAccount' => $keyword['inAccount'], 'inPlan' => $keyword['inPlan'], 'extractedFrom' => $keyword['extractedFrom'], 'segment' => $seg, 'brand' => $brand, 'compete' => $compete, 'dataAccount' => $keyword['dataAccount']); //return $ind . " | " . $keyword['keyword'] . " | " . $word['word'] . " | " . $seg; //return $insertData; } DB::table('keywords_segment')->insert($insertData); //return Response::json( array('success' => true) ); return "Elapsed time is: " . (microtime(true) - $startTime) . " seconds"; return Response::json($insertData); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // Delete the data account and all data associated with it $lp = DataAccount::find($id)->landingPageUrls()->get(); // Laravel's magic foreach ($lp as $v) { DB::table('landingpagewordcloud')->where('landing_page_urls_id', $v->id)->delete(); } DataAccount::find($id)->landingPageUrls()->delete(); DataAccount::destroy($id); Keyword::where('dataAccount', $id)->delete(); Stopword::where('dataAccount', $id)->delete(); Negativekeyword::where('dataAccount', $id)->delete(); DB::table('keywords_segment')->where('dataAccount', $id)->delete(); DB::table('segmentmap')->where('dataAccount', $id)->delete(); DB::table('wordcloud')->where('dataAccount', $id)->delete(); //DB::statement( 'drop database data_' . $id ); return Response::json(array('success' => true)); }