Jump to:

23360 Posts in 18097 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » ***SOLVED***Staff Section without individual pages?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3
Go to End
Author Topic: 1500 Views
  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: ***SOLVED***Staff Section without individual pages? Link to this post

    change...

    $p->ChamberTitle = $do->ChamberTitle;

    to...

    $p->Title = $do->ChamberTitle;

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: ***SOLVED***Staff Section without individual pages? Link to this post

    Thank you so much Swaiba

    That was giving me the title of the dataobject instead of the parent page so I tried this:

    $p->Title = 'Committee Members';

    and it worked. Should be okay, right?

    If I had another page with dataobjects would I have to repeat all that code or just add a few lines?

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: ***SOLVED***Staff Section without individual pages? Link to this post

    Hi Swaiba,

    I've been trying for a while now with no success to repeat this dataobject search fix for another page that uses dataobjects.
    I have basically the same set up as the staff section except it has only first and last names.
    I've tried repeating the code and changing some relevant info, I've tried adding to the current code but no luck so far.

    Could you give me a push in the right direction of what you think I need to do?

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: ***SOLVED***Staff Section without individual pages? Link to this post

    I've wrapped the section that needs repeating. basically you do the search again with a different dataobject::get and push the results on to the same "$dosNewResults" that is then combined at the end with the original results from the sitetree

    /////////////////////////////////////////////////////////////
    // Start Custom

    //make our our result set
    $dosNewResults = new DataObjectSet();

    $arrSearchQuery = explode(' ',$form->getSearchQuery());
    $strSearchQuery = '%'.implode('%',$arrSearchQuery).'%';

    $dos = DataObject::get('StaffMember',"(ChamberTitle LIKE '".$strSearchQuery."'"."OR Name LIKE '".$strSearchQuery."'"."OR Business LIKE '".$strSearchQuery."'"."OR Phone LIKE '".$strSearchQuery."'"."OR Email LIKE '".$strSearchQuery."') " );

    if ($dos) {
       $arr = $dos->toArray();
       foreach ($arr as $do) {
       $p = new Page();
       $p->ChamberTitle = $do->ChamberTitle;
       $p->URLSegment = '/your-chamber/Staff-members/';;
       $p->Content = $do->Description;;
       $p->Name = $do->Name;;
       $p->Business = $do->Business;;
       $p->Phone = $do->Phone;;
       $p->Email = $do->Email;;

       // $p->SearchTerm = $do->SearchTerm;;

       $p->ID = $do->ID;;
       $p->Relevance = 1;
       $p->CanViewType = 'Anyone';

       $dosNewResults->push($p);
       }
    }

    /////REPEATING section above
    //this will search another object and push the results on to the same data object set return variable
    $dos = DataObject::get('SomeOtherObject',"(ChamberTitle LIKE '".$strSearchQuery."'"."OR Name LIKE '".$strSearchQuery."'"."OR Business LIKE '".$strSearchQuery."'"."OR Phone LIKE '".$strSearchQuery."'"."OR Email LIKE '".$strSearchQuery."') " );

    if ($dos) {
       $arr = $dos->toArray();
       foreach ($arr as $do) {
       $p = new Page();
       $p->ChamberTitle = $do->ChamberTitle;
       $p->URLSegment = '/your-chamber/Staff-members/';;
       $p->Content = $do->Description;;
       $p->Name = $do->Name;;
       $p->Business = $do->Business;;
       $p->Phone = $do->Phone;;
       $p->Email = $do->Email;;

       // $p->SearchTerm = $do->SearchTerm;;

       $p->ID = $do->ID;;
       $p->Relevance = 1;
       $p->CanViewType = 'Anyone';

       $dosNewResults->push($p);
       }
    }
    /////REPEATING

    //strip out the html from the results and append them to the results
    //above - so that the ones with things to buy are first
    if ($data['Results']->Count() > 0) {
       $arr = $data['Results']->toArray();
       foreach ($arr as $do) {
          $do->Content = strip_tags($do->Content);
          $dosNewResults->push($do);
          $dosNewResults->removeDuplicates('URLSegment');
       }
    }

    $data['Results'] = $dosNewResults;
    // End Custom
    /////////////////////////////////////////////////////////////

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: ***SOLVED***Staff Section without individual pages? Link to this post

    Perfect

    I was close but not close enough,

    Thanks again Swaiba - Excellent

    1500 Views
Page: 1 2 3
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.