diff --git a/config/module.config.php b/config/module.config.php index 41600e0..02477fe 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -109,6 +109,7 @@ 'pserver_user_panel_service' => 'PServerCMS\Service\UserPanel', 'pserver_user_role_service' => 'PServerCMS\Service\UserRole', 'pserver_login_history_service' => 'PServerCMS\Service\LoginHistory', + 'pserver_coin_service' => 'PServerCMS\Service\Coin', ], 'aliases' => [ 'translator' => 'MvcTranslator', diff --git a/src/PServerCMS/Form/ChangePwd.php b/src/PServerCMS/Form/ChangePwd.php index ee2ade2..2294088 100644 --- a/src/PServerCMS/Form/ChangePwd.php +++ b/src/PServerCMS/Form/ChangePwd.php @@ -5,9 +5,11 @@ use Zend\Form\Element; use ZfcBase\Form\ProvidesEventsForm; -class ChangePwd extends ProvidesEventsForm{ +class ChangePwd extends ProvidesEventsForm +{ - public function __construct(){ + public function __construct() + { parent::__construct(); $this->add(array( @@ -59,8 +61,8 @@ public function __construct(){ * @param $which * @return $this */ - public function setWhich($which){ - $bool = $this->hasAttribute('which'); + public function setWhich($which) + { $hidden = new Element\Hidden('which'); $hidden->setLabel(' '); $hidden->setValue($which); diff --git a/src/PServerCMS/Form/ChangePwdFilter.php b/src/PServerCMS/Form/ChangePwdFilter.php index a1205d7..ec9e727 100644 --- a/src/PServerCMS/Form/ChangePwdFilter.php +++ b/src/PServerCMS/Form/ChangePwdFilter.php @@ -4,11 +4,11 @@ use ZfcBase\InputFilter\ProvidesEventsInputFilter; -class ChangePwdFilter extends ProvidesEventsInputFilter{ - - - public function __construct(){ +class ChangePwdFilter extends ProvidesEventsInputFilter +{ + public function __construct() + { $this->add(array( 'name' => 'currentPassword', 'required' => true, diff --git a/src/PServerCMS/Form/Password.php b/src/PServerCMS/Form/Password.php index 5a814eb..6a07e77 100644 --- a/src/PServerCMS/Form/Password.php +++ b/src/PServerCMS/Form/Password.php @@ -7,7 +7,8 @@ use ZfcBase\Form\ProvidesEventsForm; use Zend\ServiceManager\ServiceLocatorInterface; -class Password extends ProvidesEventsForm { +class Password extends ProvidesEventsForm +{ /** @var ServiceLocatorInterface */ protected $serviceManager; @@ -17,7 +18,8 @@ class Password extends ProvidesEventsForm { protected $entityManager; - public function __construct( ServiceLocatorInterface $serviceLocatorInterface ) { + public function __construct( ServiceLocatorInterface $serviceLocatorInterface ) + { parent::__construct(); $this->setServiceManager($serviceLocatorInterface); @@ -64,7 +66,8 @@ public function __construct( ServiceLocatorInterface $serviceLocatorInterface ) /** * @param User $user */ - public function addSecretQuestion(User $user){ + public function addSecretQuestion(User $user) + { if(!$this->getServiceManager()->get('pserver_configread_service')->get('pserver.password.secret_question')){ return; } @@ -105,14 +108,16 @@ public function addSecretQuestion(User $user){ /** * @param User $user */ - public function setUser( User $user ){ + public function setUser( User $user ) + { $this->user = $user; } /** * @return User */ - public function getUser(){ + public function getUser() + { return $this->user; } @@ -121,7 +126,8 @@ public function getUser(){ * * @return $this */ - protected function setServiceManager( ServiceLocatorInterface $oServiceManager ) { + protected function setServiceManager( ServiceLocatorInterface $oServiceManager ) + { $this->serviceManager = $oServiceManager; return $this; @@ -130,7 +136,8 @@ protected function setServiceManager( ServiceLocatorInterface $oServiceManager ) /** * @return \Doctrine\ORM\EntityManager */ - public function getEntityManager() { + public function getEntityManager() + { if (!$this->entityManager) { $this->entityManager = $this->getServiceManager()->get('Doctrine\ORM\EntityManager'); } @@ -141,14 +148,16 @@ public function getEntityManager() { /** * @return ServiceLocatorInterface */ - protected function getServiceManager() { + protected function getServiceManager() + { return $this->serviceManager; } /** * @return \PServerCMS\Options\EntityOptions */ - protected function getEntityOptions(){ + protected function getEntityOptions() + { return $this->getServiceManager()->get('pserver_entity_options'); } } \ No newline at end of file diff --git a/src/PServerCMS/Form/PwLost.php b/src/PServerCMS/Form/PwLost.php index e8039d9..7b6e144 100644 --- a/src/PServerCMS/Form/PwLost.php +++ b/src/PServerCMS/Form/PwLost.php @@ -8,9 +8,11 @@ use ZfcBase\Form\ProvidesEventsForm; use Zend\Form\Element\Captcha; -class PwLost extends ProvidesEventsForm { +class PwLost extends ProvidesEventsForm +{ - public function __construct( ServiceLocatorInterface $sm ) { + public function __construct( ServiceLocatorInterface $sm ) + { parent::__construct(); $this->add(array( diff --git a/src/PServerCMS/Form/PwLostFilter.php b/src/PServerCMS/Form/PwLostFilter.php index aca197f..1a3a113 100644 --- a/src/PServerCMS/Form/PwLostFilter.php +++ b/src/PServerCMS/Form/PwLostFilter.php @@ -11,7 +11,8 @@ class PwLostFilter extends ProvidesEventsInputFilter protected $userValidator; - public function __construct( AbstractRecord $userValidator ){ + public function __construct( AbstractRecord $userValidator ) + { $this->setUserValidator( $userValidator ); $this->add(array( @@ -33,7 +34,8 @@ public function __construct( AbstractRecord $userValidator ){ /** * @return AbstractRecord */ - public function getUserValidator() { + public function getUserValidator() + { return $this->userValidator; } @@ -42,7 +44,8 @@ public function getUserValidator() { * * @return $this */ - public function setUserValidator($userValidator) { + public function setUserValidator($userValidator) + { $this->userValidator = $userValidator; return $this; } diff --git a/src/PServerCMS/Form/Register.php b/src/PServerCMS/Form/Register.php index e88a6b0..498319a 100644 --- a/src/PServerCMS/Form/Register.php +++ b/src/PServerCMS/Form/Register.php @@ -8,9 +8,11 @@ use ZfcBase\Form\ProvidesEventsForm; use Zend\Form\Element\Captcha; -class Register extends ProvidesEventsForm { +class Register extends ProvidesEventsForm +{ - public function __construct( ServiceLocatorInterface $sm ) { + public function __construct( ServiceLocatorInterface $sm ) + { parent::__construct(); $this->add(array( diff --git a/src/PServerCMS/Form/RegisterFilter.php b/src/PServerCMS/Form/RegisterFilter.php index facf22a..3bf8baf 100644 --- a/src/PServerCMS/Form/RegisterFilter.php +++ b/src/PServerCMS/Form/RegisterFilter.php @@ -7,7 +7,8 @@ use PServerCMS\Validator; use Zend\ServiceManager\ServiceManager; -class RegisterFilter extends ProvidesEventsInputFilter { +class RegisterFilter extends ProvidesEventsInputFilter +{ protected $serviceManager; protected $entityManager; @@ -17,7 +18,8 @@ class RegisterFilter extends ProvidesEventsInputFilter { protected $striposValidator; - public function __construct( ServiceManager $serviceManager ){ + public function __construct( ServiceManager $serviceManager ) + { $this->setServiceManager($serviceManager); diff --git a/src/PServerCMS/Service/Coin.php b/src/PServerCMS/Service/Coin.php new file mode 100644 index 0000000..2f1da7b --- /dev/null +++ b/src/PServerCMS/Service/Coin.php @@ -0,0 +1,60 @@ +getForm(); + $form->setData($data); + + if(!$form->isValid()){ + return false; + } + $user = $this->getUser4Id($userId); + + if ($user) { + $data = $form->getData(); + $this->addCoins($user, $data['coins']); + } + + return true; + } + + /** + * @param UserInterface $user + * @return int + */ + public function getCoinsOfUser( UserInterface $user ) + { + return $this->getGameBackendService()->getCoins($user); + } + + /** + * @param UserInterface $user + * @param $amount + * @return bool + */ + public function addCoins( UserInterface $user, $amount ) + { + return $this->getGameBackendService()->setCoins($user, $amount); + } + + /** + * @return \ZfcBase\Form\ProvidesEventsForm + */ + public function getForm() + { + return $this->getService('pserver_admin_coin_form'); + } +} \ No newline at end of file diff --git a/src/PServerCMS/Service/Download.php b/src/PServerCMS/Service/Download.php index f0de79e..6f773fa 100644 --- a/src/PServerCMS/Service/Download.php +++ b/src/PServerCMS/Service/Download.php @@ -6,15 +6,14 @@ use PServerCMS\Entity\DownloadList; use PServerCMS\Keys\Caching; -class Download extends InvokableBase { - /** @var \PServerAdmin\Form\Download */ - protected $downloadForm; +class Download extends InvokableBase +{ /** * @return \PServerCMS\Entity\DownloadList[] */ - public function getActiveList(){ - + public function getActiveList() + { $downloadInfo = $this->getCachingHelperService()->getItem(Caching::DOWNLOAD, function() { /** @var \PServerCMS\Entity\Repository\DownloadList $repository */ $repository = $this->getEntityManager()->getRepository($this->getEntityOptions()->getDownloadList()); @@ -27,13 +26,19 @@ public function getActiveList(){ /** * @return null|\PServerCMS\Entity\DownloadList[] */ - public function getDownloadList(){ + public function getDownloadList() + { /** @var \PServerCMS\Entity\Repository\DownloadList $repository */ $repository = $this->getEntityManager()->getRepository($this->getEntityOptions()->getDownloadList()); return $repository->getDownloadList(); } - public function getDownload4Id( $id ){ + /** + * @param $id + * @return null|DownloadList + */ + public function getDownload4Id( $id ) + { /** @var \PServerCMS\Entity\Repository\DownloadList $repository */ $repository = $this->getEntityManager()->getRepository($this->getEntityOptions()->getDownloadList()); return $repository->getDownload4Id($id); @@ -45,7 +50,8 @@ public function getDownload4Id( $id ){ * * @return bool|DownloadList */ - public function download( array $data, $currentDownload = null){ + public function download( array $data, $currentDownload = null) + { if($currentDownload == null){ $currentDownload = new DownloadList(); } @@ -71,10 +77,8 @@ public function download( array $data, $currentDownload = null){ /** * @return \PServerAdmin\Form\Download */ - public function getDownloadForm(){ - if(!$this->downloadForm){ - $this->downloadForm = $this->getServiceManager()->get('pserver_admin_download_form'); - } - return $this->downloadForm; + public function getDownloadForm() + { + return $this->getService('pserver_admin_download_form'); } } \ No newline at end of file diff --git a/src/PServerCMS/Service/InvokableBase.php b/src/PServerCMS/Service/InvokableBase.php index 0f5970c..606dd59 100644 --- a/src/PServerCMS/Service/InvokableBase.php +++ b/src/PServerCMS/Service/InvokableBase.php @@ -6,33 +6,15 @@ class InvokableBase extends UserBase { - /** @var \Zend\Cache\Storage\StorageInterface */ - protected $cachingService; - /** @var CachingHelper */ - protected $cachingHelperService; - /** @var \GameBackend\DataService\DataServiceInterface */ - protected $gameBackendService; - /** @var ConfigRead */ - protected $configReadService; - /** @var UserBlock */ - protected $userBlockService; - /** @var \PServerCMS\Options\EntityOptions */ - protected $entityOptions; - /** @var \PServerCMS\Options\MailOptions */ - protected $mailOptions; - /** @var \SmallUser\Service\User */ - protected $userService; + /** @var array|object */ + protected $serviceCache; /** * @return \Zend\Cache\Storage\StorageInterface */ protected function getCachingService() { - if (!$this->cachingService) { - $this->cachingService = $this->getServiceManager()->get( 'pserver_caching_service' ); - } - - return $this->cachingService; + return $this->getService('pserver_caching_service'); } /** @@ -40,11 +22,7 @@ protected function getCachingService() */ protected function getCachingHelperService() { - if (!$this->cachingHelperService) { - $this->cachingHelperService = $this->getServiceManager()->get( 'pserver_cachinghelper_service' ); - } - - return $this->cachingHelperService; + return $this->getService('pserver_cachinghelper_service'); } /** @@ -52,11 +30,7 @@ protected function getCachingHelperService() */ protected function getGameBackendService() { - if (!$this->gameBackendService) { - $this->gameBackendService = $this->getServiceManager()->get( 'gamebackend_dataservice' ); - } - - return $this->gameBackendService; + return $this->getService('gamebackend_dataservice'); } /** @@ -76,11 +50,7 @@ protected function getUser4Id( $userId ) */ protected function getConfigService() { - if (!$this->configReadService) { - $this->configReadService = $this->getServiceManager()->get( 'pserver_configread_service' ); - } - - return $this->configReadService; + return $this->getService('pserver_configread_service'); } /** @@ -88,11 +58,7 @@ protected function getConfigService() */ protected function getUserBlockService() { - if (!$this->userBlockService) { - $this->userBlockService = $this->getServiceManager()->get( 'pserver_user_block_service' ); - } - - return $this->userBlockService; + return $this->getService('pserver_user_block_service'); } /** @@ -100,11 +66,7 @@ protected function getUserBlockService() */ protected function getEntityOptions() { - if (!$this->entityOptions) { - $this->entityOptions = $this->getServiceManager()->get( 'pserver_entity_options' ); - } - - return $this->entityOptions; + return $this->getService('pserver_entity_options'); } /** @@ -112,11 +74,7 @@ protected function getEntityOptions() */ protected function getMailOptions() { - if (!$this->mailOptions) { - $this->mailOptions = $this->getServiceManager()->get( 'pserver_mail_options' ); - } - - return $this->mailOptions; + return $this->getService('pserver_mail_options'); } /** @@ -124,11 +82,7 @@ protected function getMailOptions() */ protected function getUserService() { - if (!$this->userService) { - $this->userService = $this->getServiceManager()->get( 'small_user_service' ); - } - - return $this->userService; + return $this->getService('small_user_service'); } /** @@ -144,4 +98,17 @@ protected function addFormMessagesInFlashMessenger( FormInterface $form, $namesp } } } + + /** + * @param $serviceName + * + * @return array|object + */ + protected function getService( $serviceName ) + { + if (!isset( $this->serviceCache[$serviceName] )) { + $this->serviceCache[$serviceName] = $this->getServiceManager()->get( $serviceName ); + } + return $this->serviceCache[$serviceName]; + } } \ No newline at end of file diff --git a/src/PServerCMS/Service/PaymentNotify.php b/src/PServerCMS/Service/PaymentNotify.php index bec937d..21e2753 100644 --- a/src/PServerCMS/Service/PaymentNotify.php +++ b/src/PServerCMS/Service/PaymentNotify.php @@ -36,8 +36,7 @@ public function success( Request $request ) // save the message if gamebackend-service is unavailable $errorMessage = ''; try { - $backend = $this->getGameBackendService(); - $backend->setCoins( $user, $coins ); + $this->getCoinService()->addCoins( $user, $coins ); } catch( \Exception $e ) { $request->setStatus( $request::STATUS_ERROR ); $errorMessage = $e->getMessage(); @@ -145,4 +144,12 @@ protected function isDonateAlreadyAdded( Request $request ) $donateEntity = $this->getEntityManager()->getRepository( $this->getEntityOptions()->getDonateLog() ); return $donateEntity->isDonateAlreadyAdded( $request->getTransactionId(), $this->mapPaymentProvider2DonateType( $request ) ); } + + /** + * @return Coin + */ + protected function getCoinService() + { + return $this->getService('pserver_coin_service'); + } } \ No newline at end of file