FOSSology  4.4.0
Open Source License Compliance by Open Source Software
User.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2017 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
11 namespace Fossology\UI\Api\Models;
12 
13 require_once dirname(dirname(dirname(dirname(__DIR__)))) .
14  '/lib/php/Plugin/FO_Plugin.php';
15 
20 class User
21 {
26  private $id;
31  private $name;
36  private $description;
41  private $email;
46  private $accessLevel;
51  private $rootFolderId;
56  private $defaultGroup;
66  private $agents;
71  private $analysis;
77 
91  public function __construct($id, $name, $description, $email, $accessLevel, $root_folder_id, $emailNotification,
92  $agents, $default_group_fk=null, $defaultBucketPool=null)
93  {
94  $this->id = intval($id);
95  $this->name = $name;
96  $this->description = $description;
97  $this->email = $email;
98  switch ($accessLevel) {
99  case PLUGIN_DB_READ:
100  $this->accessLevel = "read_only";
101  break;
102  case PLUGIN_DB_WRITE:
103  $this->accessLevel = "read_write";
104  break;
105  case PLUGIN_DB_CADMIN:
106  $this->accessLevel = "clearing_admin";
107  break;
108  case PLUGIN_DB_ADMIN:
109  $this->accessLevel = "admin";
110  break;
111  default:
112  $this->accessLevel = "none";
113  }
114  $this->rootFolderId = intval($root_folder_id);
115  $this->defaultGroup = is_null($default_group_fk) ? null : intval($default_group_fk);
116  $this->emailNotification = $emailNotification;
117  $this->agents = $agents;
118  $this->analysis = new Analysis();
119  $this->analysis->setUsingString($this->agents);
120  if ($defaultBucketPool != null) {
121  $this->defaultBucketPool = intval($defaultBucketPool);
122  } else {
123  $this->defaultBucketPool = null;
124  }
125  }
126 
128 
131  public function getId()
132  {
133  return $this->id;
134  }
135 
139  public function getName()
140  {
141  return $this->name;
142  }
143 
147  public function getDescription()
148  {
149  return $this->description;
150  }
151 
155  public function getEmail()
156  {
157  return $this->email;
158  }
159 
163  public function getAccessLevel()
164  {
165  return $this->accessLevel;
166  }
167 
171  public function getRootFolderId()
172  {
173  return $this->rootFolderId;
174  }
175 
179  public function getDefaultGroupId()
180  {
181  return $this->defaultGroup;
182  }
183 
187  public function getEmailNotification()
188  {
190  }
191 
195  public function getAgents()
196  {
197  return $this->agents;
198  }
199 
203  public function getDefaultBucketPool()
204  {
206  }
207 
212  public function getJSON()
213  {
214  return json_encode($this->getArray());
215  }
216 
221  public function getArray($version = ApiVersion::V1)
222  {
223  global $container;
224  $restHelper = $container->get('helper.restHelper');
225  $returnUser = array();
226  $returnUser["id"] = $this->id;
227  $returnUser["name"] = $this->name;
228  $returnUser["description"] = $this->description;
229  if ($this->email !== null) {
230  $returnUser["email"] = $this->email;
231  $returnUser["accessLevel"] = $this->accessLevel;
232  }
233  if ($this->rootFolderId !== null && $this->rootFolderId != 0) {
234  $returnUser["rootFolderId"] = $this->rootFolderId;
235  }
236  if ($this->defaultGroup !== null) {
237  $returnUser["defaultGroup"] = $version == ApiVersion::V2 ? $restHelper->getUserDao()->getGroupNameById($this->defaultGroup) : $this->defaultGroup;
238  }
239  if ($this->emailNotification !== null) {
240  $returnUser["emailNotification"] = $this->emailNotification;
241  }
242  if ($this->agents !== null) {
243  $returnUser["agents"] = $this->analysis->getArray($version);
244  }
245  if ($this->defaultBucketPool !== null) {
246  $returnUser["defaultBucketpool"] = $this->defaultBucketPool;
247  }
248  return $returnUser;
249  }
250 }
Model to hold analysis settings.
Definition: Analysis.php:21
Model to hold user information.
Definition: User.php:21
__construct($id, $name, $description, $email, $accessLevel, $root_folder_id, $emailNotification, $agents, $default_group_fk=null, $defaultBucketPool=null)
Definition: User.php:91
getArray($version=ApiVersion::V1)
Definition: User.php:221
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
Definition: libfossology.h:38
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
Definition: libfossology.h:37
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Definition: libfossology.h:39