コード例 #1
0
 public function removeLogo(Request $request)
 {
     if ($request->imageName) {
         $logo = Logo::where('thumb', $request->imageName)->firstOrFail();
         $logoPath = 'build/images/logos/';
         $logoName = $logo->image;
         $logoThumb = $logo->thumb;
         Storage::disk('public')->delete($logoPath . $logoName);
         Storage::disk('public')->delete($logoPath . $logoThumb);
         $logo->delete();
         return 'ok';
     } else {
         return 'failed';
     }
 }
コード例 #2
0
 public static function getConfigWithUrl($chart)
 {
     $config = json_decode($chart->config);
     $config->id = $chart->id;
     $config->{"chart-notes"} = $chart->notes;
     $config->{"chart-slug"} = $chart->slug;
     $config->{"data-entry-url"} = $chart->origin_url;
     // Allow url parameters to override the chart's default
     // selected countries configuration. We need to use the raw
     // query string for this because we want to distinguish between
     // %20 and +.
     preg_match("/country=([^&]+)/", $_SERVER['QUERY_STRING'], $matches);
     if ($matches) {
         $countryCodes = array_map(function ($code) {
             return urldecode($code);
         }, explode("+", $matches[1]));
         $query = DB::table('entities')->select('id', 'name')->whereIn('code', $countryCodes)->orWhere(function ($query) use($countryCodes) {
             $query->whereIn('name', $countryCodes);
         });
         $config->{"selected-countries"} = $query->get();
     }
     // Remove any invalid variables from the chart config
     $dims = json_decode($config->{"chart-dimensions"});
     $varIds = array_map(function ($d) {
         return $d->variableId;
     }, $dims);
     $existingIds = DB::table("variables")->select('id')->whereIn('id', $varIds)->lists('name', 'id');
     if (sizeof($existingIds) != sizeof($varIds)) {
         $config->{"chart-dimensions"} = "[]";
         $config->{"form-config"}->{"variables-collection"} = [];
     }
     //possibly there could logo query parameter
     if (!empty($config) && !empty(Input::get('logo'))) {
         //there's logo query parameter, we want to display chart with different logo
         //find logo by name
         $logo = Logo::where('name', '=', Input::get('logo'))->first();
         if (!empty($logo)) {
             //set logo in config with logo from query parameter
             $config->{"second-logo"} = $logo->url;
         }
     }
     return $config;
 }
コード例 #3
0
 /**
  * @param Request $request
  */
 public function profile_logo(Request $request)
 {
     $travel_company = Auth::travel_company_staff()->get()->travel_company;
     $destinationPath = null;
     if (App::environment() == 'local') {
         $destinationPath = base_path() . '/public/images/';
     } elseif (App::environment() == 'production') {
         $destinationPath = '/home/twokays/public_html/images/';
     }
     if ($request->file('file')->isValid()) {
         $file = $request->file('file');
         $ext = $file->getClientOriginalExtension();
         $destinationPath = $destinationPath;
         $fileName = str_slug($travel_company->name) . '_logo.' . $ext;
         $full_path = '/images/' . $fileName;
         $file->move($destinationPath, $fileName);
         // uploading file to given path
         $tcl = Logo::where('travel_company_id', $travel_company->id)->first();
         if (!$tcl) {
             Logo::create(['path' => $full_path, 'travel_company_id' => $travel_company->id]);
         } else {
             $tcl->update(['path' => $full_path]);
         }
         return $full_path;
     }
 }