[WIP] Fix ergonomics rules

This commit is contained in:
Ludovic CANDELLIER
2020-03-30 00:48:17 +02:00
parent 36267139a1
commit cd9b6ea74c
106 changed files with 1392 additions and 747 deletions

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Models;
namespace App\Models\Core\App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -12,12 +12,12 @@ class Application extends Model
public function pages()
{
return $this->hasMany('App\Models\Modules\ApplicationPage');
return $this->hasMany('App\Models\Core\App\ApplicationPage');
}
public function modules()
{
return $this->hasMany('App\Models\Modules\ApplicationModule');
return $this->hasMany('App\Models\Core\App\ApplicationModule');
}
public function scopeActive($query)

View File

@@ -1,5 +1,6 @@
<?php
namespace App\Models;
namespace App\Models\Core\App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -12,7 +13,7 @@ class ApplicationModule extends Model
public function application()
{
return $this->belongsTo('App\Models\Modules\Application');
return $this->belongsTo('App\Models\Core\App\Application');
}
public function permissions()

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Models;
namespace App\Models\Application;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -12,7 +12,7 @@ class ApplicationPage extends Model
public function application()
{
return $this->belongsTo('App\Models\Modules\Application');
return $this->belongsTo('App\Models\Core\App');
}
public function scopeActive($query)

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Models\Auth;
namespace App\Models\Core\Auth;
use Laratrust\Models\LaratrustPermission;
@@ -29,12 +29,12 @@ class Permission extends LaratrustPermission
public function application()
{
return $this->belongsTo('App\Models\Application');
return $this->belongsTo('App\Models\Core\App\Application');
}
public function application_module()
{
return $this->belongsTo('App\Models\ApplicationModule');
return $this->belongsTo('App\Models\Core\App\ApplicationModule');
}
public function getDisplayNameAttribute($value)

View File

@@ -1,7 +1,6 @@
<?php
namespace App\Models;
namespace App\Models\Core\Auth;
/**
*

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Models\Auth;
namespace App\Models\Core\Auth;
use Illuminate\Database\Eloquent\Model;
@@ -10,12 +10,12 @@ class PermissionRole extends Model
public function permission()
{
return $this->belongsTo('App\Permission');
return $this->belongsTo('App\Models\Core\Auth\Permission');
}
public function role()
{
return $this->belongsTo('App\Role');
return $this->belongsTo('App\Models\Core\Auth\Role');
}
public function scopeByPermission($query, $id)

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Models\Auth;
namespace App\Models\Core\Auth;
use Illuminate\Database\Eloquent\Model;
@@ -10,17 +10,17 @@ class PermissionUser extends Model
public function permission()
{
return $this->belongsTo('App\Permission');
return $this->belongsTo('App\Models\Core\Auth\Permission');
}
public function user()
{
return $this->belongsTo('App\User');
return $this->belongsTo('App\Models\Core\Auth\User');
}
public function team()
{
return $this->belongsTo('App\Team');
return $this->belongsTo('App\Models\Core\Auth\Team');
}
public function scopeByUser($query, $id)

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Models\Auth;
namespace App\Models\Core\Auth;
use Laratrust\Models\LaratrustRole;

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Models\Auth;
namespace App\Models\Core\Auth;
use Illuminate\Database\Eloquent\Model;
@@ -11,12 +11,12 @@ class RoleUser extends Model
public function user()
{
return $this->belongsTo('App\User');
return $this->belongsTo('App\Models\Core\Auth\User');
}
public function team()
{
return $this->belongsTo('App\Team');
return $this->belongsTo('App\Models\Core\Auth\Team');
}
public function scopeByUser($query, $id)

View File

@@ -1,6 +1,6 @@
<?php
namespace App\Models\Auth;
namespace App\Models\Core\Auth;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -15,12 +15,7 @@ class Team extends LaratrustTeam
public function users()
{
return $this->hasMany('App\User');
}
public function society()
{
return $this->belongsTo('App\Models\Society');
return $this->hasMany('App\Models\Core\Auth\User');
}
public function scopeActive($query)
@@ -28,8 +23,4 @@ class Team extends LaratrustTeam
return $query->where('active', 1);
}
public function scopeBySociety($query, $id)
{
return $query->where('society_id', $id);
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace App;
namespace App\Models\Core\Auth;
use Illuminate\Database\Eloquent\Model;
@@ -11,12 +11,12 @@ class TeamUser extends Model
public function user()
{
return $this->belongsTo('App\User');
return $this->belongsTo('App\Models\Core\Auth\User');
}
public function team()
{
return $this->belongsTo('App\Team');
return $this->belongsTo('App\Models\Core\Auth\Team');
}
public function scopeByUser($query, $id)

View File

@@ -0,0 +1,225 @@
<?php
namespace App\Models\Core\Auth;
use Carbon\Carbon;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Yadahan\AuthenticationLog\AuthenticationLogable;
use Laratrust\Traits\LaratrustUserTrait;
use Mpociot\Teamwork\Traits\UserHasTeams;
use Sebastienheyd\Boilerplate\Notifications\NewUser as NewUserNotification;
use Sebastienheyd\Boilerplate\Notifications\ResetPassword as ResetPasswordNotification;
/**
* Sebastienheyd\Boilerplate\Models\User.
*
* @property int $id
* @property bool $active
* @property string $first_name
* @property string $last_name
* @property string $email
* @property string $password
* @property string $remember_token
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $deleted_at
* @property string $last_login
* @property-read string|false $avatar_path
* @property-read string $avatar_url
* @property-read mixed $name
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
* @property-read \Illuminate\Database\Eloquent\Collection|\Sebastienheyd\Boilerplate\Models\Permission[] $permissions
* @property-read \Illuminate\Database\Eloquent\Collection|\Sebastienheyd\Boilerplate\Models\Role[] $roles
*
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereActive($value)
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereDeletedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereEmail($value)
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereFirstName($value)
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereId($value)
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereLastLogin($value)
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereLastName($value)
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User wherePassword($value)
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereRememberToken($value)
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereRoleIs($role = '')
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereUpdatedAt($value)
* @mixin \Eloquent
*/
class User extends Authenticatable
{
use Notifiable;
use LaratrustUserTrait;
use SoftDeletes;
use UserHasTeams;
use AuthenticationLogable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['active', 'last_name', 'first_name', 'email', 'password', 'remember_token', 'last_login'];
protected $hidden = ['password', 'remember_token'];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function teams()
{
return $this->hasManyThrough('App\Models\Core\Auth\Team', 'App\Models\Core\Auth\TeamUser', 'user_id', 'id', 'id', 'team_id');
}
public function scopeByTeam($query, $id)
{
return $query->whereHas('teams', function ($query) use ($id) {
$query->where('id', $id);
});
}
public function scopeByUniqueTeam($query)
{
return $query->has('teams', '=', 1);
}
public function scopeActive($query)
{
return $query->where('active', 1);
}
/**
* Send the password reset notification.
*
* @param string $token
*
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
/**
* Send notification when a new user is created.
*
* @param string $token
*/
public function sendNewUserNotification($token)
{
$this->notify(new NewUserNotification($token, $this));
}
/**
* Return last name in uppercase by default.
*
* @param $value
*
* @return string
*/
public function getLastNameAttribute($value)
{
return mb_strtoupper($value);
}
/**
* Return first name with first char of every word in uppercase.
*
* @param $value
*
* @return string
*/
public function getFirstNameAttribute($value)
{
return mb_convert_case($value, MB_CASE_TITLE);
}
/**
* Return a concatenation of first name and last_name if field name does not exists.
*
* @param $value
*
* @return string
*/
public function getNameAttribute($value)
{
if (!empty($value)) {
return $value;
}
return $this->first_name.' '.$this->last_name;
}
/**
* Return last login date formatted.
*
* @param string $format
* @param string $default
*
* @return mixed|string
*/
public function getLastLogin($format = 'YYYY-MM-DD HH:mm:ss', $default = '')
{
if ($this->last_login === null) {
return $default;
}
return Carbon::createFromTimeString($this->last_login)->isoFormat($format);
}
/**
* Return role list as a string.
*
* @return string
*/
public function getRolesList()
{
$res = [];
foreach ($this->roles as $role) {
$res[] = __($role->display_name);
}
if (empty($res)) {
return '-';
}
return implode(', ', $res);
}
/**
* Check if current user has an avatar.
*
* @return string|false
*/
public function getAvatarPathAttribute()
{
return public_path('images/avatars/'.md5($this->id.$this->email).'.jpg');
}
/**
* Return current user avatar uri.
*
* @return string
*/
public function getAvatarUrlAttribute()
{
if (is_file($this->avatar_path)) {
$ts = filemtime($this->avatar_path);
return asset('images/avatars/'.md5($this->id.$this->email).'.jpg?t='.$ts);
}
return asset('/assets/vendor/boilerplate/images/default-user.png');
}
}

View File

@@ -8,25 +8,16 @@ class Customer extends Model
{
protected $guarded = ['id'];
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function Invoices()
{
return $this->hasMany('App\Models\Shop\Invoice');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function Orders()
{
return $this->hasMany('App\Models\Shop\Order');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function User()
{
return $this->belongsTo('App\User');

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class CustomerAddress extends Model
{
protected $guarded = ['id'];
public function Customer()
{
return $this->belongsTo('App\Models\Shop\Customer');
}
public function Orders()
{
return $this->hasMany('App\Models\Shop\Order');
}
}

View File

@@ -8,19 +8,19 @@ class ProductPrice extends Model
{
protected $guarded = ['id'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function Product()
{
return $this->belongsTo('App\Models\Shop\Product');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function ProductAttribute()
{
return $this->belongsTo('App\Models\Shop\ProductAttribute');
}
public function scopeByProduct($query, $id)
{
return $query->where('product_id', $id);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class ProductSection extends Model
{
protected $guarded = ['id'];
public function Product()
{
return $this->belongsTo('App\Models\Shop\Product');
}
public function Section()
{
return $this->belongsTo('App\Models\Shop\Product');
}
public function scopeByProduct($query, $id)
{
return $query->where('product_id', $id);
}
public function scopeBySection($query, $id)
{
return $query->where('section_id', $id);
}
}

View File

@@ -4,13 +4,13 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Rinvex\Categories\Traits\Categorizable,
class Section extends Model
{
protected $guarded = ['id'];
use Categorizable;
protected $guarded = ['id'];
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function Products()
{
return $this->hasMany('App\Models\Shop\Product');