updated models

pull/26/head
Ondřej Hruška 7 years ago
parent c75b25b89b
commit 6fd1d7eb89
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 51
      app/Models/Changeset.php
  2. 17
      app/Models/DataRow.php
  3. 41
      app/Models/Proposal.php
  4. 44
      app/Models/Revision.php
  5. 12
      app/Models/Row.php
  6. 37
      app/Models/Table.php
  7. 10
      app/Models/TableComment.php
  8. 18
      app/Models/User.php
  9. 3
      composer.json
  10. 59
      composer.lock
  11. 2
      database/factories/DataTableFactory.php
  12. 4
      database/migrations/2018_07_08_193600_create_revisions_table.php
  13. 6
      database/migrations/2018_07_08_194100_create_proposal_remove_row_pivot_table.php
  14. 37
      database/migrations/2018_07_08_194105_create_revision_proposal_pivot_table.php
  15. 7
      database/migrations/2018_07_12_185840_create_table_favourites_table.php
  16. 6
      database/migrations/2018_07_12_190059_create_discussion_follows_table.php

@ -1,51 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* A patch describing changes to apply or applied to a data table.
*/
class Changeset extends Model
{
/** Parent data table */
public function dataTable()
{
return $this->belongsTo(DataTable::class);
}
/** Author who created it user */
public function author()
{
return $this->belongsTo(User::class, 'author_id');
}
/** Reports of this changeset */
public function reportsOf()
{
return $this->morphMany(ContentReport::class, 'object');
}
/**
* Scope for pending changesets
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePending($query)
{
return $query->where('applied', false);
}
/**
* Scope for applied changesets
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeApplied($query)
{
return $query->where('applied', true);
}
}

@ -1,17 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Row in a data table
*/
class DataRow extends Model
{
/** Parent data table */
public function dataTable()
{
return $this->belongsTo(DataTable::class);
}
}

@ -0,0 +1,41 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Change proposal
*/
class Proposal extends Model
{
/** Added rows */
public function addedRows()
{
return $this->belongsToMany(Row::class, 'proposal_add_row_pivot');
}
/** Removed rows */
public function removedRows()
{
return $this->belongsToMany(Row::class, 'proposal_remove_row_pivot');
}
/** Authoring user */
public function author()
{
return $this->belongsTo(User::class, 'author_id');
}
/** Target revision */
public function revision()
{
return $this->belongsTo(Revision::class);
}
/** Target table (that this was submitted to) */
public function table()
{
return $this->belongsTo(Table::class);
}
}

@ -0,0 +1,44 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Riesjart\Relaquent\Model\Concerns\HasRelaquentRelationships;
/**
* Table revision (a set of rows)
*/
class Revision extends Model
{
use HasRelaquentRelationships;
/** Included rows */
public function rows()
{
return $this->belongsToMany(Row::class, 'revision_row_pivot');
}
/** Proposal that lead to this revision */
public function appliedProposal()
{
return $this->hasOneThrough(Proposal::class, 'revision_proposal_pivot');
}
/** Proposals that depend on this revision */
public function dependentProposals()
{
return $this->hasMany(Proposal::class);
}
/** Revision this orignates from */
public function parentRevision()
{
return $this->belongsTo(Revision::class, 'ancestor_id');
}
/** Tables referencing this revision */
public function tables()
{
return $this->belongsToMany(Table::class, 'table_revision_pivot');
}
}

@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Row in a data table
*/
class Row extends Model
{
}

@ -7,15 +7,8 @@ use Illuminate\Database\Eloquent\Model;
/**
* A data table object (referencing changesets and rows)
*/
class DataTable extends Model
class Table extends Model
{
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
/** Owning user */
public function owner()
{
@ -25,25 +18,31 @@ class DataTable extends Model
/** Fork precursor */
public function parentTable()
{
return $this->belongsTo(DataTable::class, 'parent_table_id');
return $this->belongsTo(Table::class, 'ancestor_id');
}
/** Fork descendants */
public function forks()
{
return $this->hasMany(DataTable::class, 'parent_table_id');
return $this->hasMany(Table::class, 'ancestor_id');
}
/** Changesets */
public function changesets()
/** All related revisions (this may include merged revisions) */
public function revisions()
{
return $this->hasMany(Changeset::class);
return $this->belongsToMany(Revision::class, 'table_revision_pivot');
}
/** Data rows */
public function dataRows()
/** Active revision */
public function activeRevision()
{
return $this->hasMany(DataRow::class);
return $this->hasOne(Revision::class, 'revision_id');
}
/** Proposals submitted to this table */
public function proposals()
{
return $this->hasMany(Proposal::class);
}
/** User-submitted comments */
@ -63,10 +62,4 @@ class DataTable extends Model
{
return $this->belongsToMany(User::class, 'discussion_follows');
}
/** Reports of this table */
public function reportsOf()
{
return $this->morphMany(ContentReport::class, 'object');
}
}

@ -10,9 +10,9 @@ use Illuminate\Database\Eloquent\Model;
class TableComment extends Model
{
/** Context data table */
public function dataTable()
public function table()
{
return $this->belongsTo(DataTable::class);
return $this->belongsTo(Table::class);
}
/** Parent comment (that we reply to; can be null) */
@ -32,10 +32,4 @@ class TableComment extends Model
{
return $this->belongsTo(User::class, 'author_id');
}
/** Reports of this comment */
public function reportsOf()
{
return $this->morphMany(ContentReport::class, 'object');
}
}

@ -34,7 +34,7 @@ class User extends Authenticatable
/** Owned tables */
public function dataTables()
{
return $this->hasMany(DataTable::class, 'owner_id');
return $this->hasMany(Table::class, 'owner_id');
}
/** Assigned OAuth identities */
@ -43,10 +43,10 @@ class User extends Authenticatable
return $this->hasMany(OAuthIdentity::class);
}
/** Assigned OAuth identities */
public function changesets()
/** Authored proposals */
public function proposals()
{
return $this->hasMany(Changeset::class, 'author_id');
return $this->hasMany(Proposal::class, 'author_id');
}
/** Authored comments */
@ -58,13 +58,13 @@ class User extends Authenticatable
/** User's favourite tables (personal collection) */
public function favouriteTables()
{
return $this->belongsToMany(DataTable::class, 'table_favourites');
return $this->belongsToMany(Table::class, 'table_favourites');
}
/** Tables whose discussions user follows (this is similar to favourites) */
public function followedDiscussions()
{
return $this->belongsToMany(DataTable::class, 'discussion_follows');
return $this->belongsToMany(Table::class, 'discussion_follows');
}
/** Reports sent by this user */
@ -73,12 +73,6 @@ class User extends Authenticatable
return $this->hasMany(ContentReport::class, 'author_id');
}
/** Reports of this user */
public function reportsOf()
{
return $this->morphMany(ContentReport::class, 'object');
}
/** Notifications for this user */
public function notifications()
{

@ -12,11 +12,12 @@
"barryvdh/laravel-ide-helper": "^2.4",
"doctrine/dbal": "^2.7",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.0",
"laravel/framework": "5.6.*",
"laravel/socialite": "^3.0",
"laravel/tinker": "^1.0",
"phpoffice/phpspreadsheet": "^1.3",
"guzzlehttp/guzzle": "^6.0"
"riesjart/relaquent": "^0.1"
},
"require-dev": {
"filp/whoops": "^2.0",

59
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "cdb2e12195da014433178600b1a1899f",
"content-hash": "7c2b00ef303415cdc522f82578d90676",
"packages": [
{
"name": "barryvdh/laravel-ide-helper",
@ -2187,6 +2187,63 @@
],
"time": "2018-01-20T00:28:24+00:00"
},
{
"name": "riesjart/relaquent",
"version": "v0.1.1",
"source": {
"type": "git",
"url": "https://github.com/riesjart/relaquent.git",
"reference": "feb8e01cc818b25770dad792b6415b6aea9e3a1d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/riesjart/relaquent/zipball/feb8e01cc818b25770dad792b6415b6aea9e3a1d",
"reference": "feb8e01cc818b25770dad792b6415b6aea9e3a1d",
"shasum": ""
},
"require": {
"illuminate/cache": "5.6.*",
"illuminate/container": "5.6.*",
"illuminate/database": "~5.6.3",
"illuminate/support": "5.6.*",
"php": ">=7.1"
},
"type": "library",
"autoload": {
"psr-4": {
"Riesjart\\Relaquent\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Richard van Baarsen",
"email": "richardvanbaarsen@gmail.com"
}
],
"description": "Extension of Laravel's Eloquent relationships: additional relationship types, query joins, pivot models, converters and helpers",
"keywords": [
"belongs-to-morph",
"converter",
"database",
"eloquent",
"has-one-through",
"illuminate",
"join",
"laravel",
"model",
"morph-one-through",
"php",
"pivot",
"relation",
"relationship",
"sql"
],
"time": "2018-02-22T10:42:19+00:00"
},
{
"name": "swiftmailer/swiftmailer",
"version": "v6.1.1",

@ -2,7 +2,7 @@
use Faker\Generator as Faker;
$factory->define(\App\Models\DataTable::class, function (Faker $faker) {
$factory->define(\App\Models\Table::class, function (Faker $faker) {
return [
//
];

@ -17,7 +17,6 @@ class CreateRevisionsTable extends Migration
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('refs'); // used for reference counting
$table->unsignedInteger('author_id')->index();
$table->unsignedInteger('ancestor_id')->index()->nullable(); // parent revision
// a column that can be used as the primary key for a table; possibly a composite column if using a comma
@ -26,9 +25,6 @@ class CreateRevisionsTable extends Migration
// author's note describing what has been changed
$table->text('note');
$table->foreign('author_id')->references('id')->on('users')
->onDelete('set null');
$table->foreign('ancestor_id')->references('id')->on('revisions')
->onDelete('set null');
});

@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProposalDeleteRowPivotTable extends Migration
class CreateProposalRemoveRowPivotTable extends Migration
{
/**
* Run the migrations.
@ -13,7 +13,7 @@ class CreateProposalDeleteRowPivotTable extends Migration
*/
public function up()
{
Schema::create('proposal_delete_row_pivot', function (Blueprint $table) {
Schema::create('proposal_remove_row_pivot', function (Blueprint $table) {
$table->unsignedInteger('proposal_id')->index();
$table->unsignedInteger('row_id')->index();
@ -32,6 +32,6 @@ class CreateProposalDeleteRowPivotTable extends Migration
*/
public function down()
{
Schema::dropIfExists('proposal_delete_row_pivot');
Schema::dropIfExists('proposal_remove_row_pivot');
}
}

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRevisionProposalPivotTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('revision_proposal_pivot', function (Blueprint $table) {
$table->unsignedInteger('proposal_id')->index();
$table->unsignedInteger('revision_id')->index();
$table->foreign('proposal_id')->references('id')->on('proposals')
->onDelete('cascade');
$table->foreign('revision_id')->references('id')->on('revisions')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('revision_proposal_pivot');
}
}

@ -14,11 +14,8 @@ class CreateTableFavouritesTable extends Migration
public function up()
{
Schema::create('table_favourites', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('user_id');
$table->unsignedInteger('table_id');
$table->unsignedInteger('user_id')->index();
$table->unsignedInteger('table_id')->index();
$table->foreign('user_id')->references('id')->on('users')
->onDelete('cascade');

@ -14,10 +14,8 @@ class CreateDiscussionFollowsTable extends Migration
public function up()
{
Schema::create('discussion_follows', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->unsignedInteger('user_id');
$table->unsignedInteger('table_id');
$table->unsignedInteger('user_id')->index();
$table->unsignedInteger('table_id')->index();
$table->foreign('user_id')->references('id')->on('users')
->onDelete('cascade');

Loading…
Cancel
Save