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.

General Questions /

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

***SOLVED***Staff Section without individual pages?


Reply


21 Posts   1703 Views

Avatar
ambient

Community Member, 123 Posts

1 October 2011 at 12:57am

Thanks Guys, I'll be looking into Uploadify except for I just noticed the data objects aren't searchable.

Since the staff section is an important part of the site it has to be searchable. Anybody know of a way to make that happen?
I've tried Lucene search and Sphinx but their set up is quite complicated and over my head, can't get either working.

If I can't get this figured out I may just have to forget it and go back to creating individual pages for a few lines of text... pity :(

Avatar
swaiba

Forum Moderator, 1799 Posts

1 October 2011 at 1:13am

I feed bad keep posting this, but it is a quick easy method to include dataobjects into the regular site search...

http://www.silverstripe.org/customising-the-cms/show/14067#post288644

Avatar
zenmonkey

Community Member, 528 Posts

1 October 2011 at 1:33am

Swaiba, just get the, to add it to the recipe's page :)

Avatar
ambient

Community Member, 123 Posts

1 October 2011 at 1:41am

My php is terrible.

I changed the line:

$dos = DataObject::get('YOURDATAOBJECT',"FIELD LIKE '".$strSearchQuery."'");

to the same as the function return DataObject from the data object php file

$dos = DataObject::get('Staff', "`MyStaffMemberID` = '{$this->ID}'".$strSearchQuery."'");

And I changed:


$p = new Page();
$p->Title = $do->SOMEFIELD;
$p->URLSegment = 'SOMEURL?POSTVAR='.$do->SOMEFIELD;;
$p->Content = $do->SOMEFIELD;;
$p->Name = $do->SOMEFIELD;;
$p->Relevance = 1;
$p->CanViewType = 'Anyone';

To:


$p = new Page();
$p = new Page();
$p->Title = $do->MemberTitle;
//$p->URLSegment = 'SOMEURL?POSTVAR='.$do->SOMEFIELD;;
$p->Content = $do->Content;;
$p->Name = $do->Name;;
$p->Relevance = 1;
$p->CanViewType = 'Anyone';

Am I missing something? I'm getting a 'Couldn't run query' error. Obviously I'm doing something wrong.

Avatar
swaiba

Forum Moderator, 1799 Posts

1 October 2011 at 1:54am

$dos = DataObject::get('Staff', "`MyStaffMemberID` = '{$this->ID}'".$strSearchQuery."'");

I don't follow that at all...

$dos = DataObject::get('YOURDATAOBJECT',"FIELD LIKE '".$strSearchQuery."'");

YOURDATAOBJECT = Staff = OK
FIELD LIKE QUERY = uses a like and it breaks up the search query text to match it against something... e.g. Name LIKE '%bob%

Avatar
ambient

Community Member, 123 Posts

1 October 2011 at 2:26am

Sorry, I should have just asked which parts of the code I need to change to get it to work.
So I'll ask now, which parts of the code I need to change to get it to work? :)

Avatar
swaiba

Forum Moderator, 1799 Posts

1 October 2011 at 2:28am

Mainly those IN CAPITALS - but read on in the thread as stew went throguh the same process

Avatar
ambient

Community Member, 123 Posts

1 October 2011 at 3:57am

Duh! Sorry, I didn't see that that post had 2 more pages.

Okay, making some progress now. It finds the relevant info but in the search results the Found in: and Read more about ""... don't display the name of the page. The links work but it just doesn't display the name of the page. Any idea on what I've done to cause that?

Heres the current code:

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

$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."') " );

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

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);
}
}
foreach ($arrSearchQuery as $strSearchQuery)
{
$strSearchQuery = '%'.$strSearchQuery.'%';

//repeat code to do DataOBject::get
//add to $dosNewResults
}

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

return $this->customise($data)->renderWith(array('Page_results', 'Page'));
}