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 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 ) ->orderBy('projectnumber') ->get(); return $usersActiveProjects; } 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; } public static function generateSalt() { $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; $alphaLength = strlen( $alphabet ) - 1; $randomString = ''; for ( $i = 0; $i < 18; $i++ ) { $n = rand( 0, $alphaLength ); $randomString .= $alphabet[ $n ]; } return sha1( $randomString ); } }