Skip to content

Commit

Permalink
Merge pull request #14 from bluzphp/develop
Browse files Browse the repository at this point in the history
Migrate to PHP 7.1
  • Loading branch information
Anton authored Nov 1, 2018
2 parents 02dc769 + 00848f5 commit 7e8f2ab
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 39 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
File renamed without changes.
8 changes: 2 additions & 6 deletions application/models/Media/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ class Grid extends \Bluz\Grid\Grid
protected $uid = 'options';

/**
* init
*
* @return self
* {@inheritdoc}
*/
public function init()
public function init() : void
{
// Array
$adapter = new SqlSource();
Expand All @@ -41,7 +39,5 @@ public function init()
$this->setDefaultLimit(25);
$this->setAllowOrders(['id', 'login', 'title', 'type', 'created', 'deleted']);
$this->setAllowFilters(['userId', 'title', 'file']);

return $this;
}
}
6 changes: 3 additions & 3 deletions application/models/Media/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
namespace Application\Media;

use Application\Users;
use Bluz\Application\Exception\BadRequestException;
use Bluz\Config\ConfigException;
use Bluz\Http\Exception\BadRequestException;
use Bluz\Proxy\Auth;
use Bluz\Proxy\Config;
use Image\Thumbnail;
Expand Down Expand Up @@ -62,7 +62,7 @@ public function __construct($media, $file)
{
$this->media = $media;
$this->media->module = $this->media->module ?: 'users';
$this->media->userId = $this->media->userId ?: Auth::getIdentity()->id ?: Users\Table::SYSTEM_USER;
$this->media->userId = $this->media->userId ?: Auth::getIdentity()->getId() ?: Users\Table::SYSTEM_USER;

$this->file = $file;
$this->name = $media->title ?? pathinfo($file->getClientFilename(), PATHINFO_FILENAME);
Expand All @@ -81,7 +81,7 @@ public function __construct($media, $file)
*/
public function moveToDir($directory)
{
$uploadPath = Config::getModuleData('media', 'upload_path');
$uploadPath = Config::get('module.media', 'upload_path');

if (empty($uploadPath)) {
throw new ConfigException('Upload path is not configured');
Expand Down
10 changes: 5 additions & 5 deletions application/models/Media/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Row extends \Bluz\Db\Row
/**
* {@inheritdoc}
*/
protected function beforeSave()
protected function beforeSave() : void
{
$this->addValidator('title')
->required()
Expand All @@ -49,7 +49,7 @@ protected function beforeSave()
*
* @return void
*/
protected function beforeInsert()
protected function beforeInsert() : void
{
$this->created = gmdate('Y-m-d H:i:s');

Expand All @@ -59,7 +59,7 @@ protected function beforeInsert()
}
// set user ID
if ($user = Auth::getIdentity()) {
$this->userId = $user->id;
$this->userId = $user->getId();
} else {
$this->userId = Users\Table::SYSTEM_USER;
}
Expand All @@ -70,7 +70,7 @@ protected function beforeInsert()
*
* @return void
*/
protected function beforeUpdate()
protected function beforeUpdate() : void
{
$this->updated = gmdate('Y-m-d H:i:s');
}
Expand All @@ -80,7 +80,7 @@ protected function beforeUpdate()
*
* @return void
*/
protected function afterDelete()
protected function afterDelete() : void
{
$this->deleteFiles();
}
Expand Down
6 changes: 3 additions & 3 deletions application/models/Media/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Table extends \Bluz\Db\Table
* Primary key(s)
* @var array
*/
protected $primary = array('id');
protected $primary = ['id'];

/**
* Get images of current user
Expand All @@ -42,12 +42,12 @@ class Table extends \Bluz\Db\Table
*/
public function getImages()
{
/** @var Row $user */
/* @var \Application\Users\Row $user */
if (!$user = Auth::getIdentity()) {
throw new Exception('User not found');
}

return $this->getImagesByUserId($user->id);
return $this->getImagesByUserId($user->getId());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion application/modules/media/controllers/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
$result = $crudController->run();

// back to grid after create or update media file
if (Request::isPost() || Request::isPut()) {
if ((Request::isPost() || Request::isPut()) && !Request::isXmlHttpRequest()) {
Response::reload();
}

Expand Down
2 changes: 1 addition & 1 deletion application/modules/media/controllers/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
namespace Application;

use Bluz\Application\Exception\BadRequestException;
use Bluz\Http\Exception\BadRequestException;
use Bluz\Config\ConfigException;
use Bluz\Controller\Controller;
use Bluz\Proxy\Request;
Expand Down
4 changes: 3 additions & 1 deletion application/modules/media/views/crud.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
*/
?>
<?php $uid = uniqid('form_', false); ?>
<form id="<?=$uid?>" action="<?=$this->url('media', 'crud')?>" class="form-horizontal" method="POST" enctype="multipart/form-data">
<form id="<?=$uid?>" action="<?=$this->url('media', 'crud')?>"
class="form-horizontal" method="POST"
<?= ($method==='PUT'?'data-ajax':'enctype="multipart/form-data"') ?>>
<input type="hidden" name="_method" value="<?=$method?>"/>
<input type="hidden" name="id" value="<?=$row->id?>"/>
<div class="modal-content">
Expand Down
2 changes: 1 addition & 1 deletion application/modules/media/views/grid.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if (!$grid) {
<hr style="display: block; clear: both"/>
<div class="card-deck">
<?php foreach ($grid->getData() as $row) : ?>
<div class="card mb-3" style="min-width: 240px; max-width: 240px">
<div class="card mb-3">
<a href="<?= $this->baseUrl($row['file']) ?>" data-ajax-preview>
<img class="card-img-top" src="<?= $this->baseUrl($row['thumb']) ?>" alt="<?= esc($row['title']) ?>">
</a>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"extra": {
"copy-files": {
"enyo/dropzone/dist/min/dropzone-amd-module.min.js": "public/js/vendor/dropzone-amd-module.min.js"
"enyo/dropzone/dist/": "public/vendor/dropzone-amd-module/"
}
}
}
11 changes: 11 additions & 0 deletions public/css/media.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@
max-height: 480px;
overflow-y: scroll;
border: 2px dashed rgba(0, 0, 0, 0.1);
}

.card-deck .card {
min-width: 240px;
max-width: 240px
}

.card-deck .card-img-top {
/*display: block;
min-width: 196px;
max-width: 196px*/
}
8 changes: 4 additions & 4 deletions public/js/bluz.media.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* - push.data.bluz
*/
/* global define,require*/
define(['jquery', 'bluz', 'bluz.notify', 'dropzone'], function ($, bluz, notify, Dropzone) {
define(['jquery', 'bluz', 'bluz.ajax', 'bluz.notify', 'dropzone'], function ($, bluz, ajax, notify, Dropzone) {
'use strict';

// Media object
Expand Down Expand Up @@ -36,7 +36,7 @@ define(['jquery', 'bluz', 'bluz.notify', 'dropzone'], function ($, bluz, notify,

// hookup for delete click
media.$previews.on('success.bluz.ajax', 'a[data-ajax-method=delete]', function () {
$(this).parents('div.image-preview').remove();
$(this).parents('div.card').remove();
});
};

Expand All @@ -59,11 +59,11 @@ define(['jquery', 'bluz', 'bluz.notify', 'dropzone'], function ($, bluz, notify,
})
.on('processing', () => {
// use element similar to bluz.ajax
bluz.showLoading();
ajax.showLoading();
media.$progress.removeAttr('hidden');
})
.on('complete', () => {
bluz.hideLoading();
ajax.hideLoading();
media.$progress.attr('hidden', '1');
media.$upload.stop(true, true);
})
Expand Down
23 changes: 11 additions & 12 deletions tests/unit/modules/media/controllers/CrudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Bluz\Proxy\Config;
use Bluz\Proxy\Db;
use Bluz\Proxy\Request;
use Bluz\Proxy\Response;
use Zend\Diactoros\UploadedFile;

/**
Expand Down Expand Up @@ -49,9 +50,15 @@ public function setUp()
*/
public static function tearDownAfterClass()
{
Db::delete('media')->where('userId = ?', 1)->execute();
$path = Config::getModuleData('media', 'upload_path').'/1';
Tools\Cleaner::delete($path);
// need to connect to DB
self::getApp();
{
Db::delete('media')->where('userId = ?', 1)->execute();
$path = Config::get('module.media', 'upload_path').'/1';
Tools\Cleaner::delete($path);
}
self::resetApp();
self::resetGlobals();
}

/**
Expand All @@ -60,7 +67,7 @@ public static function tearDownAfterClass()
public function testUploadFile()
{
// get path from config
$path = Config::getData('temp', 'path');
$path = Config::get('temp', 'path');
if (empty($path)) {
throw new Exception('Temporary path is not configured');
}
Expand Down Expand Up @@ -97,14 +104,6 @@ public function testCreateForm()
*/
public function testEditForm()
{
/*
$this->dispatchRouter('/media/crud/', ['id' => 1]);
self::assertOk();
self::assertQueryCount('form[method="PUT"]', 1);
self::assertQueryCount('input[name="id"][value="1"]', 1);
*/
// Remove the following lines when you implement this test.
// Need to create element with ID
self::markTestIncomplete(
Expand Down

0 comments on commit 7e8f2ab

Please sign in to comment.