Skip to content

Commit

Permalink
Fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcage committed Sep 3, 2023
1 parent 77e25b8 commit d8fb4da
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
3 changes: 2 additions & 1 deletion app/Console/Commands/AnonymizeVisitors.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console\Commands;

use App\Models\Visitors\Visitor;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

Expand Down Expand Up @@ -43,7 +44,7 @@ public function handle()
$visitor->id_number = sha1($visitor->id_number);
}
if ($visitor->date_of_birth !== null) {
$visitor->date_of_birth = $visitor->date_of_birth->startOfYear();
$visitor->date_of_birth = (new Carbon($visitor->date_of_birth))->startOfYear();
}
$visitor->anonymized = true;
$visitor->save();
Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/Accounting/API/BudgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Illuminate\Http\Response;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use ZipStream\Option\Archive;
use ZipStream\ZipStream;

class BudgetController extends Controller
Expand Down Expand Up @@ -137,9 +136,7 @@ public function export(Budget $budget, Request $request)
return $export->download($file_name.'.'.$file_ext);
}

$options = new Archive();
$options->setSendHttpHeaders(true);
$zip = new ZipStream($file_name.'.zip', $options);
$zip = new ZipStream(outputName: $file_name.'.zip', sendHttpHeaders: true);
$temp_file = 'temp/'.uniqid().'.'.$file_ext;
$export->store($temp_file);
$zip->addFileFromPath($file_name.'.'.$file_ext, storage_path('app/'.$temp_file));
Expand Down
7 changes: 3 additions & 4 deletions app/Http/Controllers/Accounting/API/SuppliersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\Rule;

class SuppliersController extends Controller
Expand Down Expand Up @@ -74,9 +73,9 @@ private function filterQuery(Builder $query, string $filter): Builder
->orWhere('category', 'LIKE', '%'.$filter.'%')
->orWhere('remarks', 'LIKE', '%'.$filter.'%')
->orWhere('tax_number', $filter)
->orWhere(DB::raw('REPLACE(phone, \' \', \'\')'), str_replace(' ', '', $filter))
->orWhere(DB::raw('REPLACE(mobile, \' \', \'\')'), str_replace(' ', '', $filter))
->orWhere(DB::raw('REPLACE(iban, \' \', \'\')'), str_replace(' ', '', $filter))
->orWhereRaw('REPLACE(phone, \' \', \'\') = ?', [str_replace(' ', '', $filter)])
->orWhereRaw('REPLACE(mobile, \' \', \'\') = ?', [str_replace(' ', '', $filter)])
->orWhereRaw('REPLACE(iban, \' \', \'\') = ?', [str_replace(' ', '', $filter)])
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\Rule;

class CommunityVolunteerController extends Controller
Expand Down Expand Up @@ -97,8 +96,8 @@ private function filterTerms(Builder $query, array $terms): Builder
private function filterQuery(Builder $query, string $filter): Builder
{
return $query->where(
fn (Builder $q) => $q->where(DB::raw('CONCAT(first_name, \' \', family_name)'), 'LIKE', '%'.$filter.'%')
->orWhere(DB::raw('CONCAT(family_name, \' \', first_name)'), 'LIKE', '%'.$filter.'%')
fn (Builder $q) => $q->whereRaw('CONCAT(first_name, \' \', family_name) LIKE ?', ['%'.$filter.'%'])
->orWhereRaw('CONCAT(family_name, \' \', first_name) LIKE ?', ['%'.$filter.'%'])
->orWhere('first_name', 'LIKE', '%'.$filter.'%')
->orWhere('nickname', 'LIKE', '%'.$filter.'%')
->orWhere('family_name', 'LIKE', '%'.$filter.'%')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Illuminate\Validation\Rule;
use Illuminate\View\View;
use JeroenDesloovere\VCard\VCard;
use ZipStream\Option\Archive;
use ZipStream\ZipStream;

class ImportExportController extends BaseController
Expand Down Expand Up @@ -240,9 +239,7 @@ private function downloadExportable(
\Debugbar::disable(); // Debugbar will inject additional code at end of zip file if enabled

// Download as ZIP with portraits
$options = new Archive();
$options->setSendHttpHeaders(true);
$zip = new ZipStream($file_name.'.zip', $options);
$zip = new ZipStream(outputName: $file_name.'.zip', sendHttpHeaders: true);
$temp_file = 'temp/'.uniqid().'.'.$file_ext;
$export->store($temp_file);
$zip->addFileFromPath($file_name.'.'.$file_ext, storage_path('app/'.$temp_file));
Expand Down
15 changes: 7 additions & 8 deletions app/Models/Fundraising/Donor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

class Donor extends Model
{
Expand Down Expand Up @@ -199,20 +198,20 @@ public function scopeForFilter(Builder $query, ?string $filter = ''): Builder
->map(fn ($name) => strtolower($name))
->flip();

return $wq->where(DB::raw('CONCAT(first_name, \' \', last_name)'), 'LIKE', '%'.$filter.'%')
->orWhere(DB::raw('CONCAT(last_name, \' \', first_name)'), 'LIKE', '%'.$filter.'%')
return $wq->whereRaw('CONCAT(first_name, \' \', last_name) LIKE ?', ['%'.$filter.'%'])
->orWhereRaw('CONCAT(last_name, \' \', first_name) LIKE ?', ['%'.$filter.'%'])
->orWhere('company', 'LIKE', '%'.$filter.'%')
->orWhere('first_name', 'LIKE', '%'.$filter.'%')
->orWhere('last_name', 'LIKE', '%'.$filter.'%')
->orWhere('street', 'LIKE', '%'.$filter.'%')
->orWhere('zip', $filter)
->orWhere('city', 'LIKE', '%'.$filter.'%')
->orWhere(DB::raw('CONCAT(street, \' \', city)'), 'LIKE', '%'.$filter.'%')
->orWhere(DB::raw('CONCAT(street, \' \', zip, \' \', city)'), 'LIKE', '%'.$filter.'%')
->orWhereRaw('CONCAT(street, \' \', city) LIKE ?', ['%'.$filter.'%'])
->orWhereRaw('CONCAT(street, \' \', zip, \' \', city) LIKE ?', ['%'.$filter.'%'])
// Note: Countries filter only works for complete country code or country name
->orWhere('country_code', $countries[strtolower($filter)] ?? $filter)
->orWhere('email', 'LIKE', '%'.$filter.'%')
->orWhere(DB::raw("REPLACE(REPLACE(REPLACE(REPLACE(phone, ' ', ''), '+', ''), '(', ''), ')', '')"), 'LIKE', '%'.str_replace(['+', '(', ')', ' '], '', $filter).'%');
->orWhereRaw("REPLACE(REPLACE(REPLACE(REPLACE(phone, ' ', ''), '+', ''), '(', ''), ')', '') LIKE ?", ['%'.str_replace(['+', '(', ')', ' '], '', $filter).'%']);
});
}

Expand All @@ -224,8 +223,8 @@ public function scopeForFilter(Builder $query, ?string $filter = ''): Builder
*/
public function scopeForSimpleFilter(Builder $query, string $filter): Builder
{
return $query->where(DB::raw('CONCAT(first_name, \' \', last_name)'), 'LIKE', '%'.$filter.'%')
->orWhere(DB::raw('CONCAT(last_name, \' \', first_name)'), 'LIKE', '%'.$filter.'%')
return $query->whereRaw('CONCAT(first_name, \' \', last_name) LIKE ?', ['%'.$filter.'%'])
->orWhereRaw('CONCAT(last_name, \' \', first_name) LIKE ?', ['%'.$filter.'%'])
->orWhere('company', 'LIKE', '%'.$filter.'%')
->orWhere('first_name', 'LIKE', '%'.$filter.'%')
->orWhere('last_name', 'LIKE', '%'.$filter.'%');
Expand Down

0 comments on commit d8fb4da

Please sign in to comment.