Skip to content
Snippets Groups Projects
Commit d337edad authored by llaffont's avatar llaffont
Browse files

Scaffolding de l'action edit / OPDS controller

parent c92ab31c
Branches
Tags
No related merge requests found
......@@ -20,32 +20,36 @@
*/
class Admin_OpdsController extends ZendAfi_Controller_Action {
protected $_ressource_definition = array(
'model' => 'Class_OpdsCatalog',
'messages' => array('successful_add' => 'Catalogue %s ajouté',
'successful_save' => 'Catalogue %s sauvegardé',
'successful_delete' => 'Catalogue %s supprimé'),
'actions' => array('index'),
'display_groups' => array('categorie' => array('legend' => 'Catalogue',
'elements' => array(
'libelle' => array('element' => 'text',
'options' => array('label' => 'Libellé *',
'size' => 30,
'required' => true,
'allowEmpty' => false)),
'url' => array('element' => 'text',
'options' => array('label' => 'Url *',
'size' => '90',
'required' => true,
'allowEmpty' => false,
'validators' => array('url'))
)
)
)
)
);
public function getRessourceDefinitions() {
return array(
'model' => 'Class_OpdsCatalog',
'messages' => array('successful_add' => 'Catalogue %s ajouté',
'successful_save' => 'Catalogue %s sauvegardé',
'successful_delete' => 'Catalogue %s supprimé'),
'actions' => array('edit' => array('title' => 'Modifier un catalogue OPDS')),
'display_groups' => array('categorie' => array('legend' => 'Catalogue',
'elements' => array(
'libelle' => array('element' => 'text',
'options' => array('label' => 'Libellé *',
'size' => 30,
'required' => true,
'allowEmpty' => false)),
'url' => array('element' => 'text',
'options' => array('label' => 'Url *',
'size' => '90',
'required' => true,
'allowEmpty' => false,
'validators' => array('url'))
)
)
)
)
);
}
public function init() {
parent::init();
......@@ -63,43 +67,13 @@ class Admin_OpdsController extends ZendAfi_Controller_Action {
$this->view->titre = 'Ajouter un catalogue OPDS';
$model = Class_OpdsCatalog::getLoader()->newInstance();
if ($this->_setupCatalogFormAndSave($model)) {
if ($this->_setupFormAndSave($model)) {
$this->_helper->notify(sprintf('Catalogue "%s" ajouté', $model->getLibelle()));
$this->_redirect('/admin/opds/edit/id/'.$model->getId());
}
}
public function editAction() {
$this->view->titre = 'Modifier un catalogue OPDS';
if (!$model = Class_OpdsCatalog::getLoader()->find($this->_getParam('id'))) {
$this->_redirect('/admin/opds/index');
return;
}
if ($this->_setupCatalogFormAndSave($model)) {
$this->_helper->notify(sprintf('Catalogue "%s" sauvegardé', $model->getLibelle()));
$this->_redirect('/admin/opds/edit/id/' . $model->getId());
}
}
protected function _setupCatalogFormAndSave($catalog) {
$form = $this->_getForm($catalog);
$this->view->form = $form;
if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) {
return $catalog
->updateAttributes($this->_request->getPost())
->save();
}
return false;
}
public function browseAction() {
if (!$catalog = Class_OpdsCatalog::getLoader()->find($this->_getParam('id'))) {
$this->_redirect('/admin/opds/index');
......
......@@ -23,7 +23,7 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
protected $_definitions;
public function init() {
$this->_definitions = new ZendAfi_Controller_Action_RessourceDefinitions($this->_ressource_definition);
$this->_definitions = new ZendAfi_Controller_Action_RessourceDefinitions($this->getRessourceDefinitions());
}
......@@ -32,10 +32,49 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
$model->delete();
$this->_helper->notify($this->_definitions->successfulDeleteMessage($model));
}
$this->_redirectToIndex();
}
public function editAction() {
$this->view->titre = $this->_definitions->editActionTitle();
if (!$model = $this->_definitions->find($this->_getParam('id'))) {
$this->_redirectToIndex();
return;
}
if ($this->_setupFormAndSave($model)) {
$this->_helper->notify($this->_definitions->successfulSaveMessage($model));
$this->_redirectToEdit($model);
}
}
protected function _redirectToIndex() {
$this->_redirect('/admin/'.$this->_request->getControllerName().'/index');
}
protected function _redirectToEdit($model) {
$this->_redirect('/admin/'.$this->_request->getControllerName().'/edit/id/'.$model->getId());
}
protected function _setupFormAndSave($model) {
$form = $this->_getForm($model);
$this->view->form = $form;
if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) {
return $model
->updateAttributes($this->_request->getPost())
->save();
}
return false;
}
/**
* Formulaire d'édition des catalogues
* @param Class_OpdsCatalog $model
......
......@@ -43,6 +43,17 @@ class ZendAfi_Controller_Action_RessourceDefinitions {
}
public function successfulSaveMessage($model) {
return sprintf($this->_definitions['messages']['successful_save'],
$model->getLibelle());
}
public function editActionTitle() {
return $this->_definitions['actions']['edit']['title'];
}
public function getModelName() {
return $this->_definitions['model'];
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment