Skip to content

Commit f585b9a

Browse files
committed
Merge branch 'master' into role-status-log
# Conflicts: # config/repositories.php
2 parents e68c47a + 7d5c05d commit f585b9a

16 files changed

+466
-7
lines changed

app/HMS/Entities/Email.php

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<?php
2+
3+
namespace HMS\Entities;
4+
5+
use Carbon\Carbon;
6+
use Doctrine\Common\Collections\ArrayCollection;
7+
8+
class Email
9+
{
10+
/**
11+
* @var int
12+
*/
13+
protected $id;
14+
15+
/**
16+
* @var array
17+
*/
18+
protected $toAddress;
19+
20+
/**
21+
* @var string
22+
*/
23+
protected $subject;
24+
25+
/**
26+
* @var string
27+
*/
28+
protected $body;
29+
30+
/*
31+
* @var Carbon
32+
*/
33+
protected $sentAt;
34+
35+
/**
36+
* @var \Doctrine\Common\Collections\Collection|Users[]
37+
*/
38+
protected $users;
39+
40+
/**
41+
* @var ?Role
42+
*/
43+
protected $role;
44+
45+
/**
46+
* Create a new email record.
47+
* @param array $toAddress Array of to adddress in format [ email => name]
48+
* @param string $subject
49+
* @param string $body
50+
*/
51+
public function __construct(array $toAddress, string $subject, string $body)
52+
{
53+
$this->toAddress = $toAddress;
54+
$this->subject = $subject;
55+
$this->body = $body;
56+
$this->users = new ArrayCollection();
57+
$this->sentAt = Carbon::now();
58+
}
59+
60+
/**
61+
* Gets the value of id.
62+
*
63+
* @return int
64+
*/
65+
public function getId(): int
66+
{
67+
return $this->id;
68+
}
69+
70+
/**
71+
* Gets the value of to.
72+
*
73+
* @return array
74+
*/
75+
public function getTo(): array
76+
{
77+
return $this->toAddress;
78+
}
79+
80+
/**
81+
* Sets the value of to.
82+
*
83+
* @param array $toAddress the to
84+
*
85+
* @return self
86+
*/
87+
public function setTo(array $toAddress): Email
88+
{
89+
$this->toAddress = $toAddress;
90+
91+
return $this;
92+
}
93+
94+
/**
95+
* Gets the value of subject.
96+
*
97+
* @return string
98+
*/
99+
public function getSubject()
100+
{
101+
return $this->subject;
102+
}
103+
104+
/**
105+
* Sets the value of subject.
106+
*
107+
* @param string $subject the subject
108+
*
109+
* @return self
110+
*/
111+
public function setSubject(string $subject): Email
112+
{
113+
$this->subject = $subject;
114+
115+
return $this;
116+
}
117+
118+
/**
119+
* Gets the value of body.
120+
*
121+
* @return string
122+
*/
123+
public function getBody(): string
124+
{
125+
return $this->body;
126+
}
127+
128+
/**
129+
* Sets the value of body.
130+
*
131+
* @param string $body the body
132+
*
133+
* @return self
134+
*/
135+
public function setBody($body): Email
136+
{
137+
$this->body = $body;
138+
139+
return $this;
140+
}
141+
142+
/**
143+
* Gets the value of sentAt.
144+
*
145+
* @return string
146+
*/
147+
public function getSentAt(): Carbon
148+
{
149+
return $this->sentAt;
150+
}
151+
152+
/**
153+
* Sets the value of sentAt.
154+
*
155+
* @param string $sentAt the sent at
156+
*
157+
* @return self
158+
*/
159+
public function setSentAt($sentAt): Email
160+
{
161+
$this->sentAt = $sentAt;
162+
163+
return $this;
164+
}
165+
166+
/**
167+
* Gets the value of users.
168+
*
169+
* @return \Doctrine\Common\Collections\Collection|Users[]
170+
*/
171+
public function getUsers()
172+
{
173+
return $this->users;
174+
}
175+
176+
/**
177+
* Gets the value of role.
178+
*
179+
* @return ?Role
180+
*/
181+
public function getRole()
182+
{
183+
return $this->role;
184+
}
185+
186+
/**
187+
* Sets the value of role.
188+
*
189+
* @param ?Role $role the role
190+
*
191+
* @return self
192+
*/
193+
public function setRole(?Role $role): Email
194+
{
195+
$this->role = $role;
196+
197+
return $this;
198+
}
199+
}

app/HMS/Entities/Role.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ class Role implements RoleContract
4343
protected $description;
4444

4545
/**
46-
* @var \Doctrine\Common\Collections\ArrayCollection
46+
* @var \Doctrine\Common\Collections\Collection
4747
*/
4848
protected $permissions;
4949

5050
/**
51-
* @var \Doctrine\Common\Collections\ArrayCollection
51+
* @var \Doctrine\Common\Collections\Collection
5252
*/
5353
protected $users;
5454

app/HMS/Entities/User.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class User implements AuthenticatableContract, CanResetPasswordContract, HasRole
5555
protected $rememberToken;
5656

5757
/**
58-
* @var \Doctrine\Common\Collections\ArrayCollection|\LaravelDoctrine\ACL\Contracts\Role[]
58+
* @var \Doctrine\Common\Collections\Collection|\LaravelDoctrine\ACL\Contracts\Role[]
5959
*/
6060
protected $roles;
6161

@@ -69,6 +69,11 @@ class User implements AuthenticatableContract, CanResetPasswordContract, HasRole
6969
*/
7070
protected $account;
7171

72+
/**
73+
* @var \Doctrine\Common\Collections\Collection|Email[]
74+
*/
75+
protected $emails;
76+
7277
/**
7378
* User constructor.
7479
* @param string $firstname
@@ -83,6 +88,7 @@ public function __construct(string $firstname, string $lastname, string $usernam
8388
$this->username = $username;
8489
$this->email = $email;
8590
$this->roles = new ArrayCollection();
91+
$this->emails = new ArrayCollection();
8692
}
8793

8894
/**
@@ -257,4 +263,12 @@ public function getKey()
257263
{
258264
return $this->getAuthIdentifier();
259265
}
266+
267+
/**
268+
* @return ArrayCollection|Email[]
269+
*/
270+
public function getEmails()
271+
{
272+
return $this->emails;
273+
}
260274
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#HMS.Entities.Email.dcm.yml
2+
HMS\Entities\Email:
3+
type: entity
4+
table: emails
5+
id:
6+
id:
7+
type: integer
8+
options:
9+
unsigned: true
10+
generator:
11+
strategy: AUTO
12+
fields:
13+
toAddress:
14+
type: array
15+
subject:
16+
type: string
17+
body:
18+
type: text
19+
sentAt:
20+
type: datetime
21+
gedmo:
22+
timestampable:
23+
on: create
24+
manyToOne:
25+
role:
26+
targetEntity: Role
27+
manyToMany:
28+
users:
29+
targetEntity: User
30+
joinTable:
31+
name: email_users
32+
joinColumns:
33+
email_id:
34+
referencedColumnName: id
35+
inverseJoinColumns:
36+
user_id:
37+
referencedColumnName: id

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ HMS\Entities\User:
6969
inverseJoinColumns:
7070
role_id:
7171
referencedColumnName: id
72-
72+
emails:
73+
targetEntity: Email
74+
mappedBy: users
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace HMS\Repositories\Doctrine;
4+
5+
use HMS\Entities\Role;
6+
use HMS\Entities\Email;
7+
use Doctrine\ORM\EntityRepository;
8+
use HMS\Repositories\EmailRepository;
9+
10+
// TODO: findByUserPaginate(????);
11+
class DoctrineEmailRepository extends EntityRepository implements EmailRepository
12+
{
13+
/**
14+
* @param $id
15+
* @return array
16+
*/
17+
public function find($id)
18+
{
19+
return parent::find($id);
20+
}
21+
22+
/**
23+
* @param string $role
24+
* @return array
25+
*/
26+
public function findByRole(Role $role)
27+
{
28+
return parent::findByRole($role);
29+
}
30+
31+
/**
32+
* save Email to the DB.
33+
* @param Email $email
34+
*/
35+
public function save(Email $email)
36+
{
37+
$this->_em->persist($email);
38+
$this->_em->flush();
39+
}
40+
}

app/HMS/Repositories/Doctrine/DoctrineRoleRepository.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,22 @@ public function findAll()
2929
* Finds a role based on the role name.
3030
*
3131
* @param string $roleName name of the role we want
32-
* @return Role|object
32+
* @return Role|nul
3333
*/
3434
public function findByName(string $roleName)
3535
{
3636
return parent::findOneBy(['name' => $roleName]);
3737
}
3838

39+
/**
40+
* @param string $email
41+
* @return Role|null
42+
*/
43+
public function findByOneEmail(string $email)
44+
{
45+
return parent::findByOneEmail($email);
46+
}
47+
3948
/**
4049
* store a new user in the DB.
4150
* @param Role $role

app/HMS/Repositories/Doctrine/DoctrineUserRepository.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ public function findByEmail(string $email)
3838
return parent::findByEmail($email);
3939
}
4040

41+
/**
42+
* @param string $email
43+
* @return User|null
44+
*/
45+
public function findOneByEmail(string $email)
46+
{
47+
return parent::findOneByEmail($email);
48+
}
49+
4150
/**
4251
* @param string $searchQuery
4352
* @return array

0 commit comments

Comments
 (0)