示例#1
0
 public function saveSegmentMap($dataaccount)
 {
     /* $deleteIds = Word::where('dataaccount', $dataaccount)->get( array('id') );
     			$notDeleteIds = []; $tmp = [];
     		*/
     //return Response::json( count(Input::get('idsToBeDeleted')) );
     if (count(Input::get('idsToBeDeleted')) > 0) {
         Keyword::destroy(Input::get('idsToBeDeleted'));
         // refresh wordcloud only if some keyword is deleted
         Word::where('dataaccount', $dataaccount)->delete();
         Word::createWordCloud($dataaccount);
     }
     foreach (Input::get('segmentMap') as $k => $word) {
         Word::where('dataaccount', $dataaccount)->where('word', $word['word'])->update(array('segment' => $word['segment'], 'brand' => $word['brand'], 'compete' => $word['compete'], 'negativeword' => $word['negativeword'], 'stopword' => $word['stopword']));
         //	'numword'=>$word['numword'],
         //	'dataaccount'=>$word['dataaccount']) );
         //$notDeleteIds[] = $word['id'];
         //Word::find( $word['id'] )->update($word);
     }
     /*
     foreach($deleteIds as $k=>$v)
     {
     	if(in_array($v['id'], $notDeleteIds)) $tmp[] = $v['id'];
     }
     return $tmp; 
     */
     return Response::json(array('success' => true));
     /*
     //return Response::json( count(Input::get('toBeDeleted')) );
     	if( count(Input::get('toBeDeleted')) > 0 ) Keyword::destroy(Input::get('toBeDeleted'));
     	
     	$tempId = [];
     	$tempSeg = [];
     	
     	//return Response::json( count(Input::get('segmentMap')) );
     	
     	if( count(Input::has('segmentMap')) > 0)
     	{ 
     		foreach(Input::get('segmentMap') as $key => $val)
     		{
     			$tempId[] = $val['id'];
     			$tempSeg[] = $val['segment'];
     			Keyword::find($val['id'])->update( array('usersegment' => $val['segment']) );
     		}
     	}
     	//Keyword::find($tempId)->update( array('usersegment' => $tempSeg) )->save();
     	return Response::json( Keyword::find($tempId) );
     	//return Response::json( array('success' => true) );
     	//return Response::json( Input::get('segmentMap') );
     */
 }
 public function uploadCSV()
 {
     //return public_path();
     $dataAccount = DataAccount::create(array('dataaccount' => Input::get('newdataaccount'), 'user_id' => Input::get('user_id')));
     $dataaccount = $dataAccount->id;
     //return Input::get('newdataaccount');
     if (Input::hasFile('file')) {
         $file = Input::file('file');
         $name = time() . '-' . $file->getClientOriginalName();
         //check out the edit content on bottom of my answer for details on $storage
         //$storage = public_path().'/../app/storage';
         $storage = public_path();
         $path = $storage . '/uploads/CSV/';
         // Moves file to folder on server
         $file->move($path, $name);
         // Import the moved file to DB and return OK if there were rows affected
         $this->_import_csv($path, $name, $dataaccount);
         //? 'OK' : 'No rows affected' );
         // After upload create word cloud
         return Response::json(Word::createWordCloud($dataaccount));
         return 'OK';
         //? 'OK' : 'No rows affected' );
     }
     //return Response::json( Input::file('file')->getClientOriginalName() );
 }