From c2fbcd9fb9ea58b40e23633f4da48eb1be09a5d0 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Mon, 4 May 2009 10:24:33 +0200 Subject: [PATCH] Fix action handling. --- koward/lib/Koward/Controller/ObjectController.php | 35 +++++++++++++---------- koward/lib/Koward/Form/Actions.php | 7 +++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/koward/lib/Koward/Controller/ObjectController.php b/koward/lib/Koward/Controller/ObjectController.php index ef3b5852e..6fe075244 100644 --- a/koward/lib/Koward/Controller/ObjectController.php +++ b/koward/lib/Koward/Controller/ObjectController.php @@ -151,21 +151,10 @@ class ObjectController extends Koward_Controller_Application $this->allowEdit = $this->koward->hasAccess('object/edit/' . $this->object_type, Koward::PERM_EDIT); - $actions = $this->object->getActions(); - if (!empty($actions)) { - $buttons = array(); - foreach ($actions as $action) { - if (isset($this->koward->objects[$this->object_type]['actions'][$action]) - && $this->koward->hasAccess('object/action/' . $this->object_type . '/' . $action, - Koward::PERM_EDIT)) { - $buttons[] = $this->koward->objects[$this->object_type]['actions'][$action]; - } - } - } - + $buttons = $this->_getButtons($this->object, $this->object_type); if (!empty($buttons)) { try { - $this->actions = new Koward_Form_Actions($buttons); + $this->actions = new Koward_Form_Actions($this->object, $buttons); $this->post = $this->urlFor(array('controller' => 'object', 'action' => 'view', @@ -176,8 +165,8 @@ class ObjectController extends Koward_Controller_Application /** Reload the object */ $this->object = $this->koward->getObject($this->params->id); - $actions = $this->object->getActions(); - $this->actions = new Koward_Form_Actions($this->object); + $buttons = $this->_getButtons($this->object, $this->object_type); + $this->actions = new Koward_Form_Actions($this->object, $buttons); } } catch (Exception $e) { $this->koward->notification->push($e->getMessage(), 'horde.error'); @@ -204,6 +193,22 @@ class ObjectController extends Koward_Controller_Application $this->render(); } + private function _getButtons(&$object, $type) + { + $actions = $object->getActions(); + if (!empty($actions)) { + $buttons = array(); + foreach ($actions as $action) { + if (isset($this->koward->objects[$type]['actions'][$action]) + && $this->koward->hasAccess('object/action/' . $type . '/' . $action, + Koward::PERM_EDIT)) { + $buttons[] = $this->koward->objects[$type]['actions'][$action]; + } + } + } + return $buttons; + } + public function add() { $this->object = null; diff --git a/koward/lib/Koward/Form/Actions.php b/koward/lib/Koward/Form/Actions.php index 69db861f0..eb081ed02 100644 --- a/koward/lib/Koward/Form/Actions.php +++ b/koward/lib/Koward/Form/Actions.php @@ -15,7 +15,7 @@ class Koward_Form_Actions extends Horde_Form { */ protected $koward; - public function __construct($buttons) + public function __construct(&$object, $buttons) { $this->koward = &Koward::singleton(); @@ -23,6 +23,8 @@ class Koward_Form_Actions extends Horde_Form { $this->setTitle(_("Object actions")); + $this->object = $object; + if (!empty($buttons)) { $this->setButtons($buttons); } @@ -34,7 +36,8 @@ class Koward_Form_Actions extends Horde_Form { $submit = Util::getFormData('submitbutton'); if (!empty($submit)) { - foreach ($this->koward->objects[$this->type]['actions'] as $action => $label) { + $type = $this->koward->getType($this->object); + foreach ($this->koward->objects[$type]['actions'] as $action => $label) { if ($submit == $label) { $this->object->$action(); } -- 2.11.0