Skip to content

Commit

Permalink
Added notification flags back into people
Browse files Browse the repository at this point in the history
  • Loading branch information
inghamn committed Jun 26, 2018
1 parent 51a350d commit 33f7106
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 35 deletions.
8 changes: 8 additions & 0 deletions blocks/html/account/info.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,5 +31,11 @@ use Application\Auth;
<table>
<tr><th><?= $this->_('email'); ?></th><td><?= $this->email; ?></th></tr>
<tr><th><?= $this->_('phone'); ?></th><td><?= $this->phone; ?></th></tr>
<tr><th><?= $this->_('notify_updates' ); ?></th>
<td><?= $this->notify_updates ? $this->_('yes') : $this->_('no'); ?></td>
</tr>
<tr><th><?= $this->_('notify_emergency'); ?></th>
<td><?= $this->notify_emergency ? $this->_('yes') : $this->_('no'); ?></td>
</tr>
</table>
</section>
14 changes: 11 additions & 3 deletions blocks/html/people/info.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,8 +41,14 @@ if (Auth::isAllowed('people', 'update')) {
<div class="tools"><?= $editButton; ?></div>
</header>
<table>
<tr><th><?= $this->_('department'); ?></th><td><?= $this->department; ?></th></tr>
<tr><th><?= $this->_('email' ); ?></th><td><?= $this->email; ?></th></tr>
<tr><th><?= $this->_('phone' ); ?></th><td><?= $this->phone; ?></th></tr>
<tr><th><?= $this->_('department'); ?></th><td><?= $this->department; ?></td></tr>
<tr><th><?= $this->_('email' ); ?></th><td><?= $this->email; ?></td></tr>
<tr><th><?= $this->_('phone' ); ?></th><td><?= $this->phone; ?></td></tr>
<tr><th><?= $this->_('notify_updates' ); ?></th>
<td><?= $this->notify_updates ? $this->_('yes') : $this->_('no'); ?></td>
</tr>
<tr><th><?= $this->_('notify_emergency'); ?></th>
<td><?= $this->notify_emergency ? $this->_('yes') : $this->_('no'); ?></td>
</tr>
</table>
</section>
8 changes: 4 additions & 4 deletions blocks/html/people/partials/personInfoFields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -46,7 +48,6 @@ echo $h->field([
'attr' => ['inputmode'=>'tel']
]);

/*
$options = [
['value'=>1, 'label'=>$this->_('yes')],
['value'=>0, 'label'=>$this->_('no' )]
Expand All @@ -55,16 +56,15 @@ echo $h->field([
'name' => 'notify_updates',
'id' => 'notify_updates',
'label' => $this->_('notify_updates'),
'value' => $notify_updates,
'value' => $this->notify_updates,
'type' => 'select',
'options' => $options
]);
echo $h->field([
'name' => 'notify_emergency',
'id' => 'notify_emergency',
'label' => $this->_('notify_emergency'),
'value' => $notify_emergency,
'value' => $this->notify_emergency,
'type' => 'select',
'options' => $options
]);
*/
24 changes: 0 additions & 24 deletions blocks/html/people/partials/personalInfo.inc

This file was deleted.

4 changes: 3 additions & 1 deletion src/Application/Views/Account/InfoView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Application/Views/Account/UpdateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
]);
Expand Down
4 changes: 3 additions & 1 deletion src/Application/Views/People/InfoView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Application/Views/People/UpdateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
]);
Expand Down
39 changes: 37 additions & 2 deletions src/Domain/People/DataStorage/ZendDbPeopleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/Domain/People/Entities/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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; }
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Domain/People/UseCases/Update/UpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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; }
}
}
}
2 changes: 2 additions & 0 deletions src/Domain/People/UseCases/UpdateAccount/UpdateAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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; }
}
}
}

1 comment on commit 33f7106

@inghamn
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates #151

Please sign in to comment.