2014-05-28 09:35:46 +02:00
|
|
|
<?php
|
|
|
|
|
2014-06-03 14:24:37 +02:00
|
|
|
/**
|
|
|
|
* Class ProgramHelper
|
|
|
|
*/
|
2014-05-28 11:02:52 +02:00
|
|
|
class ProgramHelper {
|
2014-05-28 09:35:46 +02:00
|
|
|
|
2014-06-03 14:24:37 +02:00
|
|
|
/**
|
|
|
|
* @param bool $doDelimiter
|
|
|
|
* @return Program[]
|
|
|
|
*/
|
2014-05-28 09:35:46 +02:00
|
|
|
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;
|
2014-05-28 11:02:52 +02:00
|
|
|
foreach (Program::model()->findAll($criteria) as $row) {
|
2014-05-28 09:35:46 +02:00
|
|
|
$dropDownModels[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($doDelimiter)
|
|
|
|
{
|
|
|
|
$dropDownModels[] = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$criteria = new CDbCriteria;
|
|
|
|
$criteria->order = "add_date DESC";
|
|
|
|
$criteria->limit = 8;
|
2014-05-28 17:19:57 +02:00
|
|
|
$criteria->condition = "Sterne >= 4 AND visible=1 AND enabled=1";
|
2014-05-28 11:02:52 +02:00
|
|
|
foreach (Program::model()->findAll($criteria) as $row) {
|
2014-06-02 19:31:14 +02:00
|
|
|
$contains = false;
|
|
|
|
foreach($dropDownModels as $modelElem)
|
2014-06-03 14:24:37 +02:00
|
|
|
if ($modelElem != null && $modelElem->ID == $row->ID)
|
2014-06-02 19:31:14 +02:00
|
|
|
$contains = true;
|
|
|
|
if (! $contains)
|
|
|
|
$dropDownModels[] = $row;
|
2014-05-28 09:35:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $dropDownModels;
|
|
|
|
}
|
|
|
|
|
2014-06-03 14:24:37 +02:00
|
|
|
/**
|
2014-06-16 20:36:48 +02:00
|
|
|
* @param DateTime $date
|
2014-06-03 14:24:37 +02:00
|
|
|
* @return Program
|
|
|
|
*/
|
2014-06-16 20:36:48 +02:00
|
|
|
public static function GetRecentProg($date)
|
2014-05-28 09:35:46 +02:00
|
|
|
{
|
|
|
|
$criteria = new CDbCriteria;
|
|
|
|
$criteria->order = "add_date DESC";
|
2014-06-16 20:36:48 +02:00
|
|
|
$criteria->condition = "DATEDIFF('" . $date->format('Y-m-d') . "', add_date) <= 14 AND visible=1 AND enabled=1";
|
2014-05-28 09:35:46 +02:00
|
|
|
$criteria->limit = 1;
|
|
|
|
|
2014-05-28 11:02:52 +02:00
|
|
|
return Program::model()->find($criteria);
|
2014-05-28 09:35:46 +02:00
|
|
|
}
|
|
|
|
|
2014-06-03 14:24:37 +02:00
|
|
|
/**
|
2014-06-16 20:36:48 +02:00
|
|
|
* @param string $date
|
2014-06-03 14:24:37 +02:00
|
|
|
* @return Program
|
|
|
|
*/
|
2014-06-16 20:36:48 +02:00
|
|
|
public static function GetDailyProg($date = 'now')
|
2014-05-28 09:35:46 +02:00
|
|
|
{
|
2014-06-16 20:36:48 +02:00
|
|
|
if ($date == 'now') {
|
|
|
|
$date = new DateTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
$recent = self::GetRecentProg($date);
|
2014-05-28 09:35:46 +02:00
|
|
|
|
|
|
|
if ($recent != null)
|
|
|
|
return $recent;
|
|
|
|
|
|
|
|
$toparray = self::GetHighlightedProgList(false);
|
|
|
|
|
|
|
|
$msrand = new SeededRandom();
|
2014-06-16 20:36:48 +02:00
|
|
|
$msrand->seedWithDailySeed($date);
|
2014-05-28 09:35:46 +02:00
|
|
|
|
|
|
|
$result = $msrand->getRandomElement($toparray);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2014-06-03 14:24:37 +02:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-05-28 09:35:46 +02:00
|
|
|
public static function GetProgDropDownList()
|
|
|
|
{
|
|
|
|
$progDropDown = array();
|
|
|
|
|
|
|
|
$dropDownModels = self::GetHighlightedProgList(true);
|
|
|
|
|
|
|
|
foreach ($dropDownModels as $row) {
|
|
|
|
if (is_null($row))
|
2014-06-06 12:02:56 +02:00
|
|
|
$progDropDown[] = MsHtml::menuDivider();
|
2014-05-28 09:35:46 +02:00
|
|
|
else
|
2014-06-03 14:24:37 +02:00
|
|
|
$progDropDown[] = array('label' => $row->Name, 'url' => $row->getLink());
|
2014-05-28 09:35:46 +02:00
|
|
|
}
|
|
|
|
return $progDropDown;
|
|
|
|
}
|
|
|
|
|
2014-07-05 21:15:24 +02:00
|
|
|
public static function convertDescriptionListToTabs($descriptions, $name) {
|
|
|
|
$tabs = array();
|
|
|
|
|
|
|
|
foreach($descriptions as $desc)
|
|
|
|
{
|
|
|
|
if ($desc['type'] === 0)
|
|
|
|
{
|
|
|
|
$tabs[] =
|
|
|
|
[
|
|
|
|
'label' => $desc['name'],
|
|
|
|
'items' => self::convertDescriptionListToTabs($desc['items'], $name),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
else if (strcasecmp($desc['name'], 'index') == 0) // == 0 : true
|
|
|
|
{
|
|
|
|
$tabs[] =
|
|
|
|
[
|
|
|
|
'label' => $name,
|
|
|
|
'content' => self::getDescriptionMarkdownTab($desc['path']),
|
|
|
|
'active' => true,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$tabs[] =
|
|
|
|
[
|
|
|
|
'label' => $desc['name'],
|
|
|
|
'content' => self::getDescriptionMarkdownTab($desc['path']),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tabs;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getDescriptionMarkdownTab($path)
|
|
|
|
{
|
|
|
|
$content = file_get_contents($path);
|
|
|
|
|
|
|
|
$result = '<div class="markdownOwner"><div><p>';
|
2014-07-10 22:32:47 +02:00
|
|
|
$result .= ParsedownHelper::parse($content);
|
2014-07-05 21:15:24 +02:00
|
|
|
$result .= '</p></div></div>';
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $filename
|
|
|
|
* @param $number
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getIndexedFilename($filename, &$number)
|
|
|
|
{
|
|
|
|
$bn = basename($filename, '.markdown');
|
|
|
|
|
|
|
|
if ($bn[0] >= '0' && $bn[0] <= '9' && $bn[1] >= '0' && $bn[1] <= '9' && $bn[2] == '_')
|
|
|
|
{
|
|
|
|
$name = substr($bn, 3);
|
|
|
|
$number = substr($bn, 0, 2) + 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$name = $bn;
|
|
|
|
$number = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $name;
|
|
|
|
}
|
2014-05-28 09:35:46 +02:00
|
|
|
}
|