This commit is contained in:
2017-12-25 20:23:32 +01:00
parent 1175a4f8ff
commit 0cc882060c
36 changed files with 781 additions and 86 deletions
+55
View File
@@ -0,0 +1,55 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 25/12/2017
* Time: 10:20
*/
use \Illuminate\Database\Eloquent\Model as Eloquent;
class BaseModel extends Eloquent {
/**
* The name of the "created at" column.
*
* @var string
*/
const CREATED_AT = 'created_by';
/**
* The name of the "updated at" column.
*
* @var string
*/
const UPDATED_AT = 'last_update_date';
protected $guarded = [];
protected $hidden = ['creation_date', 'last_update_date', 'created_by', 'updated_by'];
protected static $oldValue;
public static function boot()
{
parent::boot();
static::creating( function ( $model ) {
if ( AUTHENTICATED )
{
$user = User::find(USERID);
$model->created_by = $user->username;
$model->updated_by = $user->username;
}
} );
static::updating( function ( $model ) {
if ( AUTHENTICATED )
{
$user = User::find(USERID);
$model->updated_by = $user->username;
}
} );
}
}
+15 -7
View File
@@ -18,20 +18,28 @@ class Page extends Eloquent {
}
public static function getPages($user)
public static function getPages( $user )
{
$pages = Page::whereRaw( 'id = page_id AND ' )
->with( ['subpages' => function($q){
$q->whereRaw('id != page_id');
}] )
$pages = Page::whereRaw( 'id = page_id' )
->with( [
'subpages' => function ( $q ) use ( $user ) {
$q->whereRaw(
"id != page_id AND ((SELECT {$user->role} & pagelevel) != 0 OR pagelevel = 0)" );
}] )
->get();
return $pages;
}
public static function getAppPages()
public static function getAppPages( $user )
{
$appPages = Page::whereRaw
$appPages = Page::select( 'id', 'pageurl' )
->whereAppPage( 'T' )
->whereRaw(
"((SELECT {$user->role} & pagelevel) != 0 OR pagelevel = 0)" )
->get();
return $appPages;
}
+46
View File
@@ -0,0 +1,46 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 25/12/2017
* Time: 17:07
*/
class Role extends BaseModel {
protected $table = "roles";
public function user()
{
return $this->hasOne( 'User', 'role', 'rolelevel' );
}
public static function getAllRoles( $archive )
{
$roleHierarchy = Role::getUserroleHierachy();
$roles = Role::orderBy( 'rolehierarchy' )
->where( 'rolehierarchy', '>=', $roleHierarchy );
if ( $archive == 'F' ) $roles = $roles->whereArchive( 'F' );
$roles = $roles->get();
return $roles;
}
public static function getUserroleHierachy()
{
$userrole = User::getUserRoleHierarchy();
if( $userrole == 0 ) return 0;
$roleHierarchy = Role::whereRolelevel($userrole)
->first()
->rolehierarchy;
return $roleHierarchy;
}
}
+34 -3
View File
@@ -7,12 +7,43 @@
*/
use \Illuminate\Database\Eloquent\Model as Eloquent;
class User extends Eloquent {
class User extends BaseModel {
protected $table = "users";
public function role()
{
return $this->belongsTo( 'Role', 'level', 'rolelevel' );
}
public static function getAllUsers( $archive )
{
$users = User::orderBy( 'lastname' );
if ( $archive == 'F' ) $users = $users->whereArchive( 'F' );
$users = $users->get();
return $users;
}
public static function getUserRoleHierarchy()
{
$userrole = User::find( USERID )->role;
return $userrole;
}
public static function checkUsername( $username )
{
$username = strtoupper( $username );
$user = User::whereRaw( "UCASE(username) = {$username}" );
if ( $user->count() == 0 ) return FALSE;
return TRUE;
}
}