Pārlūkot izejas kodu

Added viewing packages by user.

xaav 14 gadi atpakaļ
vecāks
revīzija
b9c8c4e4dc

+ 38 - 0
src/Packagist/WebBundle/Controller/UserController.php

@@ -0,0 +1,38 @@
+<?php
+
+/*
+ * This file is part of Packagist.
+ *
+ * (c) Jordi Boggiano <j.boggiano@seld.be>
+ *     Nils Adermann <naderman@naderman.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Packagist\WebBundle\Controller;
+
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+
+class UserController extends Controller
+{
+    /**
+     * @Template()
+     * @Route("/user/{id}/packages", name="user_packages")
+     */
+    public function packagesAction($id)
+    {
+        $user = $this->getDoctrine()
+            ->getRepository('PackagistWebBundle:User')
+            ->findOneById($id);
+
+        if (empty($user)) {
+            throw new NotFoundHttpException();
+        }
+
+        return array('user' => $user);
+    }
+}

+ 24 - 0
src/Packagist/WebBundle/Resources/views/User/packages.html.twig

@@ -0,0 +1,24 @@
+{% extends "PackagistWebBundle::layout.html.twig" %}
+
+{% block content %}
+    <h1>Packages by {{ user.username }}</h1>
+    {% for package in user.packages %}
+        <section class="package">
+            <h2>{{ package.name }}</h2>
+            {% if package.versions[0] is defined %}
+                <p class="description">{{ package.versions[0].description }}</p>
+                <p class="license">License: {{ package.versions[0].license|default("Unknown") }}</p>
+                <p class="links">
+                    {% if package.versions[0].homepage %}
+                        Homepage: <a href="{{ package.versions[0].homepage }}">{{ package.versions[0].homepage|replace({'http://': ''}) }}</a><br />
+                    {% endif %}
+                    Tags: {% for tag in package.versions[0].tags %}{{ tag.name }}{{ loop.last ? '' : ', ' }}{% endfor %}
+                </p>
+            {% elseif package.crawledAt == null %}
+                This package has not been crawled yet, some information is missing.
+            {% else %}
+                This package has no released version yet, and little information is available yet.
+            {% endif %}
+        </section>
+    {% endfor %}
+{% endblock %}