Diversen opmerkingen Peter (23-08-2019)
This commit is contained in:
@@ -9,117 +9,130 @@
|
||||
|
||||
class User extends BaseModel {
|
||||
|
||||
protected $table = "users";
|
||||
protected $table = "users";
|
||||
|
||||
public function projectemployees()
|
||||
{
|
||||
return $this->hasMany( 'Projectemployee' );
|
||||
}
|
||||
public function projectemployees()
|
||||
{
|
||||
return $this->hasMany( 'Projectemployee' );
|
||||
}
|
||||
|
||||
public function employeetargets()
|
||||
{
|
||||
return $this->hasMany( 'Employeetarget' );
|
||||
}
|
||||
public function employeetargets()
|
||||
{
|
||||
return $this->hasMany( 'Employeetarget' );
|
||||
}
|
||||
|
||||
public function projectemployee()
|
||||
{
|
||||
return $this->hasOne( 'Projectemployee' );
|
||||
}
|
||||
public function projectemployee()
|
||||
{
|
||||
return $this->hasOne( 'Projectemployee' );
|
||||
}
|
||||
|
||||
public function role()
|
||||
{
|
||||
return $this->belongsTo( 'Role', 'level', 'rolelevel' );
|
||||
}
|
||||
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' );
|
||||
public static function getAllUsers( $archive )
|
||||
{
|
||||
$users = User::selectRaw( "*, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" )
|
||||
->orderBy( 'lastname' );
|
||||
|
||||
if ( $archive == 'F' ) $users = $users->whereArchive( 'F' );
|
||||
if ( $archive == 'F' ) $users = $users->whereArchive( 'F' );
|
||||
|
||||
$users = $users->get();
|
||||
$users = $users->get();
|
||||
|
||||
return $users;
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
|
||||
public static function getUserRoleHierarchy()
|
||||
{
|
||||
$userrole = User::find( USERID )->role;
|
||||
public static function getUserRoleHierarchy()
|
||||
{
|
||||
$userrole = User::find( USERID )->role;
|
||||
|
||||
return $userrole;
|
||||
}
|
||||
return $userrole;
|
||||
}
|
||||
|
||||
public static function getUserWithprojects()
|
||||
{
|
||||
$usersWithProjects =
|
||||
User::selectRaw( "users.id, CONCAT(users.firstname, ' ', users.middlename, ' ', users.lastname) AS fullname" )
|
||||
->with( [
|
||||
'projectemployees.project' => function ( $q ) {
|
||||
$q->whereArchive( 'F' );
|
||||
}] )
|
||||
->get();
|
||||
public static function getUserWithprojects()
|
||||
{
|
||||
$usersWithProjects =
|
||||
User::selectRaw( "users.id, CONCAT(users.firstname, ' ', users.middlename, ' ', users.lastname) AS fullname" )
|
||||
->with( [
|
||||
'projectemployees.project' => function ( $q ) {
|
||||
$q->whereArchive( 'F' );
|
||||
}] )
|
||||
->get();
|
||||
|
||||
return $usersWithProjects;
|
||||
}
|
||||
return $usersWithProjects;
|
||||
}
|
||||
|
||||
public static function checkUsername( $username )
|
||||
{
|
||||
$username = strtoupper( $username );
|
||||
public static function getUserActiveProjects( $userID )
|
||||
{
|
||||
$usersActiveProjects =
|
||||
User::selectRaw( "PRJ.id AS projectID, projectname, projectnumber, CONCAT(projectnumber, '-', projectname) AS projectFull" )
|
||||
->join( 'projectemployees AS PRE', 'PRE.user_id', '=', 'users.id' )
|
||||
->join( 'projects AS PRJ', 'PRJ.id', '=', 'PRE.project_id' )
|
||||
->where( 'PRJ.archive', '=', 'F' )
|
||||
->where( 'users.id', '=', $userID )
|
||||
->get();
|
||||
|
||||
$user = User::whereRaw( "UCASE(username) = {$username}" );
|
||||
return $usersActiveProjects;
|
||||
}
|
||||
|
||||
if ( $user->count() == 0 ) return FALSE;
|
||||
public static function checkUsername( $username )
|
||||
{
|
||||
$username = strtoupper( $username );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
$user = User::whereRaw( "UCASE(username) = {$username}" );
|
||||
|
||||
public static function saveUser( $userID, $user )
|
||||
{
|
||||
$user = (array) $user;
|
||||
if ( $user->count() == 0 ) return FALSE;
|
||||
|
||||
if ( $userID == 0 )
|
||||
{
|
||||
$user = User::create( $user );
|
||||
$userID = $user['id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
User::whereId( $userID )->update( $user );
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return $userID;
|
||||
}
|
||||
public static function saveUser( $userID, $user )
|
||||
{
|
||||
$user = (array) $user;
|
||||
|
||||
public static function removeUser( $userID )
|
||||
{
|
||||
User::whereId( $userID )->delete();
|
||||
}
|
||||
if ( $userID == 0 )
|
||||
{
|
||||
$user = User::create( $user );
|
||||
$userID = $user['id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
User::whereId( $userID )->update( $user );
|
||||
}
|
||||
|
||||
public static function getUniqueProjectUsers()
|
||||
{
|
||||
//TODO: date range
|
||||
$projectusers = User::selectRaw( "
|
||||
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();
|
||||
->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;
|
||||
}
|
||||
return $projectusers;
|
||||
}
|
||||
|
||||
public static function getSaltedPassword( $password, $salt )
|
||||
{
|
||||
$saltedpassword = sha1( sha1( $password ) . $salt );
|
||||
public static function getSaltedPassword( $password, $salt )
|
||||
{
|
||||
$saltedpassword = sha1( sha1( $password ) . $salt );
|
||||
|
||||
return $saltedpassword;
|
||||
}
|
||||
return $saltedpassword;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user