Commit 963f4156 by pupi1985

Wrap action calls into own method to allow extension

parent 89df11c3
......@@ -645,7 +645,7 @@ function qa_message_html_defaults()
/**
* Return $voteview parameter to pass to qa_post_html_fields() in /qa-include/app/format.php.
* @param $postorbasetype The post, or for compatibility just a basetype, i.e. 'Q', 'A' or 'C'
* @param string|array $postorbasetype The post, or for compatibility just a basetype, i.e. 'Q', 'A' or 'C'
* @param bool $full Whether full post is shown
* @param bool $enabledif Whether to do checks for voting buttons (i.e. will always disable voting if false)
* @return bool|string Possible values:
......
......@@ -193,7 +193,7 @@ function qa_get_request_content()
qa_set_template($route->getId());
$controllerClass = $route->getController();
$ctrl = new $controllerClass();
$qa_content = call_user_func_array(array($ctrl, $route->getFunction()), $route->getParameters());
$qa_content = $ctrl->executeAction($route->getAction(), $route->getParameters());
} elseif (isset($routing[$requestlower])) {
qa_set_template($firstlower);
......
......@@ -21,4 +21,17 @@ namespace Q2A\Controllers;
abstract class BaseController
{
// TODO: constructor taking Database class parameter
/**
* Execute the given action with the given parameters on this controller.
*
* @param string $action Action to execute
* @param array $parameters Parameters to send to the action
*
* @return mixed
*/
public function executeAction($action, $parameters)
{
return call_user_func_array(array($this, $action), $parameters);
}
}
......@@ -143,7 +143,7 @@ class UserMessages extends \Q2A\Controllers\BaseController
// Sub menu for navigation in user pages
$ismyuser = isset($loginuserid) && $loginuserid == (QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid']);
$ismyuser = isset($loginuserid) && $loginuserid == $useraccount['userid'];
$qa_content['navigation']['sub'] = qa_user_sub_navigation($handle, 'wall', $ismyuser);
......
......@@ -33,18 +33,18 @@ class Route
private $controller;
/** @var string */
private $function;
private $action;
/** @var array */
private $parameters;
public function __construct($id = null, $httpMethod = null, $routePath = null, $controller = null, $function = null)
public function __construct($id = null, $httpMethod = null, $routePath = null, $controller = null, $action = null)
{
$this->id = $id;
$this->setHttpMethod($httpMethod);
$this->routePath = $routePath;
$this->controller = $controller;
$this->function = $function;
$this->action = $action;
$this->parameters = array();
}
......@@ -126,17 +126,17 @@ class Route
/**
* @return string
*/
public function getFunction()
public function getAction()
{
return $this->function;
return $this->action;
}
/**
* @param string $function
* @param string $action
*/
public function setFunction($function)
public function setAction($action)
{
$this->function = $function;
$this->action = $action;
}
/**
......
Markdown is supported
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