Extend sitefinity datamodel: custom PageProvider not registered?
I'm trying to extend the sitefinity data model to allow users to select categories they are interested in. In that way, we can build a custom widget which displays only news content for a registered user which he would like to see.
In order to accomplish that I've folowed the following tutorial: www.sitefinity.com/.../extending-the-sitefinity-model
In the last step, I need to register the provider in the sitefinity backend. So far so good: the type is recognized and it seems the provider is registered.
However, in the custom widget the Provider collection of the pagemanager I'm trying to reach (PageManager.GetManager().Providers) still only contains the default OpenAccessDataProvider.
Am I on the right track for this approach? How can I get a reference to the new Custom Provider? Any other suggestions?
Hi Mark,
Normally the code you have provided should returns both provider (default and your custom one).
Could you please check and ensure that the settings are correct as per that article. Can you attach also a screenshot of the settings you have and the code implemented?
From other hand, the scenario you have described is covered by Categories/Tags widgets for default and custom classifications and setting the proper permissions for News Items.
I hope this information helps.
Regards,
Svetoslav Manchev
Telerik
If you have any suggestions how users can filter news by categories themselves without making a new PageProvider and CustomType, please let me know.In the attached files you can see:
- the settings page for the custom PageProvider (settings.png)
- a screenshot from the Visual Studio project in the Solution Explorer (project.png)
- a screenshot during debugging with info about the registered providers (debug.png)
Kind regards
Mark
Hello Mark,
You can easily filter the news using the Categories widget. For example create a Category
Colours > Red & Blue and add them to the News Items.
Than drop the News and Categories widget on a Page.
Short video demonstration how it works could be found here.
I hope this helps.
Regards,
Svetoslav Manchev
Telerik
Hello Svetoslav,
Thanxs for your reply. However, I do not want the admin user to filter the news based on the categories, but the end users of the website themselves. For each user, the news widget must show the news items filtered on the categories which the end user is interested in.
Any suggestions why the PageProvider is'nt registered?
Hi Mark,
The List of News and the filtering was done on the frontend.
So the end users will filter the News by the categories available. The last 10 seconds of the video are on frontend page.
Regards,
Svetoslav Manchev
Telerik
Hello,
I've watched the video a few times, it's rather quick and therefor a bit hard to understand. I see what you mean, the end user can switch between categories to display the related news items.
The difference between this approach and the requirements I'm trying to implement is that the end user has to be able to select categories up front, in his profile. A news widget must display the items from a category based on this profile. So for each user, the news widget will contain different news items.
At this point, the user cannot change categories to display other news items. He must return to his profile page to change his preferences.
Kind regards,
Mark
Hi Mark,
In order to propose possible solution, would you please elaborate a little more about the scenario that you want to achieve?
Regards,
Svetoslav Manchev
Telerik
I want a news widget on a page which shows news items personalized for each registered user.
In order to acchieve this, I need registered users to select which categories they are interested in. For this purpose, I have implemented a user profile widget where the users can change their profile, but also can check/uncheck categories in a TreeView. I need to extend the database to store the checked categories per registered user.
Second, I will need a news widget which reads the preferred categories for the current user and displays only the news items in those categories.
Kind regards,
Mark van der Kolk
PS. Still no answer to my original question, why is the PageProvider not registered?
Hi Mark,
We have answer you in the opened support ticket.
Once you have the solution you can share it with the community.
Regards,
Svetoslav Manchev
Telerik
Hello Mark,
Since the solution I have suggested in the support ticket has helped to achieved the desired functionality, I would like to share it with the community. Here is the reply from the support ticket you have opened:
What I can suggest in order to achieve the desired behavior is to create a custom classification (categories) field in your user profile where you can store the categories selected by the user.
Then in the BtnSave_Click() method of your custom user profile widget you can first get the list of categories ids from the user profile of the current user, then add to this list for example the new category selected by the user, and set the value of the custom categories field to the updated categories list. Here is a sample code for your convenience demonstrating how to set the value of the custom categories field (please refer to the code marked in yellow):
public
static
MembershipCreateStatus CreateUser(
string
username,
string
password,
string
firstName,
string
lastName,
string
mail,
string
secretQuestion,
string
secretAnswer,
bool
isApproved)
UserManager userManager = UserManager.GetManager();
UserProfileManager profileManager = UserProfileManager.GetManager();
System.Web.Security.MembershipCreateStatus status;
User user = userManager.CreateUser(username, password, mail, secretQuestion, secretAnswer, isApproved,
null
,
out
status);
if
(status == MembershipCreateStatus.Success)
SitefinityProfile sfProfile = profileManager.CreateProfile(user, Guid.NewGuid(),
typeof
(SitefinityProfile))
as
SitefinityProfile;
if
(sfProfile !=
null
)
sfProfile.FirstName = firstName;
sfProfile.LastName = lastName;
// Get the category
var category = GetCategoryByName(
"admins"
);
// Get a list of the categories in the user profile, add the new category, then add the list of categories into the profile.
var catlist = sfProfile.GetValue<TrackedList<Guid>>(
"Category"
);
catlist.Add(category.Id);
sfProfile.SetValue(
"Category"
,catlist);
userManager.SaveChanges();
profileManager.RecompileItemUrls(sfProfile);
profileManager.SaveChanges();
return
status;
public
static
Taxon GetCategoryByName(
string
name)
TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
HierarchicalTaxonomy category = taxonomyManager.GetTaxonomy<HierarchicalTaxonomy>(TaxonomyManager.CategoriesTaxonomyId);
if
(category ==
null
)
return
null
;
return
category.Taxa.Where(t => t.Name == name).SingleOrDefault();
var catlist = sfProfile.GetValue<TrackedList<Guid>>(
"Category"
);