I am trying to build a "Latest Comments" widget for Orchard CMS.
I know I could directly query the SQL, but is there an API I can use in Orchard to get the latest comments on the whole blog (and which blog post each comment belongs to, etc)? I've been looking at IContentManager::Query, but I'm not exactly clear how I can use this to get the information I want.
Check out the CommentsService in the Orchard.Comments module. Orchard.Comments.Services.CommentsService. It's really close to what you need. Since the service returns the query, you could just tack on some additional sorting like this...
var query = commentsService.GetCommentsForCommentedContent(blogId);
var comments = query.OrderByDescending(c => c.CommentDateUtc).Slice(10);
Something like that.
Related
I have created a custom post type that for the sake of this question we can call "my_cpt".
I have also created a new role which we can call "my_role".
What I want to do is give "my_role" access to "my_cpt" without adding the "edit_posts" capability because that gives access to other post types which I do not want the role to have access to.
I have tried variations of numerous bits of code I have found but none have worked so I don't really know where to begin. Based on that I don't have any base code to display here.
A plugin like this one should enable you to do this: https://www.role-editor.com/
Ended up being easier than I thought.
I created a couple capabilities... "read_my_cpt" and "edit_my_cpt".
The "my_role" has permissions to both the capabilities.
I then just had to change the capability_type for the CPT to "my_cpt" instead of "post"
I am attempting to use the SqlProfileProvider in an application and can't seem to use it the way I want to. I would like to be able to simply call up a profile like this:
Profile p = Profile.GetProfile("naspinski");
p.Organization = "new_org";
but I can't seem to find the correct way to use the GetProfile() that I seem to see scattered around the net. Is there a way to grab, read and modify profiles?
I am using it in MVC 3 and will not be actually logging in as the specific user, this will be pulling users from the db that are specified. Thank you.
To retrieve the profile:
var profile = ProfileBase.Create(HttpContext.Profile.UserName, true);
And here's the MSDN documentation. And a nice blog post about custom profiles.
Is there some kind of SQL Statement that I can used to do a search on 1 Column in my table that is similar to what I am looking for.
Like if I am looking for something to do with a "Car" but I spell it as "Kar" it must return items of "car".
Or
If I am looking for "My Company" and I spell it as "MyCompany" it must still retun "My Company".
Select * from TableName where Column Like '%company%' will return "My Company" but I need more as the user will not always know how to spell. So I need something more advanced like some small Google App or something...
That feature is in the text services so if you build a full-text search index, you should be able to use the feature.
Have a look here:
http://msdn.microsoft.com/en-us/library/ms187384.aspx
http://msdn.microsoft.com/en-us/library/ms142571.aspx
This is quite an involved problem. The quick answer is to use the SQL Server soundex algorithm, but it's pretty hopeless. Try the suggestions on this SO answer. (Updated)
Read this blog post: http://googlesystem.blogspot.com/2007/04/simplified-version-of-googles-spell.html
This is something you could implement with SQL, but it's not a built in feature.
Another way to help you users find what they are looking for is to implement type-ahead on the search field. If the user type: "my" he will get "My Company" as a suggestion and likely go with that.
You can easily implement type ahead using jquery or other javascript libraries. Here's a list of type ahead plugins for jQuery: http://plugins.jquery.com/plugin-tags/typeahead
No. A full text index might get you closer, depending on your requirements (what exact features are you looking for?) One option would be roll you own .NET assembly with the desired features add it (CREATE ASSEMBLY) to sql server and use that to search.
I’m very new to programming with RSS feeds to please forgive me if this sounds like a really general question.
Is it possible to take multiple RSS feeds from multiple sites and combine them as a single object to show to the end user?
For example, could I take the latest news headlines from one site, the latest blog updates from a totally different site and combine them into a single list to show the user?
I have seen this sort of question asked before and it seems like its possible, but the slight twist is I want to let the user add any feed that they want from any source
I’m looking to do this in ASP.NET
Many thanks!
You can use the SyndicationFeed class to work with RSS feeds in .Net.
You probably want to do something like this (untested):
var allItems = new List<SyndicationItem>();
foreach(var feedUrl in whatever) { //In your list of urls
using(var reader = XmlReader.Create(url))
allItems.AddRange(SyndicationFeed.Load(reader).Items);
}
var newFeed = new SyndicationFeed(items);
//Do something with newFeed
You should add error handling in case one of the feeds is unavailable or invalid.
It is possible, yes.
For a good example of this kind of thing in action, check out Yahoo! Pipes.
This would probably be a good application of LINQ to XML, but I'll leave the implementation up to you.
...or, in other words, how to create a simple join as I would do in SQL?
Suppose I want the following information:
Just as an example:
a person's full name
a person's hobbies.
His full name is in a (content profile) node type 'name_and_address' and his hobbies are in 'hobbies'.
In SQL, I would link them together by node.uid.
I've seen a bit about using relationships, but that goes with user-node-refs.
I just want the same user from one content-type and the other.
Now how could I get his name and his hobbies in 1 view?
There is a how to here does this do the job?
If not...
Views can be extended with custom joins, filters etc. If you are lucky there will be a module for this already. Some modules even provide their own views plugins.
You can write your own views plugins, although the documentation is a little fragmented.
The other thing that should be noted is that views isn't always the answer. Sometimes writing a custom query and display handler will do what you want with much less hassle.
Look at the relationships section of the view. This allows you to relate (ie join) different types of content (ie tables). It's not especially intuitive to someone used to SQL, but this video explains much of it. http://www.drupalove.com/drupal-video/demonstration-how-use-views-2s-relationships
You could use views_embed_view() in your template files to manually specify where they appear (and by extension render one view right below another).
You could override this function in a custom module (modulename_embed_view($name, $display_id)) in order to selectively edit what data is allowed out to the page.
Ex):
function modulename_embed_view($name, $display_id) {
if (strcmp($_GET['q'], 'node/123') === 0) {
$view = views_get_view($name);
$view2 = views_get_view('second view');
$output = $view['some element'] . $view2['element'];
}
return $output;
}
I know that this is very much a hack - I just wanted to show how one might use php to manually render and modify views in your template files.