Skip to content

Commit

Permalink
added new coin service
Browse files Browse the repository at this point in the history
  • Loading branch information
kokspflanze committed May 21, 2015
1 parent f2bc443 commit 3cb847b
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 97 deletions.
1 change: 1 addition & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 6 additions & 4 deletions src/PServerCMS/Form/ChangePwd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/PServerCMS/Form/ChangePwdFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 18 additions & 9 deletions src/PServerCMS/Form/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use ZfcBase\Form\ProvidesEventsForm;
use Zend\ServiceManager\ServiceLocatorInterface;

class Password extends ProvidesEventsForm {
class Password extends ProvidesEventsForm
{

/** @var ServiceLocatorInterface */
protected $serviceManager;
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -121,7 +126,8 @@ public function getUser(){
*
* @return $this
*/
protected function setServiceManager( ServiceLocatorInterface $oServiceManager ) {
protected function setServiceManager( ServiceLocatorInterface $oServiceManager )
{
$this->serviceManager = $oServiceManager;

return $this;
Expand All @@ -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');
}
Expand All @@ -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');
}
}
6 changes: 4 additions & 2 deletions src/PServerCMS/Form/PwLost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 6 additions & 3 deletions src/PServerCMS/Form/PwLostFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -33,7 +34,8 @@ public function __construct( AbstractRecord $userValidator ){
/**
* @return AbstractRecord
*/
public function getUserValidator() {
public function getUserValidator()
{
return $this->userValidator;
}

Expand All @@ -42,7 +44,8 @@ public function getUserValidator() {
*
* @return $this
*/
public function setUserValidator($userValidator) {
public function setUserValidator($userValidator)
{
$this->userValidator = $userValidator;
return $this;
}
Expand Down
6 changes: 4 additions & 2 deletions src/PServerCMS/Form/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions src/PServerCMS/Form/RegisterFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use PServerCMS\Validator;
use Zend\ServiceManager\ServiceManager;

class RegisterFilter extends ProvidesEventsInputFilter {
class RegisterFilter extends ProvidesEventsInputFilter
{
protected $serviceManager;
protected $entityManager;

Expand All @@ -17,7 +18,8 @@ class RegisterFilter extends ProvidesEventsInputFilter {
protected $striposValidator;


public function __construct( ServiceManager $serviceManager ){
public function __construct( ServiceManager $serviceManager )
{

$this->setServiceManager($serviceManager);

Expand Down
60 changes: 60 additions & 0 deletions src/PServerCMS/Service/Coin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php


namespace PServerCMS\Service;

use PServerCMS\Entity\UserInterface;

class Coin extends InvokableBase
{

/**
* @param $data
* @param $user
* @return bool
*/
public function addCoinsForm($data, $userId)
{
$form = $this->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');
}
}
30 changes: 17 additions & 13 deletions src/PServerCMS/Service/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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();
}
Expand All @@ -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');
}
}
Loading

0 comments on commit 3cb847b

Please sign in to comment.