diff --git a/app/contracts/IMemberCardService1.php b/app/contracts/IMemberCardService1.php index f523b837..75bc53de 100644 --- a/app/contracts/IMemberCardService1.php +++ b/app/contracts/IMemberCardService1.php @@ -12,6 +12,27 @@ use vhs\services\IContract; interface IMemberCardService1 extends IContract { + /** + * @permission administrator + * + * @param $filters + * + * @return mixed + */ + public function CountGenuineCards($filters); + + /** + * @permission administrator|user + * + * @param $userid + * @param $filters + * + * @return mixed + * + * @throws \Exception + */ + public function CountGenuineUserCards($userid, $filters); + /** * @permission administrator * diff --git a/app/contracts/IPreferenceService1.php b/app/contracts/IPreferenceService1.php index 74234d69..8a1279e7 100644 --- a/app/contracts/IPreferenceService1.php +++ b/app/contracts/IPreferenceService1.php @@ -12,6 +12,15 @@ use vhs\services\IContract; interface IPreferenceService1 extends IContract { + /** + * @permission administrator + * + * @param $filters + * + * @return array + */ + public function CountSystemPreferences($filters); + /** * @permission administrator * diff --git a/app/contracts/IPrivilegeService1.php b/app/contracts/IPrivilegeService1.php index d0b517b1..58e13af2 100644 --- a/app/contracts/IPrivilegeService1.php +++ b/app/contracts/IPrivilegeService1.php @@ -12,6 +12,15 @@ use vhs\services\IContract; interface IPrivilegeService1 extends IContract { + /** + * @permission administrator|user|grants + * + * @param $filters + * + * @return mixed + */ + public function CountPrivileges($filters); + /** * @permission administrator * diff --git a/app/services/MemberCardService.php b/app/services/MemberCardService.php index d475572d..f2c6de7b 100644 --- a/app/services/MemberCardService.php +++ b/app/services/MemberCardService.php @@ -22,6 +22,31 @@ use vhs\security\exceptions\UnauthorizedException; class MemberCardService implements IMemberCardService1 { + /** + * @permission administrator + * + * @param $filters + * + * @return mixed + */ + public function CountGenuineCards($filters) { + return GenuineCard::count($filters); + } + + /** + * @permission administrator + * + * @param $userid + * @param $filters + * + * @return mixed + */ + public function CountGenuineUserCards($userid, $filters) { + $filters = $this->addUserIDToFilters($userid, $filters); + + return GenuineCard::count($filters); + } + /** * @permission administrator * @@ -208,4 +233,28 @@ public function ValidateGenuineCard($key) { return !is_null($keys) && count($keys) == 1; } + + private function addUserIDToFilters($userid, $filters) { + $userService = new UserService(); + $user = $userService->GetUser($userid); + + if (is_string($filters)) { + //todo total hack.. this is to support GET params for downloading payments + $filters = json_decode($filters); + } + + if (is_null($user)) { + throw new UnauthorizedException('User not found or you do not have access'); + } + + $userFilter = Filter::Equal('userid', $user->id); + + if (is_null($filters) || $filters == '') { + $filters = $userFilter; + } else { + $filters = Filter::_And($userFilter, $filters); + } + + return $filters; + } } diff --git a/app/services/PreferenceService.php b/app/services/PreferenceService.php index 2d204e37..2f86bfac 100644 --- a/app/services/PreferenceService.php +++ b/app/services/PreferenceService.php @@ -16,6 +16,17 @@ use vhs\services\Service; class PreferenceService extends Service implements IPreferenceService1 { + /** + * @permission administrator + * + * @param $filters + * + * @return array + */ + public function CountSystemPreferences($filters) { + return SystemPreference::count($filters); + } + /** * @permission administrator * diff --git a/app/services/PrivilegeService.php b/app/services/PrivilegeService.php index bf2593eb..18b5f7cb 100644 --- a/app/services/PrivilegeService.php +++ b/app/services/PrivilegeService.php @@ -19,6 +19,17 @@ use vhs\services\ServiceRegistry; class PrivilegeService extends Service implements IPrivilegeService1 { + /** + * @permission administrator|user|grants + * + * @param $filters + * + * @return mixed + */ + public function CountPrivileges($filters) { + return Privilege::count($filters); + } + /** * @permission administrator *