hasMany( 'Projectemployee' ); } public function employeetargets() { return $this->hasMany( 'Employeetarget' ); } 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 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; } 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; } public static function getSaltedPassword( $password, $salt ) { $saltedpassword = sha1( sha1( $password ) . $salt ); return $saltedpassword; } }