From 94c006f371153b5a9e5ad485299c0a7a862ad8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Mon, 2 Jun 2014 19:31:14 +0200 Subject: [PATCH] Added Pagination to Programs/index --- .idea/workspace.xml | 325 +++++++++--------- DB_Changes.txt | 3 +- www/css/styles.css | 5 + www/protected/components/ProgramHelper.php | 7 +- www/protected/components/SeededRandom.php | 2 +- www/protected/components/ThumbnailPreview.php | 1 + .../components/views/thumbnailPreview.php | 22 +- .../controllers/ProgramsController.php | 10 +- www/protected/views/programs/index.php | 53 ++- 9 files changed, 241 insertions(+), 187 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b55b5ba..ebcbb86 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,13 +2,13 @@ - - - - + + + + @@ -66,7 +66,7 @@ - + @@ -75,26 +75,65 @@ - + - - - - - - - - + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -103,7 +142,7 @@ - + @@ -133,7 +172,6 @@ @@ -245,7 +284,6 @@ - @@ -552,6 +590,7 @@ + @@ -690,24 +729,24 @@ - - - - - - - + - + + + + + + + - + @@ -792,13 +831,6 @@ - - - - - - - @@ -811,58 +843,34 @@ - - - - - - - - - - - - + - - - + - - - + - - - + - - - - - - + - - - + @@ -874,118 +882,62 @@ - - - + - - - + - - - - - - - - - - - - - - - - - - - - - + - - - + - - - + - - - + - - - + - - - - - - - - - - + - - - - - - - - - - + - - - + - - - + - - - + @@ -997,23 +949,17 @@ - - - + - - - + - - - + @@ -1025,7 +971,12 @@ - + + + + + + @@ -1039,47 +990,89 @@ + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - + + + + + + + + + + + - + - - - - - - - - + - + + + + + + + + + + + + + + + diff --git a/DB_Changes.txt b/DB_Changes.txt index eed96ac..27d3cc5 100644 --- a/DB_Changes.txt +++ b/DB_Changes.txt @@ -1,4 +1,5 @@ othervalues -> Added Column SValue othervalues -> Added Key "AdminPassword" programme -> Added Column ThumbnailName -programme -> Changed Sieb_des_Erasthothenes -> Sieb des Erasthothenes (also ren Imagefiles) \ No newline at end of file +programme -> Changed Sieb_des_Erasthothenes -> Sieb des Erasthothenes (also ren Imagefiles) +programme -> Adjusted Star Ratings \ No newline at end of file diff --git a/www/css/styles.css b/www/css/styles.css index 001e1e6..169b57d 100644 --- a/www/css/styles.css +++ b/www/css/styles.css @@ -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 */ } \ No newline at end of file diff --git a/www/protected/components/ProgramHelper.php b/www/protected/components/ProgramHelper.php index 4f8553c..58bc30e 100644 --- a/www/protected/components/ProgramHelper.php +++ b/www/protected/components/ProgramHelper.php @@ -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; diff --git a/www/protected/components/SeededRandom.php b/www/protected/components/SeededRandom.php index c674430..3c9c322 100644 --- a/www/protected/components/SeededRandom.php +++ b/www/protected/components/SeededRandom.php @@ -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) diff --git a/www/protected/components/ThumbnailPreview.php b/www/protected/components/ThumbnailPreview.php index 4ccc7ea..ba0f488 100644 --- a/www/protected/components/ThumbnailPreview.php +++ b/www/protected/components/ThumbnailPreview.php @@ -3,6 +3,7 @@ class ThumbnailPreview extends CWidget { public $caption = ''; public $link = ''; + public $enabled = true; public $description = ''; public $category = ''; public $language = []; diff --git a/www/protected/components/views/thumbnailPreview.php b/www/protected/components/views/thumbnailPreview.php index b4fca28..394a8ff 100644 --- a/www/protected/components/views/thumbnailPreview.php +++ b/www/protected/components/views/thumbnailPreview.php @@ -4,21 +4,29 @@
  • -
    +
    ">
    + caption) > 13) ? ["

    ", "

    "] : ["

    ", "

    "]; ?> + + + caption) > 13) - echo '

    ' . $this->caption . '

    '; - else - echo '

    ' . $this->caption . '

    '; + if ($this->enabled) + echo '' . $this->caption . ''; + else + echo '' . $this->caption . ''; ?> -

    description; ?>

    + + +

    + description; ?> +

    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); } /** diff --git a/www/protected/views/programs/index.php b/www/protected/views/programs/index.php index 04f5f2e..9608876 100644 --- a/www/protected/views/programs/index.php +++ b/www/protected/views/programs/index.php @@ -4,14 +4,21 @@ ?> 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; + +?> + +breadcrumbs = array( + 'Programs', + ); + + $this->menu = array( + array('label' => 'Create Program', 'url' => array('create')), + array('label' => 'Manage Program', 'url' => array('admin')), + ); ?>

    @@ -22,17 +29,23 @@ $this->menu = array(
    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 '
      '; - 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( ?>
    + + 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', + ]); + } + ?> +