Skip to content

Commit f72c759

Browse files
committed
Merge branch 'master' into #355-2fa
# Conflicts: # app/HMS/Entities/User.php # app/Http/Kernel.php
2 parents 4f104f6 + f35cf75 commit f72c759

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1294
-243
lines changed

Vagrantfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
1515
config.vm.hostname = "hmsdev.nottingtest.org.uk"
1616

1717
config.vm.provider :virtualbox do |vb|
18-
vb.customize ['modifyvm', :id, '--memory', '2048']
18+
vb.customize ['modifyvm', :id, '--memory', '4096']
1919
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
2020
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
2121
vb.customize ['guestproperty', 'set', :id,

app/Exceptions/Handler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function unauthorized($request, AuthorizationException $exception)
7676
return response()->json(['error' => 'Unauthorized.'], IlluminateResponse::HTTP_FORBIDDEN);
7777
}
7878

79-
flash('Unauthorized', 'error');
79+
flash('Unauthorized')->error();
8080

8181
return redirect()->route('home');
8282
}

app/HMS/Doctrine/CarbonDateType.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace HMS\Doctrine;
4+
5+
class CarbonDateType extends CarbonType
6+
{
7+
/**
8+
* {@inheritdoc}
9+
*/
10+
protected $getFormatString = 'getDateFormatString';
11+
}

app/HMS/Doctrine/CarbonTimeType.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace HMS\Doctrine;
4+
5+
class CarbonTimeType extends CarbonType
6+
{
7+
/**
8+
* {@inheritdoc}
9+
*/
10+
protected $getFormatString = 'getTimeFormatString';
11+
}

app/HMS/Doctrine/CarbonType.php

+72-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,88 @@
22

33
namespace HMS\Doctrine;
44

5+
use DateTime;
6+
use DateTimeZone;
57
use Carbon\Carbon;
8+
use InvalidArgumentException;
69
use Doctrine\DBAL\Types\DateTimeType;
10+
use Doctrine\DBAL\Types\ConversionException;
711
use Doctrine\DBAL\Platforms\AbstractPlatform;
812

913
class CarbonType extends DateTimeType
1014
{
15+
/**
16+
* @var null|\DateTimeZone
17+
*/
18+
private static $utc = null;
19+
20+
/**
21+
* Function name to call on AbstractPlatform to get the relevent string format.
22+
*
23+
* @var string
24+
*/
25+
protected $getFormatString = 'getDateTimeFormatString';
26+
27+
/**
28+
* Converts the Datetime to UTC before storing to database.
29+
*
30+
* @param mixed $value
31+
* @param AbstractPlatform $platform
32+
*
33+
* @return mixed|null
34+
*/
35+
public function convertToDatabaseValue($value, AbstractPlatform $platform)
36+
{
37+
if ($value === null) {
38+
return null;
39+
}
40+
41+
if (is_null(self::$utc)) {
42+
self::$utc = new \DateTimeZone('UTC');
43+
}
44+
45+
if ($value instanceof DateTime) {
46+
$value->setTimezone(self::$utc);
47+
}
48+
49+
return parent::convertToDatabaseValue($value, $platform);
50+
}
51+
52+
/**
53+
* Converts the Datetime from UTC to default timezone.
54+
*
55+
* @param mixed $value
56+
* @param AbstractPlatform $platform
57+
*
58+
* @return Carbon|null
59+
* @throws ConversionException
60+
* @throws InvalidArgumentException
61+
*/
1162
public function convertToPHPValue($value, AbstractPlatform $platform)
1263
{
13-
$result = parent::convertToPHPValue($value, $platform);
64+
if ($value === null || $value instanceof Carbon) {
65+
return $value;
66+
}
67+
68+
if (is_null(self::$utc)) {
69+
self::$utc = new \DateTimeZone('UTC');
70+
}
71+
72+
$converted = Carbon::createFromFormat(
73+
$platform->{$this->getFormatString}(),
74+
$value,
75+
self::$utc
76+
);
77+
$converted->setTimezone(new DateTimeZone(date_default_timezone_get()));
1478

15-
if ($result instanceof \DateTime) {
16-
return Carbon::instance($result);
79+
if (! $converted) {
80+
throw ConversionException::conversionFailedFormat(
81+
$value,
82+
$this->getName(),
83+
$platform->{$this->getFormatString}()
84+
);
1785
}
1886

19-
return $result;
87+
return $converted;
2088
}
2189
}

app/HMS/Entities/User.php

+53
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace HMS\Entities;
44

5+
use HMS\Entities\GateKeeper\Pin;
56
use HMS\Entities\Banking\Account;
67
use Laravel\Passport\HasApiTokens;
8+
use HMS\Entities\GateKeeper\RfidTag;
79
use HMS\Traits\Entities\SoftDeletable;
810
use HMS\Traits\Entities\Timestampable;
911
use LaravelDoctrine\ACL\Roles\HasRoles;
@@ -90,6 +92,16 @@ class User implements
9092
*/
9193
protected $emails;
9294

95+
/**
96+
* @var null|Pin
97+
*/
98+
protected $pin;
99+
100+
/**
101+
* @var ArrayCollection|RfidTag[]
102+
*/
103+
protected $rfidTags;
104+
93105
/**
94106
* @var bool
95107
*/
@@ -120,6 +132,7 @@ public function __construct(
120132
$this->email = $email;
121133
$this->roles = new ArrayCollection();
122134
$this->emails = new ArrayCollection();
135+
$this->rfidTags = new ArrayCollection();
123136
$this->google2faEnable = false;
124137
}
125138

@@ -352,6 +365,46 @@ public function getEmails()
352365
return $this->emails;
353366
}
354367

368+
/**
369+
* @return null|HMS\Entities\GateKeeper\Pin
370+
*/
371+
public function getPin()
372+
{
373+
return $this->pin;
374+
}
375+
376+
/**
377+
* @param null|HMS\Entities\GateKeeper\Pin $pin
378+
*
379+
* @return self
380+
*/
381+
public function setPin(Pin $pin)
382+
{
383+
$this->pin = $pin;
384+
385+
return $this;
386+
}
387+
388+
/**
389+
* @return RfidTag[]
390+
*/
391+
public function getRfidTags()
392+
{
393+
return $this->rfidTags;
394+
}
395+
396+
/**
397+
* @param ArrayCollection|RfidTag[] $rfidTags
398+
*
399+
* @return self
400+
*/
401+
public function setRfidTags($rfidTags)
402+
{
403+
$this->rfidTags = $rfidTags;
404+
405+
return $this;
406+
}
407+
355408
/**
356409
* @return bool
357410
*/

app/HMS/Mappings/HMS.Entities.GateKeeper.Pin.dcm.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ HMS\Entities\GateKeeper\Pin:
2727
type: integer
2828
options:
2929
default: 10
30-
manyToOne:
30+
oneToOne:
3131
user:
32-
targetEntity: \HMS\Entities\User
32+
targetEntity: \HMS\Entities\User
33+
inversedBy: pin

app/HMS/Mappings/HMS.Entities.User.dcm.yml

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ HMS\Entities\User:
6363
targetEntity: Profile
6464
mappedBy: user
6565
cascade: ["all"]
66+
pin:
67+
targetEntity: \HMS\Entities\GateKeeper\Pin
68+
mappedBy: user
69+
oneToMany:
70+
rfidTags:
71+
targetEntity: \HMS\Entities\GateKeeper\RfidTag
72+
mappedBy: user
6673
manyToOne:
6774
account:
6875
targetEntity: \HMS\Entities\Banking\Account

app/HMS/Repositories/Doctrine/DoctrineRoleRepository.php

+22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace HMS\Repositories\Doctrine;
44

55
use HMS\Entities\Role;
6+
use HMS\Entities\User;
67
use Doctrine\ORM\EntityRepository;
78
use HMS\Repositories\RoleRepository;
89
use Doctrine\Common\Collections\ArrayCollection;
@@ -57,6 +58,27 @@ public function findOneByEmail(string $email)
5758
return parent::findOneByEmail($email);
5859
}
5960

61+
/**
62+
* Find all the team roles a given user has.
63+
*
64+
* @param User $user
65+
*
66+
* @return Roles[]
67+
*/
68+
public function findTeamsForUser(User $user)
69+
{
70+
$q = parent::createQueryBuilder('role')
71+
->leftJoin('role.users', 'user')
72+
->where('role.name LIKE :name')
73+
->andWhere('user.id = :user_id');
74+
75+
$q = $q->setParameter('name', 'team.%')
76+
->setParameter('user_id', $user->getId())
77+
->getQuery();
78+
79+
return $q->getResult();
80+
}
81+
6082
/**
6183
* Store a new user in the DB.
6284
*

app/HMS/Repositories/Members/Doctrine/DoctrineProjectRepository.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ class DoctrineProjectRepository extends EntityRepository implements ProjectRepos
1717
* @param User $user
1818
* @param int $perPage
1919
* @param string $pageName
20+
* @param bool $active
2021
*
2122
* @return \Illuminate\Pagination\LengthAwarePaginator
2223
*/
23-
public function paginateByUser(User $user, $perPage = 15, $pageName = 'page')
24+
public function paginateByUser(User $user, $perPage = 15, $pageName = 'page', $active = false)
2425
{
2526
$q = parent::createQueryBuilder('project')
2627
->where('project.user = :user_id');
2728

29+
if ($active) {
30+
$q->andWhere('project.state = :project_state')
31+
->orderBy('project.startDate', 'DESC')
32+
->setParameter('project_state', ProjectState::ACTIVE);
33+
}
34+
2835
$q = $q->setParameter('user_id', $user->getId())->getQuery();
2936

3037
return $this->paginate($q, $perPage, $pageName);

app/HMS/Repositories/Members/ProjectRepository.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ interface ProjectRepository
1111
* @param User $user
1212
* @param int $perPage
1313
* @param string $pageName
14+
* @param bool $active
1415
*
1516
* @return \Illuminate\Pagination\LengthAwarePaginator
1617
*/
17-
public function paginateByUser(User $user, $perPage = 15, $pageName = 'page');
18+
public function paginateByUser(User $user, $perPage = 15, $pageName = 'page', $active = false);
1819

1920
/**
2021
* Return number of active projects for a user.

app/HMS/Repositories/RoleRepository.php

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace HMS\Repositories;
44

55
use HMS\Entities\Role;
6+
use HMS\Entities\User;
67
use Doctrine\Common\Collections\ArrayCollection;
78

89
interface RoleRepository
@@ -37,6 +38,15 @@ public function findOneByName(string $roleName);
3738
*/
3839
public function findOneByEmail(string $email);
3940

41+
/**
42+
* Find all the team roles a given user has.
43+
*
44+
* @param User $user
45+
*
46+
* @return Roles[]
47+
*/
48+
public function findTeamsForUser(User $user);
49+
4050
/**
4151
* Store a new user in the DB.
4252
*

app/HMS/Repositories/Tools/BookingRepository.php

+9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ public function findInductionByTool(Tool $tool);
116116
*/
117117
public function findMaintenanceByTool(Tool $tool);
118118

119+
/**
120+
* Find bookings for a given user that are either now or in the futuer no matter the tool.
121+
*
122+
* @param User $user
123+
*
124+
* @return Booking[]
125+
*/
126+
public function findFutureByUser(User $user);
127+
119128
/**
120129
* Save Booking to the DB.
121130
*

app/HMS/Repositories/Tools/Doctrine/DoctrineBookingRepository.php

+24
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,30 @@ public function findMaintenanceByTool(Tool $tool)
246246
return parent::findBy(['tool' => $tool, 'type' => BookingType::MAINTENANCE], ['start' => 'ASC']);
247247
}
248248

249+
/**
250+
* Find bookings for a given user that are either now or in the futuer no matter the tool.
251+
*
252+
* @param User $user
253+
*
254+
* @return Booking[]
255+
*/
256+
public function findFutureByUser(User $user)
257+
{
258+
$now = Carbon::now();
259+
260+
$expr = Criteria::expr();
261+
$criteria = Criteria::create()
262+
->where(
263+
$expr->andX(
264+
$expr->eq('user', $user),
265+
$expr->gte('end', $now)
266+
)
267+
)
268+
->orderBy(['start' => Criteria::ASC]);
269+
270+
return $this->matching($criteria)->toArray();
271+
}
272+
249273
/**
250274
* Save Booking to the DB.
251275
*

app/Http/Controllers/Banking/BankTransactionsController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function index(Request $request)
8989
}
9090

9191
if (is_null($user->getAccount())) {
92-
flash('No Account for ' . $user->getName())->error();
92+
flash('No Account for ' . $user->getFirstname())->error();
9393

9494
return redirect()->route('home');
9595
}

0 commit comments

Comments
 (0)