Added Searching
This commit is contained in:
parent
193c9f376d
commit
2af3e05fe1
@ -674,3 +674,37 @@ ul.nav li.dropdown-append:hover > ul.dropdown-menu {
|
||||
.blogFooterRight {
|
||||
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;
|
||||
}
|
||||
|
||||
|
BIN
www/images/search/sresult_blog.png
Normal file
BIN
www/images/search/sresult_blog.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
BIN
www/images/search/sresult_highscores.png
Normal file
BIN
www/images/search/sresult_highscores.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
www/images/search/sresult_log.png
Normal file
BIN
www/images/search/sresult_log.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
@ -11,5 +11,3 @@ defined('YII_CUSTOM_ENV') or define('YII_CUSTOM_ENV', 'dev');
|
||||
|
||||
require_once($yii);
|
||||
Yii::createWebApplication($config)->run();
|
||||
|
||||
// TODO-MS Add Search (Blog + progs + log) jew auch metadata / desc ...
|
@ -15,6 +15,7 @@ class MSController extends CController
|
||||
|
||||
public $title = null;
|
||||
|
||||
public $searchvalue = '';
|
||||
|
||||
public function beforeAction($e){
|
||||
Yii::app()->hitcounter->increment();
|
||||
|
@ -21,7 +21,7 @@ class MSMainController extends MSController
|
||||
{
|
||||
return array(
|
||||
array('allow',
|
||||
'actions'=>array('index', 'about', 'debugerror', 'error', 'login', 'logout'),
|
||||
'actions'=>array('index', 'about', 'debugerror', 'error', 'login', 'logout', 'search'),
|
||||
'users'=>array('*'),
|
||||
),
|
||||
array('allow',
|
||||
@ -149,5 +149,20 @@ class MSMainController extends MSController
|
||||
$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,
|
||||
]);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -126,4 +126,41 @@ class HighscoreGames extends CActiveRecord
|
||||
else
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -113,4 +113,41 @@ class Log extends CActiveRecord
|
||||
public function getLink() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -279,4 +279,47 @@ class Program extends CActiveRecord
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,7 @@
|
||||
'placeholder' => 'Search',
|
||||
'inputOptions' =>
|
||||
[
|
||||
'value' => $this->searchvalue,
|
||||
'append' => MsHtml::submitButton(MsHtml::icon(MsHtml::ICON_SEARCH)),
|
||||
'addOnOptions' =>
|
||||
[
|
||||
|
32
www/protected/views/msmain/searchresults.php
Normal file
32
www/protected/views/msmain/searchresults.php
Normal 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>
|
@ -10,6 +10,3 @@ require_once($yiic);
|
||||
// TODO-MS BefunGen -> MS.de
|
||||
// TODO-MS jClipCorn -> MS.de
|
||||
// TODO-MS jQCCounter (OLD DATE !) -> MS.de
|
||||
|
||||
|
||||
//TODO-MS Add Guest counter
|
Loading…
Reference in New Issue
Block a user