You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4KB

  1. <?php
  2. namespace common\logic\User\UserGroup\Repository;
  3. use common\helpers\GlobalParam;
  4. use common\logic\AbstractRepository;
  5. use common\logic\User\UserGroup\Model\UserGroup;
  6. class UserGroupRepository extends AbstractRepository
  7. {
  8. protected UserGroupRepositoryQuery $query;
  9. public function loadDependencies(): void
  10. {
  11. $this->loadQuery(UserGroupRepositoryQuery::class);
  12. }
  13. public function getDefaultOptionsSearch(): array
  14. {
  15. return [
  16. self::WITH => [],
  17. self::JOIN_WITH => [],
  18. self::ORDER_BY => '',
  19. self::ATTRIBUTE_ID_PRODUCER => 'user_group.id_producer'
  20. ];
  21. }
  22. public function findOneUserGroupById(int $id)
  23. {
  24. return $this->createDefaultQuery()
  25. ->filterById($id)
  26. ->findOne();
  27. }
  28. public function findOneUserGroupByName(string $name)
  29. {
  30. return $this->createDefaultQuery()
  31. ->filterByName($name)
  32. ->findOne();
  33. }
  34. public function findUserGroups()
  35. {
  36. return $this->createDefaultQuery()->find();
  37. }
  38. public function populateUserGroupDropdownList(): array
  39. {
  40. $userGroupsArrayDropdown = ['' => '--'];
  41. $userGroupsArray = $this->findUserGroups();
  42. foreach ($userGroupsArray as $userGroup) {
  43. $userGroupsArrayDropdown[$userGroup['id']] = $userGroup['name'];
  44. }
  45. return $userGroupsArrayDropdown;
  46. }
  47. }