updated models

This commit is contained in:
2018-07-14 12:24:24 +02:00
parent c75b25b89b
commit 6fd1d7eb89
16 changed files with 225 additions and 129 deletions
-51
View File
@@ -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);
}
}
-17
View File
@@ -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);
}
}
+41
View File
@@ -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);
}
}
+44
View File
@@ -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');
}
}
+12
View File
@@ -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');
}
}
+2 -8
View File
@@ -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');
}
}
+6 -12
View File
@@ -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()
{