File manager - Edit - /var/www/html/pcadigital/api/app/Repositories/OccurrenceRepository.php
Back
<?php namespace App\Repositories; use App\Models\Occurrence; use Illuminate\Support\Facades\DB; class OccurrenceRepository { public function occurrenceView() { return DB::select(DB::raw('SELECT organ_name, oc.name, oc.created_at, h.status, oc.id as occurrence_id, oc.description, oc.code as code, ca.name as category_name, h.id as historic_id, h.images_url, h.final_comment FROM occurrences AS oc INNER JOIN (SELECT * FROM historics WHERE id IN ( SELECT MAX(id) FROM historics GROUP BY occurrence_id )) AS h ON oc.id = h.occurrence_id inner join categories ca on h.category_id = ca.id')); } public function getResolvedOccurrencesByUser(string $id) { return DB::select(DB::raw('SELECT organ_name, oc.name, oc.created_at, h.status, oc.id as occurrence_id, oc.description, oc.code as code, ca.name as category_name, h.id as historic_id, h.images_url, h.final_comment FROM occurrences AS oc INNER JOIN (SELECT * FROM historics WHERE id IN ( SELECT MAX(id) FROM historics WHERE status = "REPROVADO" or status = "CONCLUÍDO" GROUP BY occurrence_id )) AS h ON oc.id = h.occurrence_id inner join categories ca on h.category_id = ca.id WHERE oc.created_by = :value'), ["value" => $id]); } public function getOccurrencesByUserPaginated(string $id) { return Occurrence::where('created_by', $id) ->orderBy('id', 'DESC') ->paginate(10); } public function getAllUnresolvedOccurrences() { return DB::select(DB::raw('SELECT organ_name, oc.created_by as created_by, oc.name, oc.created_at, h.status, oc.id as occurrence_id, oc.description, oc.code as code, ca.name as category_name, h.id as historic_id, h.images_url, h.final_comment FROM occurrences AS oc INNER JOIN (SELECT * FROM historics WHERE id IN ( SELECT MAX(id) FROM historics WHERE status not in ("REPROVADO","CONCLUÍDO") GROUP BY occurrence_id )) AS h ON oc.id = h.occurrence_id inner join categories ca on h.category_id = ca.id')); } public function getAllUnresolvedOccurrencesByUserFollow(string $id) { return DB::select(DB::raw('SELECT organ_name, oc.name, oc.created_at, h.status, oc.id as occurrence_id, oc.description, oc.code as code, ca.name as category_name, h.id as historic_id, h.images_url, h.final_comment FROM occurrences AS oc INNER JOIN (SELECT * FROM historics WHERE id IN ( SELECT MAX(id) FROM historics WHERE status not in ("REPROVADO","CONCLUÍDO") GROUP BY occurrence_id )) AS h ON oc.id = h.occurrence_id inner join categories ca on h.category_id = ca.id inner join occurrence_followers as ocf on ocf.occurrence_id = oc.id inner join followers as f on f.id = ocf.follower_id where f.auth_uuid = :value'), ["value" => $id]); } public function getResolvedOccurrences() { return DB::select(DB::raw('SELECT organ_name, oc.name, oc.created_at, h.status, oc.id as occurrence_id, oc.description, oc.code as code, oc.id as id,oc.latitude, oc.longitude, ca.name as category_name, h.id as historic_id FROM occurrences AS oc INNER JOIN (SELECT * FROM historics WHERE id IN ( SELECT MAX(id) FROM historics WHERE status = "REPROVADO" or status = "CONCLUÍDO" GROUP BY occurrence_id )) AS h ON oc.id = h.occurrence_id inner join categories ca on h.category_id = ca.id')); } public function getAllByUser(string $id) { return Occurrence::select([ 'organ_name', 'occurrences.name', 'occurrences.created_at', 'historics.status', 'occurrences.id as occurrence_id', 'occurrences.description', 'occurrences.code', 'categories.name as category_name', 'historics.id as historic_id', 'historics.images_url', 'historics.final_comment' ]) ->join('historics', function($join) { $join->on('occurrences.id', '=', 'historics.occurrence_id') ->whereIn('historics.id', function($query) { $query->select(DB::raw('MAX(id)')) ->from('historics') ->groupBy('occurrence_id'); }); }) ->join('categories', 'historics.category_id', '=', 'categories.id') ->where('occurrences.created_by', $id) ->orderBy('historics.created_at', 'desc'); } public function getAllOccurrences($createdAt = null) { $query = Occurrence::filter() ->select([ 'organ_name', 'occurrences.name', 'occurrences.created_at', 'h.status', 'occurrences.id as occurrence_id', 'occurrences.description', 'occurrences.code as code', 'categories.name as category_name', 'h.id as historic_id', 'h.organ_id as organ_id', 'h.images_url', 'h.final_comment' ]) ->join('historics as h', function($join) { $join->on('occurrences.id', '=', 'h.occurrence_id') ->whereIn('h.id', function($query) { $query->select(DB::raw('MAX(id)')) ->from('historics') ->groupBy('occurrence_id'); }); }) ->join('categories', 'h.category_id', '=', 'categories.id'); if($createdAt) { $query = $query->whereDate('occurrences.created_at', '=', $createdAt); } return $query->orderBy('h.created_at', 'desc')->paginate(); } public function getOcurrenceByOrg($userOrganIds, $createdAt = null) { $query = Occurrence::filter() ->select([ 'organ_name', 'occurrences.name', 'occurrences.created_at', 'h.status', 'occurrences.id as occurrence_id', 'occurrences.description', 'occurrences.code as code', 'categories.name as category_name', 'h.id as historic_id', 'h.organ_id as organ_id', 'h.images_url', 'h.final_comment' ]) ->join('historics as h', function($join) use($userOrganIds) { $join->on('occurrences.id', '=', 'h.occurrence_id') ->whereIn('h.id', function($query) use($userOrganIds) { $query->select(DB::raw('MAX(id)')) ->from('historics') ->whereIn('h.organ_id', $userOrganIds) ->groupBy('occurrence_id'); }); }) ->join('categories', 'h.category_id', '=', 'categories.id'); if ($createdAt) { $query = $query->whereDate('occurrences.created_at', '=', $createdAt); } return $query->orderBy('h.created_at', 'desc')->paginate(); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings