Added proper Description Implementation and Layout for programs
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
31
www/protected/components/widgets/ProgDescription.php
Normal file
31
www/protected/components/widgets/ProgDescription.php
Normal 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,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
16
www/protected/components/widgets/views/progDescription.php
Normal file
16
www/protected/components/widgets/views/progDescription.php
Normal 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>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user