diff --git a/www/css/styles.css b/www/css/styles.css index 47dcd20..23548ca 100644 --- a/www/css/styles.css +++ b/www/css/styles.css @@ -673,4 +673,38 @@ ul.nav li.dropdown-append:hover > ul.dropdown-menu { .blogFooterRight { float: right; -} \ No newline at end of file +} + +/* 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; +} + diff --git a/www/images/search/sresult_blog.png b/www/images/search/sresult_blog.png new file mode 100644 index 0000000..2aceb23 Binary files /dev/null and b/www/images/search/sresult_blog.png differ diff --git a/www/images/search/sresult_highscores.png b/www/images/search/sresult_highscores.png new file mode 100644 index 0000000..c5bb291 Binary files /dev/null and b/www/images/search/sresult_highscores.png differ diff --git a/www/images/search/sresult_log.png b/www/images/search/sresult_log.png new file mode 100644 index 0000000..f32e9d7 Binary files /dev/null and b/www/images/search/sresult_log.png differ diff --git a/www/index.php b/www/index.php index 500ee99..fc9fc7f 100644 --- a/www/index.php +++ b/www/index.php @@ -10,6 +10,4 @@ defined('YII_DEBUG') or define('YII_DEBUG',true); 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 ... \ No newline at end of file +Yii::createWebApplication($config)->run(); \ No newline at end of file diff --git a/www/protected/components/MSController.php b/www/protected/components/MSController.php index b3ffe01..9fd723e 100644 --- a/www/protected/components/MSController.php +++ b/www/protected/components/MSController.php @@ -15,6 +15,7 @@ class MSController extends CController public $title = null; + public $searchvalue = ''; public function beforeAction($e){ Yii::app()->hitcounter->increment(); diff --git a/www/protected/controllers/MsmainController.php b/www/protected/controllers/MsmainController.php index fa22025..8215d51 100644 --- a/www/protected/controllers/MsmainController.php +++ b/www/protected/controllers/MsmainController.php @@ -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, + ]); + } } \ No newline at end of file diff --git a/www/protected/models/BlogPost.php b/www/protected/models/BlogPost.php index b1d6753..349b01a 100644 --- a/www/protected/models/BlogPost.php +++ b/www/protected/models/BlogPost.php @@ -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; + } } diff --git a/www/protected/models/HighscoreGames.php b/www/protected/models/HighscoreGames.php index ff8bf9d..3255a16 100644 --- a/www/protected/models/HighscoreGames.php +++ b/www/protected/models/HighscoreGames.php @@ -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; + } } diff --git a/www/protected/models/Log.php b/www/protected/models/Log.php index e0559d9..81649a3 100644 --- a/www/protected/models/Log.php +++ b/www/protected/models/Log.php @@ -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; + } } diff --git a/www/protected/models/Program.php b/www/protected/models/Program.php index 65558c6..f63a8ab 100644 --- a/www/protected/models/Program.php +++ b/www/protected/models/Program.php @@ -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; + } } diff --git a/www/protected/views/layouts/main.php b/www/protected/views/layouts/main.php index cd8d128..74821e4 100644 --- a/www/protected/views/layouts/main.php +++ b/www/protected/views/layouts/main.php @@ -64,6 +64,7 @@ 'placeholder' => 'Search', 'inputOptions' => [ + 'value' => $this->searchvalue, 'append' => MsHtml::submitButton(MsHtml::icon(MsHtml::ICON_SEARCH)), 'addOnOptions' => [ diff --git a/www/protected/views/msmain/searchresults.php b/www/protected/views/msmain/searchresults.php new file mode 100644 index 0000000..9a14fe1 --- /dev/null +++ b/www/protected/views/msmain/searchresults.php @@ -0,0 +1,32 @@ +pageTitle = 'Search - ' . $searchstring; +$this->searchvalue = $searchstring; + +$this->breadcrumbs= + [ + 'Search' + ]; + +?> + +
+
+ results found for "" + + +
+ + + +

+ +

+ +
+ +
+
\ No newline at end of file diff --git a/www/protected/yiic.php b/www/protected/yiic.php index d6aea25..8dfd10a 100644 --- a/www/protected/yiic.php +++ b/www/protected/yiic.php @@ -9,7 +9,4 @@ require_once($yiic); // TODO-MS SharkSim (OLD DATE !) -> MS.de // TODO-MS BefunGen -> MS.de // TODO-MS jClipCorn -> MS.de -// TODO-MS jQCCounter (OLD DATE !) -> MS.de - - -//TODO-MS Add Guest counter \ No newline at end of file +// TODO-MS jQCCounter (OLD DATE !) -> MS.de \ No newline at end of file