Permalink
Browse files

Working module following functional testing

- both view helpers had an incorrect suffix
- added missing imports throughout
- fixed Where usage in table gateway
- fixed how username is retrieved in controller
- fixed how identifier is retrieved in controller
- fixed identifier regex for status route
- added validation group to form
- fixed markup and layout as needed
- added missing "register" view script
- fixed invalid regex options in input filter
  • Loading branch information...
weierophinney committed Jun 1, 2012
1 parent 886c29b commit a44db708ee73aa18404bd8e52c90cf6b24b8821b
View
@@ -8,7 +8,9 @@ public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
- __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
+ 'namespaces' => array(
+ __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
+ ),
),
);
}
View
@@ -48,7 +48,7 @@
'options' => array(
'route' => '/status/:identifier',
'constraints' => array(
- 'identifier' => '[a-zA-Z][0-9]{8}',
+ 'identifier' => '[a-zA-Z0-9]{8}',
),
'defaults' => array(
'action' => 'status',
@@ -74,4 +74,9 @@
'phly-peep-table' => 'PhlyPeep\Service\PeepTableFactory',
),
),
+ 'view_manager' => array(
+ 'template_path_stack' => array(
+ 'phly-peep' => __DIR__ . '/../view',
+ ),
+ ),
);
@@ -50,16 +50,19 @@ public function submitAction()
}
$peep = new Model\PeepEntity();
- $peep->setUsername($identity->getUsername());
- $peep->setEmail($identity->getEmail());
- $peep->setDisplayName($identity->getDisplayName());
-
$form = new Model\PeepForm();
$form->bind($peep);
- $request = $this->getRequest();
- $post = $request->post();
- $form->setData($post->toArray());
+ $request = $this->getRequest();
+ $data = $request->post();
+ $data['username'] = $identity->getUsername();
+ $data['email'] = $identity->getEmail();
+ $data['display_name'] = $identity->getDisplayName();
+ $data['timestamp'] = $_SERVER['REQUEST_TIME'];
+ $form->setData($data);
+ $form->setValidationGroup(
+ 'peep_text', 'username', 'email', 'display_name', 'timestamp', 'secure'
+ );
if (!$form->isValid()) {
$viewModel = new ViewModel(array(
@@ -71,17 +74,21 @@ public function submitAction()
$this->service->insertPeep($peep);
- return $this->redirect()->toRoute('phly-peep/user', array('user' => $identity->getUsername()));
+ return $this->redirect()->toRoute(
+ 'phly-peep/user',
+ array('username' => $identity->getUsername())
+ );
}
public function usernameAction()
{
- $request = $this->getRequest();
- $username = $request->query()->get('username', false);
+ $routeMatch = $this->getEvent()->getRouteMatch();
+ $username = $routeMatch->getParam('username', false);
if (!$username) {
return $this->redirect()->toRoute('phly-peep');
}
+ $request = $this->getRequest();
$page = $request->query()->get('page', 1);
return array(
@@ -92,8 +99,8 @@ public function usernameAction()
public function statusAction()
{
- $request = $this->getRequest();
- $identifier = $request->query()->get('identifier', false);
+ $routeMatch = $this->getEvent()->getRouteMatch();
+ $identifier = $routeMatch->getParam('identifier', false);
if (!$identifier) {
return $this->redirect()->toRoute('phly-peep');
}
@@ -94,7 +94,7 @@ public function getIdentifier()
if (null === $this->identifier) {
$username = $this->getUsername();
$timestamp = $this->getTimestamp();
- if ($username && $getTimestamp) {
+ if ($username && $timestamp) {
$this->setIdentifier(hash('crc32', $username . ':' . $timestamp));
}
}
@@ -18,7 +18,7 @@ public function __construct()
array(
'name' => 'Regex',
'options' => array(
- 'regex' => '/^[a-zA-Z0-9]{8}$/',
+ 'pattern' => '/^[a-zA-Z0-9]{8}$/',
),
),
),
@@ -34,7 +34,7 @@ public function __construct()
array(
'name' => 'Regex',
'options' => array(
- 'regex' => '/^[a-zA-Z0-9_]+$',
+ 'pattern' => '/^[a-zA-Z0-9_]+$/',
),
),
),
@@ -2,6 +2,8 @@
namespace PhlyPeep\Model;
+use Zend\Paginator\Paginator;
+
class PeepService
{
protected $pageSize = 20;
@@ -2,12 +2,16 @@
namespace PhlyPeep\Model;
+use SplObjectStorage;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
+use Zend\Db\Sql\Expression;
+use Zend\Db\Sql\Where;
use Zend\Db\TableGateway\AbstractTableGateway;
class PeepTable extends AbstractTableGateway
{
+ protected $peepPrototype;
protected $table = 'peep';
protected $tableName = 'peep';
@@ -40,8 +44,9 @@ public function fetchUserTimeline($user, $offset = 0, $limit = 20)
{
$select = $this->getSql()->select();
- $where = $select->where();
+ $where = new Where();
$where->equalTo('username', $user);
+ $select->where($where);
$select->offset($offset)
->limit($limit)
@@ -52,8 +57,9 @@ public function fetchUserTimeline($user, $offset = 0, $limit = 20)
public function fetchUserTimelineCount($user)
{
$select = $this->getCountSelect();
- $where = $select->where();
+ $where = new Where();
$where->equalTo('username', $user);
+ $select->where($where);
return $this->getCountFromSelect($select);
}
@@ -84,7 +90,7 @@ protected function getPeepsFromSelect($select)
{
$resultset = $this->selectWith($select);
$peeps = new SplObjectStorage();
- foreach ($resultSet as $row) {
+ foreach ($resultset as $row) {
$peep = $this->getPeepFromRow($row);
$peeps->attach($peep);
}
@@ -2,6 +2,8 @@
namespace PhlyPeep\View;
+use PhlyPeep\Model;
+use Zend\Authentication\AuthenticationService;
use Zend\View\Helper\AbstractHelper;
class PeepForm extends AbstractHelper
@@ -13,12 +15,16 @@ public function setAuthService(AuthenticationService $auth)
$this->auth = $auth;
}
- public function __invoke($form, $template = 'phly-peep/peep/form')
+ public function __invoke($form = null, $template = 'phly-peep/peep/form')
{
- if (!$this->auth || $this->auth->hasIdentity()) {
+ if (!$this->auth || !$this->auth->hasIdentity()) {
return $this->view->render('phly-peep/peep/register');
}
+ if (null === $form) {
+ $form = new Model\PeepForm();
+ }
+
return $this->view->render($template, array('form' => $form));
}
}
File renamed without changes.
@@ -9,7 +9,7 @@ $form = $this->form;
$form->setAttributes(array(
'method' => 'post',
'action' => $this->url('phly-peep/submit'),
- 'class' => 'well',
+ 'class' => 'well form-vertical',
));
$label = $this->plugin('form_label');
echo $this->form()->openTag($form);
@@ -23,6 +23,7 @@ if ($peepElement->getMessages()) {
}
echo $this->formInput($form->get('secure'));
?>
+<br />
<button type="submit" class="btn">Peep!</button>
<?php echo $this->form()->closeTag() ?>
</div>
@@ -3,7 +3,7 @@ $form = $this->form;
$form->setAttributes(array(
'method' => 'post',
'action' => $this->url('phly-peep/submit'),
- 'class' => 'well',
+ 'class' => 'well form-vertical',
));
$label = $this->plugin('form_label');
echo $this->form()->openTag($form);
@@ -14,5 +14,6 @@ echo $label->openTag() . $this->escape($peepElement->getAttribute('label')) . $l
echo $this->formTextarea($peepElement);
echo $this->formInput($form->get('secure'));
?>
+<br />
<button type="submit" class="btn">Peep!</button>
<?php echo $this->form()->closeTag() ?>
@@ -22,7 +22,7 @@ $url = $this->url('phly-peep/user', array('username' => $username));
<?php
$date = new DateTime();
$date->setTimestamp($peep->getTimestamp());
- $date->setTimezone('UTC');
+ $date->setTimezone(new DateTimezone('UTC'));
echo $date->format('h:i a - d M Y');
?>
</a>
@@ -0,0 +1 @@
+<p>You need to <a href="<?php echo $this->url('zfcuser') ?>">login or register to peep</a>!</p>

0 comments on commit a44db70

Please sign in to comment.