Added Pagination to Programs/index
This commit is contained in:
@@ -103,4 +103,9 @@ ul.nav li.dropdown-append:hover > ul.dropdown-menu {
|
||||
|
||||
.thumbnailInnerDescription {
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
.thumbnailDisabled {
|
||||
opacity: 0.4;
|
||||
/*filter: alpha(opacity=40); *//* msie */
|
||||
}
|
||||
@@ -24,7 +24,12 @@ class ProgramHelper {
|
||||
$criteria->limit = 8;
|
||||
$criteria->condition = "Sterne >= 4 AND visible=1 AND enabled=1";
|
||||
foreach (Program::model()->findAll($criteria) as $row) {
|
||||
$dropDownModels[] = $row;
|
||||
$contains = false;
|
||||
foreach($dropDownModels as $modelElem)
|
||||
if ($modelElem != null && $modelElem->attributes['ID'] == $row->attributes['ID'])
|
||||
$contains = true;
|
||||
if (! $contains)
|
||||
$dropDownModels[] = $row;
|
||||
}
|
||||
|
||||
return $dropDownModels;
|
||||
|
||||
@@ -28,7 +28,7 @@ class SeededRandom
|
||||
|
||||
$this->RSeed = ($this->RSeed * 125) % 2796203;
|
||||
|
||||
return $this->RSeed % ($max - $min + 1) + $min;
|
||||
return $this->RSeed % ($max - $min) + $min;
|
||||
}
|
||||
|
||||
function getRandomElement(array $arr)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
class ThumbnailPreview extends CWidget {
|
||||
public $caption = '';
|
||||
public $link = '';
|
||||
public $enabled = true;
|
||||
public $description = '';
|
||||
public $category = '';
|
||||
public $language = [];
|
||||
|
||||
@@ -4,21 +4,29 @@
|
||||
|
||||
<li class="span3 thumbnailParentSpan">
|
||||
<div >
|
||||
<div class="thumbnail">
|
||||
<div class="thumbnail <?php if (! $this->enabled) print("thumbnailDisabled"); ?>">
|
||||
<div class="thumbnailInnerHead">
|
||||
<a href="<?php echo $this->link; ?>">
|
||||
<a <?php if($this->enabled) echo 'href="'. $this->link . '"'; ?>>
|
||||
<img style="width: 100%" src="<?php echo $this->image; ?>">
|
||||
</a>
|
||||
</div>
|
||||
<div class="caption">
|
||||
<?php $h_level = (strlen($this->caption) > 13) ? ["<h3>", "</h3>"] : ["<h2>", "</h2>"]; ?>
|
||||
|
||||
<?php echo $h_level[0]; ?>
|
||||
|
||||
<?php
|
||||
if ( strlen($this->caption) > 13)
|
||||
echo '<h3><a class="progThumbnailCaption" href="' . $this->link . '">' . $this->caption . '</a></h3>';
|
||||
else
|
||||
echo '<h2><a class="progThumbnailCaption" href="' . $this->link . '">' . $this->caption . '</a></h2>';
|
||||
if ($this->enabled)
|
||||
echo '<a class="progThumbnailCaption" href="' . $this->link . '">' . $this->caption . '</a>';
|
||||
else
|
||||
echo '<a class="progThumbnailCaption">' . $this->caption . '</a>';
|
||||
?>
|
||||
|
||||
<p class="thumbnailInnerDescription"><?php echo $this->description; ?></p>
|
||||
<?php echo $h_level[1]; ?>
|
||||
|
||||
<p class="thumbnailInnerDescription">
|
||||
<?php echo $this->description; ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?php
|
||||
|
||||
@@ -141,7 +141,15 @@ class ProgramsController extends Controller
|
||||
{
|
||||
$this->layout = '//layouts/main';
|
||||
|
||||
$this->render('index');
|
||||
$data = array();
|
||||
|
||||
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
|
||||
$data['page'] = $_GET['page'];
|
||||
} else {
|
||||
$data['page'] = 1;
|
||||
}
|
||||
|
||||
$this->render('index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,14 +4,21 @@
|
||||
?>
|
||||
|
||||
<?php
|
||||
$this->breadcrumbs = array(
|
||||
'Programs',
|
||||
);
|
||||
|
||||
$this->menu = array(
|
||||
array('label' => 'Create Program', 'url' => array('create')),
|
||||
array('label' => 'Manage Program', 'url' => array('admin')),
|
||||
);
|
||||
const PROGS_INDEX_ROWSIZE = 4;
|
||||
const PROGS_INDEX_PAGESIZE = 16;
|
||||
|
||||
?>
|
||||
|
||||
<?php
|
||||
$this->breadcrumbs = array(
|
||||
'Programs',
|
||||
);
|
||||
|
||||
$this->menu = array(
|
||||
array('label' => 'Create Program', 'url' => array('create')),
|
||||
array('label' => 'Manage Program', 'url' => array('admin')),
|
||||
);
|
||||
?>
|
||||
|
||||
<div class="container">
|
||||
@@ -22,17 +29,23 @@ $this->menu = array(
|
||||
<div class="row-fluid">
|
||||
|
||||
<?php
|
||||
|
||||
$criteria = new CDbCriteria;
|
||||
$criteria->order = "add_date DESC";
|
||||
$criteria->condition = "visible=1";
|
||||
|
||||
$all = Program::model()->findAll($criteria);
|
||||
$rows = ceil((count($all) / 4));
|
||||
|
||||
for ($i = 0; $i < $rows; $i++) {
|
||||
$pagecount = ceil(count($all) / PROGS_INDEX_PAGESIZE);
|
||||
|
||||
$all = array_slice($all, ($page - 1) * PROGS_INDEX_PAGESIZE, PROGS_INDEX_PAGESIZE);
|
||||
|
||||
$rowcount = ceil((count($all) / PROGS_INDEX_ROWSIZE));
|
||||
|
||||
for ($i = 0; $i < $rowcount; $i++) {
|
||||
echo '<ul class="thumbnails">';
|
||||
|
||||
foreach (array_slice($all, $i * 4, 4) as $record) {
|
||||
foreach (array_slice($all, $i * PROGS_INDEX_ROWSIZE, PROGS_INDEX_ROWSIZE) as $record) {
|
||||
$this->widget('ThumbnailPreview',
|
||||
[
|
||||
'caption' => $record->attributes['Thumbnailname'],
|
||||
@@ -44,6 +57,7 @@ $this->menu = array(
|
||||
'starcount' => $record->attributes['Sterne'],
|
||||
'downloads' => $record->attributes['Downloads'],
|
||||
'date' => new DateTime($record->attributes['add_date']),
|
||||
'enabled' => $record->attributes['enabled'],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -52,5 +66,24 @@ $this->menu = array(
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
if ($pagecount > 1) {
|
||||
$pagination_arr = array();
|
||||
|
||||
$pagination_arr[] = ['label' => '«', 'url' => '?page=' . ($page-1), 'disabled' => ($page <= 1)];
|
||||
for($i = 1; $i <= $pagecount; $i++) {
|
||||
$pagination_arr[] = ['label' => $i, 'url' => '?page=' . $i, 'active' => ($i == $page)];
|
||||
}
|
||||
$pagination_arr[] = ['label' => '»', 'url' => '?page=' . ($page+1), 'disabled' => ($page >= $pagecount)];
|
||||
|
||||
echo TbHtml::pagination($pagination_arr,
|
||||
[
|
||||
'align' => 'right',
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user