1
0

Better MVC in programs/index (logic -> controller)

This commit is contained in:
Mike Schwörer 2014-06-06 09:47:15 +02:00
parent 610cd7c0a4
commit d478647418
3 changed files with 53 additions and 44 deletions

View File

@ -2,6 +2,8 @@
class ProgramsController extends MSController class ProgramsController extends MSController
{ {
const PROGS_INDEX_ROWSIZE = 4;
const PROGS_INDEX_PAGESIZE = 16;
public $layout='//layouts/column2'; public $layout='//layouts/column2';
@ -141,14 +143,41 @@ class ProgramsController extends MSController
{ {
$this->layout = '//layouts/main'; $this->layout = '//layouts/main';
$data = array();
if (isset($_GET['page']) && is_numeric($_GET['page'])) { if (isset($_GET['page']) && is_numeric($_GET['page'])) {
$data['page'] = $_GET['page']; $page = $_GET['page'];
} else { } else {
$data['page'] = 1; $page = 1;
} }
$criteria = new CDbCriteria;
$criteria->order = "Sterne DESC, add_date DESC";
$criteria->condition = "visible=1";
$all = Program::model()->findAll($criteria);
/* @var $all Program[] */
$pagecount = ceil(count($all) / self::PROGS_INDEX_PAGESIZE);
$all = array_slice($all, ($page - 1) * self::PROGS_INDEX_PAGESIZE, self::PROGS_INDEX_PAGESIZE);
$rowcount = ceil((count($all) / self::PROGS_INDEX_ROWSIZE));
$progdata = array();
for ($i = 0; $i < $rowcount; $i++) {
$progdata[] = array();
foreach (array_slice($all, $i * self::PROGS_INDEX_ROWSIZE, self::PROGS_INDEX_ROWSIZE) as $record) {
$progdata[$i][] = $record;
}
}
//#######
$data = array();
$data['page'] = $page;
$data['pagecount'] = $pagecount;
$data['rowcount'] = $rowcount;
$data['data'] = $progdata;
$this->render('index', $data); $this->render('index', $data);
} }

View File

@ -1,13 +1,9 @@
<?php <?php
/* @var $this ProgramController */ /* @var $this ProgramsController */
/* @var $dataProvider CActiveDataProvider */ /* @var $page integer */
?> /* @var $pagecount integer */
/* @var $rowcount integer */
<?php /* @var $data Program[][] */
const PROGS_INDEX_ROWSIZE = 4;
const PROGS_INDEX_PAGESIZE = 16;
?> ?>
<?php <?php
@ -27,47 +23,31 @@
<br><br> <br><br>
<div class="row-fluid"> <div class="row-fluid">
<?php <?php
$criteria = new CDbCriteria; foreach($data as $datarow) {
$criteria->order = "Sterne DESC, add_date DESC";
$criteria->condition = "visible=1";
$all = Program::model()->findAll($criteria);
$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">'; echo '<ul class="thumbnails">';
foreach (array_slice($all, $i * PROGS_INDEX_ROWSIZE, PROGS_INDEX_ROWSIZE) as $record) { foreach($datarow as $dataelem) {
/* @var $record Program */
$this->widget('ThumbnailProgPreview', $this->widget('ThumbnailProgPreview',
[ [
'caption' => $record->Thumbnailname, 'caption' => $dataelem->Thumbnailname,
'link' => $record->getLink(), 'link' => $dataelem->getLink(),
'description' => $record->Description, 'description' => $dataelem->Description,
'category' => $record->Kategorie, 'category' => $dataelem->Kategorie,
'language' => $record->getLanguageList(), 'language' => $dataelem->getLanguageList(),
'image' => $record->getImagePath(), 'image' => $dataelem->getImagePath(),
'starcount' => $record->Sterne, 'starcount' => $dataelem->Sterne,
'downloads' => $record->Downloads, 'downloads' => $dataelem->Downloads,
'date' => new DateTime($record->add_date), 'date' => new DateTime($dataelem->add_date),
'enabled' => $record->enabled, 'enabled' => $dataelem->enabled,
'programminglang' => $record->programming_lang, 'programminglang' => $dataelem->programming_lang,
]); ]);
} }
echo '</ul>'; echo '</ul>';
} }
?>
?>
</div> </div>
<?php <?php

View File

@ -1,5 +1,5 @@
<?php <?php
/* @var $this ProgramController */ /* @var $this ProgramsController */
/* @var $model Program */ /* @var $model Program */
?> ?>