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

@@ -2,7 +2,7 @@
-------------------------------------------------- */
.footer {
padding: 70px 0;
padding: 45px 0;
margin-top: 70px;
border-top: 1px solid #e5e5e5;
background-color: #f5f5f5;

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'] */;
}
}

View File

@@ -7,9 +7,9 @@
$this->pageTitle = 'Manage - ' . Yii::app()->name;
$this->breadcrumbs =
[
'Admin',
];
[
'Admin',
];
?>
<div class="container">
@@ -22,9 +22,9 @@ $this->breadcrumbs =
echo MsHtml::stackedTabs(
[
['label' => 'Show', 'url' => '/log'],
['label' => 'Manage', 'url' => '/log/admin'],
['label' => 'Create', 'url' => '/log/create'],
['label' => 'Show', 'url' => '/log'],
['label' => 'Manage', 'url' => '/log/admin'],
['label' => 'Create', 'url' => '/log/create'],
]
); ?>
</div>
@@ -35,9 +35,9 @@ $this->breadcrumbs =
echo MsHtml::stackedTabs(
[
['label' => 'Show', 'url' => '/programs'],
['label' => 'Manage', 'url' => '/programs/admin'],
['label' => 'Create', 'url' => '/programs/create'],
['label' => 'Show', 'url' => '/programs'],
['label' => 'Manage', 'url' => '/programs/admin'],
['label' => 'Create', 'url' => '/programs/create'],
]
); ?>
</div>
@@ -48,8 +48,8 @@ $this->breadcrumbs =
echo MsHtml::stackedTabs(
[
['label' => 'Show', 'url' => '/programupdates'],
['label' => 'Manage', 'url' => '/programupdates/admin'],
['label' => 'Show', 'url' => '/programupdates'],
['label' => 'Manage', 'url' => '/programupdates/admin'],
['label' => 'Create', 'url' => '/programupdates/create'],
]
); ?>
@@ -61,8 +61,8 @@ $this->breadcrumbs =
echo MsHtml::stackedTabs(
[
['label' => 'Home', 'url' => '#'],
['label' => 'Profile', 'url' => '#'],
['label' => 'Home', 'url' => '#'],
['label' => 'Profile', 'url' => '#'],
['label' => 'Messages', 'url' => '#'],
]
); ?>
@@ -71,7 +71,7 @@ $this->breadcrumbs =
<div class="well well-small">
<?php
$egh = $egh = (new ExtendedGitGraph('Mikescher'))->loadFinishedData();
$egh = $egh = (new ExtendedGitGraph('Mikescher'))->loadFinishedData();
?>
<h2>ExtendedGitGraph</h2>
@@ -86,4 +86,41 @@ $this->breadcrumbs =
<a class="btn btn-primary" href="?do_egh_update=1"> Update </a>
</div>
<div class="well well-small">
<h2>Program of the day</h2>
<hr>
<?php
$data = array();
$now = new DateTime();
for ($i = 0; $i < 100; $i++) {
$data[] =
[
'Date' => $now->format('d.m.Y :: D'),
'Name' => ProgramHelper::GetDailyProg($now)->Name,
];
$now->modify('+1 day');
}
$this->widget('bootstrap.widgets.TbGridView',
[
'type' => TbHtml::GRID_TYPE_CONDENSED,
'dataProvider' => new CArrayDataProvider($data,
[
'keyField' => 'Date',
'Pagination' =>
[
'PageSize' => 14,
]
]),
]
); ?>
</div>
</div>