1
0

Added ProgOfTheDay to AdminArea (+Bugfix)

This commit is contained in:
2014-06-16 20:36:48 +02:00
parent e7c7881afb
commit 2ebe660272
5 changed files with 245 additions and 214 deletions

View File

@@ -43,24 +43,30 @@ class ProgramHelper {
}
/**
* @param DateTime $date
* @return Program
*/
public static function GetRecentProg()
public static function GetRecentProg($date)
{
$criteria = new CDbCriteria;
$criteria->order = "add_date DESC";
$criteria->condition = "DATEDIFF(CURDATE(), add_date) <= 14 AND visible=1 AND enabled=1";
$criteria->condition = "DATEDIFF('" . $date->format('Y-m-d') . "', add_date) <= 14 AND visible=1 AND enabled=1";
$criteria->limit = 1;
return Program::model()->find($criteria);
}
/**
* @param string $date
* @return Program
*/
public static function GetDailyProg()
public static function GetDailyProg($date = 'now')
{
$recent = self::GetRecentProg();
if ($date == 'now') {
$date = new DateTime();
}
$recent = self::GetRecentProg($date);
if ($recent != null)
return $recent;
@@ -68,7 +74,7 @@ class ProgramHelper {
$toparray = self::GetHighlightedProgList(false);
$msrand = new SeededRandom();
$msrand->seedWithDailySeed();
$msrand->seedWithDailySeed($date);
$result = $msrand->getRandomElement($toparray);

View File

@@ -16,9 +16,13 @@ class SeededRandom
$this->get();
}
function seedWithDailySeed()
function seedWithDailySeed($date)
{
$this->seed($this->getDailySeed());
$this->seed(($date->format('Y') % 100) * 10459);
$max = $date->format('z');
for ($i = 0; $i < $max; $i++) {
$this->get();
}
}
function get($min = 0, $max = 9999999)
@@ -35,11 +39,4 @@ class SeededRandom
{
return $arr[$this->get(0, count($arr))];
}
function getDailySeed()
{
$now = getdate();
return ($now['year'] % 100) * 366 + $now['yday'] /* * $now['seconds'] */;
}
}