Skip to content

Commit

Permalink
#211 - removed the CreateController along with links and unit tests, …
Browse files Browse the repository at this point in the history
…and moved the logic to render the admin menu to the Controller parent class to reduce some duplication
  • Loading branch information
alphadevx committed Sep 2, 2015
1 parent 79f809e commit 9b9ef49
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 516 deletions.
13 changes: 9 additions & 4 deletions Alpha/Controller/ActiveRecordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Alpha\Util\Http\Response;
use Alpha\Util\Helper\Validator;
use Alpha\View\View;
use Alpha\View\ViewState;
use Alpha\Exception\IllegalArguementException;
use Alpha\Exception\ResourceNotFoundException;
use Alpha\Exception\ResourceNotAllowedException;
Expand Down Expand Up @@ -171,7 +172,7 @@ public function doGET($request)
}

// set up the title and meta details
if ($params['view'] == 'edit') {
if (isset($params['view']) && $params['view'] == 'edit') {
if (!isset($this->title)) {
$this->setTitle('Editing a '.$record->getFriendlyClassName());
}
Expand Down Expand Up @@ -201,7 +202,7 @@ public function doGET($request)
$body .= View::displayPageHead($this);
$body .= View::renderDeleteForm($request->getURI());

if ($params['view'] == 'edit') {
if (isset($params['view']) && $params['view'] == 'edit') {
$fields = array('formAction' => $this->request->getURI());
$body .= $view->editView();
} else {
Expand Down Expand Up @@ -565,18 +566,22 @@ public function doDELETE($request)
*/
public function after_displayPageHead_callback()
{
$body = parent::after_displayPageHead_callback();

// set the start point for the list pagination
if ($this->request->getParam('start') != null) {
$this->startPoint = $this->request->getParam('start');

$accept = $this->request->getAccept();

if ($accept == 'application/json') {
return '[';
$body .= '[';
}

return '';
$body .= '';
}

return $body;
}

/**
Expand Down
23 changes: 0 additions & 23 deletions Alpha/Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,27 +745,6 @@ public function during_displayPageHead_callback()
}
}

/**
* Use this callback to inject in the admin menu template fragment for admin users of
* the backend only.
*
* @since 1.2
*/
public function after_displayPageHead_callback()
{
$menu = '';

$config = ConfigProvider::getInstance();
$sessionProvider = $config->get('session.provider.name');
$session = SessionProviderFactory::getInstance($sessionProvider);

if ($session->get('currentUser') != null && ActiveRecord::isInstalled() && $session->get('currentUser')->inGroup('Admin') && mb_strpos($this->request->getURI(), '/tk/') !== false) {
$menu .= View::loadTemplateFragment('html', 'adminmenu.phtml', array());
}

return $menu;
}

/**
* Callback that inserts the CMS level header
*
Expand Down Expand Up @@ -947,8 +926,6 @@ private function setMode()

if ($this->request->getParam('act') == 'Alpha\Controller\ListController') {
$this->mode = 'read';
} elseif ($this->request->getParam('act') == 'Alpha\Controller\CreateController') {
$this->mode = 'create';
} elseif ($this->request->getParam('act') == 'Alpha\Controller\EditController') {
$this->mode = 'edit';
} else {
Expand Down
12 changes: 0 additions & 12 deletions Alpha/Controller/CacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,6 @@ public function doPOST($request)

return new Response(200, $body, array('Content-Type' => 'text/html'));
}

/**
* Use this callback to inject in the admin menu template fragment
*
* @since 1.2
*/
public function after_displayPageHead_callback()
{
$menu = View::loadTemplateFragment('html', 'adminmenu.phtml', array());

return $menu;
}
}

?>
28 changes: 26 additions & 2 deletions Alpha/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Alpha\Exception\FileNotFoundException;
use Alpha\Controller\Front\FrontController;
use Alpha\View\View;
use Alpha\View\ViewState;
use ReflectionClass;
use Exception;

Expand Down Expand Up @@ -1437,10 +1438,33 @@ public function getRequest()
*/
public function setRequest($request)
{
if ($request instanceof Request)
if ($request instanceof Request) {
$this->request = $request;
else
} else {
throw new IllegalArguementException('Invalid request object ['.print_r($request, true).'] passed');
}
}

/**
* Use this callback to inject in the admin menu template fragment
*
* @return string
* @since 1.2
*/
public function after_displayPageHead_callback()
{
$accept = $this->request->getAccept();

if ($accept != 'application/json') {
$viewState = ViewState::getInstance();
if ($viewState->get('renderAdminMenu') === true) {
$menu = View::loadTemplateFragment('html', 'adminmenu.phtml', array());

return $menu;
}
} else {
return '';
}
}
}

Expand Down
Loading

0 comments on commit 9b9ef49

Please sign in to comment.