Skip to content

Commit

Permalink
- refactoring
Browse files Browse the repository at this point in the history
- default user entity changed to small-user
- added unit-tests [basics]
  • Loading branch information
kokspflanze committed Apr 4, 2015
1 parent 5013192 commit 929ef68
Show file tree
Hide file tree
Showing 33 changed files with 1,454 additions and 946 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
INSTALL.txt
LICENSE.txt
README.txt
demos/
extras/documentation
composer.phar
composer.lock
.*
!.gitignore
!.travis.yml
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7
- hhvm
- hhvm-nightly

matrix:
fast_finish: true
allow_failures:
- php: hhvm
- php: hhvm-nightly

before_script:
- composer update --prefer-source --dev

script:
- mkdir -p build/logs
# Run tests
- php ./vendor/bin/phpunit --configuration tests/phpunit.xml

after_script:
- php vendor/bin/coveralls -v
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ZfcTicketSystem
===============
# ZfcTicketSystem

Master
[![Build Status](https://travis-ci.org/kokspflanze/ZfcTicketSystem.svg?branch=master)](https://travis-ci.org/kokspflanze/ZfcTicketSystem?branch=master)
[![Coverage Status](https://coveralls.io/repos/kokspflanze/ZfcTicketSystem/badge.svg?branch=master)](https://coveralls.io/r/kokspflanze/ZfcTicketSystem?branch=master)

- run the SQL script [db/dump.sql]

Expand Down
60 changes: 35 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
{
"name": "kokspflanze/zfc-ticket-system",
"description": "ZendFramework 2 TicketSystem Module",
"type": "library",
"keywords": [
"framework",
"zf2",
"twig",
"ticketsystem"
],
"homepage": "https://github.com/kokspflanze/ZfcTicketSystem",
"autoload": {
"psr-0": {
"ZfcTicketSystem\\": "src/"
}
},
"authors": [
{
"name": "Oliver"
}
],
"require": {
"php": ">=5.4",
"doctrine/doctrine-orm-module": "0.*",
"zf-commons/zfc-user-doctrine-orm": "0.*"
}
"name": "kokspflanze/zfc-ticket-system",
"description": "ZendFramework 2 TicketSystem Module",
"type": "library",
"keywords": [
"framework",
"zf2",
"twig",
"ticketsystem"
],
"homepage": "https://github.com/kokspflanze/ZfcTicketSystem",
"autoload": {
"psr-0": {
"ZfcTicketSystem\\": "src/",
"ZfcTicketSystemTest\\": "tests/"
}
},
"authors": [
{
"name": "Oliver",
"email": "kokspflanze@gmx.de"
}
],
"require": {
"php": ">=5.4",
"doctrine/doctrine-orm-module": "0.*",
"zf-commons/zfc-user-doctrine-orm": "0.*",
"kokspflanze/small-user": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"zendframework/zendframework": "~2.4",
"fabpot/php-cs-fixer": "~1.0",
"satooshi/php-coveralls": "dev-master",
"phpunit/phpcov": "~2.0"
}
}
1 change: 1 addition & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
'ticket_category' => 'ZfcTicketSystem\Entity\TicketCategory',
'ticket_entry' => 'ZfcTicketSystem\Entity\TicketEntry',
'ticket_subject' => 'ZfcTicketSystem\Entity\TicketSubject',
'user' => 'SmallUser\Entity\User'
],
],
];
78 changes: 41 additions & 37 deletions src/ZfcTicketSystem/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,46 @@

use ZfcTicketSystem\Entity\TicketSubject;

class AdminController extends BaseController {

public function indexAction(){
$type = $this->params()->fromRoute('type');

return array(
'ticketList' => $this->getTicketService()->getTickets4Type($type)
);
}

public function viewAction(){
$ticketId = $this->params()->fromRoute('id');
$ticketSubject = $this->getTicketService()->getTicketSubject4Admin($ticketId);
// Fallback if not task
if(!$ticketSubject){
return $this->redirect()->toRoute('zfc-ticketsystem-admin', array('type' => 0));
}

$form = $this->getTicketService()->getTicketSystemEntryForm();

$request = $this->getRequest();
if($request->isPost()){
$ticketSubject->setType(TicketSubject::TypeOpen);
$oTicketSystem = $this->getTicketService()->newEntry($this->params()->fromPost(), $this->getAuthService()->getIdentity(), $ticketSubject);
if($oTicketSystem){
return $this->redirect()->toRoute('zfc-ticketsystem-admin', array('id' => $ticketId, 'action' => 'view'));
}
}

$entry = $ticketSubject->getTicketEntry();

return array(
'form' => $form,
'ticket' => $ticketSubject,
'entry' => $entry
);
}
class AdminController extends BaseController
{

public function indexAction()
{
$type = $this->params()->fromRoute( 'type' );

return array(
'ticketList' => $this->getTicketService()->getTickets4Type( $type )
);
}

public function viewAction()
{
$ticketId = $this->params()->fromRoute( 'id' );
$ticketSubject = $this->getTicketService()->getTicketSubject4Admin( $ticketId );
// Fallback if not task
if (!$ticketSubject) {
return $this->redirect()->toRoute( 'zfc-ticketsystem-admin', array( 'type' => 0 ) );
}

$form = $this->getTicketService()->getTicketSystemEntryForm();

$request = $this->getRequest();
if ($request->isPost()) {
$ticketSubject->setType( TicketSubject::TYPE_OPEN );
$oTicketSystem = $this->getTicketService()->newEntry( $this->params()->fromPost(), $this->getAuthService()->getIdentity(),
$ticketSubject );
if ($oTicketSystem) {
return $this->redirect()->toRoute( 'zfc-ticketsystem-admin', array( 'id' => $ticketId, 'action' => 'view' ) );
}
}

$entry = $ticketSubject->getTicketEntry();

return array(
'form' => $form,
'ticket' => $ticketSubject,
'entry' => $entry
);
}

}
51 changes: 27 additions & 24 deletions src/ZfcTicketSystem/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,35 @@

use Zend\Mvc\Controller\AbstractActionController;

class BaseController extends AbstractActionController {
/** @var \ZfcTicketSystem\Service\TicketSystem */
protected $ticketService;
/** @var \Zend\Authentication\AuthenticationService */
protected $authService;
class BaseController extends AbstractActionController
{
/** @var \ZfcTicketSystem\Service\TicketSystem */
protected $ticketService;
/** @var \Zend\Authentication\AuthenticationService */
protected $authService;

/**
* @return \ZfcTicketSystem\Service\TicketSystem
*/
protected function getTicketService(){
if (!$this->ticketService) {
$this->ticketService = $this->getServiceLocator()->get('zfcticketsystem_ticketsystem_service');
}
/**
* @return \ZfcTicketSystem\Service\TicketSystem
*/
protected function getTicketService()
{
if (!$this->ticketService) {
$this->ticketService = $this->getServiceLocator()->get( 'zfcticketsystem_ticketsystem_service' );
}

return $this->ticketService;
}
return $this->ticketService;
}

/**
* @return \Zend\Authentication\AuthenticationService
*/
protected function getAuthService() {
if (!$this->authService) {
$config = $this->getServiceLocator()->get('Config');
$this->authService = $this->getServiceLocator()->get($config['zfc-ticket-system']['auth_service']);
}
/**
* @return \Zend\Authentication\AuthenticationService
*/
protected function getAuthService()
{
if (!$this->authService) {
$config = $this->getServiceLocator()->get( 'Config' );
$this->authService = $this->getServiceLocator()->get( $config['zfc-ticket-system']['auth_service'] );
}

return $this->authService;
}
return $this->authService;
}
}
113 changes: 58 additions & 55 deletions src/ZfcTicketSystem/Controller/TicketSystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,66 @@
class TicketSystemController extends BaseController
{

public function indexAction()
public function indexAction()
{
$view = new ViewModel(array(
'ticketList' => $this->getTicketService()->getTickets4User($this->getLoggedInUserId())
));
$view->setTemplate('zfc-ticket-system/index');
return $view;
}

public function newAction(){

$form = $this->getTicketService()->getTicketSystemNewForm();

$request = $this->getRequest();
if($request->isPost()){
$ticketSystem = $this->getTicketService()->newTicket($this->params()->fromPost(), $this->getAuthService()->getIdentity());
if($ticketSystem){
return $this->redirect()->toRoute('zfc-ticketsystem');
}
}
$view = new ViewModel(array('form' => $form));
$view->setTemplate('zfc-ticket-system/new');

return $view;
}

public function viewAction()
$view = new ViewModel( array(
'ticketList' => $this->getTicketService()->getTickets4User( $this->getLoggedInUserId() )
) );
$view->setTemplate( 'zfc-ticket-system/index' );

return $view;
}

public function newAction()
{

$form = $this->getTicketService()->getTicketSystemNewForm();

$request = $this->getRequest();
if ($request->isPost()) {
$ticketSystem = $this->getTicketService()->newTicket( $this->params()->fromPost(), $this->getAuthService()->getIdentity() );
if ($ticketSystem) {
return $this->redirect()->toRoute( 'zfc-ticketsystem' );
}
}
$view = new ViewModel( array( 'form' => $form ) );
$view->setTemplate( 'zfc-ticket-system/new' );

return $view;
}

public function viewAction()
{
$ticketId = $this->params()->fromRoute('id');
$ticketSubject = $this->getTicketService()->getTicketSubject($this->getLoggedInUserId(), $ticketId);
// Fallback if not task
if(!$ticketSubject){
return $this->redirect()->toRoute('zfc-ticketsystem');
}

$form = $this->getTicketService()->getTicketSystemEntryForm();

$request = $this->getRequest();
if($request->isPost()){
$ticketSubject->setType(TicketSubject::TypeNew);
$ticketSystem = $this->getTicketService()->newEntry($this->params()->fromPost(), $this->getAuthService()->getIdentity(), $ticketSubject);
if($ticketSystem){
return $this->redirect()->toRoute('zfc-ticketsystem', array('id' => $ticketId, 'action' => 'view'));
}
}

$entry = $ticketSubject->getTicketEntry();

$view = new ViewModel(array(
'form' => $form,
'ticket' => $ticketSubject,
'entry' => $entry
));
$view->setTemplate('zfc-ticket-system/view');

return $view;
}
$ticketId = $this->params()->fromRoute( 'id' );
$ticketSubject = $this->getTicketService()->getTicketSubject( $this->getLoggedInUserId(), $ticketId );
// Fallback if not task
if (!$ticketSubject) {
return $this->redirect()->toRoute( 'zfc-ticketsystem' );
}

$form = $this->getTicketService()->getTicketSystemEntryForm();

$request = $this->getRequest();
if ($request->isPost()) {
$ticketSubject->setType( TicketSubject::TYPE_NEW );
$ticketSystem = $this->getTicketService()->newEntry( $this->params()->fromPost(), $this->getAuthService()->getIdentity(),
$ticketSubject );
if ($ticketSystem) {
return $this->redirect()->toRoute( 'zfc-ticketsystem', array( 'id' => $ticketId, 'action' => 'view' ) );
}
}

$entry = $ticketSubject->getTicketEntry();

$view = new ViewModel( array(
'form' => $form,
'ticket' => $ticketSubject,
'entry' => $entry
) );
$view->setTemplate( 'zfc-ticket-system/view' );

return $view;
}

/**
* @return int
Expand Down
Loading

0 comments on commit 929ef68

Please sign in to comment.