James Motley
wading in the water Posts:19
|
07-30-2007 08:16 AM |
|
To recap my dilemma: I wan't to save/display a default image for each user who registers and does not have one to upload initially. This way when I setup the User Directory module or Tailored Text module, there will always be some kind of photo showing up either from the user or just a default image. As an immediate solution to this problem utilizing the existing Dynamic Registration form functionality, Chad has suggested using a SQL "If" statement. Chad, will you please expand on this with a SQL example and where it should be implemented? |
|
|
|
|
Chad Nash Posts:5260
|
07-31-2007 08:39 PM |
|
James,
Hi. Yes I remember discussing this with you earlier. Basically you have set the 'Default' value for the field so that a blank or default image appears (its not listed in the documentation but you can use an image URL as a default value in the textbox). Although this works initially when the user navigates to the page, if they save their registration without ever selecting an image the default is not saved. Ill review this in the future, since there is technically no file to upload this is why it works differently than other field types.
So... What you can do is:
If this is a dedicated server you can setup a SQL Query that will execute maybe on a daily basis, if this is not a dedicated server you can just execute the query every once in a while under Host, SQL or you can set it up within Dynamic Registration as a Dynamic SQL Event. The only downside to setting it up as a Dynamic SQL Event is that is would be executed each time a user registers, not a big deal as this would have minimal performance impact but still maybe not something you would need to do if this was a required field.
Next, I would suggest linking the image field to a DotNetNuke Core extended field. You don't need to in order for the directory to work but the query would change slightly since you would be updating Dynamic Registration tables and not the core tables.
For this example we will assuming you are linking the image field to a core field and so we will be updating the core database directly.
1. Add a core field under Admin, User Accounts, Profile Properties 2. Lets assume you named the field 'MyImage' 3. Find the profile property Definition ID by going to Host, SQL and executing a query like this: select * from ProfilePropertyDefinition Where PropertyNAme = 'MyImage'
Pay attention to the first column to determine the PropertyDefinitionID for the field.
4. Next create a SQL query to update users where there is no image, lets assume for this query that the profile definitionID is 50 (so replace the 50 below with your actual profile definitionID)
Update UserProfile Set PRopertyValue = 'http://www.yoursite.com/0/yourdefaultimage.jpg' Where PropertyValue = '' AND PropertyDEfinitionID = 50
Now this is assuming you were linking to the core extended fields. You are not you would end up updating the DynamicRegistration_QuestionResponse table and not the UserProfile table. I can provide that query for you as well if you need it.
If you need additional assistance let me know, we also can handle this for you if you open a support ticket.
Ill review this in the future and see if we can upload a file for the default value when an image is never uploaded.
-Chad
|
|
|
|
|
Daniel Cooper
wading in the water Posts:16
|
04-04-2009 11:33 PM |
|
Hi, I followed these steps but it's not working. I set a default image, which works on the registration form but later on the value is blank. The image upload is linked to a DNN core profile field, but if the form submission is blank the property is not added to the user, even as '', so the above SQL isn't working for me. |
|
|
|
|
Chad Nash Posts:5260
|
04-07-2009 01:12 PM |
|
Daniel, Hi. Do you know if your site uses object qualifiers? For example, if you go to Host/SQL and execute: Select * from sysobjects where name like '%Portals%' and xtype='u' Does it show table names such as 'Portals' or does it show table names such as 'dnn_portals'? If your site uses object qualifiers the query might need tweaked slightly. -Chad |
|
|
|
|
Daniel Cooper
wading in the water Posts:16
|
05-19-2009 05:14 AM |
|
Yes, I get 'Portals' and 'UserPortals |
|
|
|
|
David To
river guide Posts:2719
|
05-19-2009 06:37 AM |
|
If you go to HOST/SQL and type in sql: select * from userroles does it return any listings or error out? If it errors out, you will need to type in the objectqualifier: select * from userportals_userroles or select * from portals_userroles Can you see if this will work? If so, you will need to change your SQL update query as such. -- David |
|
|
|
|
Daniel Cooper
wading in the water Posts:16
|
05-19-2009 07:02 AM |
|
I get results with select * from userroles The trouble seems to be that I get nothing with: SELECT * from UserProfile where PropertyDefinitionID = 58 Where 58 is the field for the image filename. |
|
|
|
|
David To
river guide Posts:2719
|
05-20-2009 12:26 PM |
|
I don't under your statement " I set a default image, which works on the registration form but later on the value is blank." If you set the image field in the DR form to have a default image, but when the user submits the form, are you saying that it's not adding in the userprofile table the PropertyDefinitionID of 58 which is a DNN core field that you linked to for the image field? -- David |
|
|
|
|
Jon
wading in the water Posts:20
|
06-04-2009 04:15 PM |
|
I think I know what Daniel's issue is as I have the same problem. The issue is that when a field is not filled in, an entry will never be made for it in userprofile. So, an Insert needs to be made to create that property in userprofile, not an update - which will always fail if the field was never filled in by the user. Chad's SQL could only work if the user had already specified an image during registration.
I too would very much like the ability to setup a default image that sticks. I'm not sure quite how to resolve this issue properly.
I could live with it if DynamicUserDirectory could be convinced to ignore empty/missing images, but it doesn't seem like it can.
|
|
|
|
|
David To
river guide Posts:2719
|
06-05-2009 09:04 AM |
|
Hi Jon, you can create an SQL stored procedure and call the stored procedure in the DR form completion event to check if a record exists, then update the image. If not, then insert the record with a default image. SQL stored procedure are very powerful and you can perform pretty much anything to the SQL database tables. -- David |
|
|
|
|
Jon
wading in the water Posts:20
|
06-09-2009 09:28 PM |
|
Thanks for the response David - the issue is I don't know how to write those. I guess I will need to figure it out some how. I was kind of hoping the module could deal with this, but it doesn't, so tough luck for me. |
|
|
|
|
David To
river guide Posts:2719
|
06-10-2009 09:06 AM |
|
Jon, a quick pointer in the right direction. Do something like the following. Note you will need to pass the UserID and the picture token name (from DR) to the stored procedure. Also note the propertyname of the picture token and put it in place of the 'UserPicture' in the stored procedure. create procedure usp_UserProfilePicture(@UserID int, @Picture nvarchar(500)) as begin declare @pictureVar nvarchar(500) If (@Picture = '') set @pictureVar = 'path/defaultimage.jpg' else set @pictureVar = @Picture declare @pictureID int set @pictureID = (select PropertyDefinitionID from ProfilePropertyDefinition where PropertyName = 'UserPicture') -- if record doesn't exist, insert a new record if not exists(select userid from UserProfile where userid = @UserID and PropertyDefinitionID = @pictureID) begin insert into UserProfile(UserID,PropertyDefinitionID,PropertyValue,Visibility,LastUpdateDate) values(@UserID,@pictureID,@pictureVar,2,getdate()) end else -- record exists, update it instead begin update UserProfile set PropertyValue = @pictureVar where UserId = @UserID end end |
|
|
|
|
Jon
wading in the water Posts:20
|
06-10-2009 03:24 PM |
|
David - you are right, this is a powerful technique I took your example and made some modifications to suit our naming. The main changes are:
1. rename variables/names to match what we are doing.
2. change the update command - it had 2 problems: A) it didn't update the LastUpdatedDate, and B) the WHERE clause was modified to specify the PropertyDefinitionId - the way it was, it would update *all* PropertyValues for that UserID to PictureVar... Definitely not what you wanted
At any rate, thanks alot, this was very useful in pointing me toward the light! Using an SP may also allow me to work around some issues with DUD filters. For your (or google's) edification here is the complete SQL I'm now using for this particular task:
-- based on quick pointer example from David To/dnncreative
if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}{objectQualifier}vwg_CheckVendorLogoProperty') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure {databaseOwner}{objectQualifier}vwg_CheckVendorLogoProperty
GO
-- no logo: exec vwg_CheckVendorLogoProperty 279, 'spacer.gif'
-- has logo: exec vwg_CheckVendorLogoProperty 263, 'spacer.gif'
create procedure vwg_CheckVendorLogoProperty(@UserID int, @newLogoVal nvarchar(500))
as
begin
declare @logoVar nvarchar(500)
if (@newLogoVal = '') set @logoVar = 'spacer.gif' else set @logoVar = @newLogoVal
declare @logoID int
set @logoID = (select PropertyDefinitionID from ProfilePropertyDefinition where PropertyName = 'Logo')
-- if record doesn't exist, insert a new record
if not exists(select userid from UserProfile where userid = @UserID and PropertyDefinitionID = @logoID)
begin
insert into UserProfile(UserID,PropertyDefinitionID,PropertyValue,Visibility,LastUpdatedDate) values(@UserID,@logoID,@logoVar,2,getdate())
-- DEBUG select UserId, PropertyValue from UserProfile where userid = @UserID AND PropertyDefinitionID = @logoID
end
else
-- record exists, update it instead
begin
update UserProfile set PropertyValue = @logoVar, LastUpdatedDate = getdate() where UserId = @UserID AND PropertyDefinitionID = @logoID
-- DEBUG select PropertyValue,LastUpdatedDate from UserProfile where userid = @UserID and PropertyDefinitionID = @logoID
end
end
|
|
|
|
|
Corey
going with the flow Posts:33
|
10-15-2009 10:09 AM |
|
I know nothing about SQL statements and stored procedures. I need a default image to show up in user profiles where the user did not upload an image. I think that is what they are doing above, but I can't figure out how to apply that technique. My profile property for the image is "Logo" Can anyone show me specifically how to accomplish this? |
|
|
|
|
David To
river guide Posts:2719
|
10-15-2009 01:15 PM |
|
HI, what is the shortname of your picture upload field? Also, you say your profile property is "Logo"; what is the propertydefinitionID? You can obtain this by going to Host / SQL and typing in: select * from profilepropertydefinition where propertyname = 'Logo' make a note of the propertydefinitionID since you will need it in the stored procedure Jon posted above. -- David |
|
|
|
|
Jon
wading in the water Posts:20
|
10-15-2009 02:52 PM |
|
Actually David, The SP looks up the propertyID for you in the code segment:
declare @logoID int
set @logoID = (select PropertyDefinitionID from ProfilePropertyDefinition where PropertyName = 'Logo')
So, assuming the shortname of the property field is Logo, nothing should need changing. If it is named differently, then just change 'Logo' to 'Whatever_you_are_using' and it should just work (TM).
Corey, the procedure I posted (and will post again, since some quoting seems to have been munged) needs to be loaded into your DB. Then you set up an SQL completion event that calls this procedure, passing it the UserID and the value of the logo field you are using. In the SP, if the value is empty, 'spacer.,gif' will be placed into the property table for that user, else, whatever they uploaded will be placed there.
If you are unfamiliar with SQL and Stored Procedures (SP) it will be well worth your while to become familiar with them. While I found many of the Datasprings modules are capable, you will almost always need to 'tweak' things for your specific requirements, and SP/SQL knowlege is very important.
So, I'll repost the SP here (using a 'blockquote' tag which will hopefully preserve all of the characters).
To load it into your DB, you will need to use SQL Exec from Host in dnn (with host privileges of course). Cut/paste into the command box, check 'Execute as script' and submit it.
Then to call it, in your SQL completion event for the form, you will need an SQL statement to the effect of:
exec vwg_CheckVendorLogoProperty $UserID, $Field_containing_logo
Where $Field_containing_logo is the value they entered for their logo on your form.
Hope that helps. Really, SQL and SP knowlege are very important when dealing with this stuff
So, here is the same procedure in a 'block quote' which will hopefully preserve all the characters. Good luck!
(You may want to change the names for the function and variables to more properly fit your site, once you've got a handle on what's going on. It's really not as bad as it may seem at first glance
if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}{objectQualifier}vwg_CheckVendorLogoProperty') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure {databaseOwner}{objectQualifier}vwg_CheckVendorLogoProperty
GO
-- no logo: exec vwg_CheckVendorLogoProperty 279, 'spacer.gif'
-- has logo: exec vwg_CheckVendorLogoProperty 263, 'spacer.gif'
create procedure vwg_CheckVendorLogoProperty(@UserID int, @newLogoVal nvarchar(500))
as
begin
declare @logoVar nvarchar(500)
if (@newLogoVal = '') set @logoVar = 'spacer.gif' else set @logoVar = @newLogoVal
declare @logoID int
set @logoID = (select PropertyDefinitionID from ProfilePropertyDefinition where PropertyName = 'Logo')
-- if record doesn't exist, insert a new record
if not exists(select userid from UserProfile where userid = @UserID and PropertyDefinitionID = @logoID)
begin
insert into UserProfile(UserID,PropertyDefinitionID,PropertyValue,Visibility,LastUpdatedDate) values(@UserID,@logoID,@logoVar,2,getdate())
-- DEBUG select UserId, PropertyValue from UserProfile where userid = @UserID AND PropertyDefinitionID = @logoID
end
else
-- record exists, update it instead
begin
update UserProfile set PropertyValue = @logoVar, LastUpdatedDate = getdate() where UserId = @UserID AND PropertyDefinitionID = @logoID
-- DEBUG select PropertyValue,LastUpdatedDate from UserProfile where userid = @UserID and PropertyDefinitionID = @logoID
end
end
|
|
|
|
|
David To
river guide Posts:2719
|
10-16-2009 07:26 AM |
|
Cool. Very thorough work. Thanks for posting this up. Hope you are all set Jon. -- David |
|
|
|
|