Skip to content
This repository was archived by the owner on May 1, 2019. It is now read-only.

Commit 0e3a204

Browse files
committed
Merge pull request #444 from gianarb/feature/modules-from-user
Feature/modules from user
2 parents 3e3c202 + 86d56b3 commit 0e3a204

File tree

7 files changed

+177
-2
lines changed

7 files changed

+177
-2
lines changed

module/User/view/user/helper/new-users.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div class="col-md-12">
1111
<?php endif; ?>
1212
<div class="col-md-3">
13-
<a href="https://github.com/<?php echo $this->escapeHtmlAttr($user->getUserName()); ?>" data-delay="0" rel="tooltip" title="<?php echo $this->escapeHtmlAttr($user->getUserName()); ?>" class="thumbnail">
13+
<a href="<?php echo $this->url('modules-for-user', ['owner' => $user->getUserName()]); ?>" data-delay="0" rel="tooltip" title="<?php echo $this->escapeHtmlAttr($user->getUserName()); ?>" class="thumbnail">
1414
<img src="<?php echo $this->escapeHtmlAttr($user->getPhotoUrl()) ?>" alt="<?php echo $this->escapeHtmlAttr($user->getUsername()) ?>" class="img-responsive">
1515
</a>
1616
</div>

module/ZfModule/config/module.config.php

+14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'controllers' => [
1212
'factories' => [
1313
Controller\IndexController::class => Controller\IndexControllerFactory::class,
14+
Controller\UserController::class => Controller\UserControllerFactory::class,
1415
],
1516
],
1617
'router' => [
@@ -25,6 +26,19 @@
2526
],
2627
],
2728
],
29+
'modules-for-user' => [
30+
'type' => 'Segment',
31+
'options' => [
32+
'route' => '/user/:owner',
33+
'constrains' => [
34+
'owner' => '[a-zA-Z][a-zA-Z0-9_-]*',
35+
],
36+
'defaults' => [
37+
'controller' => Controller\UserController::class,
38+
'action' => 'modulesForUser',
39+
],
40+
],
41+
],
2842
'zf-module' => [
2943
'type' => 'Segment',
3044
'options' => [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
namespace ZfModule\Controller;
3+
4+
use Zend\Mvc\Controller\AbstractActionController;
5+
use Zend\View\Model\ViewModel;
6+
use ZfModule\Mapper;
7+
8+
class UserController extends AbstractActionController
9+
{
10+
/**
11+
* @var Mapper\Module
12+
*/
13+
private $moduleMapper;
14+
15+
/**
16+
* @param Mapper\Module $moduleMapper
17+
*/
18+
public function __construct(Mapper\Module $moduleMapper)
19+
{
20+
$this->moduleMapper = $moduleMapper;
21+
}
22+
23+
public function modulesForUserAction()
24+
{
25+
$params = $this->params();
26+
$query = $params->fromQuery('query', null);
27+
$page = (int) $params->fromQuery('page', 1);
28+
$owner = $params->fromRoute('owner');
29+
30+
$modules = $this->moduleMapper->pagination($page, 10, $owner, 'created_at', 'DESC');
31+
32+
return new ViewModel([
33+
'modules' => $modules,
34+
'query' => $query,
35+
]);
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace ZfModule\Controller;
4+
5+
use Zend\Mvc\Controller\ControllerManager;
6+
use Zend\ServiceManager\FactoryInterface;
7+
use Zend\ServiceManager\ServiceLocatorInterface;
8+
use ZfModule\Mapper;
9+
use ZfModule\Service;
10+
11+
class UserControllerFactory implements FactoryInterface
12+
{
13+
/**
14+
* @param ServiceLocatorInterface $controllerManager
15+
* @return IndexController
16+
*/
17+
public function createService(ServiceLocatorInterface $controllerManager)
18+
{
19+
/* @var ControllerManager $controllerManager */
20+
$serviceManager = $controllerManager->getServiceLocator();
21+
22+
/* @var Mapper\Module $moduleMapper */
23+
$moduleMapper = $serviceManager->get(Mapper\Module::class);
24+
25+
/* @var Service\Module $moduleService */
26+
$moduleService = $serviceManager->get(Service\Module::class);
27+
28+
return new UserController(
29+
$moduleMapper,
30+
$moduleService
31+
);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace ZfModuleTest\Integration\Controller;
4+
5+
use ApplicationTest\Integration\Util\Bootstrap;
6+
use Zend\Paginator;
7+
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
8+
use ZfModule\Controller;
9+
use ZfModule\Mapper;
10+
11+
class UserControllerTest extends AbstractHttpControllerTestCase
12+
{
13+
protected function setUp()
14+
{
15+
parent::setUp();
16+
17+
$this->setApplicationConfig(Bootstrap::getConfig());
18+
}
19+
20+
public function testUserPageCanBeAccessed()
21+
{
22+
$moduleMapper = $this->getMockBuilder(Mapper\Module::class)->getMock();
23+
24+
$moduleMapper
25+
->expects($this->once())
26+
->method('pagination')
27+
->with(
28+
$this->equalTo(1),
29+
$this->equalTo(10),
30+
$this->equalTo("gianarb"),
31+
$this->equalTo('created_at'),
32+
$this->equalTo('DESC')
33+
)
34+
->willReturn(new Paginator\Paginator(new Paginator\Adapter\Null()))
35+
;
36+
37+
$this->getApplicationServiceLocator()
38+
->setAllowOverride(true)
39+
->setService(
40+
Mapper\Module::class,
41+
$moduleMapper
42+
)
43+
;
44+
45+
$this->dispatch('/user/gianarb');
46+
47+
$this->assertControllerName(Controller\UserController::class);
48+
$this->assertActionName('modulesForUser');
49+
}
50+
}

module/ZfModule/view/zf-module/index/view.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php $this->headTitle($this->escapeHtmlAttr($module) . ' module by ' . $this->escapeHtmlAttr($vendor)); ?>
22
<?php $this->headMeta()->appendName('description', $this->escapeHtmlAttr($repository->description)); ?>
33

4-
<h3><?php echo $vendor ?> / <?php echo $module ?> </h3>
4+
<h3><a href="<?php echo $this->url('modules-for-user', ['owner' => $vendor]); ?>"><?php echo $this->escapeHtml($vendor); ?></a> / <?php echo $this->escapeHtml($module); ?> </h3>
55

66
<div class="row">
77
<div class="col-md-8">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php $this->layout()->withLargeHeader = false; ?>
2+
3+
<div class="col-xs-12 col-md-8">
4+
<?php if (count($this->modules) >= 1): ?>
5+
<?php foreach ($this->modules as $module): ?>
6+
<?php /* @var ZfModule\Entity\Module $module */ ?>
7+
<div class="module-row">
8+
<div class="module-info">
9+
<div class="row">
10+
<div class="hidden-xs col-sm-2">
11+
<img src="<?php echo $this->escapeHtmlAttr($module->getPhotoUrl()) ?>" alt="<?php echo $this->escapeHtmlAttr($module->getOwner()) ?>" class="thumbnail img-responsive">
12+
</div>
13+
<div class="col-xs-7 col-sm-6">
14+
<p>
15+
<a href="<?php echo $this->url('view-module', ['vendor' => $this->escapeUrl($module->getOwner()), 'module' => $this->escapeUrl($module->getName())]) ?>">
16+
<strong><?php echo $this->escapeHtml($module->getOwner()); ?>/<?php echo $this->escapeHtml($module->getName()); ?></strong>
17+
</a>
18+
</p>
19+
<p><span class="zf-green">Created:</span> <?php echo $this->dateFormat($module->getCreatedAtDateTime(), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); ?></p>
20+
</div>
21+
<div class="col-xs-4">
22+
<a target="_blank" href="<?php echo $this->escapeHtmlAttr($module->getUrl()) ?>">Show module on GitHub</a>
23+
</div>
24+
</div>
25+
</div>
26+
<div class="module-description">
27+
<p><?php echo $this->escapeHtml($module->getDescription()) ?></p>
28+
</div>
29+
</div>
30+
<?php endforeach; ?>
31+
<?php echo $this->paginationControl($this->modules, 'Sliding', 'application/index/pagination', ['query' => $this->query]) ?>
32+
<?php endif; ?>
33+
</div>
34+
35+
<div class="hidden-xs hidden-sm col-md-4">
36+
<div class="sidebar">
37+
<?php echo $this->newModule() ?>
38+
<?php echo $this->newUsers() ?>
39+
</div>
40+
</div>
41+

0 commit comments

Comments
 (0)