#15: Number of hits to albums/photos are now recorded in the database
This commit is contained in:
parent
d2d6c5a465
commit
def4a28b10
@ -57,6 +57,11 @@ class AlbumController extends Controller
|
|||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DB::transaction(function () use ($album) {
|
||||||
|
$album->hits++;
|
||||||
|
$album->save();
|
||||||
|
});
|
||||||
|
|
||||||
return Theme::render(sprintf('gallery.album_%s', $requestedView), [
|
return Theme::render(sprintf('gallery.album_%s', $requestedView), [
|
||||||
'album' => $album,
|
'album' => $album,
|
||||||
'allowed_views' => $validViews,
|
'allowed_views' => $validViews,
|
||||||
|
@ -13,6 +13,7 @@ use App\Http\Middleware\VerifyCsrfToken;
|
|||||||
use App\Photo;
|
use App\Photo;
|
||||||
use Guzzle\Http\Mimetypes;
|
use Guzzle\Http\Mimetypes;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
@ -60,6 +61,11 @@ class PhotoController extends Controller
|
|||||||
$photoStream = $album->getAlbumSource()->fetchPhotoContent($photo, $thumbnail);
|
$photoStream = $album->getAlbumSource()->fetchPhotoContent($photo, $thumbnail);
|
||||||
$mimeType = Mimetypes::getInstance()->fromFilename($photo->storage_file_name);
|
$mimeType = Mimetypes::getInstance()->fromFilename($photo->storage_file_name);
|
||||||
|
|
||||||
|
DB::transaction(function () use ($photo) {
|
||||||
|
$photo->hits_download++;
|
||||||
|
$photo->save();
|
||||||
|
});
|
||||||
|
|
||||||
return response()->stream(
|
return response()->stream(
|
||||||
function() use ($photoStream)
|
function() use ($photoStream)
|
||||||
{
|
{
|
||||||
@ -95,6 +101,11 @@ class PhotoController extends Controller
|
|||||||
$returnAlbumUrl = $referer;
|
$returnAlbumUrl = $referer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DB::transaction(function () use ($photo) {
|
||||||
|
$photo->hits++;
|
||||||
|
$photo->save();
|
||||||
|
});
|
||||||
|
|
||||||
return Theme::render('gallery.photo', [
|
return Theme::render('gallery.photo', [
|
||||||
'album' => $album,
|
'album' => $album,
|
||||||
'is_original_allowed' => $isOriginalAllowed,
|
'is_original_allowed' => $isOriginalAllowed,
|
||||||
|
10
app/VisitorHit.php
Normal file
10
app/VisitorHit.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class VisitorHit extends Model
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateVisitorHitsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('visitor_hits', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->unsignedInteger('album_id')->nullable();
|
||||||
|
$table->unsignedBigInteger('photo_id')->nullable();
|
||||||
|
$table->unsignedInteger('user_id')->nullable();
|
||||||
|
$table->string('album_view')->nullable();
|
||||||
|
$table->timestamp('hit_at');
|
||||||
|
$table->string('ip_address');
|
||||||
|
$table->string('user_agent');
|
||||||
|
|
||||||
|
$table->foreign('album_id')
|
||||||
|
->references('id')->on('albums')
|
||||||
|
->onDelete('no action');
|
||||||
|
$table->foreign('photo_id')
|
||||||
|
->references('id')->on('photos')
|
||||||
|
->onDelete('no action');
|
||||||
|
$table->foreign('user_id')
|
||||||
|
->references('id')->on('users')
|
||||||
|
->onDelete('no action');
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('visitor_hits');
|
||||||
|
}
|
||||||
|
}
|
42
database/migrations/2017_04_16_095657_attach_hit_columns.php
Normal file
42
database/migrations/2017_04_16_095657_attach_hit_columns.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class AttachHitColumns extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('albums', function (Blueprint $table) {
|
||||||
|
$table->bigInteger('hits');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('photos', function (Blueprint $table) {
|
||||||
|
$table->bigInteger('hits');
|
||||||
|
$table->bigInteger('hits_download');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('photos', function (Blueprint $table) {
|
||||||
|
$table->bigInteger('hits_download');
|
||||||
|
$table->dropColumn('hits');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('albums', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('hits');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user