Hey guys,
Was wondering if somebody can help me theory craft for SS. I have ArticleHolder and ArticlePage. Holder will list all the Pages. What I want to achieve is user enters tags in a single field in the following manner: Tags-> News, History, Gaming, Other
Then when on the page I click on tag News, I get articles that have the word news in the field above.
At the moment I am achieving that in the following manner:
ArticlePage::get()->filter('category:PartialMatch', $tag)->sort('Date DESC');
Problem with this is that I have tag called Newstorie then it will return under news.
My solution is to get all the results that partially contain the word and then clean up after by looping through each results and spliting it on the comma. Could would look like something like this:
public function filterArticles($tag){
$result = ArticlePage::get()->filter('category:PartialMatch', $tag)->sort('Date DESC');
$exists = FALSE;
foreach ($result as $temp){
$tempArray = $temp->category->split(',');
foreach ($tempArray as $currentArray){
if($currentArray == $tag){
$exists = TRUE;
}
}
if($exists == FALSE){
$result = $result->subtract($temp);
}
else{
$exists = FALSE;
}
}
return $result;
}
I cannot get subtract nor split to work.
What would be a better way to accomplish this, or at least how do I get split and subtract to work.