FOSSology  4.4.0
Open Source License Compliance by Open Source Software
demohello.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2013 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
14 namespace Fossology\DemoHello;
15 
17 use Symfony\Component\HttpFoundation\Request;
20 
25 class DemoHello extends DefaultPlugin
26 {
27  const NAME = "demo_hello";
28 
29  public function __construct()
30  {
31  parent::__construct(self::NAME, array(
32  self::TITLE => _("Demo Hello World"),
33  self::MENU_LIST => "Help::Demo::Hello World",
34  self::PERMISSION => Auth::PERM_READ
35  ));
36  }
37 
42  protected function WhoAmI()
43  {
44  $user_pk = Auth::getUserId();
45 
46  if (empty($user_pk))
47  {
48  return _("You are not logged in");
49  }
50 
51  $userDao = $this->getObject('dao.user');
52  return $userDao->getUserName($user_pk);
53  }
54 
58  protected function handle(Request $request)
59  {
60  $UserName = $this->WhoAmI();
61  $Hello = _("Hello");
62  $OutBuf = "<h2>$Hello $UserName </h2>";
63  $OutBuf .= _("Wasn't that easy?");
64 
65  return $this->render('include/base.html.twig', $this->mergeWithDefault(array('message' => $OutBuf)));
66  }
67 
68 }
69 
70 register_plugin(new DemoHello());
UI component for demomod (Visible in menu)
Definition: demohello.php:26
handle(Request $request)
Generate response.
Definition: demohello.php:58
WhoAmI()
Find out who I am from my user record.
Definition: demohello.php:42
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
static getUserId()
Get the current user's id.
Definition: Auth.php:68
render($templateName, $vars=null, $headers=null)