1
0

Added Searching

This commit is contained in:
2014-08-04 14:57:13 +02:00
parent 193c9f376d
commit 2af3e05fe1
14 changed files with 242 additions and 10 deletions

View File

@@ -119,4 +119,41 @@ class BlogPost extends CActiveRecord
return '/blog/' . $this->ID . '/' . $name;
}
/**
* @param $search string[]
* @return array()
*/
public static function getSearchResults($search)
{
/* @var $all BlogPost[] */
/* @var $resultarr BlogPost[] */
$all = BlogPost::model()->findAll();
$resultarr = array();
foreach($search as $searchpart)
{
foreach($all as $post)
{
if (stripos($post->Title, $searchpart) !== false && ! in_array($post, $resultarr))
$resultarr []= $post;
}
}
$result = array();
foreach($resultarr as $post)
{
$result []=
[
'Name' => $post->Title,
'Description' => null,
'Link' => $post->GetLink(),
'Image' => '/images/search/sresult_blog.png',
];
}
return $result;
}
}