Ecodev /
my-ichtus
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Application\Repository; |
||
| 6 | |||
| 7 | use Application\Model\Log; |
||
| 8 | use Application\Model\User; |
||
| 9 | |||
| 10 | use Ecodev\Felix\Repository\LimitedAccessSubQuery; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @extends AbstractRepository<Log> |
||
| 14 | */ |
||
| 15 | class LogRepository extends AbstractRepository implements \Ecodev\Felix\Repository\LogRepository, LimitedAccessSubQuery |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Log message to be used when a door is opened. |
||
| 19 | */ |
||
| 20 | final public const DOOR_OPENED = 'door opened: '; |
||
| 21 | /** |
||
| 22 | * Log message to be used when the datatrans webhook starts. |
||
| 23 | */ |
||
| 24 | final public const DATATRANS_WEBHOOK_BEGIN = 'datatrans webhook begin'; |
||
| 25 | /** |
||
| 26 | * Log message to be used when the datatrans webhook finishes. |
||
| 27 | */ |
||
| 28 | final public const DATATRANS_WEBHOOK_END = 'datatrans webhook end'; |
||
| 29 | |||
| 30 | use \Ecodev\Felix\Repository\Traits\LogRepository; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 31 | |||
| 32 | /** |
||
| 33 | * Returns pure SQL to get ID of all objects that are accessible to given user. |
||
| 34 | */ |
||
| 35 | public function getAccessibleSubQuery(?\Ecodev\Felix\Model\User $user): string |
||
| 36 | { |
||
| 37 | if (!$user) { |
||
| 38 | return '-1'; |
||
| 39 | } |
||
| 40 | |||
| 41 | // Sysops and responsible can read all logs |
||
| 42 | if (in_array($user->getRole(), [User::ROLE_RESPONSIBLE, User::ROLE_ADMINISTRATOR], true)) { |
||
| 43 | return ''; |
||
| 44 | } |
||
| 45 | |||
| 46 | $subquery = ' |
||
| 47 | SELECT log.id FROM `log` WHERE |
||
| 48 | message LIKE ' . $this->getEntityManager()->getConnection()->quote(self::DOOR_OPENED . '%') . ' |
||
| 49 | AND log.creator_id = ' . $user->getId(); |
||
| 50 | |||
| 51 | return $subquery; |
||
| 52 | } |
||
| 53 | } |
||
| 54 |