Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

Preview: DataObjectManager module


Go to End


379 Posts   95931 Views

Avatar
micahsheets

Community Member, 165 Posts

22 April 2009 at 11:52am

Edited: 22/04/2009 12:00pm

Uncle Cheese,
I used your Testimonials example as a basis for my own Testimonials class and TestimonialsPage type. My page type first displays a random testimonial and then I have previous and next buttons that I want to page through all of the testimonials one by one. I tried using what you added to the image_gallery for next and prev albums as a basis to add this to my TestimonialsPage. However I cannot figure a way for my adjacentTestimonial() function to know the ID of the randomly selected initial Testimonial. I don't know how to set up parameters inside a class and even if I did have a parameter that would hold the Testimonial DataObject I need there is no way of making sure my currentTestimonial function runs before the NextTestimonial and PrevTestimonial functions run so that variable could very well be null and I couldn't get the ID so I could get the next or previous one from the Testimonials table.

Maybe the problem could be approached this from a completely different angle.

One more note: In your ImageGalleryPage.php file that I am using as reference for prev/next functionality, $this->current_album is set in SingleAlbumView() and tested in CurrentAlbum() however I am not sure how this works as I can't find where that is declared.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

22 April 2009 at 11:58am

If you want a truly random order with pagination, you need to do one of two things:

1) Bring down the DataObjectSet of randomly ordered testimonials all into one page and navigate between them with Javascript
2) Store a session variable that is an array of the initial sort order of testimonials, and once set, use that to navigate your testimonials.

Apart from that, I don't know that you can randomly order a record set with every refresh of the page and expect coherent results.

Avatar
NickJacobs

Community Member, 148 Posts

22 April 2009 at 12:56pm

Edited: 22/04/2009 1:31pm

@micahsheets
This is a different angle, may or may not be what you are looking for:

All I would do is generate a random set of testimonials (either a limited set or all of them) ie :

function getRandomQuote() { 
      return DataObject::get("Testimonial","", "RAND()", "",6); 
   } 

output on the template, something like:

<div id="testimonials" style="display:none">
<% control getRandomQuote %>
<div class="testimonial-text">$Testimonial</div
<div class="testimonial-author">$Author</div>
<% end_control %>

<div class="controls"><a id="prev" href="#" >prev</a><a id="next" href="#" >next</a></div>

</div>

then use jQuery cycle (or something similar) to allow you to page through the testimonials.

I hide the div first so you don't get the whole lot of them showing at the start, then use jquery to unhide once the page has loaded. jquery should look something like:

$(document).ready(function(){	

$('#testimonials').cycle({ 
		prev:   '#prev', 
		next:   '#next',		
		timeout: 0 
		});	
$('#testimonials').show();		
});

I've used it for images here, but it should work equally well for text-based content.

Avatar
NickJacobs

Community Member, 148 Posts

22 April 2009 at 1:02pm

I've been trying for the last few days to implement front-end searching through dataobjects. I've looked through the wiki & forum and tried lots of options, but buggered if I can get it sorted. Has anyone successfully implemented a dataobject search (ie a keyword search through 2 or more dataobject feilds) that you could share??

Avatar
Victor

Community Member, 128 Posts

22 April 2009 at 1:28pm

$resultsF = DataObject::get("FacultyPage"," `lastname` LIKE '".$data['LastName']."%' AND `firstname` LIKE '".$data['FirstName']."%'");

HTH. Victor

Avatar
UncleCheese

Forum Moderator, 4102 Posts

22 April 2009 at 2:10pm

Edited: 22/04/2009 2:10pm

@victor -- LIKE is not a reliable search function to use since it doesn't allow natural language. For instance, searching "Silverstripe camp" will not match the record "Silverstripe summer camps"

@Tsunami -- Glad you asked. I was just about to post this as a snippet. I had to do this for a client on Friday. Took a long time, but it came out pretty good. I built a class called CustomSearchForm, a subclass of SearchForm, which by default searches SiteTree and File, and you add more classes to it.

$form->addCustomClass('MyDataObject');

There are a few things you need to add to your dataobject class like:

$searchable_fields = array ('Author','Quote');

I'll post it soon. Works pretty well. You can actually test it at http://riskpayments.bluehousegroup.com. Search on anything in the Knowledge Base section. Those are all GlossaryTerm dataobjects, and you'll see they come up in the site search.

Avatar
NickJacobs

Community Member, 148 Posts

22 April 2009 at 2:39pm

@UncleCheese
cool...i look forward to seeing it:)
since I seem to be finding uses for dataobjectmanager in all sorts of different places in my projects, search ability was sooner or later gonna be an issue....I'm glad you cracked it & I can stop banging my head against the wall! Thanks

Avatar
robinp

Community Member, 33 Posts

22 April 2009 at 6:04pm

@UncleCheese if you don't think the DataObjectManager module is the solution for what do think the solution could be ? it's working quite well I've made to dataobject_manager/javascript/dataobject_manager.js line 105 like hu suggested.

cheers

robin

Go to Top