1
0

Added Searching

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

View File

@ -674,3 +674,37 @@ ul.nav li.dropdown-append:hover > ul.dropdown-menu {
.blogFooterRight { .blogFooterRight {
float: right; float: right;
} }
/* SearchResults
-------------------------------------------------- */
.sresults_main {
box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.35);
}
.sresults_image {
height: 100px;
padding-right: 10px;
}
.sresults_section {
border-bottom: 1px solid #D0D0D0;
margin: 10px;
overflow: hidden;
padding-bottom: 5px;
display: block;
}
.sresults_caption {
margin-top: 0px;
}
.sresults_desc {
width: 65%;
}
.sresults_info {
color: #929292;
font-size: small;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -11,5 +11,3 @@ defined('YII_CUSTOM_ENV') or define('YII_CUSTOM_ENV', 'dev');
require_once($yii); require_once($yii);
Yii::createWebApplication($config)->run(); Yii::createWebApplication($config)->run();
// TODO-MS Add Search (Blog + progs + log) jew auch metadata / desc ...

View File

@ -15,6 +15,7 @@ class MSController extends CController
public $title = null; public $title = null;
public $searchvalue = '';
public function beforeAction($e){ public function beforeAction($e){
Yii::app()->hitcounter->increment(); Yii::app()->hitcounter->increment();

View File

@ -21,7 +21,7 @@ class MSMainController extends MSController
{ {
return array( return array(
array('allow', array('allow',
'actions'=>array('index', 'about', 'debugerror', 'error', 'login', 'logout'), 'actions'=>array('index', 'about', 'debugerror', 'error', 'login', 'logout', 'search'),
'users'=>array('*'), 'users'=>array('*'),
), ),
array('allow', array('allow',
@ -149,5 +149,20 @@ class MSMainController extends MSController
$this->redirect(Yii::app()->homeUrl); $this->redirect(Yii::app()->homeUrl);
} }
public function action public function actionSearch($search)
{
$searchsplit = preg_split('[\+| ]', $search, 8, PREG_SPLIT_NO_EMPTY);
$results = array_merge(
Program::getSearchResults($searchsplit),
BlogPost::getSearchResults($searchsplit),
Log::getSearchResults($searchsplit),
HighscoreGames::getSearchResults($searchsplit));
$this->render('searchresults',
[
'searchstring' => $search,
'result' => $results,
]);
}
} }

View File

@ -119,4 +119,41 @@ class BlogPost extends CActiveRecord
return '/blog/' . $this->ID . '/' . $name; 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;
}
} }

View File

@ -126,4 +126,41 @@ class HighscoreGames extends CActiveRecord
else else
return null; return null;
} }
/**
* @param $search string[]
* @return array()
*/
public static function getSearchResults($search)
{
/* @var $all HighscoreGames[] */
/* @var $resultarr HighscoreGames[] */
$all = HighscoreGames::model()->findAll();
$resultarr = array();
foreach($search as $searchpart)
{
foreach($all as $hgame)
{
if (stripos($hgame->NAME, $searchpart) !== false && ! in_array($hgame, $resultarr))
$resultarr []= $hgame;
}
}
$result = array();
foreach($resultarr as $hgame)
{
$result []=
[
'Name' => $hgame->NAME . ' (Highscore)',
'Description' => null,
'Link' => $hgame->GetListLink(),
'Image' => '/images/search/sresult_highscores.png',
];
}
return $result;
}
} }

View File

@ -113,4 +113,41 @@ class Log extends CActiveRecord
public function getLink() { public function getLink() {
return '/log/' . $this->ID; return '/log/' . $this->ID;
} }
/**
* @param $search string[]
* @return array()
*/
public static function getSearchResults($search)
{
/* @var $all Log[] */
/* @var $resultarr Log[] */
$all = Log::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_log.png',
];
}
return $result;
}
} }

View File

@ -279,4 +279,47 @@ class Program extends CActiveRecord
{ {
return HighscoreGames::model()->findByPk($this->highscore_gid); return HighscoreGames::model()->findByPk($this->highscore_gid);
} }
/**
* @param $search string[]
* @return array()
*/
public static function getSearchResults($search)
{
/* @var $all Program[] */
/* @var $resultarr Program[] */
$all = Program::model()->findAll();
$resultarr = array();
foreach($search as $searchpart)
{
foreach($all as $prog)
{
if (! $prog->enabled || ! $prog->visible)
continue;
if (stripos($prog->Name, $searchpart) !== false && ! in_array($prog, $resultarr))
$resultarr []= $prog;
if (stripos($prog->Description, $searchpart) !== false && ! in_array($prog, $resultarr))
$resultarr []= $prog;
}
}
$result = array();
foreach($resultarr as $prog)
{
$result []=
[
'Name' => $prog->Name,
'Description' => $prog->Description,
'Link' => $prog->GetLink(),
'Image' => $prog->GetImagePath(),
];
}
return $result;
}
} }

View File

@ -64,6 +64,7 @@
'placeholder' => 'Search', 'placeholder' => 'Search',
'inputOptions' => 'inputOptions' =>
[ [
'value' => $this->searchvalue,
'append' => MsHtml::submitButton(MsHtml::icon(MsHtml::ICON_SEARCH)), 'append' => MsHtml::submitButton(MsHtml::icon(MsHtml::ICON_SEARCH)),
'addOnOptions' => 'addOnOptions' =>
[ [

View File

@ -0,0 +1,32 @@
<?php
/* @var $this MsMainController */
/* @var $searchstring string */
/* @var $result array() */
$this->pageTitle = 'Search - ' . $searchstring;
$this->searchvalue = $searchstring;
$this->breadcrumbs=
[
'Search'
];
?>
<div class="container">
<div class="sresults_main well">
<span class="sresults_info"><?php echo count($result); ?> results found for "<?php echo $searchstring; ?>"</span>
<?php foreach($result as $section): ?>
<div class="sresults_section">
<?php if (! is_null($section['Image'])): ?>
<img class="sresults_image pull-left" src="<?php echo $section['Image'];?>">
<?php endif; ?>
<h3 class="sresults_caption"><a href="<?php echo $section['Link'];?>"><?php echo $section['Name'];?></a></h3>
<?php if (! is_null($section['Description'])): ?>
<p class="sresults_desc"><?php echo $section['Description'];?></p>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</div>

View File

@ -10,6 +10,3 @@ require_once($yiic);
// TODO-MS BefunGen -> MS.de // TODO-MS BefunGen -> MS.de
// TODO-MS jClipCorn -> MS.de // TODO-MS jClipCorn -> MS.de
// TODO-MS jQCCounter (OLD DATE !) -> MS.de // TODO-MS jQCCounter (OLD DATE !) -> MS.de
//TODO-MS Add Guest counter