diff options
| author | horus_arch | 2018-02-17 00:31:33 +0100 |
|---|---|---|
| committer | horus_arch | 2018-02-17 00:31:33 +0100 |
| commit | 13724d7e56299213e9b10eef6f315569127b53f2 (patch) | |
| tree | ba8f74f632a50752db057921848ad612a6c2fdef | |
| parent | 19fa2ecee653c17c15efc02e26b2724757778d48 (diff) | |
| download | alkobote-13724d7e56299213e9b10eef6f315569127b53f2.tar.gz | |
Minor refactoring. (website)
| -rw-r--r-- | site/app/Http/Controllers/FeedController.php | 9 | ||||
| -rw-r--r-- | site/app/Http/Controllers/SearchController.php | 11 | ||||
| -rw-r--r-- | site/app/Libraries/Utility.php | 12 |
3 files changed, 17 insertions, 15 deletions
diff --git a/site/app/Http/Controllers/FeedController.php b/site/app/Http/Controllers/FeedController.php index 77d845a..3fac630 100644 --- a/site/app/Http/Controllers/FeedController.php +++ b/site/app/Http/Controllers/FeedController.php @@ -8,6 +8,7 @@ use App\Http\Controllers\Controller; use Carbon; use Illuminate\Support\Facades\Input; +use App\Libraries\Utility; class FeedController extends Controller { /** @@ -59,7 +60,7 @@ class FeedController extends Controller { $view_name = str_replace("_feed", "", \Request::route()->getName()); if ( "search" == $view_name ) { $query = Input::get("q"); - $q = "%" . $this->escapeLike($query) . "%"; + $q = "%" . Utility::escapeLike($query) . "%"; $data = DB::table('all_view')->where('name', 'like', $q)->orWhere('spirit_type', 'like', $q)->orderBy($sort_by, $order_by)->limit(20)->get(); } else { $data = DB::table($view_name . '_view')->orderBy($sort_by, $order_by)->limit(20)->get(); @@ -124,10 +125,4 @@ class FeedController extends Controller { return $feed->render('atom'); } - - private function escapeLike($string) { - $search = array('%', '_'); - $replace = array('\%', '\_'); - return str_replace($search, $replace, $string); - } } diff --git a/site/app/Http/Controllers/SearchController.php b/site/app/Http/Controllers/SearchController.php index 4a454f8..2587d9b 100644 --- a/site/app/Http/Controllers/SearchController.php +++ b/site/app/Http/Controllers/SearchController.php @@ -8,6 +8,8 @@ use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Input; +use App\Libraries\Utility; + class SearchController extends Controller { /** * Shows the index page. @@ -53,7 +55,7 @@ class SearchController extends Controller { } $query = Input::get("q"); - $q = "%" . $this->escapeLike($query) . "%"; + $q = "%" . Utility::escapeLike($query) . "%"; $data = DB::table('all_view')->where('name', 'like', $q)->orWhere('spirit_type', 'like', $q)->orderBy($sort_by, $order_by)->simplePaginate(20); #$data = DB::table('whisky_view')->orderBy('procent', 'DESC')->limit(100)->simplePaginate(20); #var_dump($data); exit; @@ -72,11 +74,4 @@ class SearchController extends Controller { return view('search', ['data' => $data, 'search_phrase' => $query, 'rss_feed' => '/search/feed/?' . $query_string ]); } - - private function escapeLike($string) { - $search = array('%', '_'); - $replace = array('\%', '\_'); - return str_replace($search, $replace, $string); - } - } diff --git a/site/app/Libraries/Utility.php b/site/app/Libraries/Utility.php new file mode 100644 index 0000000..95a8b80 --- /dev/null +++ b/site/app/Libraries/Utility.php @@ -0,0 +1,12 @@ +<?php +namespace App\Libraries; +use App\Libraries\Utility; + +class Utility { + + public static function escapeLike($string) { + $search = array('%', '_'); + $replace = array('\%', '\_'); + return str_replace($search, $replace, $string); + } +} |
