diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5b11ed1..6695e42 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,13 +2,13 @@ - - - - - - + + + + + + @@ -66,7 +66,7 @@ - + @@ -75,23 +75,72 @@ - + - + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -104,16 +153,7 @@ - - - - - - - - - - + @@ -134,9 +174,7 @@ @@ -234,6 +277,7 @@ + @@ -406,6 +450,28 @@ + + + + + + + + + + + + - - + @@ -577,7 +642,7 @@ - + @@ -585,12 +650,12 @@ - + - + @@ -615,23 +680,6 @@ - - - - - - - - - - - - - - - - - @@ -762,11 +810,6 @@ - - - - - @@ -787,11 +830,6 @@ - - - - - @@ -824,13 +862,6 @@ - - - - - - - @@ -840,42 +871,31 @@ - - - + - + + + + + + - + - - - - - - - - - - - - - - - + - + @@ -889,13 +909,66 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/www/protected/components/ProgrammeHelper.php b/www/protected/components/ProgrammeHelper.php new file mode 100644 index 0000000..8e6cd4f --- /dev/null +++ b/www/protected/components/ProgrammeHelper.php @@ -0,0 +1,75 @@ +order = "add_date DESC"; + $criteria->condition = "visible=1 AND enabled=1"; + $criteria->limit = 3; + foreach (Programme::model()->findAll($criteria) as $row) { + $dropDownModels[] = $row; + } + + if ($doDelimiter) + { + $dropDownModels[] = null; + } + + $criteria = new CDbCriteria; + $criteria->order = "add_date DESC"; + $criteria->limit = 8; + $criteria->condition = "Sterne=4 AND visible=1 AND enabled=1"; + foreach (Programme::model()->findAll($criteria) as $row) { + $dropDownModels[] = $row; + } + + return $dropDownModels; + } + + public static function GetRecentProg() + { + $criteria = new CDbCriteria; + $criteria->order = "add_date DESC"; + $criteria->condition = "DATEDIFF(CURDATE(), add_date) <= 14 AND visible=1 AND enabled=1"; + $criteria->limit = 1; + + return Programme::model()->find($criteria); + } + + public static function GetDailyProg() + { + $recent = self::GetRecentProg(); + + if ($recent != null) + return $recent; + + $toparray = self::GetHighlightedProgList(false); + + $msrand = new SeededRandom(); + $msrand->seedWithDailySeed(); + + $result = $msrand->getRandomElement($toparray); + + return $result; + } + + public static function GetProgDropDownList() + { + $progDropDown = array(); + + $dropDownModels = self::GetHighlightedProgList(true); + + foreach ($dropDownModels as $row) { + if (is_null($row)) + $progDropDown[] = TbHtml::menuDivider(); + else + $progDropDown[] = array('label' => $row->attributes['Name'], 'url' => '/programme/' . $row->attributes['Name']); + } + return $progDropDown; + } + +} \ No newline at end of file diff --git a/www/protected/components/SeededRandom.php b/www/protected/components/SeededRandom.php new file mode 100644 index 0000000..c674430 --- /dev/null +++ b/www/protected/components/SeededRandom.php @@ -0,0 +1,45 @@ +RSeed = abs(intval($s)) % 9999999 + 1; + $this->get(); + } + + function seedWithDailySeed() + { + $this->seed($this->getDailySeed()); + } + + function get($min = 0, $max = 9999999) + { + if ($this->RSeed == 0) + $this->seed(mt_rand()); + + $this->RSeed = ($this->RSeed * 125) % 2796203; + + return $this->RSeed % ($max - $min + 1) + $min; + } + + function getRandomElement(array $arr) + { + return $arr[$this->get(0, count($arr))]; + } + + function getDailySeed() + { + $now = getdate(); + + return ($now['year'] % 100) * 366 + $now['yday']; + } +} \ No newline at end of file diff --git a/www/protected/components/UserIdentity.php b/www/protected/components/UserIdentity.php index 07c387f..3362eaa 100644 --- a/www/protected/components/UserIdentity.php +++ b/www/protected/components/UserIdentity.php @@ -20,7 +20,7 @@ class UserIdentity extends CUserIdentity $users=array( // username => password 'demo'=>'demo', - 'admin'=>'admin', + 'admin'=>'admin', //TODO Change me ); if(!isset($users[$this->username])) $this->errorCode=self::ERROR_USERNAME_INVALID; diff --git a/www/protected/controllers/SiteController.php b/www/protected/controllers/SiteController.php index 645505b..32e9be5 100644 --- a/www/protected/controllers/SiteController.php +++ b/www/protected/controllers/SiteController.php @@ -6,7 +6,11 @@ class SiteController extends Controller public function actionIndex() { - $this->render('index'); + $data = array(); + + $data['program'] = ProgrammeHelper::GetDailyProg(); + + $this->render('index', $data); } public function actionError() diff --git a/www/protected/views/layouts/main.php b/www/protected/views/layouts/main.php index fdecfe3..c9b40fd 100644 --- a/www/protected/views/layouts/main.php +++ b/www/protected/views/layouts/main.php @@ -1,35 +1,3 @@ -order = "add_date DESC"; - $criteria->limit = 3; - foreach (Programme::model()->findAll($criteria) as $row) { - $dropDownModels[] = $row; - } - $dropDownModels[] = null; - - $criteria = new CDbCriteria; - $criteria->order = "add_date DESC"; - $criteria->limit = 8; - $criteria->condition = "Sterne=4 AND visible=1"; - foreach (Programme::model()->findAll($criteria) as $row) { - $dropDownModels[] = $row; - } - - foreach ($dropDownModels as $row) { - if (is_null($row)) - $progDropDown[] = TbHtml::menuDivider(); - else - $progDropDown[] = array('label' => $row->attributes['Name'], 'url' => '/programme/' . $row->attributes['Name']); - } - return $progDropDown; -} -?> - @@ -77,7 +45,7 @@ function GetProgDropDownList() ['label' => 'Home', 'url' => '/', 'active' => ($this->selectedNav === 'index')], ['label' => 'Blog', 'url' => '#', 'active' => ($this->selectedNav === 'blog')], ['label' => 'Programme', 'url' => '/programme/', 'active' => ($this->selectedNav === 'prog')], - ['label' => '', 'items' => GetProgDropDownList(), 'htmlOptions' => ['class' => 'dropdown-append']], + ['label' => '', 'items' => ProgrammeHelper::GetProgDropDownList(), 'htmlOptions' => ['class' => 'dropdown-append']], ['label' => 'About', 'url' => '/about', 'active' => ($this->selectedNav === 'about')], ], ], diff --git a/www/protected/views/site/index.php b/www/protected/views/site/index.php index b30692c..6171de2 100644 --- a/www/protected/views/site/index.php +++ b/www/protected/views/site/index.php @@ -17,7 +17,7 @@ $this->selectedNav = 'index';

Hello, world!

- + Daily Program: Name; ?>