public static function getDefaultByUser(Users $user): Companies
    {
        //verify the user has a default company
        $defaultCompany = UserConfig::findFirst([
            'conditions' => 'users_id = ?0 and name = ?1',
            'bind' => [$user->getId(), self::DEFAULT_COMPANY],
        ]);

        //found it
        if ($defaultCompany) {
            return self::findFirst($defaultCompany->value);
        }

        //second try
        $defaultCompany = UsersAssociatedCompany::findFirst([
            'conditions' => 'users_id = ?0 and user_active =?1',
            'bind' => [$user->getId(), 1],
        ]);

        if ($defaultCompany) {
            return self::findFirst($defaultCompany->company_id);
        }

        throw new Exception(_("User doesn't have an active company"));
    }
public static function getDefaultByUser(Users $user): Companies
    {
        //verify the user has a default company
        $defaultCompany = UserConfig::findFirst([
            'conditions' => 'users_id = ?0 and name = ?1',
            'bind' => [$user->getId(), self::DEFAULT_COMPANY],
        ]);

        //found it
        if ($defaultCompany) {
            return self::findFirst($defaultCompany->value);
        }

        //second try
        $defaultCompany = UsersAssociatedCompany::findFirst([
            'conditions' => 'users_id = ?0 and user_active =?1',
            'bind' => [$user->getId(), 1],
        ]);

        if ($defaultCompany) {
            return self::findFirst($defaultCompany->company_id);
        }

        throw new Exception(_("User doesn't have an active company"));
    }
public static function getDefaultByUser ( Users $ user ) : Companies { //verify the user has a default company $ defaultCompany = UserConfig :: findFirst ( [ 'conditions' => 'users_id = ?0 and name = ?1' , 'bind' => [ $ user -> getId ( ) , self :: DEFAULT_COMPANY ] , ] ) ; //found it if ( $ defaultCompany ) { return self :: findFirst ( $ defaultCompany -> value ) ; } //second try $ defaultCompany = UsersAssociatedCompany :: findFirst ( [ 'conditions' => 'users_id = ?0 and user_active =?1' , 'bind' => [ $ user -> getId ( ) , 1 ] , ] ) ; if ( $ defaultCompany ) { return self :: findFirst ( $ defaultCompany -> company_id ) ; } throw new Exception ( _ ( "User doesn't have an active company" ) ) ; }
Get the default company the users has selected

@param  Users  $user
@return Companies
Get the default company the users has selected