1
0

Added Code for DailyProg

This commit is contained in:
2014-05-28 09:35:46 +02:00
parent 5210478251
commit d74a13f661
7 changed files with 286 additions and 121 deletions

View File

@@ -0,0 +1,75 @@
<?php
class ProgrammeHelper {
public static function GetHighlightedProgList($doDelimiter)
{
$dropDownModels = array();
$criteria = new CDbCriteria;
$criteria->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;
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* Created by PhpStorm.
* User: Mike
* Date: 28.05.14
* Time: 09:15
*/
class SeededRandom
{
var $RSeed = 0;
function seed($s = 0)
{
$this->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'];
}
}

View File

@@ -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;

View File

@@ -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()

View File

@@ -1,35 +1,3 @@
<?php // ###### FUNCTIONS ######
function GetProgDropDownList()
{
$progDropDown = array();
$dropDownModels = array();
$criteria = new CDbCriteria;
$criteria->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;
}
?>
<!DOCTYPE html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
@@ -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')],
],
],

View File

@@ -17,7 +17,7 @@ $this->selectedNav = 'index';
<!-- Main hero unit for a primary marketing message or call to action -->
<div class="hero-unit">
<h1>Hello, world!</h1>
Daily Program: <?php echo $program->Name; ?>
<p>
<ul>