1 | <?php |
||
18 | class DefaultController extends Controller |
||
19 | { |
||
20 | /** |
||
21 | * @Route("/", name="homepage") |
||
22 | * @Cache(expires="tomorrow", public=true) |
||
23 | */ |
||
24 | public function indexAction() |
||
25 | { |
||
26 | $posts = $this->get('AppBundle\Repository\PostRepository')->findLatest(); |
||
27 | |||
28 | $jsonData = json_decode(file_get_contents('http://knpbundles.com/newest.json'), true); |
||
29 | |||
30 | return $this->render('default/index.html.twig', [ |
||
31 | 'posts' => $posts, |
||
32 | 'bundles' => $jsonData['results'] |
||
33 | ]); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @Route("/copyrights", name="copyrights") |
||
38 | * @param Request $request |
||
39 | * @return Response |
||
40 | */ |
||
41 | public function copyrightAction(Request $request) |
||
|
|||
42 | { |
||
43 | return $this->render('default/copyright.html.twig'); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @Route("/join-us", name="join") |
||
48 | * @param Request $request |
||
49 | * @return Response |
||
50 | */ |
||
51 | public function joinAction(Request $request) |
||
52 | { |
||
53 | return $this->render('default/join.html.twig'); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @Route("/contact", name="contact") |
||
58 | * @Cache(maxage="20", public=true) |
||
59 | * |
||
60 | * @param Request $request |
||
61 | * @return RedirectResponse|Response |
||
62 | */ |
||
63 | public function contactAction(Request $request) |
||
64 | { |
||
65 | $contact = new Contact(); |
||
66 | |||
67 | $form = $this->createFormBuilder($contact) |
||
68 | ->add('name', TextType::class) |
||
69 | ->add('email', EmailType::class) |
||
70 | ->add('message', TextareaType::class) |
||
71 | ->add('send', SubmitType::class) |
||
72 | ->getForm(); |
||
73 | |||
74 | $form->handleRequest($request); |
||
75 | |||
76 | if($form->isSubmitted() && $form->isValid()) { |
||
77 | // send email to admin |
||
78 | $message = \Swift_Message::newInstance() |
||
79 | ->setSubject('Message from Symfony.si') |
||
80 | ->setFrom($contact->getEmail()) |
||
81 | ->setTo($this->container->getParameter('symfonysi_admin_email')) |
||
82 | ->setBody( |
||
83 | $this->renderView( |
||
84 | 'emails/email.txt.twig', |
||
85 | [ |
||
86 | 'name' => $contact->getName(), |
||
87 | 'email' => $contact->getEmail(), |
||
88 | 'message' => $contact->getMessage() |
||
89 | ] |
||
90 | ) |
||
91 | ) |
||
92 | ; |
||
93 | $this->get('mailer')->send($message); |
||
94 | |||
95 | return $this->redirect($this->generateUrl('contact_success')); |
||
96 | } |
||
97 | |||
98 | return $this->render('default/contact.html.twig', [ |
||
99 | 'form' => $form->createView(), |
||
100 | ]); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @Route("/contact-succeeded", name="contact_success") |
||
105 | * @param Request $request |
||
106 | * @return Response |
||
107 | */ |
||
108 | public function contactSuccessAction(Request $request) |
||
112 | |||
113 | /** |
||
114 | * @Route("/contributors", name="contributors") |
||
115 | * @param Request $request |
||
116 | * @return Response |
||
117 | */ |
||
118 | public function contributorsAction(Request $request) |
||
119 | { |
||
120 | $cache = $this->get('cache.app'); |
||
121 | $contributorsFromCache = $cache->getItem('app.contributors'); |
||
122 | if (!$contributorsFromCache->isHit()) { |
||
123 | $client = new \Github\Client(); |
||
124 | |||
125 | $repos = [ |
||
126 | ['symfony-si', 'symfony.si'], |
||
127 | ['symfony-si', 'symfony-must-watch'], |
||
128 | ['symfony-si', 'symfony-resources'], |
||
129 | ['symfony-si', 'symfony-cheatsheet'], |
||
130 | ]; |
||
131 | $contributors = []; |
||
132 | foreach ($repos as $repo) { |
||
133 | $organizationApi = $client->api('repo'); |
||
134 | $paginator = new \Github\ResultPager($client); |
||
135 | $parameters = [$repo[0], $repo[1]]; |
||
136 | $repoContributors = $paginator->fetchAll($organizationApi, 'contributors', $parameters); |
||
137 | foreach ($repoContributors as $contributor) { |
||
138 | $contributors[$contributor['login']] = [ |
||
139 | 'html_url' => $contributor['html_url'], |
||
140 | 'avatar_url' => $contributor['avatar_url'], |
||
141 | 'contributions' => (isset($contributors[$contributor['login']]['contributions'])) ? $contributors[$contributor['login']]['contributions'] + $contributor['contributions'] : $contributor['contributions'], |
||
142 | ]; |
||
143 | } |
||
144 | } |
||
145 | |||
146 | uasort($contributors, function($a, $b) { |
||
147 | return $a['contributions'] <=> $b['contributions']; |
||
148 | }); |
||
149 | |||
150 | $contributors = array_reverse($contributors); |
||
151 | |||
152 | $contributorsFromCache->set($contributors); |
||
153 | $cache->save($contributorsFromCache); |
||
154 | } else { |
||
155 | $contributors = $contributorsFromCache->get(); |
||
156 | } |
||
157 | |||
158 | return $this->render('default/contributors.html.twig', [ |
||
159 | 'contributors' => $contributors |
||
160 | ]); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * @Route("/resources", name="resources") |
||
165 | * @param Request $request |
||
166 | * @return Response |
||
167 | */ |
||
168 | public function resourcesAction(Request $request) |
||
169 | { |
||
170 | $file = $this->get('kernel')->getRootDir().'/../vendor/symfony-si/symfony-resources/README.md'; |
||
171 | $content = (file_exists($file)) ? file_get_contents($file) : '<h1>Symfony resources</h1>'; |
||
172 | |||
173 | return $this->render('default/resources.html.twig', ['html' => $content]); |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * @Route("/cheatsheet", name="cheatsheet") |
||
178 | * @return Response |
||
179 | */ |
||
180 | public function cheatsheetAction() |
||
187 | |||
188 | /** |
||
189 | * @Route("/ecosystem", name="ecosystem") |
||
190 | * @return Response |
||
191 | */ |
||
192 | public function ecosystemAction() |
||
304 | |||
305 | /** |
||
306 | * @Route("/code-of-conduct", name="conduct") |
||
307 | * @Cache(expires="tomorrow", public=true) |
||
308 | * |
||
309 | * @return Response |
||
310 | */ |
||
311 | public function conductAction() |
||
318 | } |
||
319 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.