Skip to content

Commit

Permalink
Added a notifications field in the people table
Browse files Browse the repository at this point in the history
Updates #144
  • Loading branch information
inghamn committed Apr 27, 2018
1 parent 12c46c9 commit 6aac1f4
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 31 deletions.
15 changes: 9 additions & 6 deletions blocks/html/account/info.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ foreach ($fields as $f) {
$get = 'get'.ucfirst($f);
$$f = parent::escape($this->person->$get());
}
$notifications = $this->person->getNotifications() ? $this->_('yes') : $this->_('no');
?>
<section>
<header>
Expand All @@ -32,12 +33,14 @@ foreach ($fields as $f) {


<table>
<tr><th><?= $this->_('firstname' ); ?></th><td><?= $firstname; ?></th></tr>
<tr><th><?= $this->_('lastname' ); ?></th><td><?= $lastname; ?></th></tr>
<tr><th><?= $this->_('department'); ?></th><td><?= $department; ?></th></tr>
<tr><th><?= $this->_('email' ); ?></th><td><?= $email; ?></th></tr>
<tr><th><?= $this->_('phone' ); ?></th><td><?= $phone; ?></th></tr>
<tr><th><?= $this->_('username' ); ?></th><td><?= $username; ?></th></tr>
<tr><th><?= $this->_('firstname' ); ?></th><td><?= $firstname; ?></th></tr>
<tr><th><?= $this->_('lastname' ); ?></th><td><?= $lastname; ?></th></tr>
<tr><th><?= $this->_('department' ); ?></th><td><?= $department; ?></th></tr>
<tr><th><?= $this->_('email' ); ?></th><td><?= $email; ?></th></tr>
<tr><th><?= $this->_('phone' ); ?></th><td><?= $phone; ?></th></tr>
<tr><th><?= $this->_('username' ); ?></th><td><?= $username; ?></th></tr>
<tr><th><?= $this->_('notifications'); ?></th><td><?= $notifications; ?></th></tr>
</table>
</table>

</section>
10 changes: 6 additions & 4 deletions blocks/html/people/info.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ foreach ($fields as $f) {
$get = 'get'.ucfirst($f);
$$f = $this->person->$get();
}
$notifications = $this->person->getNotifications() ? $this->_('yes') : $this->_('no');

$return_url = Url::current_url(BASE_HOST);
$h = $this->template->getHelper('buttonLink');
Expand Down Expand Up @@ -39,9 +40,10 @@ if (Person::isAllowed('people', 'update')) {
<div class="tools"><?= $editButton; ?></div>
</header>
<table>
<tr><th><?= $this->_('department'); ?></th><td><?= $department; ?></th></tr>
<tr><th><?= $this->_('email' ); ?></th><td><?= $email; ?></th></tr>
<tr><th><?= $this->_('phone' ); ?></th><td><?= $phone; ?></th></tr>
<tr><th><?= $this->_('username' ); ?></th><td><?= $username; ?></th></tr>
<tr><th><?= $this->_('department' ); ?></th><td><?= $department; ?></th></tr>
<tr><th><?= $this->_('email' ); ?></th><td><?= $email; ?></th></tr>
<tr><th><?= $this->_('phone' ); ?></th><td><?= $phone; ?></th></tr>
<tr><th><?= $this->_('username' ); ?></th><td><?= $username; ?></th></tr>
<tr><th><?= $this->_('notifications'); ?></th><td><?= $notifications; ?></th></tr>
</table>
</section>
15 changes: 14 additions & 1 deletion blocks/html/people/partials/personInfoFields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
declare (strict_types=1);

$fields = ['firstname', 'lastname', 'email', 'phone'];
$fields = ['firstname', 'lastname', 'email', 'phone', 'notifications'];
foreach ($fields as $f) {
$get = 'get'.ucfirst($f);
$$f = parent::escape($this->person->$get());
Expand Down Expand Up @@ -48,3 +48,16 @@ echo $h->field([
'type' => 'tel',
'attr' => ['inputmode'=>'tel']
]);

$options = [
['value'=>1, 'label'=>$this->_('yes')],
['value'=>0, 'label'=>$this->_('no' )]
];
echo $h->field([
'name' => 'notifications',
'id' => 'notifications',
'label' => $this->_('notifications'),
'value' => $notifications,
'type' => 'select',
'options' => $options
]);
3 changes: 2 additions & 1 deletion scripts/migrations/1.1-1.2/databaseChanges.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
alter table eventTypes add cifsType varchar(128);
alter table events add foreign key (eventType_id) references eventTypes(id);
alter table events add foreign key (eventType_id) references eventTypes(id);
alter table people add notifications boolean;
19 changes: 10 additions & 9 deletions scripts/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ create table departments (
);

create table people (
id int unsigned not null primary key auto_increment,
firstname varchar(128) not null,
lastname varchar(128) not null,
email varchar(255) not null,
phone varchar(16),
username varchar(40) unique,
password varchar(40),
id int unsigned not null primary key auto_increment,
department_id int unsigned,
firstname varchar(128) not null,
lastname varchar(128) not null,
email varchar(255) not null,
phone varchar(16),
username varchar(40) unique,
password varchar(40),
authenticationMethod varchar(40),
role varchar(30),
department_id int unsigned,
role varchar(30),
notifications boolean
foreign key (department_id) references departments(id)
);

Expand Down
8 changes: 6 additions & 2 deletions src/Models/PeopleTable.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
/**
* @copyright 2013 City of Bloomington, Indiana
* @copyright 2014-2018 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <[email protected]>
*/
namespace Application\Models;

Expand Down Expand Up @@ -34,6 +33,11 @@ public function find($fields=null, $order='lastname', $paginated=false, $limit=n
}
break;

case 'notifications':
if ($value) { $select->where('notifications = 1'); }
else { $select->where('notifications != 1'); }
break;

default:
$select->where([$key=>$value]);
}
Expand Down
16 changes: 8 additions & 8 deletions src/Models/Person.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
/**
* @copyright 2009-2015 City of Bloomington, Indiana
* @copyright 2009-2018 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <[email protected]>
*/
namespace Application\Models;
use Blossom\Classes\ActiveRecord;
Expand Down Expand Up @@ -96,9 +95,7 @@ public function save()
*/
public function deleteUserAccount()
{
$userAccountFields = array(
'username', 'password', 'authenticationMethod', 'role'
);
$userAccountFields = ['username', 'password', 'authenticationMethod', 'role'];
foreach ($userAccountFields as $f) {
$this->data[$f] = null;
}
Expand All @@ -123,12 +120,14 @@ public function getUsername() { return parent::get('username'); }
public function getPassword() { return parent::get('password'); } # Encrypted
public function getRole() { return parent::get('role'); }
public function getAuthenticationMethod() { return parent::get('authenticationMethod'); }
public function getNotifications(): int { return parent::get('notifications') ? 1 : 0; }
public function getDepartment_id() { return parent::get('getDepartment_id'); }
public function getDepartment() { return parent::getForeignKeyObject(__namespace__.'\Department', 'department_id'); }

public function setUsername ($s) { parent::set('username', $s); }
public function setRole ($s) { parent::set('role', $s); }
public function setAuthenticationMethod($s) { parent::set('authenticationMethod', $s); }
public function setNotifications ($b) { parent::set('notifications', $b ? 1 : 0); }
public function setDepartment_id($i) { parent::setForeignKeyField (__namespace__.'\Department', 'department_id', $i); }
public function setDepartment ($i) { parent::setForeignKeyObject(__namespace__.'\Department', 'department_id', $i); }

Expand All @@ -144,7 +143,7 @@ public function setPassword($s)
*/
public function handleUpdate($post)
{
$fields = array( 'firstname', 'middlename', 'lastname', 'email', 'phone' );
$fields = ['firstname', 'middlename', 'lastname', 'email', 'phone', 'notifications'];
foreach ($fields as $field) {
if (isset($post[$field])) {
$set = 'set'.ucfirst($field);
Expand All @@ -158,10 +157,10 @@ public function handleUpdate($post)
*/
public function handleUpdateUserAccount($post)
{
$fields = array(
$fields = [
'firstname', 'lastname', 'email', 'phone', 'department_id',
'username', 'authenticationMethod', 'role'
);
];

foreach ($fields as $f) {
if (isset($post[$f])) {
Expand Down Expand Up @@ -277,4 +276,5 @@ public function populateFromExternalIdentity(ExternalIdentity $identity)
$this->setPhone($identity->getPhone());
}
}

}

0 comments on commit 6aac1f4

Please sign in to comment.