From 74436ec57a009ee72391b3553342f0d39128c66f Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Tue, 10 Dec 2013 14:15:21 +0200 Subject: [PATCH] Tyhjien korttipohjien haku tietokannasta --- application/controllers/welcome.php | 2 +- application/models/ecard_model.php | 43 +++++++++++++++++++++++++++++ application/views/new.php | 10 ++++--- tables.sql | 14 ++++++++++ 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/application/controllers/welcome.php b/application/controllers/welcome.php index 94d44bf..916a55b 100644 --- a/application/controllers/welcome.php +++ b/application/controllers/welcome.php @@ -65,7 +65,7 @@ class Welcome extends CI_Controller 'page_title' => array( 'Uusi eKortti', 'Ystäväkylä eKortti' ), 'page_classes' => array( 'new_card' ), 'count' => $this->card_count, - 'images' => fetchBaseCards(), + 'images' => $this->ecard->getCardsTemplates(1), 'user' => $this->user ); diff --git a/application/models/ecard_model.php b/application/models/ecard_model.php index 79f1562..8a4693f 100644 --- a/application/models/ecard_model.php +++ b/application/models/ecard_model.php @@ -183,6 +183,49 @@ class Ecard_model extends MY_Model return true; } + /** + * getCardTemplates fetches templates from database + * + * @param bool $status Card templates based on status + * @param integer $limit How many should we fetch + * @param integer $offset Offset for limit + * + * @return object Cards sorted by database ID + */ + public function getCardsTemplates($status = 1, $limit = 25, $offset = 0) + { + $return = new stdClass(); + + // Get templates from database + $result = $this->db->get_where( + 'templates', + array( + 'card_status' => $status + ), + $limit, + $offset + ) + ->result_object(); + + // Make easier to use, remove non existing + if (!empty($result)) { + foreach ($result as $image) { + + $image->card_path = APPPATH . '../assets/basecards/' . $image->card_filename; + + if (! is_readable($image->card_path)) { + continue; + } + + $image->card_url = site_url('assets/basecards/' . $image->card_filename); + $return->{$image->id} = $image; + } + } + + // Return our defaults, or our counts + return $return; + } + /** * countStatuses * Get numbers for card statuses diff --git a/application/views/new.php b/application/views/new.php index 69ebcbc..965bbec 100644 --- a/application/views/new.php +++ b/application/views/new.php @@ -78,12 +78,14 @@ $image) { - $name = pathinfo($image, PATHINFO_FILENAME); - ?> '>Kuva: