1
0

Added proper Description Implementation and Layout for programs

This commit is contained in:
2014-07-05 21:15:24 +02:00
parent eb5c4fd7e0
commit 427b5b1dc4
13 changed files with 600 additions and 227 deletions

View File

@@ -20,4 +20,20 @@ class MsHelper {
return $val;
}
public static function startsWith($haystack, $needle)
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
public static function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
}

View File

@@ -99,4 +99,74 @@ class ProgramHelper {
return $progDropDown;
}
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)
{
$md = new CMarkdown;
$content = file_get_contents($path);
$result = '<div class="markdownOwner"><div><p>';
$result .= $md->transform($content);
$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;
}
}

View File

@@ -0,0 +1,31 @@
<?php
class ProgDescription extends CWidget {
/**
* @var $program Program
*/
public $program;
public function run() {
$descriptions = $this->program->getDescriptions();
if (count($descriptions) === 1)
{
$this->render('progDescription',
[
'name' => $this->program->Name,
'descriptions' => $descriptions,
]);
}
else
{
$this->render('progDescription_tabbed',
[
'name' => $this->program->Name,
'descriptions' => $descriptions,
]);
}
}
}

View File

@@ -0,0 +1,16 @@
<?php
/* @var $this ProgDescription */
/* @var $name string */
/* @var $descriptions array() */
?>
<div class="well progview_maincol">
<div class="progview_caption" >
<h1 class="text-center"><?php echo $name; ?></h1>
</div>
<?php
echo ProgramHelper::getDescriptionMarkdownTab($descriptions[0]['path']);
?>
</div>

View File

@@ -0,0 +1,20 @@
<?php
/* @var $this ProgDescription */
/* @var $name string */
/* @var $descriptions array() */
?>
<div class="progview_maincol">
<div class="progview_caption" >
<h1 class="text-center"><?php echo $name; ?></h1>
</div>
<?php
$this->widget('bootstrap.widgets.TbTabs',
[
'tabs' => ProgramHelper::convertDescriptionListToTabs($descriptions, $name),
]
);
?>
</div>