-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kyle Spraggs
committed
Jul 29, 2013
1 parent
c990753
commit c1b4a57
Showing
52 changed files
with
254 additions
and
31 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?php | ||
|
||
namespace SpiffyCrud\Controller; | ||
|
||
use SpiffyCrud\CrudManager; | ||
use Zend\Http\Response; | ||
use Zend\Mvc\Controller\AbstractActionController; | ||
use Zend\View\Model\ViewModel; | ||
|
||
abstract class AbstractCrud extends AbstractActionController | ||
{ | ||
/** | ||
* @var CrudManager | ||
*/ | ||
protected $crudManager; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
abstract public function getModelName(); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
abstract public function getReadRoute(); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
abstract public function getCreateRoute(); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
abstract public function getDeleteRoute(); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
abstract public function getUpdateRoute(); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function readAction() | ||
{ | ||
$manager = $this->getCrudManager(); | ||
$model = $manager->get($this->getModelName()); | ||
|
||
$viewModel = new ViewModel(array( | ||
'model' => $model, | ||
'name' => $this->getModelName(), | ||
'data' => $manager->findAll($this->getModelName()), | ||
'createRoute' => $this->getCreateRoute(), | ||
'updateRoute' => $this->getUpdateRoute(), | ||
'deleteRoute' => $this->getDeleteRoute(), | ||
)); | ||
$viewModel->setTemplate('spiffy-crud/controller/read'); | ||
return $viewModel; | ||
} | ||
|
||
/** | ||
* @return array|Response | ||
*/ | ||
public function createAction() | ||
{ | ||
$name = $this->getModelName(); | ||
$manager = $this->getCrudManager(); | ||
$model = $manager->get($name); | ||
$form = $manager->getForm($name); | ||
$prg = $this->prg(); | ||
|
||
if ($prg instanceof Response) { | ||
return $prg; | ||
} elseif (false !== $prg) { | ||
$form->setData($prg); | ||
|
||
if ($form->isValid()) { | ||
$this->getCrudManager()->persist($name, $form->getData()); | ||
return $this->redirect()->toRoute($this->getReadRoute()); | ||
} | ||
} | ||
|
||
$viewModel = new ViewModel(array( | ||
'model' => $model, | ||
'form' => $form, | ||
'name' => $name, | ||
'createRoute' => $this->getCreateRoute(), | ||
)); | ||
$viewModel->setTemplate('spiffy-crud/controller/create'); | ||
return $viewModel; | ||
} | ||
|
||
/** | ||
* @return array|Response | ||
*/ | ||
public function updateAction() | ||
{ | ||
$name = $this->getModelName(); | ||
$id = $this->params('id'); | ||
$manager = $this->getCrudManager(); | ||
$entity = $manager->find($name, $id); | ||
$form = $manager->getForm($name, $entity); | ||
$prg = $this->prg(); | ||
|
||
if ($prg instanceof Response) { | ||
return $prg; | ||
} elseif (false !== $prg) { | ||
$form->setData($prg); | ||
|
||
if ($form->isValid()) { | ||
$this->getCrudManager()->persist($name, $entity); | ||
return $this->redirect()->toRoute($this->getReadRoute()); | ||
} | ||
} | ||
|
||
$viewModel = new ViewModel(array( | ||
'entity' => $entity, | ||
'form' => $form, | ||
'name' => $name, | ||
'id' => $id, | ||
'updateRoute' => $this->getUpdateRoute(), | ||
)); | ||
$viewModel->setTemplate('spiffy-crud/controller/update'); | ||
return $viewModel; | ||
} | ||
|
||
/** | ||
* @return Response | ||
*/ | ||
public function deleteAction() | ||
{ | ||
$name = $this->getModelName(); | ||
$manager = $this->getCrudManager(); | ||
$entity = $manager->find($name, $this->params('id')); | ||
|
||
$manager->remove($name, $entity); | ||
return $this->redirect()->toRoute($this->getReadRoute()); | ||
} | ||
|
||
/** | ||
* @param \SpiffyCrud\CrudManager $crudManager | ||
* @return $this | ||
*/ | ||
public function setCrudManager($crudManager) | ||
{ | ||
$this->crudManager = $crudManager; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return \SpiffyCrud\CrudManager | ||
*/ | ||
public function getCrudManager() | ||
{ | ||
if (!$this->crudManager instanceof CrudManager) { | ||
$this->crudManager = $this->getServiceLocator()->get('SpiffyCrud\CrudManager'); | ||
} | ||
return $this->crudManager; | ||
} | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace SpiffyCrud\Model; | ||
|
||
class Model extends AbstractModel | ||
{ | ||
|
||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h1>Create</h1> | ||
|
||
<?php echo $this->partial( | ||
'spiffy-crud/crud/form', | ||
array( | ||
'form' => $form, | ||
'url' => $this->url($createRoute) | ||
) | ||
);?> | ||
<a href="<?php echo $this->url('spiffy_crud/details', array('name' => $name)); ?>">Back to List</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h1>Details for <?php echo $model->getDisplayName(); ?></h1> | ||
|
||
<p> | ||
<a href="<?php echo $this->url($createRoute); ?>">Create</a> | ||
</p> | ||
|
||
<?php echo $this->spiffycrud($name, $data); ?> | ||
|
||
<p style="clear:left;"> | ||
<a href="<?php echo $this->url($createRoute); ?>">Create</a> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<h1>Update</h1> | ||
|
||
<?php echo $this->partial( | ||
'spiffy-crud/crud/form', | ||
array( | ||
'form' => $form, | ||
'url' => $this->url($updateRoute, array('id' => $id)) | ||
) | ||
);?> |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.