100 lines
2.3 KiB
PHP
100 lines
2.3 KiB
PHP
<?php
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 21/12/2017
|
|
* Time: 18:04
|
|
*/
|
|
|
|
|
|
class User extends BaseModel {
|
|
|
|
protected $table = "users";
|
|
|
|
public function projectemployees()
|
|
{
|
|
return $this->hasMany( 'Projectemployee' );
|
|
}
|
|
|
|
public function projectemployee()
|
|
{
|
|
return $this->hasOne( 'Projectemployee' );
|
|
}
|
|
|
|
public function role()
|
|
{
|
|
return $this->belongsTo( 'Role', 'level', 'rolelevel' );
|
|
}
|
|
|
|
public static function getAllUsers( $archive )
|
|
{
|
|
$users = User::selectRaw( "*, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" )
|
|
->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;
|
|
}
|
|
|
|
public static function saveUser( $userID, $user )
|
|
{
|
|
$user = (array) $user;
|
|
|
|
if ( $userID == 0 )
|
|
{
|
|
$user = User::create( $user );
|
|
$userID = $user['id'];
|
|
}
|
|
else
|
|
{
|
|
User::whereId( $userID )->update( $user );
|
|
}
|
|
|
|
return $userID;
|
|
}
|
|
|
|
public static function removeUser( $userID )
|
|
{
|
|
User::whereId( $userID )->delete();
|
|
}
|
|
|
|
public static function getUniqueProjectUsers()
|
|
{
|
|
//TODO: date range
|
|
$projectusers = User::selectRaw( "
|
|
users.id,
|
|
CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname,
|
|
SUBSTR(MD5(users.id), 1, 6) AS slug" )
|
|
->join( 'projectemployees AS PEM', 'PEM.user_id', '=', 'users.id' )
|
|
->with( [
|
|
'projectemployee.project' => function ( $q ) {
|
|
$q->selectRaw( "id, YEAR(startdate) AS instroom, COALESCE(YEAR(enddate), '') AS uitstroom" );
|
|
}] )
|
|
->distinct()
|
|
->get();
|
|
|
|
return $projectusers;
|
|
}
|
|
|
|
|
|
} |