-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '50-crud-for-schools-frontend' of https://github.com/blu…
…milksoftware/interns2024b into 106-crud-for-users-frontend
- Loading branch information
Showing
150 changed files
with
2,475 additions
and
1,400 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions; | ||
|
||
use App\Models\UserQuiz; | ||
use Carbon\Carbon; | ||
|
||
class CloseUserQuizAction | ||
{ | ||
public function execute(UserQuiz $userQuiz): void | ||
{ | ||
$userQuiz->closed_at = Carbon::now(); | ||
$userQuiz->save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Helpers; | ||
|
||
class RegonHelper | ||
{ | ||
public const array WEIGHTS_SHORT = [8, 9, 2, 3, 4, 5, 6, 7]; | ||
public const array WEIGHTS_LONG = [2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8]; | ||
|
||
public static function generateShortRegon() | ||
{ | ||
$digits = ""; | ||
|
||
for ($i = 0; $i < 8; $i++) { | ||
$digits .= rand(0, 9); | ||
} | ||
|
||
$checksum = self::calculateChecksum(str_split($digits), self::WEIGHTS_SHORT); | ||
|
||
return $digits . $checksum; | ||
} | ||
|
||
public static function generateLongRegon() | ||
{ | ||
$digits = ""; | ||
|
||
for ($i = 0; $i < 13; $i++) { | ||
$digits .= rand(0, 9); | ||
} | ||
|
||
$checksum = self::calculateChecksum(str_split($digits), self::WEIGHTS_LONG); | ||
|
||
return $digits . $checksum; | ||
} | ||
|
||
/*** | ||
* @param array<string> $number | ||
* @param array<int> $wages | ||
*/ | ||
public static function calculateChecksum(array $number, array $wages): int | ||
{ | ||
$sum = 0; | ||
|
||
for ($i = 0; $i < count($wages); $i++) { | ||
$sum += $wages[$i] * intval($number[$i]); | ||
} | ||
|
||
$checksum = $sum % 11; | ||
|
||
if ($checksum === 10) { | ||
return 0; | ||
} | ||
|
||
return $checksum; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Helpers; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Pagination\LengthAwarePaginator; | ||
use Illuminate\Support\Facades\Lang; | ||
use Symfony\Component\HttpFoundation\Response as Status; | ||
|
||
class SortHelper | ||
{ | ||
public function __construct( | ||
private Request $request, | ||
) {} | ||
|
||
/** | ||
* @param array<string> $allowedFields | ||
* @param array<string> $ignoredFields | ||
*/ | ||
public function sort(Builder $query, array $allowedFields, array $ignoredFields): Builder | ||
{ | ||
[$field, $order] = $this->getSortParameters(); | ||
|
||
if (!in_array($field, $allowedFields, true)) { | ||
if (in_array($field, $ignoredFields, true)) { | ||
return $query; | ||
} | ||
|
||
abort(Status::HTTP_BAD_REQUEST, Lang::get("validation.custom.sorting.unsupported_field", ["attribute" => $field])); | ||
} | ||
|
||
return $query->orderBy($field, $order); | ||
} | ||
|
||
/** | ||
* @return array<string> | ||
*/ | ||
public function getSortParameters(): array | ||
{ | ||
$field = $this->request->query("sort", "id"); | ||
$ascending = $this->request->query("order", "desc") === "asc"; | ||
|
||
return [$field, $ascending ? "asc" : "desc"]; | ||
} | ||
|
||
public function search(Builder $query, string $field): Builder | ||
{ | ||
$searchText = $this->request->query("search"); | ||
|
||
if ($searchText) { | ||
return $query->where($field, "ilike", "%$searchText%"); | ||
} | ||
|
||
return $query; | ||
} | ||
|
||
public function paginate(Builder $query): LengthAwarePaginator | ||
{ | ||
$limit = (int)$this->request->query("limit", "50"); | ||
|
||
if (!$limit || $limit < 0) { | ||
$limit = 50; | ||
} | ||
|
||
return $query->paginate($limit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.