Jump to:

7912 Posts in 1355 Topics by 930 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Preview: DataObjectManager module

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Go to End
Author Topic: 54246 Views
  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: Preview: DataObjectManager module Link to this post

    @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.

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: Preview: DataObjectManager module Link to this post

    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??

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Preview: DataObjectManager module Link to this post

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

    HTH. Victor

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    @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.

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: Preview: DataObjectManager module Link to this post

    @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

  • robinp
    Avatar
    Community Member
    33 Posts

    Re: Preview: DataObjectManager module Link to this post

    @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

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Preview: DataObjectManager module Link to this post

    Hi Uncle Cheese,

    I've run across a bug re ManyManyDataObjectManager's field list. Setting one up like this:

          $tablefield = new ManyManyDataObjectManager(
             $this,
             'Qualities',
             'QualityHomePage',
             array(
                'Title' => 'Quality',
                'Primary' => 'Primary'
             ),
             'getCMSFields_forPopup'
          );
          $tablefield->setParentClass('QuoteModel');
          $fields->addFieldToTab('Root.Main', $tablefield);


    causes a SQL error. The problem is that the field array contains a field name of "Primary", which is a MySQL reserved word. MySQL requires that reserved words be escaped when used as field names in SQL. This isn't being done. The query being run looks like:

    SELECT `SiteTree`.*, `QualityHomePage`.*, `SiteTree`.ID, if(`SiteTree`.ClassName,`SiteTree`.ClassName,'SiteTree') AS RecordClassName,
    Primary,
    IF(`QuoteModelID` IS NULL, '0', '1') AS Checked FROM `SiteTree` LEFT JOIN `QualityHomePage` ON `QualityHomePage`.ID = `SiteTree`.ID LEFT JOIN `QuoteModel_Qualities` ON (`SiteTree`.`ID` = `QualityHomePageID` AND `QuoteModelID` = '4') WHERE (`SiteTree`.ClassName IN ('QualityHomePage')) GROUP BY `SiteTree`.ID ORDER BY Sort LIMIT 0, 10

    If I change the field type to ManyManyComplexTableField but don't otherwise change the arguments passed to the field's constructor, the resulting query looks like:

    SELECT `SiteTree`.*, `QualityHomePage`.*, `SiteTree`.ID, if(`SiteTree`.ClassName,`SiteTree`.ClassName,'SiteTree') AS RecordClassName,
    `Primary`,
    IF(`QuoteModelID` IS NULL, '0', '1') AS Checked FROM `SiteTree` LEFT JOIN `QualityHomePage` ON `QualityHomePage`.ID = `SiteTree`.ID LEFT JOIN `QuoteModel_Qualities` ON (`SiteTree`.`ID` = `QualityHomePageID` AND `QuoteModelID` = '4') WHERE (`SiteTree`.ClassName IN ('QualityHomePage')) GROUP BY `SiteTree`.ID ORDER BY Sort LIMIT 0,10

    So, ManyManyComplexTableField properly escapes the field with tick marks while ManyManyDataObjectManager doesn't. Would you be willing to fix this?

    Thank you,
    Ben

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    @Ben - Thanks for flushing that out. I'll look into it. My guess is that it goes all the way up to DOM, since MMDOM differs only marginally from MMCTF.

    @robinp - My apologies. In my previous message, I had mixed up your name with cmswarrior. The message to you was directed at him/her, and vice-versa. Glad you got it working. I'd like to make that a config setting but it's a little tricky converting PHP to Javascript. Did you find a setting that was more comfortable for you?

    54246 Views
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.