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

Feature/modules from user #444

Merged
merged 7 commits into from
Mar 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion module/User/view/user/helper/new-users.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="col-md-12">
<?php endif; ?>
<div class="col-md-3">
<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">
<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">
<img src="<?php echo $this->escapeHtmlAttr($user->getPhotoUrl()) ?>" alt="<?php echo $this->escapeHtmlAttr($user->getUsername()) ?>" class="img-responsive">
</a>
</div>
Expand Down
14 changes: 14 additions & 0 deletions module/ZfModule/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'controllers' => [
'factories' => [
Controller\IndexController::class => Controller\IndexControllerFactory::class,
Controller\UserController::class => Controller\UserControllerFactory::class,
Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

],
],
'router' => [
Expand All @@ -25,6 +26,19 @@
],
],
],
'modules-for-user' => [
'type' => 'Segment',
'options' => [
'route' => '/user/:owner',
'constrains' => [
'owner' => '[a-zA-Z][a-zA-Z0-9_-]*',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit restrictive IMO. Not sure what github's username limitations are

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm I don't find a github's username restriction

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Username may only contain alphanumeric characters or single hyphens, and cannot begin or end with a hyphen

so we would end up like this ^^ ^(?!.*--.*)([a-zA-Z0-9][a-zA-Z0-9-]+?[a-zA-Z0-9])$|(^[a-zA-Z0-9]+$) 🐠

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😕

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The 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' => [
Expand Down
37 changes: 37 additions & 0 deletions module/ZfModule/src/ZfModule/Controller/UserController.php
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,
]);
}
}
33 changes: 33 additions & 0 deletions module/ZfModule/src/ZfModule/Controller/UserControllerFactory.php
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');
}
}
2 changes: 1 addition & 1 deletion module/ZfModule/view/zf-module/index/view.phtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php $this->headTitle($this->escapeHtmlAttr($module) . ' module by ' . $this->escapeHtmlAttr($vendor)); ?>
<?php $this->headMeta()->appendName('description', $this->escapeHtmlAttr($repository->description)); ?>

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

<div class="row">
<div class="col-md-8">
Expand Down
41 changes: 41 additions & 0 deletions module/ZfModule/view/zf-module/user/modules-for-user.phtml
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>