-
Notifications
You must be signed in to change notification settings - Fork 158
Feature/modules from user #444
Changes from all commits
49e2028
172b11c
6527a77
f75e966
0d31b7d
197eafc
86d56b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
'controllers' => [ | ||
'factories' => [ | ||
Controller\IndexController::class => Controller\IndexControllerFactory::class, | ||
Controller\UserController::class => Controller\UserControllerFactory::class, | ||
], | ||
], | ||
'router' => [ | ||
|
@@ -25,6 +26,19 @@ | |
], | ||
], | ||
], | ||
'modules-for-user' => [ | ||
'type' => 'Segment', | ||
'options' => [ | ||
'route' => '/user/:owner', | ||
'constrains' => [ | ||
'owner' => '[a-zA-Z][a-zA-Z0-9_-]*', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit restrictive IMO. Not sure what github's username limitations are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mm I don't find a github's username restriction There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
so we would end up like this ^^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😕 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second match is not really needed ( see http://regexper.com/#%2F^%28%3F!.*--.*%29%28[a-zA-Z0-9][a-zA-Z0-9-]%2B%3F[a-zA-Z0-9]%29%24|%28^[a-zA-Z0-9]%2B%24%29%2F ) This is sufficient: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without the second match group you wouldn't catch usernames with les then 3 characters 😃 |
||
], | ||
'defaults' => [ | ||
'controller' => Controller\UserController::class, | ||
'action' => 'modulesForUser', | ||
], | ||
], | ||
], | ||
'zf-module' => [ | ||
'type' => 'Segment', | ||
'options' => [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
namespace ZfModule\Controller; | ||
|
||
use Zend\Mvc\Controller\AbstractActionController; | ||
use Zend\View\Model\ViewModel; | ||
use ZfModule\Mapper; | ||
|
||
class UserController extends AbstractActionController | ||
{ | ||
/** | ||
* @var Mapper\Module | ||
*/ | ||
private $moduleMapper; | ||
|
||
/** | ||
* @param Mapper\Module $moduleMapper | ||
*/ | ||
public function __construct(Mapper\Module $moduleMapper) | ||
{ | ||
$this->moduleMapper = $moduleMapper; | ||
} | ||
|
||
public function modulesForUserAction() | ||
{ | ||
$params = $this->params(); | ||
$query = $params->fromQuery('query', null); | ||
$page = (int) $params->fromQuery('page', 1); | ||
$owner = $params->fromRoute('owner'); | ||
|
||
$modules = $this->moduleMapper->pagination($page, 10, $owner, 'created_at', 'DESC'); | ||
|
||
return new ViewModel([ | ||
'modules' => $modules, | ||
'query' => $query, | ||
]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace ZfModule\Controller; | ||
|
||
use Zend\Mvc\Controller\ControllerManager; | ||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
use ZfModule\Mapper; | ||
use ZfModule\Service; | ||
|
||
class UserControllerFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @param ServiceLocatorInterface $controllerManager | ||
* @return IndexController | ||
*/ | ||
public function createService(ServiceLocatorInterface $controllerManager) | ||
{ | ||
/* @var ControllerManager $controllerManager */ | ||
$serviceManager = $controllerManager->getServiceLocator(); | ||
|
||
/* @var Mapper\Module $moduleMapper */ | ||
$moduleMapper = $serviceManager->get(Mapper\Module::class); | ||
|
||
/* @var Service\Module $moduleService */ | ||
$moduleService = $serviceManager->get(Service\Module::class); | ||
|
||
return new UserController( | ||
$moduleMapper, | ||
$moduleService | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace ZfModuleTest\Integration\Controller; | ||
|
||
use ApplicationTest\Integration\Util\Bootstrap; | ||
use Zend\Paginator; | ||
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; | ||
use ZfModule\Controller; | ||
use ZfModule\Mapper; | ||
|
||
class UserControllerTest extends AbstractHttpControllerTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setApplicationConfig(Bootstrap::getConfig()); | ||
} | ||
|
||
public function testUserPageCanBeAccessed() | ||
{ | ||
$moduleMapper = $this->getMockBuilder(Mapper\Module::class)->getMock(); | ||
|
||
$moduleMapper | ||
->expects($this->once()) | ||
->method('pagination') | ||
->with( | ||
$this->equalTo(1), | ||
$this->equalTo(10), | ||
$this->equalTo("gianarb"), | ||
$this->equalTo('created_at'), | ||
$this->equalTo('DESC') | ||
) | ||
->willReturn(new Paginator\Paginator(new Paginator\Adapter\Null())) | ||
; | ||
|
||
$this->getApplicationServiceLocator() | ||
->setAllowOverride(true) | ||
->setService( | ||
Mapper\Module::class, | ||
$moduleMapper | ||
) | ||
; | ||
|
||
$this->dispatch('/user/gianarb'); | ||
|
||
$this->assertControllerName(Controller\UserController::class); | ||
$this->assertActionName('modulesForUser'); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php $this->layout()->withLargeHeader = false; ?> | ||
|
||
<div class="col-xs-12 col-md-8"> | ||
<?php if (count($this->modules) >= 1): ?> | ||
<?php foreach ($this->modules as $module): ?> | ||
<?php /* @var ZfModule\Entity\Module $module */ ?> | ||
<div class="module-row"> | ||
<div class="module-info"> | ||
<div class="row"> | ||
<div class="hidden-xs col-sm-2"> | ||
<img src="<?php echo $this->escapeHtmlAttr($module->getPhotoUrl()) ?>" alt="<?php echo $this->escapeHtmlAttr($module->getOwner()) ?>" class="thumbnail img-responsive"> | ||
</div> | ||
<div class="col-xs-7 col-sm-6"> | ||
<p> | ||
<a href="<?php echo $this->url('view-module', ['vendor' => $this->escapeUrl($module->getOwner()), 'module' => $this->escapeUrl($module->getName())]) ?>"> | ||
<strong><?php echo $this->escapeHtml($module->getOwner()); ?>/<?php echo $this->escapeHtml($module->getName()); ?></strong> | ||
</a> | ||
</p> | ||
<p><span class="zf-green">Created:</span> <?php echo $this->dateFormat($module->getCreatedAtDateTime(), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); ?></p> | ||
</div> | ||
<div class="col-xs-4"> | ||
<a target="_blank" href="<?php echo $this->escapeHtmlAttr($module->getUrl()) ?>">Show module on GitHub</a> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="module-description"> | ||
<p><?php echo $this->escapeHtml($module->getDescription()) ?></p> | ||
</div> | ||
</div> | ||
<?php endforeach; ?> | ||
<?php echo $this->paginationControl($this->modules, 'Sliding', 'application/index/pagination', ['query' => $this->query]) ?> | ||
<?php endif; ?> | ||
</div> | ||
|
||
<div class="hidden-xs hidden-sm col-md-4"> | ||
<div class="sidebar"> | ||
<?php echo $this->newModule() ?> | ||
<?php echo $this->newUsers() ?> | ||
</div> | ||
</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ocramius I have wrote a new UserController
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!