update code
This commit is contained in:
54
app/Entities/Attachment.php
Normal file
54
app/Entities/Attachment.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Prettus\Repository\Contracts\Transformable;
|
||||
use Prettus\Repository\Traits\TransformableTrait;
|
||||
|
||||
/**
|
||||
* Class Attachment.
|
||||
*
|
||||
* @package namespace App\Entities;
|
||||
*/
|
||||
class Attachment extends Model implements Transformable
|
||||
{
|
||||
use TransformableTrait;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'document_id',
|
||||
'name',
|
||||
'extension',
|
||||
'size',
|
||||
'path',
|
||||
'downloads',
|
||||
];
|
||||
|
||||
/**
|
||||
* All of the relationships to be touched.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $touches = ['document'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'size' => 'decimal:2',
|
||||
'downloads' => 'integer'
|
||||
];
|
||||
|
||||
public function document(){
|
||||
return $this->belongsTo(Document::class);
|
||||
}
|
||||
|
||||
}
|
||||
63
app/Entities/Book.php
Normal file
63
app/Entities/Book.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Prettus\Repository\Contracts\Transformable;
|
||||
use Prettus\Repository\Traits\TransformableTrait;
|
||||
|
||||
/**
|
||||
* Class Book.
|
||||
*
|
||||
* @package namespace App\Entities;
|
||||
*/
|
||||
class Book extends Model implements Transformable
|
||||
{
|
||||
use TransformableTrait;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['id', 'name'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public $appends = ['unread', 'count'];
|
||||
|
||||
public const DI = 2;
|
||||
public const DEN = 1;
|
||||
public const NOIBO = 3;
|
||||
|
||||
public function documents(){
|
||||
return $this->hasMany(Document::class);
|
||||
}
|
||||
|
||||
public function isComeIn(){
|
||||
return $this->id == self::DEN;
|
||||
}
|
||||
|
||||
public function isComeOut(){
|
||||
return $this->id == self::DI;
|
||||
}
|
||||
|
||||
public function isPrivate(){
|
||||
return $this->id == self::NOIBO;
|
||||
}
|
||||
|
||||
public function getUnreadAttribute(){
|
||||
return $this->documents()
|
||||
->wherehas('receivers', function($query) {
|
||||
return $query->where('id', auth()->id())->where('seen', false);
|
||||
})->count();
|
||||
}
|
||||
|
||||
public function getCountAttribute(){
|
||||
return $this->documents()
|
||||
->wherehas('receivers', function($query) {
|
||||
return $query->where('id', auth()->id());
|
||||
})->count();
|
||||
}
|
||||
|
||||
}
|
||||
35
app/Entities/Department.php
Normal file
35
app/Entities/Department.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Prettus\Repository\Contracts\Transformable;
|
||||
use Prettus\Repository\Traits\TransformableTrait;
|
||||
|
||||
/**
|
||||
* Class Department.
|
||||
*
|
||||
* @package namespace App\Entities;
|
||||
*/
|
||||
class Department extends Model implements Transformable
|
||||
{
|
||||
use TransformableTrait;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['id', 'name', 'tel'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
public function users(){
|
||||
return $this->hasMany(User::class);
|
||||
}
|
||||
|
||||
}
|
||||
100
app/Entities/Document.php
Normal file
100
app/Entities/Document.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Prettus\Repository\Contracts\Transformable;
|
||||
use Prettus\Repository\Traits\TransformableTrait;
|
||||
|
||||
/**
|
||||
* Class Document.
|
||||
*
|
||||
* @package namespace App\Entities;
|
||||
*/
|
||||
class Document extends Model implements Transformable
|
||||
{
|
||||
use TransformableTrait;
|
||||
use \App\Traits\ActionCallable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'symbol',
|
||||
'abstract',
|
||||
'book_id',
|
||||
'type_id',
|
||||
'signer_id',
|
||||
'sign_at',
|
||||
'creator_id',
|
||||
'writer_id',
|
||||
'effective_at',
|
||||
'publisher_id',
|
||||
'link_id',
|
||||
];
|
||||
|
||||
public $appends = [
|
||||
'seen',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'effective_at' => 'date:Y-m-d',
|
||||
'sign_at' => 'date:Y-m-d',
|
||||
];
|
||||
|
||||
public function receivers(){
|
||||
return $this->belongsToMany(User::class, 'document_receivers')->withPivot(['seen']);;
|
||||
}
|
||||
|
||||
public function organizes(){
|
||||
return $this->belongsToMany(Organize::class, 'document_organizes');
|
||||
}
|
||||
|
||||
public function type(){
|
||||
return $this->belongsTo(DocumentType::class, 'type_id');
|
||||
}
|
||||
|
||||
public function attachments(){
|
||||
return $this->hasMany(Attachment::class);
|
||||
}
|
||||
|
||||
public function book(){
|
||||
return $this->belongsTo(Book::class);
|
||||
}
|
||||
|
||||
public function publisher(){
|
||||
return $this->belongsTo(Organize::class, 'publisher_id');
|
||||
}
|
||||
|
||||
public function signer(){
|
||||
return $this->belongsTo(Signer::class);
|
||||
}
|
||||
|
||||
public function creator(){
|
||||
return $this->belongsTo(User::class, 'creator_id');
|
||||
}
|
||||
|
||||
public function writer(){
|
||||
return $this->belongsTo(User::class, 'writer_id');
|
||||
}
|
||||
|
||||
public function linkTo(){
|
||||
return $this->belongsTo(Document::class, 'link_id');
|
||||
}
|
||||
|
||||
public function linked(){
|
||||
return $this->hasMany(Document::class, 'link_id');
|
||||
}
|
||||
|
||||
public function getSeenAttribute(){
|
||||
$receiver = $this->receivers()->where('id', auth()->id())->first();
|
||||
if($receiver){
|
||||
return $receiver->pivot->seen;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
35
app/Entities/DocumentType.php
Normal file
35
app/Entities/DocumentType.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Prettus\Repository\Contracts\Transformable;
|
||||
use Prettus\Repository\Traits\TransformableTrait;
|
||||
|
||||
/**
|
||||
* Class DocumentType.
|
||||
*
|
||||
* @package namespace App\Entities;
|
||||
*/
|
||||
class DocumentType extends Model implements Transformable
|
||||
{
|
||||
use TransformableTrait;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['id', 'name'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
public function documents(){
|
||||
return $this->hasMany(Documents::class);
|
||||
}
|
||||
|
||||
}
|
||||
40
app/Entities/Organize.php
Normal file
40
app/Entities/Organize.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Prettus\Repository\Contracts\Transformable;
|
||||
use Prettus\Repository\Traits\TransformableTrait;
|
||||
|
||||
/**
|
||||
* Class Organize.
|
||||
*
|
||||
* @package namespace App\Entities;
|
||||
*/
|
||||
class Organize extends Model implements Transformable
|
||||
{
|
||||
use TransformableTrait;
|
||||
use \App\Traits\ActionCallable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['id', 'name'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
public function publishedDocuments(){
|
||||
return $this->hasMany(Document::class, 'publisher_id');
|
||||
}
|
||||
|
||||
public function receivedDocuments(){
|
||||
return $this->belongsToMany(Document::class, 'document_organizes');
|
||||
}
|
||||
|
||||
}
|
||||
31
app/Entities/Signer.php
Normal file
31
app/Entities/Signer.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Prettus\Repository\Contracts\Transformable;
|
||||
use Prettus\Repository\Traits\TransformableTrait;
|
||||
|
||||
/**
|
||||
* Class Signer.
|
||||
*
|
||||
* @package namespace App\Entities;
|
||||
*/
|
||||
class Signer extends Model implements Transformable
|
||||
{
|
||||
use TransformableTrait;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['id', 'name', 'description'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function documents(){
|
||||
return $this->hasMany(Document::class);
|
||||
}
|
||||
|
||||
}
|
||||
35
app/Entities/Title.php
Normal file
35
app/Entities/Title.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Prettus\Repository\Contracts\Transformable;
|
||||
use Prettus\Repository\Traits\TransformableTrait;
|
||||
|
||||
/**
|
||||
* Class Title.
|
||||
*
|
||||
* @package namespace App\Entities;
|
||||
*/
|
||||
class Title extends Model implements Transformable
|
||||
{
|
||||
use TransformableTrait;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['id', 'name'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
public function users(){
|
||||
return $this->hasMany(User::class);
|
||||
}
|
||||
|
||||
}
|
||||
88
app/Entities/User.php
Normal file
88
app/Entities/User.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use Illuminate\Contracts\Auth\CanResetPassword;
|
||||
use Illuminate\Auth\Passwords\CanResetPassword as CanResetPasswordTrait;
|
||||
use Prettus\Repository\Contracts\Transformable;
|
||||
use Prettus\Repository\Traits\TransformableTrait;
|
||||
|
||||
class User extends Authenticatable implements Transformable, CanResetPassword
|
||||
{
|
||||
use HasApiTokens, Notifiable, HasRoles, CanResetPasswordTrait, TransformableTrait;
|
||||
use \App\Traits\ActionCallable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'tel',
|
||||
'birthday',
|
||||
'department_id',
|
||||
'title_id',
|
||||
'active',
|
||||
];
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'active' => 'boolean',
|
||||
'birthday' => 'date:Y-m-d',
|
||||
];
|
||||
|
||||
public function groups(){
|
||||
return $this->belongsToMany(Group::class, GroupUser::class);
|
||||
}
|
||||
|
||||
public function department(){
|
||||
return $this->belongsTo(Department::class);
|
||||
}
|
||||
|
||||
public function title(){
|
||||
return $this->belongsTo(Title::class);
|
||||
}
|
||||
|
||||
public function createdDocuments(){
|
||||
return $this->hasMany(Document::class, 'creator_id');
|
||||
}
|
||||
|
||||
public function wroteDocuments(){
|
||||
return $this->hasMany(Document::class, 'writer_id');
|
||||
}
|
||||
|
||||
public function receivedDocuments(){
|
||||
return $this->belongsToMany(Document::class, 'document_receivers');
|
||||
}
|
||||
|
||||
public function getDocumentsAttribute(){
|
||||
return $this->createdDocuments->merge($this->receivedDocuments)->merge($this->wroteDocuments());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user