Skip to content

Commit

Permalink
Merge pull request #20 from bluzphp/develop
Browse files Browse the repository at this point in the history
Migrate to PHP 7.1
  • Loading branch information
Anton authored Oct 31, 2018
2 parents 2739031 + 8e2fa89 commit 46eb67b
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 34 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: php
php:
- 7.0
- 7.1
- 7.2
- master
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @link https://github.com/bluzphp/skeleton/wiki/Module-Contact-Us
* @return array
*/
return array(
return [
'secretKey' => 'secret key',
'siteKey' => 'site key'
);
];
10 changes: 4 additions & 6 deletions application/models/ContactUs/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@
*/
class Grid extends \Bluz\Grid\Grid
{
const DEFAULT_LIMIT = 25;
public const DEFAULT_LIMIT = 25;

/**
* @var string
*/
protected $uid = 'contact_us';

/**
* init
*
* @return self
* {@inheritdoc}
* @throws \Bluz\Grid\GridException
*/
public function init()
public function init() : void
{
$adapter = new SqlSource();
$adapter->setSource('SELECT * FROM contact_us');
Expand All @@ -41,6 +40,5 @@ public function init()
$this->setAllowFilters(['name', 'email', 'subject', 'message', 'markRead', 'markAnswered']);
$this->addAlias('markAnswered', 'answered');
$this->addAlias('markRead', 'readed');
return $this;
}
}
8 changes: 4 additions & 4 deletions application/models/ContactUs/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Row extends \Bluz\Db\Row
/**
* {@inheritdoc}
*/
protected function beforeSave()
protected function beforeSave() : void
{
if (!Auth::getIdentity()) {
$this->addValidator('name')
Expand All @@ -61,13 +61,13 @@ protected function beforeSave()
/**
* {@inheritdoc}
*/
public function beforeInsert()
public function beforeInsert() : void
{
$this->created = gmdate('Y-m-d H:i:s');

/* @var \Application\Users\Row $user */
if ($user = Auth::getIdentity()) {
$this->userId = $user->id;
$this->userId = $user->getId();
} else {
$this->userId = \Application\Users\Table::SYSTEM_USER;
}
Expand All @@ -76,7 +76,7 @@ public function beforeInsert()
/**
* {@inheritdoc}
*/
protected function beforeUpdate()
protected function beforeUpdate() : void
{
$this->updated = gmdate('Y-m-d H:i:s');
}
Expand Down
6 changes: 5 additions & 1 deletion application/modules/contact-us/controllers/answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@

namespace Application;

use Bluz\Application\Exception\NotFoundException;
use Bluz\Controller\Controller;
use Bluz\Http\Exception\NotFoundException;

/**
* @param int $id
*
* @throws NotFoundException
* @throws \Bluz\Common\Exception\ConfigurationException
* @throws \Bluz\Db\Exception\DbException
* @throws \Bluz\Db\Exception\InvalidPrimaryKeyException
* @throws \Bluz\Db\Exception\TableNotFoundException
*/
return function ($id) {
/**
Expand Down
10 changes: 8 additions & 2 deletions application/modules/contact-us/controllers/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@

namespace Application;

use Application\ContactUs;
use Bluz\Controller\Mapper\Crud;
use Bluz\Controller\Controller;
use Bluz\Controller\Mapper\Crud;

/**
* @accept HTML
* @accept JSON
* @privilege Management
*
* @return mixed
* @throws \Bluz\Common\Exception\CommonException
* @throws \Bluz\Common\Exception\ComponentException
* @throws \Bluz\Controller\ControllerException
* @throws \Bluz\Http\Exception\ForbiddenException
* @throws \Bluz\Http\Exception\NotAcceptableException
* @throws \Bluz\Http\Exception\NotAllowedException
* @throws \Bluz\Http\Exception\NotImplementedException
*/
return function () {
/**
Expand Down
12 changes: 6 additions & 6 deletions application/modules/contact-us/controllers/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

namespace Application;

use Application\ContactUs\Row;
use Bluz\Controller\Controller;
use Bluz\Db\Exception\DbException;
use Bluz\Proxy\Request;
use Bluz\Proxy\Messages;
use Bluz\Controller\Controller;
use Bluz\Proxy\Layout;
use Bluz\Proxy\Config;
use Bluz\Proxy\Response;
Expand All @@ -26,7 +25,8 @@
* @param string $message
*
* @return array
* @throws ValidatorException
* @throws \Bluz\Common\Exception\ConfigurationException
* @throws \Bluz\Http\Exception\RedirectException
*/
return function ($name, $email, $subject, $message) {
/**
Expand All @@ -46,13 +46,13 @@
$this->assign('subject', $subject);
$this->assign('message', $message);

$this->assign('siteKey', Config::getModuleData('contact-us', 'siteKey'));
$this->assign('siteKey', Config::get('module.contact-us', 'siteKey'));

if (Request::isPost()) {
$row = new Row();
$row = new ContactUs\Row();

if (!$user) {
$reCaptcha = new ReCaptcha(Config::getModuleData('contact-us', 'secretKey'));
$reCaptcha = new ReCaptcha(Config::get('module.contact-us', 'secretKey'));
$response = $reCaptcha->verify(Request::getParam('g-recaptcha-response'), $_SERVER['REMOTE_ADDR']);

if (!$response->isSuccess()) {
Expand Down
8 changes: 6 additions & 2 deletions application/modules/contact-us/controllers/read.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@

namespace Application;

use Bluz\Application\Exception\NotFoundException;
use Bluz\Controller\Controller;
use Bluz\Http\Exception\NotFoundException;
use Bluz\Proxy\Request;

/**
* @param int $id
*
* @throws NotFoundException
* @throws \Bluz\Common\Exception\ConfigurationException
* @throws \Bluz\Db\Exception\DbException
* @throws \Bluz\Db\Exception\InvalidPrimaryKeyException
* @throws \Bluz\Db\Exception\TableNotFoundException
*/
return function ($id) {
/**
* @var Controller $this
*/
$row = ContactUs\Table::findRow($id);
if (empty($row)) {
if (!$row) {
throw new NotFoundException('Row not found');
}

Expand Down
11 changes: 8 additions & 3 deletions application/modules/contact-us/controllers/reply.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,30 @@

namespace Application;

use Bluz\Application\Exception\NotFoundException;
use Bluz\Controller\Controller;
use Bluz\Http\Exception\NotFoundException;
use Bluz\Proxy\Messages;
use Bluz\Proxy\Request;
use Bluz\Proxy\Mailer;
use Bluz\Controller\Controller;
use Bluz\Proxy\Response;

/**
* @param int $id
* @param string $message
*
* @throws NotFoundException
* @throws \Bluz\Common\Exception\ConfigurationException
* @throws \Bluz\Db\Exception\DbException
* @throws \Bluz\Db\Exception\InvalidPrimaryKeyException
* @throws \Bluz\Db\Exception\TableNotFoundException
* @throws \Bluz\Http\Exception\RedirectException
*/
return function ($id, $message) {
/**
* @var Controller $this
*/
$row = ContactUs\Table::findRow($id);
if (empty($row)) {
if (!$row) {
throw new NotFoundException('Row not found');
}

Expand Down
14 changes: 7 additions & 7 deletions application/modules/contact-us/views/grid.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
<div class="clearfix" data-spy="grid" data-grid="<?= $grid->getUid() ?>">
<nav class="navbar navbar-light bg-light justify-content-between">
<div>
<a href="<?= $grid->filter('markRead', 'eq', '', true) ?>" class="btn btn-secondary navbar-btn <?= (
$grid->getFilter('markRead', 'eq') === null && $grid->getFilter('markRead', 'ne') === null ? 'btn-info' : ''
<a href="<?= $grid->filter('markRead', 'eq', '', true) ?>" class="btn <?= (
$grid->getFilter('markRead', 'eq') === null && $grid->getFilter('markRead', 'ne') === null ? 'btn-info' : 'btn-secondary'
) ?>" data-ajax>all</a>
<a href="<?= $grid->filter('markRead', 'ne', 1) ?>" class="btn btn-secondary navbar-btn <?= (
$grid->getFilter('markRead', 'ne') ? 'btn-info' : ''
<a href="<?= $grid->filter('markRead', 'ne', 1) ?>" class="btn <?= (
$grid->getFilter('markRead', 'ne') ? 'btn-info' : 'btn-secondary'
) ?>" data-ajax>Unread</a>
<a href="<?= $grid->filter('markRead', 'eq', 1) ?>" class="btn btn-secondary navbar-btn <?= (
$grid->getFilter('markRead', 'eq') ? 'btn-info' : ''
<a href="<?= $grid->filter('markRead', 'eq', 1) ?>" class="btn <?= (
$grid->getFilter('markRead', 'eq') ? 'btn-info' : 'btn-secondary'
) ?>" data-ajax>Read</a>
</div>
<form action="<?= $this->url('contact-us', 'grid') ?>" class="form-inline filter-form" data-ajax>
Expand Down Expand Up @@ -89,7 +89,7 @@
</a>
</td>
<td><?= $row['created'] ?></td>
<td class="controls">
<td class="controls d-flex justify-content-around">
<a href="<?= $this->url('contact-us', 'reply', ['id' => $row['id']]) ?>"
class="btn btn-secondary btn-xs reply"
data-ajax-dialog data-ajax-method="get" data-modal-style="width:700px;">
Expand Down

0 comments on commit 46eb67b

Please sign in to comment.