Example #1
0
 /**
  * [queryDataAction query data by use ajax get data follow flag]
  * @param  [integer] $dataid [data id]
  * @param  [integer] $cond_id [condtion id]
  * @param  [string] $flag   [to specific data is own agency or all agency]
  * @param  [integer] $agencyid [agenc id]
  * @return [array]         [collection of data]
  */
 public function queryDataAction($dataid, $cond_id, $flag, $agencyid = "")
 {
     $data_name = Data::find($dataid)->data_name;
     $qData = new QueryData();
     $rsData = $qData->queryDataNHC($this->policy_id, $dataid, $cond_id, $flag, $agencyid);
     if ($rsData) {
         if ($dataid == 11) {
             list($tb_name, $field, $datefield, $tele_id) = explode("-", $rsData['info_querydata']->table_name);
         } else {
             list($tb_name, $field, $datefield) = explode("-", $rsData['info_querydata']->table_name);
         }
         if ($dataid == 6) {
             $teleid = 'dam_id';
         } else {
             $teleid = 'tele_station_id';
         }
     } else {
         $rsData['data'] = null;
         $data_name = null;
         $datefield = null;
         $field = null;
         $teleid = null;
     }
     // var_dump($rsData);exit;
     // return View::make('querydata.ajax_test')
     // 			->with('paginator',$rsData['data']);
     return View::make('querydata.ajax_data')->with('paginator', $rsData['data'])->with('data_name', $data_name)->with('field_date', $datefield)->with('field_value', $field)->with('teleid', $teleid);
 }
Example #2
0
 /**
  * [queryDataNHC query data from view ] Get all data used by request data for download
  * @param  [integet] $requestdata_id   [request data id]
  * @return [array]           [collection of data]
  */
 public static function queryDataNHCAll($requestdata_id)
 {
     $results = RequestData::find($requestdata_id);
     $rs = QueryData::where('data_id', '=', $results->data_id)->where('cond_id', '=', $results->cond_id)->where('agency_code', '=', $results->agency_code)->select('table_name', 'condition', 'period', 'agency_code')->get();
     $result_query = $rs[0];
     if ($results->agency_code == '02005') {
         list($tb_name, $field, $datefield, $tele_id) = explode("-", $result_query->table_name);
         Config::get('nhc/site.debug_db') ? $date = Config::get('nhc/site.debug.' . $datefield) : ($date = DB::raw($result_query->condition));
         $nhc_data = DB::connection('nhc_data')->table($tb_name)->where('tele_station_id', '=', $tele_id)->where('agency_id', '=', $results->agency_code)->where(DB::raw($datefield . '::date'), '=', $date)->where(DB::raw($datefield . '::date'), '<=', $result_query->period)->orderBy($field, 'DESC')->select('*')->take(100)->get();
     } else {
         list($tb_name, $field, $datefield) = explode("-", $result_query->table_name);
         Config::get('nhc/site.debug_db') ? $date = Config::get('nhc/site.debug.' . $datefield) : ($date = DB::raw($result_query->condition));
         //echo $date;
         $nhc_data = DB::connection('nhc_data')->table($tb_name)->where('agency_id', '=', $results->agency_code)->where(DB::raw($datefield . '::date'), '=', $date)->where(DB::raw($datefield . '::date'), '<=', $result_query->period)->orderBy($field, 'DESC')->select('*')->take(100)->get();
         //->get();
     }
     return $nhc_data;
 }
 /**
  * [resultRequestDownload description]
  * @param  [type] $req_id [description]
  * @return [type]         [description]
  */
 public function resultRequestDownload($req_id)
 {
     $download_paht = Config::get('nhc/site.download_paht');
     // /Library/WebServer/Documents/lv_nhc/sites/app/downlad/
     $data = QueryData::queryDataNHCAll($req_id);
     $req_info = RequestData::find($req_id);
     $filename = Carbon::createFromTimeStamp(strtotime($req_info['updated_at']))->format('Y_m_d');
     $path = $download_paht . $req_info['agency_code'];
     $full_path_file = $path . '/' . $req_info['agency_code'] . '_' . $filename . '.csv';
     if (!file_exists($full_path_file)) {
         system('mkdir -p ' . $path);
         //echo $path;exit; //
     }
     if (file_exists($full_path_file)) {
         //$full_path_file = $path.'/'.$req_info['agency_code'].'_'.$filename.'.csv';
         $req_info->downloaded = true;
         $req_info->save();
         return Response::download($full_path_file, $req_info['agency_code'] . '_' . $filename . '.csv', array('content-type' => 'text/csv'));
     } else {
         $file = fopen($full_path_file, 'w');
         foreach ($data as $row) {
             fputcsv($file, (array) $row);
         }
         fclose($file);
         $req_info->downloaded = true;
         $req_info->save();
         return Response::download($full_path_file, $req_info['agency_code'] . '_' . $filename . '.csv', array('content-type' => 'text/csv'));
     }
 }