Skip to content

Commit

Permalink
Lots of work for ZF2beta4 changes. (still broke)
Browse files Browse the repository at this point in the history
  • Loading branch information
valorin committed May 24, 2012
1 parent d4308e7 commit 80ec6b4
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 173 deletions.
16 changes: 8 additions & 8 deletions config/autoload/local.php
Expand Up @@ -11,21 +11,21 @@
* credentials from accidentally being comitted into version control.
*/
return array(
'di' => array(
'instance' => array(
'Zend\Db\Adapter\Adapter' => array(
'parameters' => array(
'driver' => array(
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => function ($sm) {
return new Zend\Db\Adapter\Adapter(
array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=wyoa;hostname=localhost',
'username' => 'wyoa',
'password' => 'Lu2joh0sohghaiM9',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
),
),
)
);
},
),
),
);
16 changes: 8 additions & 8 deletions config/autoload/local.php.dist
Expand Up @@ -12,21 +12,21 @@
*/

return array(
'di' => array(
'instance' => array(
'Zend\Db\Adapter\Adapter' => array(
'parameters' => array(
'driver' => array(
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => function ($sm) {
return new Zend\Db\Adapter\Adapter(
array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=wyoa;hostname=localhost',
'username' => 'wyoa',
'password' => 'PASSWORD',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
),
),
)
);
},
),
),
);
14 changes: 7 additions & 7 deletions module/Application/view/layout/layout.phtml
Expand Up @@ -38,16 +38,16 @@ echo $this->doctype()."\n";
<?php echo $this->content; ?>
</div><div class='extras'>
<aside class='history'>
<?= $this->history((isset($oPage) ? $oPage : null)); ?>
<?= $this->history((isset($page) ? $page : null)); ?>
</aside><aside class='page-info'>
<h3>Page Information</h3>
<?php if (isset($oPage)): ?>
<?php if (isset($page)): ?>
<ul>
<li>Page #<?php echo $oPage->id; ?></li>
<li>Visits: <?php echo $oPage->visits; ?></li>
<li>Created: <?php echo $oPage->created; ?></li>
<li>Created by: <?php echo $oPage->user_id; ?></li>
<li>Updated: <?php echo $oPage->updated; ?></li>
<li>Page #<?php echo $page->id; ?></li>
<li>Visits: <?php echo $page->visits; ?></li>
<li>Created: <?php echo $page->created; ?></li>
<li>Created by: <?php echo $page->user_id; ?></li>
<li>Updated: <?php echo $page->updated; ?></li>
<li>Updated by: </li>
<!-- <li><a href='#edit'>Edit Page</a></li> -->
</ul>
Expand Down
58 changes: 58 additions & 0 deletions module/Story/Module.php
Expand Up @@ -13,6 +13,64 @@
*/
class Module
{
public function getServiceConfiguration()
{
return array(
'factories' => array(
'PageVersionTable' => function ($sm) {
$class = new Model\PageVersionTable($sm->get('DbAdapter'));
return $class;
},
'ChoiceTable' => function ($sm) {
$class = new Model\ChoiceTable(
$sm->get('DbAdapter'),
new Model\Choice($sm->get('DbAdapter'))
);
return $class;
},
'PageTable' => function ($sm) {
$page = new Model\Page(
$sm->get('DbAdapter'), $sm->get('ChoiceTable'),
$sm->get('PageVersionTable')
);
$class = new Model\PageTable($sm->get('DbAdapter'), $page);
return $class;
},
'HistoryManager' => function ($sm) {
$class = new Model\HistoryManager(
$sm->get('PageTable'), $sm->get('ChoiceTable')
);
return $class;
},
'Story\View\Helper\Special' => function ($sm) {
$class = new View\Helper\Special;
$class->setDir(__DIR__ .'/view/story/special');
return $class;
},
'Story\View\Helper\History' => function ($sm) {
$class = new View\Helper\History;
$class->setHistoryManager($sm->get('HistoryManager'));
return $class;
},
/*
'PageController' => function ($sm) {
$class = new Controller\PageController();
$class->setPageTable($sm->get('PageTable'));
$class->setHistoryManager($sm->get('HistoryManager'));
return $class;
},
'ChoiceController' => function ($sm) {
$class = new Controller\ChoiceController();
$class->setChoiceTable($sm->get('ChoiceTable'));
$class->setHistoryManager($sm->get('HistoryManager'));
return $class;
},
*/
),
);
}


public function getAutoloaderConfig()
{
return array(
Expand Down
96 changes: 20 additions & 76 deletions module/Story/config/module.config.php
@@ -1,64 +1,25 @@
<?php
return array(
'di' => array(
'instance' => array(
'Story\Controller\PageController' => array(
'parameters' => array(
'pageTable' => 'Story\Model\PageTable',
'historyManager' => 'Story\Model\HistoryManager',
),
),
'Story\Controller\ChoiceController' => Array(
'parameters' => Array(
'choiceTable' => 'Story\Model\ChoiceTable',
'historyManager' => 'Story\Model\HistoryManager',
),
),
'Story\Model\HistoryManager' => Array(
'parameters' => Array(
'pageTable' => 'Story\Model\PageTable',
'choiceTable' => 'Story\Model\ChoiceTable',
),
),
'Story\Model\PageVersionTable' => array(
'parameters' => array(
'adapter' => 'Zend\Db\Adapter\Adapter',
),
),
'Story\Model\ChoiceTable' => array(
'parameters' => array(
'adapter' => 'Zend\Db\Adapter\Adapter',
'choice' => 'Story\Model\Choice',
),
),
'Story\Model\Choice' => Array(
'parameters' => Array(
'adapter' => 'Zend\Db\Adapter\Adapter',
),
),
'Story\Model\PageTable' => array(
'parameters' => array(
'adapter' => 'Zend\Db\Adapter\Adapter',
'page' => 'Story\Model\Page',
),
),
'Story\Model\Page' => Array(
'parameters' => Array(
'adapter' => 'Zend\Db\Adapter\Adapter',
'pageVersionTable' => 'Story\Model\PageVersionTable',
'choiceTable' => 'Story\Model\ChoiceTable',
),
),
'Story\View\Helper\Special' => Array(
'parameters' => Array(
'sDir' => __DIR__ .'/../view/story/special',
),
),
'Story\View\Helper\History' => Array(
'parameters' => Array(
'historyManager' => 'Story\Model\HistoryManager',
),
),
'service_manager' => array(
'aliases' => array(
'DbAdapter' => 'Zend\Db\Adapter\Adapter',
),
),
'controller' => array(
'classes' => array(
'page' => 'Story\Controller\PageController',
'choice' => 'Story\Controller\ChoiceController',
),
),
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
'helper_map' => array(
'special' => 'Story\View\Helper\Special',
'page' => 'Story\View\Helper\Page',
'chance' => 'Story\View\Helper\Chance',
'history' => 'Story\View\Helper\History',
),
),
'router' => array(
Expand Down Expand Up @@ -107,21 +68,4 @@
),
),
),
'controller' => array(
'classes' => array(
'page' => 'Story\Controller\PageController',
'choice' => 'Story\Controller\ChoiceController',
),
),
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
'helper_map' => array(
'special' => 'Story\View\Helper\Special',
'page' => 'Story\View\Helper\Page',
'chance' => 'Story\View\Helper\Chance',
'history' => 'Story\View\Helper\History',
),
),
);
63 changes: 48 additions & 15 deletions module/Story/src/Story/Controller/PageController.php
Expand Up @@ -19,14 +19,14 @@
class PageController extends ActionController
{
/**
* @var Story\Model\PageTable
* @var PageTable
*/
protected $_pageTable;
protected $pageTable;

/**
* @var HistoryManager
*/
protected $_historyManager;
protected $historyManager;


/**
Expand All @@ -38,16 +38,16 @@ public function indexAction()
/**
* Retrieve page id
*/
$nPage = $this->getEvent()->getRouteMatch()->getParam('id', 1);
$page = $this->getEvent()->getRouteMatch()->getParam('id', 1);
$choice = $this->getEvent()->getRouteMatch()->getParam('choice', null);


/**
* Load Page
*/
$oPage = $this->_pageTable->get($nPage);
$page = $this->getPageTable()->get($page);

if (!$oPage) {
if (!$page) {
return Array();
}

Expand All @@ -56,21 +56,21 @@ public function indexAction()
* Increment Visits Counter
* TODO: Add History record
*/
//$oPage->incrementVisits();
//$page->incrementVisits();


/**
* Add to History Manager
*/
$this->_historyManager->addPage($oPage, $choice);
$this->getHistoryManager()->addPage($page, $choice);


/**
* Return page to layout and view
*/
$this->layout()->oPage = $oPage;
$this->layout()->page = $page;

return Array('oPage' => $oPage);
return Array('page' => $page);
}


Expand All @@ -85,27 +85,60 @@ public function newAction()


/**
* Inject PageTable Class
* Get the PageTable class
*
* @param PageTable $pageTable
* @return PageTable
*/
public function getPageTable()
{
if (is_null($this->pageTable)) {
$this->pageTable = $this->getServiceLocator()->get("PageTable");
}

return $this->pageTable;
}


/**
* Set the PageTable class
*
* @param PageTable $pageTable
* @return PageController
*/
public function setPageTable(PageTable $pageTable)
{
$this->_pageTable = $pageTable;
$this->pageTable = $pageTable;

return $this;
}


/**
* Get the HistoryManager class
*
* @return HistoryManager
*/
public function getHistoryManager()
{
if (is_null($this->historyManager)) {
$this->historyManager = $this->getServiceLocator()->get(
"HistoryManager"
);
}

return $this->historyManager;
}


/**
* Set the HistoryManager class
*
* @param HistoryManager $historyManager History Manager class
* @param HistoryManager $historyManager
* @return PageController
*/
public function setHistoryManager(HistoryManager $historyManager)
{
$this->_historyManager = $historyManager;
$this->historyManager = $historyManager;

return $this;
}
Expand Down

0 comments on commit 80ec6b4

Please sign in to comment.