diff --git a/blocks/html/account/info.inc b/blocks/html/account/info.inc
index 4f571ad..4cb2ef9 100644
--- a/blocks/html/account/info.inc
+++ b/blocks/html/account/info.inc
@@ -5,6 +5,8 @@
* @param string $this->fullname
* @param string $this->email
* @param string $this->phone
+ * @param bool $this->notify_updates
+ * @param bool $this->notify_emergency
*/
declare (strict_types=1);
use Application\Auth;
@@ -29,5 +31,11 @@ use Application\Auth;
= $this->_('email'); ?> | = $this->email; ?> |
= $this->_('phone'); ?> | = $this->phone; ?> |
+ = $this->_('notify_updates' ); ?> |
+ = $this->notify_updates ? $this->_('yes') : $this->_('no'); ?> |
+
+ = $this->_('notify_emergency'); ?> |
+ = $this->notify_emergency ? $this->_('yes') : $this->_('no'); ?> |
+
diff --git a/blocks/html/people/info.inc b/blocks/html/people/info.inc
index 36f56c1..6d4366a 100644
--- a/blocks/html/people/info.inc
+++ b/blocks/html/people/info.inc
@@ -8,6 +8,8 @@
* @param string $this->department
* @param string $this->email
* @param string $this->phone
+ * @param bool $this->notify_updates
+ * @param bool $this->notify_emergency
*/
use Application\Auth;
use Blossom\Classes\Url;
@@ -39,8 +41,14 @@ if (Auth::isAllowed('people', 'update')) {
= $editButton; ?>
- = $this->_('department'); ?> | = $this->department; ?> |
- = $this->_('email' ); ?> | = $this->email; ?> |
- = $this->_('phone' ); ?> | = $this->phone; ?> |
+ = $this->_('department'); ?> | = $this->department; ?> |
+ = $this->_('email' ); ?> | = $this->email; ?> |
+ = $this->_('phone' ); ?> | = $this->phone; ?> |
+ = $this->_('notify_updates' ); ?> |
+ = $this->notify_updates ? $this->_('yes') : $this->_('no'); ?> |
+
+ = $this->_('notify_emergency'); ?> |
+ = $this->notify_emergency ? $this->_('yes') : $this->_('no'); ?> |
+
diff --git a/blocks/html/people/partials/personInfoFields.inc b/blocks/html/people/partials/personInfoFields.inc
index 52621bd..847422b 100644
--- a/blocks/html/people/partials/personInfoFields.inc
+++ b/blocks/html/people/partials/personInfoFields.inc
@@ -6,6 +6,8 @@
* @param string $this->lastname
* @param string $this->email
* @param string $this->phone
+ * @param bool $this->notify_updates
+ * @param bool $this->notify_emergency
*/
declare (strict_types=1);
@@ -46,7 +48,6 @@ echo $h->field([
'attr' => ['inputmode'=>'tel']
]);
-/*
$options = [
['value'=>1, 'label'=>$this->_('yes')],
['value'=>0, 'label'=>$this->_('no' )]
@@ -55,7 +56,7 @@ echo $h->field([
'name' => 'notify_updates',
'id' => 'notify_updates',
'label' => $this->_('notify_updates'),
- 'value' => $notify_updates,
+ 'value' => $this->notify_updates,
'type' => 'select',
'options' => $options
]);
@@ -63,8 +64,7 @@ echo $h->field([
'name' => 'notify_emergency',
'id' => 'notify_emergency',
'label' => $this->_('notify_emergency'),
- 'value' => $notify_emergency,
+ 'value' => $this->notify_emergency,
'type' => 'select',
'options' => $options
]);
-*/
diff --git a/blocks/html/people/partials/personalInfo.inc b/blocks/html/people/partials/personalInfo.inc
deleted file mode 100644
index cbe4ce1..0000000
--- a/blocks/html/people/partials/personalInfo.inc
+++ /dev/null
@@ -1,24 +0,0 @@
-person
- */
-declare (strict_types=1);
-use Application\Models\Person;
-
-$fields = ['id', 'fullname', 'department', 'email', 'phone'];
-foreach ($fields as $f) {
- $get = 'get'.ucfirst($f);
- $$f = $this->person->$get();
-}
-$notify_updates = $this->person->getNotify_updates () ? $this->_('yes') : $this->_('no');
-$notify_emergency = $this->person->getNotify_emergency() ? $this->_('yes') : $this->_('no');
-?>
-
- = $this->_('department' ); ?> | = $department; ?> |
- = $this->_('email' ); ?> | = $email; ?> |
- = $this->_('phone' ); ?> | = $phone; ?> |
- = $this->_('notify_updates' ); ?> | = $notify_updates; ?> |
- = $this->_('notify_emergency'); ?> | = $notify_emergency; ?> |
-
diff --git a/src/Application/Views/Account/InfoView.php b/src/Application/Views/Account/InfoView.php
index 8b99722..358f248 100644
--- a/src/Application/Views/Account/InfoView.php
+++ b/src/Application/Views/Account/InfoView.php
@@ -26,7 +26,9 @@ public function __construct(InfoResponse $response)
'fullname' => parent::escape($response->person->fullname()),
'username' => parent::escape($_SESSION['USER']->username),
'email' => parent::escape($response->person->email),
- 'phone' => parent::escape($response->person->phone)
+ 'phone' => parent::escape($response->person->phone),
+ 'notify_updates' => $response->person->notify_updates,
+ 'notify_emergency' => $response->person->notify_emergency
];
$this->blocks[] = new Block('account/info.inc', $vars);
}
diff --git a/src/Application/Views/Account/UpdateView.php b/src/Application/Views/Account/UpdateView.php
index 297eaf0..8937a21 100644
--- a/src/Application/Views/Account/UpdateView.php
+++ b/src/Application/Views/Account/UpdateView.php
@@ -29,6 +29,8 @@ public function __construct(UpdateAccountRequest $request, ?UpdateAccountRespons
'lastname' => parent::escape($request->lastname),
'email' => parent::escape($request->email),
'phone' => parent::escape($request->phone),
+ 'notify_updates' => $request->notify_updates,
+ 'notify_emergency' => $request->notify_emergency,
'title' => $this->vars['title']
]);
diff --git a/src/Application/Views/People/InfoView.php b/src/Application/Views/People/InfoView.php
index f3b57a4..391102a 100644
--- a/src/Application/Views/People/InfoView.php
+++ b/src/Application/Views/People/InfoView.php
@@ -29,7 +29,9 @@ public function __construct(InfoResponse $response)
'username' => parent::escape($person->username),
'department' => parent::escape($person->department_name),
'email' => parent::escape($person->email),
- 'phone' => parent::escape($person->phone)
+ 'phone' => parent::escape($person->phone),
+ 'notify_updates' => $person->notify_updates,
+ 'notify_emergency' => $person->notify_emergency
];
$this->blocks[] = new Block('people/info.inc', $vars);
}
diff --git a/src/Application/Views/People/UpdateView.php b/src/Application/Views/People/UpdateView.php
index 9302ea7..167214d 100644
--- a/src/Application/Views/People/UpdateView.php
+++ b/src/Application/Views/People/UpdateView.php
@@ -31,6 +31,8 @@ public function __construct(UpdateRequest $request, ?UpdateResponse $response)
'lastname' => parent::escape($request->lastname),
'email' => parent::escape($request->email),
'phone' => parent::escape($request->phone),
+ 'notify_updates' => $request->notify_updates,
+ 'notify_emergency' => $request->notify_emergency,
'title' => $this->vars['title']
]);
diff --git a/src/Domain/People/DataStorage/ZendDbPeopleRepository.php b/src/Domain/People/DataStorage/ZendDbPeopleRepository.php
index b2d63fd..2fb73b7 100644
--- a/src/Domain/People/DataStorage/ZendDbPeopleRepository.php
+++ b/src/Domain/People/DataStorage/ZendDbPeopleRepository.php
@@ -6,10 +6,12 @@
declare (strict_types=1);
namespace Domain\People\DataStorage;
+use Domain\Notifications\Metadata as Notification;
use Domain\People\Entities\Person;
use Domain\People\UseCases\Search\SearchRequest;
use Domain\ZendDbRepository;
+use Zend\Db\Sql\Literal;
use Zend\Db\Sql\Select;
class ZendDbPeopleRepository extends ZendDbRepository implements PeopleRepository
@@ -46,10 +48,21 @@ public function columns(): array
private function baseSelect(): Select
{
+ $updates = Notification::TYPE_UPDATES;
+ $emergency = Notification::TYPE_EMERGENCY;
+
return $this->sql->select()
->columns($this->columns())
->from(['p'=>self::TABLE])
- ->join(['d'=>'departments'], 'p.department_id=d.id', ['department_name'=>'name'], Select::JOIN_LEFT);
+ ->join(['d'=>'departments'], 'p.department_id=d.id', ['department_name'=>'name'], Select::JOIN_LEFT)
+ ->join(['nu' => 'notificationEmails'],
+ new Literal("p.email=nu.email and nu.type='$updates'"),
+ ['notify_updates'=>new Literal('case when nu.email is not null then 1 else 0 end')],
+ Select::JOIN_LEFT)
+ ->join(['ne' => 'notificationEmails'],
+ new Literal("p.email=ne.email and ne.type='$emergency'"),
+ ['notify_emergency'=>new Literal('case when ne.email is not null then 1 else 0 end')],
+ Select::JOIN_LEFT);
}
public function load(int $person_id): Person
@@ -106,13 +119,35 @@ public function search(SearchRequest $req): array
*/
public function save(Person $p): int
{
- return parent::saveToTable([
+ $current = $p->id ? $this->load($p->id) : new Person();
+
+ $id = parent::saveToTable([
'id' => $p->id,
'firstname' => $p->firstname,
'lastname' => $p->lastname,
'email' => $p->email,
'phone' => $p->phone
], self::TABLE);
+
+ if ($p->email) {
+ if ($current->notify_updates !== $p->notify_updates) {
+ $type = Notification::TYPE_UPDATES;
+ $sql = $p->notify_updates
+ ? 'insert into notificationEmails set email=?, type=?'
+ : 'delete from notificationEmails where email=? and type=?';
+ $this->zend_db->query($sql, [$p->email, $type]);
+ }
+
+ if ($current->notify_emergency !== $p->notify_emergency) {
+ $type = Notification::TYPE_EMERGENCY;
+ $sql = $p->notify_emergency
+ ? 'insert into notificationEmails set email=?, type=?'
+ : 'delete from notificationEmails where email=? and type=?';
+ $this->zend_db->query($sql, [$p->email, $type]);
+ }
+ }
+
+ return $id;
}
/**
diff --git a/src/Domain/People/Entities/Person.php b/src/Domain/People/Entities/Person.php
index 4b62666..0d9ef74 100644
--- a/src/Domain/People/Entities/Person.php
+++ b/src/Domain/People/Entities/Person.php
@@ -18,6 +18,9 @@ class Person
public $department_id;
public $department_name;
+ public $notify_updates = false;
+ public $notify_emergency = false;
+
public function __construct(?array $data=null)
{
@@ -31,6 +34,9 @@ public function __construct(?array $data=null)
if (!empty($data['department_id' ])) { $this->department_id = (int)$data['department_id' ]; }
if (!empty($data['department_name'])) { $this->department_name = $data['department_name']; }
+
+ if (!empty($data['notify_updates' ])) { $this->notify_updates = $data['notify_updates' ] ? true : false; }
+ if (!empty($data['notify_emergency'])) { $this->notify_emergency = $data['notify_emergency'] ? true : false; }
}
}
diff --git a/src/Domain/People/UseCases/Update/UpdateRequest.php b/src/Domain/People/UseCases/Update/UpdateRequest.php
index aebd8e4..ffedb33 100644
--- a/src/Domain/People/UseCases/Update/UpdateRequest.php
+++ b/src/Domain/People/UseCases/Update/UpdateRequest.php
@@ -13,6 +13,8 @@ class UpdateRequest
public $lastname;
public $email;
public $phone;
+ public $notify_updates = false;
+ public $notify_emergency = false;
public function __construct(?array $data=null)
{
@@ -22,6 +24,9 @@ public function __construct(?array $data=null)
if (!empty($data['lastname' ])) { $this->lastname = $data['lastname' ]; }
if (!empty($data['email' ])) { $this->email = $data['email' ]; }
if (!empty($data['phone' ])) { $this->phone = $data['phone' ]; }
+
+ if (!empty($data['notify_updates' ])) { $this->notify_updates = $data['notify_updates' ] ? true : false; }
+ if (!empty($data['notify_emergency'])) { $this->notify_emergency = $data['notify_emergency'] ? true : false; }
}
}
}
diff --git a/src/Domain/People/UseCases/UpdateAccount/UpdateAccount.php b/src/Domain/People/UseCases/UpdateAccount/UpdateAccount.php
index 1c1a6e3..9c99692 100644
--- a/src/Domain/People/UseCases/UpdateAccount/UpdateAccount.php
+++ b/src/Domain/People/UseCases/UpdateAccount/UpdateAccount.php
@@ -29,6 +29,8 @@ public function __invoke(UpdateAccountRequest $req): UpdateAccountResponse
$res->person->lastname = $req->lastname;
$res->person->email = $req->email;
$res->person->phone = $req->phone;
+ $res->person->notify_updates = $req->notify_updates;
+ $res->person->notify_emergency = $req->notify_emergency;
$validation = $validate($res->person);
if ($validation->errors) { return new UpdateAccountResponse(null, $validation->errors); }
diff --git a/src/Domain/People/UseCases/UpdateAccount/UpdateAccountRequest.php b/src/Domain/People/UseCases/UpdateAccount/UpdateAccountRequest.php
index d9a75bf..32f1a6d 100644
--- a/src/Domain/People/UseCases/UpdateAccount/UpdateAccountRequest.php
+++ b/src/Domain/People/UseCases/UpdateAccount/UpdateAccountRequest.php
@@ -13,6 +13,8 @@ class UpdateAccountRequest
public $lastname;
public $email;
public $phone;
+ public $notify_updates = false;
+ public $notify_emergency = false;
public function __construct(int $id, array $data=null)
{
@@ -23,6 +25,8 @@ public function __construct(int $id, array $data=null)
if (!empty($data['lastname' ])) { $this->lastname = $data['lastname' ]; }
if (!empty($data['email' ])) { $this->email = $data['email' ]; }
if (!empty($data['phone' ])) { $this->phone = $data['phone' ]; }
+ if (!empty($data['notify_updates' ])) { $this->notify_updates = $data['notify_updates' ] ? true : false; }
+ if (!empty($data['notify_emergency'])) { $this->notify_emergency = $data['notify_emergency'] ? true : false; }
}
}
}