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.

54 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->query = $this->loadService(UserGroupRepositoryQuery::class);
  12. }
  13. public function getDefaultOptionsSearch(): array
  14. {
  15. return [
  16. 'with' => [],
  17. 'join_with' => [],
  18. 'orderby' => '',
  19. 'attribute_id_producer' => ''
  20. ];
  21. }
  22. public function findOneUserGroupById(int $id)
  23. {
  24. return UserGroup::searchOne(['id' => $id]);
  25. }
  26. public function findOneUserGroupByName(string $name)
  27. {
  28. return UserGroup::searchOne(['name' => $name]);
  29. }
  30. public function findUserGroups()
  31. {
  32. return UserGroup::find()->where('id_producer = ' . GlobalParam::getCurrentProducerId())->all();
  33. }
  34. public function populateUserGroupDropdownList(): array
  35. {
  36. $userGroupsArrayDropdown = ['' => '--'];
  37. $userGroupsArray = $this->findUserGroups();
  38. foreach ($userGroupsArray as $userGroup) {
  39. $userGroupsArrayDropdown[$userGroup['id']] = $userGroup['name'];
  40. }
  41. return $userGroupsArrayDropdown;
  42. }
  43. }